forked from circlecloud/tera
feat: alpine 0.0.1 version complate
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
@@ -14,6 +14,7 @@ import net = require("net");
|
||||
import * as crypto from 'crypto';
|
||||
import "./library"
|
||||
import "./crypto-library"
|
||||
import CConnect from './connect'
|
||||
const HARD_PACKET_PERIOD = 20;
|
||||
global.BUF_TYPE = 1;
|
||||
global.STR_TYPE = 2;
|
||||
@@ -57,12 +58,9 @@ const FORMAT_PACKET_SEND_TCP = "{\
|
||||
Hash:hash,\
|
||||
Data:data,\
|
||||
}";
|
||||
export default class CTransport extends require("./connect")
|
||||
{
|
||||
export default class CTransport extends CConnect {
|
||||
UseRNDHeader
|
||||
BAN_IP
|
||||
ip
|
||||
port
|
||||
CanSend
|
||||
SendFormatMap
|
||||
ActualNodes
|
||||
@@ -233,7 +231,7 @@ export default class CTransport extends require("./connect")
|
||||
this.SendTrafficFree -= Node.SendTrafficLimit
|
||||
}
|
||||
Node.SendTrafficCurrent = 0
|
||||
global.ADD_TO_STAT("MAX:NODE_TRAFFIC_LIMIT:" + NodeName(Node), 1000 / global.STAT_PERIOD * Node.SendTrafficLimit / 1024, 1)
|
||||
global.ADD_TO_STAT("MAX:NODE_TRAFFIC_LIMIT:" + global.NodeName(Node), 1000 / global.STAT_PERIOD * Node.SendTrafficLimit / 1024, 1)
|
||||
}
|
||||
this.SendTrafficFree += TRAFIC_LIMIT_NODE
|
||||
global.ADD_TO_STAT("SEND_TRAFFIC_FREE", this.SendTrafficFree / 1024)
|
||||
@@ -243,7 +241,7 @@ export default class CTransport extends require("./connect")
|
||||
var Str = "";
|
||||
if (Info.Data && Info.Data.Length)
|
||||
Str = " LENGTH=" + Info.Data.Length
|
||||
global.TO_DEBUG_LOG("GET:" + Info.Method + Str + " from: Node=" + NodeInfo(Info.Node))
|
||||
global.TO_DEBUG_LOG("GET:" + Info.Method + Str + " from: Node=" + global.NodeInfo(Info.Node))
|
||||
}
|
||||
if (global.ADDRLIST_MODE) {
|
||||
var StrOK = ",HAND,GETNODES,";
|
||||
@@ -269,7 +267,7 @@ export default class CTransport extends require("./connect")
|
||||
var Arr = [];
|
||||
var it = this.ActualNodes.iterator(), Item;
|
||||
while ((Item = it.next()) !== null) {
|
||||
if (GetSocketStatus(Item.Socket) >= 100)
|
||||
if (global.GetSocketStatus(Item.Socket) >= 100)
|
||||
Arr.push(Item)
|
||||
else {
|
||||
this.DeleteNodeFromActive(Item)
|
||||
@@ -467,7 +465,7 @@ export default class CTransport extends require("./connect")
|
||||
return 0;
|
||||
var startTime = process.hrtime();
|
||||
global.ADD_TO_STAT("GETDATA(KB)", buf.length / 1024)
|
||||
global.ADD_TO_STAT("GETDATA(KB):" + NodeName(Node), buf.length / 1024, 1)
|
||||
global.ADD_TO_STAT("GETDATA(KB):" + global.NodeName(Node), buf.length / 1024, 1)
|
||||
if (!Node.TransferSize)
|
||||
Node.TransferSize = 0
|
||||
Node.TransferSize += buf.length / 1024
|
||||
@@ -480,7 +478,7 @@ export default class CTransport extends require("./connect")
|
||||
}
|
||||
global.ADD_TO_STAT("GET:" + Buf.Method)
|
||||
global.ADD_TO_STAT("GET:(KB)" + Buf.Method, buf.length / 1024)
|
||||
global.ADD_TO_STAT("GET:" + Buf.Method + ":" + NodeName(Node), 1, 1)
|
||||
global.ADD_TO_STAT("GET:" + Buf.Method + ":" + global.NodeName(Node), 1, 1)
|
||||
var Param = this.MethodTiming[Buf.Method];
|
||||
if (this.StopDoSendPacket(Param, Node, Buf.Method)) {
|
||||
return 1;
|
||||
@@ -679,8 +677,8 @@ export default class CTransport extends require("./connect")
|
||||
Info = Node.SendPacket.min()
|
||||
if (!Info)
|
||||
return 0;
|
||||
global.ADD_TO_STAT("MAX:NODE_BUF_WRITE:" + NodeName(Node), Node.BufWrite.length / 1024, 1)
|
||||
global.ADD_TO_STAT("MAX:NODE_SEND_BUF_PACKET_COUNT:" + NodeName(Node), Node.SendPacket.size, 1)
|
||||
global.ADD_TO_STAT("MAX:NODE_BUF_WRITE:" + global.NodeName(Node), Node.BufWrite.length / 1024, 1)
|
||||
global.ADD_TO_STAT("MAX:NODE_SEND_BUF_PACKET_COUNT:" + global.NodeName(Node), Node.SendPacket.size, 1)
|
||||
if (Node.BufWrite.length > 2 * TRAFIC_LIMIT_1S) {
|
||||
return 2;
|
||||
}
|
||||
@@ -698,8 +696,8 @@ export default class CTransport extends require("./connect")
|
||||
Node.BufWrite = Buffer.concat([Node.BufWrite, BufWrite])
|
||||
global.ADD_TO_STAT("SEND:" + Info.Method)
|
||||
global.ADD_TO_STAT("SEND:(KB)" + Info.Method, BufWrite.length / 1024)
|
||||
global.ADD_TO_STAT("SEND:" + Info.Method + ":" + NodeName(Node), 1, 1)
|
||||
global.TO_DEBUG_LOG("SEND " + Info.Method + " to " + NodeInfo(Node) + " LENGTH=" + BufWrite.length)
|
||||
global.ADD_TO_STAT("SEND:" + Info.Method + ":" + global.NodeName(Node), 1, 1)
|
||||
global.TO_DEBUG_LOG("SEND " + Info.Method + " to " + global.NodeInfo(Node) + " LENGTH=" + BufWrite.length)
|
||||
return 1;
|
||||
}
|
||||
DoSendPacket() {
|
||||
@@ -728,7 +726,7 @@ export default class CTransport extends require("./connect")
|
||||
var CanCountSend = Node.SendTrafficLimit - Node.SendTrafficCurrent;
|
||||
if (CanCountSend < CountSend) {
|
||||
if (this.SendTrafficFree < CountSend) {
|
||||
global.ADD_TO_STAT("LIMIT_SENDDATA:" + NodeName(Node), Value, 1)
|
||||
global.ADD_TO_STAT("LIMIT_SENDDATA:" + global.NodeName(Node), Value, 1)
|
||||
continue NEXT_NODE;
|
||||
}
|
||||
this.SendTrafficFree -= CountSend
|
||||
@@ -739,7 +737,7 @@ export default class CTransport extends require("./connect")
|
||||
Node.BufWrite = Node.BufWrite.slice(CountSend)
|
||||
this.ADD_CURRENT_STAT_TIME("SEND_DATA", Value)
|
||||
global.ADD_TO_STAT("SENDDATA(KB)", Value)
|
||||
global.ADD_TO_STAT("SENDDATA(KB):" + NodeName(Node), Value, 1)
|
||||
global.ADD_TO_STAT("SENDDATA(KB):" + global.NodeName(Node), Value, 1)
|
||||
}
|
||||
}
|
||||
CheckPOWTicketConnect(Socket, data) {
|
||||
@@ -773,18 +771,18 @@ export default class CTransport extends require("./connect")
|
||||
Node.NextConnectDelta = 1000
|
||||
Node.WaitConnectFromServer = 0
|
||||
Node.GrayConnect = 0
|
||||
global.AddNodeInfo(Node, "3. SERVER OK CONNECT for client node " + SocketInfo(Socket))
|
||||
global.AddNodeInfo(Node, "3. SERVER OK CONNECT for client node " + global.SocketInfo(Socket))
|
||||
this.AddNodeToActive(Node)
|
||||
Node.Socket = Socket
|
||||
SetSocketStatus(Socket, 3)
|
||||
SetSocketStatus(Socket, 100)
|
||||
global.SetSocketStatus(Socket, 3)
|
||||
global.SetSocketStatus(Socket, 100)
|
||||
Socket.Node = Node
|
||||
Socket.write(this.GetBufFromData("POW_CONNECT0", "OK", 2))
|
||||
return;
|
||||
}
|
||||
else {
|
||||
Node.NextConnectDelta = 60 * 1000
|
||||
global.ToLog("Error Sign Node from " + NodeInfo(Node))
|
||||
global.ToLog("Error Sign Node from " + global.NodeInfo(Node))
|
||||
this.AddCheckErrCount(Node, 10, "Error Sign Node")
|
||||
}
|
||||
}
|
||||
@@ -820,7 +818,7 @@ export default class CTransport extends require("./connect")
|
||||
this.AddToBanIP(Socket.remoteAddress, "ERROR_SIGN_CLIENT")
|
||||
return;
|
||||
}
|
||||
global.AddNodeInfo(Node, "1. SERVER OK POW for client node " + SocketInfo(Socket))
|
||||
global.AddNodeInfo(Node, "1. SERVER OK POW for client node " + global.SocketInfo(Socket))
|
||||
Node.FromIP = Info.FromIP
|
||||
Node.FromPort = Info.FromPort
|
||||
Node.SecretForReconnect = crypto.randomBytes(20)
|
||||
@@ -829,11 +827,11 @@ export default class CTransport extends require("./connect")
|
||||
Node.NextConnectDelta = 1000
|
||||
Node.WaitConnectFromServer = 0
|
||||
Node.GrayConnect = 1
|
||||
global.AddNodeInfo(Node, "5. CLIENT OK GRAY CONNECT " + SocketInfo(Socket))
|
||||
global.AddNodeInfo(Node, "5. CLIENT OK GRAY CONNECT " + global.SocketInfo(Socket))
|
||||
this.AddNodeToActive(Node)
|
||||
Node.Socket = Socket
|
||||
SetSocketStatus(Socket, 3)
|
||||
SetSocketStatus(Socket, 100)
|
||||
global.SetSocketStatus(Socket, 3)
|
||||
global.SetSocketStatus(Socket, 100)
|
||||
Socket.Node = Node
|
||||
Socket.write(this.GetBufFromData("POW_CONNECT0", "OK", 2))
|
||||
return;
|
||||
@@ -865,7 +863,7 @@ export default class CTransport extends require("./connect")
|
||||
}
|
||||
let SOCKET = sock;
|
||||
global.socketInit(SOCKET, "c")
|
||||
SetSocketStatus(SOCKET, 0)
|
||||
global.SetSocketStatus(SOCKET, 0)
|
||||
global.AddNodeInfo(SOCKET, "Client *" + SOCKET.ConnectID + " connected from " + SOCKET.remoteAddress + ":" + SOCKET.remotePort, 1)
|
||||
global.ADD_TO_STAT("ClientConnected")
|
||||
SOCKET.HashRND = crypto.randomBytes(32)
|
||||
@@ -904,9 +902,9 @@ export default class CTransport extends require("./connect")
|
||||
SOCKET.on('end', function() {
|
||||
global.ADD_TO_STAT("ClientEnd")
|
||||
var Node = SOCKET.Node;
|
||||
var Status = GetSocketStatus(SOCKET);
|
||||
var Status = global.GetSocketStatus(SOCKET);
|
||||
if (Status)
|
||||
global.AddNodeInfo(Node, "Get socket end *" + SOCKET.ConnectID + " from client Stat: " + SocketStatistic(SOCKET))
|
||||
global.AddNodeInfo(Node, "Get socket end *" + SOCKET.ConnectID + " from client Stat: " + global.SocketStatistic(SOCKET))
|
||||
if (Node && Status === 200) {
|
||||
Node.SwapSockets()
|
||||
SOCKET.WasClose = 1
|
||||
@@ -914,12 +912,12 @@ export default class CTransport extends require("./connect")
|
||||
})
|
||||
SOCKET.on('close', function(err) {
|
||||
global.ADD_TO_STAT("ClientClose")
|
||||
if (SOCKET.ConnectID && GetSocketStatus(SOCKET))
|
||||
global.AddNodeInfo(SOCKET.Node, "Get socket close *" + SOCKET.ConnectID + " from client Stat: " + SocketStatistic(SOCKET))
|
||||
if (SOCKET.ConnectID && global.GetSocketStatus(SOCKET))
|
||||
global.AddNodeInfo(SOCKET.Node, "Get socket close *" + SOCKET.ConnectID + " from client Stat: " + global.SocketStatistic(SOCKET))
|
||||
if (!SOCKET.WasClose && SOCKET.Node) {
|
||||
global.CloseSocket(SOCKET, "GET CLOSE")
|
||||
}
|
||||
SetSocketStatus(SOCKET, 0)
|
||||
global.SetSocketStatus(SOCKET, 0)
|
||||
})
|
||||
SOCKET.on('error', function(err) {
|
||||
global.ADD_TO_STAT("ERRORS")
|
||||
@@ -999,7 +997,7 @@ export default class CTransport extends require("./connect")
|
||||
global.CloseSocket(Context.Socket, "CLOSE_SOCKET")
|
||||
}
|
||||
SendCloseSocket(Socket, Str) {
|
||||
global.AddNodeInfo(Socket.Node, "CLOSE_SOCKET " + SocketInfo(Socket) + " - " + Str)
|
||||
global.AddNodeInfo(Socket.Node, "CLOSE_SOCKET " + global.SocketInfo(Socket) + " - " + Str)
|
||||
if (Socket.WasClose) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user