@@ -12,6 +12,7 @@
|
||||
require("./library.js");
|
||||
const net = require("net");
|
||||
var ConnectIDCount = 1;
|
||||
let RBTree = global.RBTree;
|
||||
module.exports = class CNode {
|
||||
addrStr
|
||||
ip
|
||||
@@ -81,6 +82,16 @@ module.exports = class CNode {
|
||||
SendPacketNum
|
||||
Socket
|
||||
Socket2
|
||||
ReconnectFromServer
|
||||
SecretForReconnect
|
||||
Self
|
||||
addrStrTemp
|
||||
DoubleConnection
|
||||
PubKey
|
||||
addrArr
|
||||
SocketStart
|
||||
WaitConnectFromServer
|
||||
WaitConnectIP
|
||||
constructor(addrStr, ip, port) {
|
||||
this.addrStr = addrStr
|
||||
this.ip = ip.trim()
|
||||
@@ -131,7 +142,7 @@ module.exports = class CNode {
|
||||
this.StartTimeGetNodes = 0
|
||||
this.NextGetNodesDelta = 1000
|
||||
this.PingStart = 0
|
||||
this.NextPing = MIN_PERIOD_PING
|
||||
this.NextPing = global.MIN_PERIOD_PING
|
||||
this.SendBlockArr = []
|
||||
this.LoadBlockArr = []
|
||||
this.SendBlockCount = 0
|
||||
@@ -175,7 +186,7 @@ module.exports = class CNode {
|
||||
NODE.SocketStart = Date.now()
|
||||
NODE.Socket = net.createConnection(NODE.port, NODE.ip, function() {
|
||||
if (NODE.Socket) {
|
||||
socketInit(NODE.Socket, "s")
|
||||
global.socketInit(NODE.Socket, "s")
|
||||
global.AddNodeInfo(NODE, "OK connected *" + NODE.Socket.ConnectID)
|
||||
NODE.Socket.ConnectToServer = true
|
||||
SetSocketStatus(NODE.Socket, 2)
|
||||
@@ -194,7 +205,7 @@ module.exports = class CNode {
|
||||
NODE.SocketStart = Date.now()
|
||||
NODE.Socket2 = net.createConnection(NODE.port, NODE.ip, function() {
|
||||
if (NODE.Socket2) {
|
||||
socketInit(NODE.Socket2, "s")
|
||||
global.socketInit(NODE.Socket2, "s")
|
||||
global.AddNodeInfo(NODE, "OK Reconnected *" + NODE.Socket2.ConnectID)
|
||||
NODE.Socket2.ConnectToServer = true
|
||||
SetSocketStatus(NODE.Socket2, 2)
|
||||
@@ -287,7 +298,7 @@ module.exports = class CNode {
|
||||
global.CloseSocket(SOCKET, Buf ? "Method=" + Buf.Method + ":" + Str : "=CLIENT ON DATA=")
|
||||
}
|
||||
else {
|
||||
socketRead(Socket, data)
|
||||
global.socketRead(Socket, data)
|
||||
global.SERVER.OnGetFromTCP(NODE, Socket, data)
|
||||
}
|
||||
})
|
||||
@@ -323,13 +334,13 @@ module.exports = class CNode {
|
||||
var Info = this.GetPOWClientData(0);
|
||||
Info.Reconnect = 1
|
||||
Info.SecretForReconnect = Node.SecretForReconnect
|
||||
var BufWrite = global.BufLib.GetBufferFromObject(Info, FORMAT_POW_TO_SERVER, 1200, {});
|
||||
var BufWrite = global.BufLib.GetBufferFromObject(Info, global.FORMAT_POW_TO_SERVER, 1200, {});
|
||||
var BufAll = global.SERVER.GetBufFromData("POW_CONNECT7", BufWrite, 1);
|
||||
Socket.write(BufAll)
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
var Buf = global.BufLib.GetObjectFromBuffer(data, FORMAT_POW_TO_CLIENT, {});
|
||||
var Buf = global.BufLib.GetObjectFromBuffer(data, global.FORMAT_POW_TO_CLIENT, {});
|
||||
}
|
||||
catch (e) {
|
||||
global.SERVER.Sendglobal.CloseSocket(Socket, "FORMAT_POW_TO_CLIENT")
|
||||
@@ -341,7 +352,7 @@ module.exports = class CNode {
|
||||
global.SERVER.Sendglobal.CloseSocket(Socket, "SELF")
|
||||
return;
|
||||
}
|
||||
var addrStr = GetHexFromAddres(Buf.addrArr);
|
||||
var addrStr = global.GetHexFromAddres(Buf.addrArr);
|
||||
if (!Node.StartFindList && addrStr !== Node.addrStr) {
|
||||
global.AddNodeInfo(Node, "END: CHANGED ADDR: " + Node.addrStr.substr(0, 16) + "->" + addrStr.substr(0, 16))
|
||||
global.SERVER.Sendglobal.CloseSocket(Socket, "ADDRESS_HAS_BEEN_CHANGED")
|
||||
@@ -354,9 +365,9 @@ module.exports = class CNode {
|
||||
}
|
||||
var Result = false;
|
||||
if (Buf.PubKeyType === 2 || Buf.PubKeyType === 3) {
|
||||
Result = secp256k1.verify(Buffer.from(shaarr(addrStr)), Buffer.from(Buf.Sign), Buffer.from([Buf.PubKeyType].concat(Buf.addrArr)))
|
||||
Result = global.secp256k1.verify(Buffer.from(global.shaarr(addrStr)), Buffer.from(Buf.Sign), Buffer.from([Buf.PubKeyType].concat(Buf.addrArr)))
|
||||
if (!Result) {
|
||||
Result = secp256k1.verify(Buffer.from(sha3(addrStr)), Buffer.from(Buf.Sign), Buffer.from([Buf.PubKeyType].concat(Buf.addrArr)))
|
||||
Result = global.secp256k1.verify(Buffer.from(global.sha3(addrStr)), Buffer.from(Buf.Sign), Buffer.from([Buf.PubKeyType].concat(Buf.addrArr)))
|
||||
}
|
||||
}
|
||||
if (!Result) {
|
||||
@@ -365,7 +376,7 @@ module.exports = class CNode {
|
||||
global.SERVER.Sendglobal.CloseSocket(Socket, "ERROR_SIGN_SERVER")
|
||||
return;
|
||||
}
|
||||
if (Buf.MIN_POWER_POW_HANDSHAKE > 1 + MIN_POWER_POW_HANDSHAKE) {
|
||||
if (Buf.MIN_POWER_POW_HANDSHAKE > 1 + global.MIN_POWER_POW_HANDSHAKE) {
|
||||
global.ToLog("END: BIG_MIN_POWER_POW_HANDSHAKE ADDR: " + addrStr.substr(0, 16) + " from ip: " + Socket.remoteAddress)
|
||||
return 0;
|
||||
}
|
||||
@@ -384,18 +395,18 @@ module.exports = class CNode {
|
||||
Node.PubKey = Buffer.from([Buf.PubKeyType].concat(Buf.addrArr))
|
||||
Node.addrArr = Buf.addrArr
|
||||
Node.addrStr = addrStr
|
||||
if (global.CompareArr(SERVER.addrArr, Node.addrArr) === 0) {
|
||||
if (global.CompareArr(global.SERVER.addrArr, Node.addrArr) === 0) {
|
||||
Node.Self = 1
|
||||
return 0;
|
||||
}
|
||||
var Hash = shaarr2(Buf.addrArr, Buf.HashRND);
|
||||
var nonce = CreateNoncePOWExternMinPower(Hash, 0, Buf.MIN_POWER_POW_HANDSHAKE);
|
||||
var Hash = global.shaarr2(Buf.addrArr, Buf.HashRND);
|
||||
var nonce = global.CreateNoncePOWExternMinPower(Hash, 0, Buf.MIN_POWER_POW_HANDSHAKE);
|
||||
var Info;
|
||||
if (WALLET.WalletOpen && IsDeveloperAccount(WALLET.PubKeyArr)) {
|
||||
if (global.WALLET.WalletOpen && global.IsDeveloperAccount(global.WALLET.PubKeyArr)) {
|
||||
Info = this.GetPOWClientData(0)
|
||||
Info.Reconnect = 255
|
||||
Info.Sign = secp256k1.sign(SHA3BUF(Hash), WALLET.KeyPair.getPrivateKey('')).signature
|
||||
Result = CheckDevelopSign(Hash, Info.Sign)
|
||||
Info.Sign = global.secp256k1.sign(global.SHA3BUF(Hash), global.WALLET.KeyPair.getPrivateKey('')).signature
|
||||
Result = global.CheckDevelopSign(Hash, Info.Sign)
|
||||
if (!Result) {
|
||||
throw "ERROR DEVELOPSIGN!";
|
||||
}
|
||||
@@ -403,19 +414,19 @@ module.exports = class CNode {
|
||||
else {
|
||||
Info = this.GetPOWClientData(nonce)
|
||||
Info.PubKeyType = global.SERVER.PubKeyType
|
||||
Info.Sign = secp256k1.sign(Buffer.from(Hash), global.SERVER.KeyPair.getPrivateKey('')).signature
|
||||
Info.Sign = global.secp256k1.sign(Buffer.from(Hash), global.SERVER.KeyPair.getPrivateKey('')).signature
|
||||
}
|
||||
var BufWrite = global.BufLib.GetBufferFromObject(Info, FORMAT_POW_TO_SERVER, 1200, {});
|
||||
var BufWrite = global.BufLib.GetBufferFromObject(Info, global.FORMAT_POW_TO_SERVER, 1200, {});
|
||||
var BufAll = global.SERVER.GetBufFromData("POW_CONNECT6", BufWrite, 1);
|
||||
Socket.write(BufAll)
|
||||
return 1;
|
||||
}
|
||||
GetPOWClientData(nonce) {
|
||||
var Node = this;
|
||||
var Info = {};
|
||||
Info.DEF_NETWORK = GetNetworkName()
|
||||
Info.DEF_VERSION = DEF_VERSION
|
||||
Info.DEF_CLIENT = DEF_CLIENT
|
||||
var Info: any = {};
|
||||
Info.DEF_NETWORK = global.GetNetworkName()
|
||||
Info.DEF_VERSION = global.DEF_VERSION
|
||||
Info.DEF_CLIENT = global.DEF_CLIENT
|
||||
Info.addrArr = global.SERVER.addrArr
|
||||
Info.ToIP = Node.ip
|
||||
Info.ToPort = Node.port
|
||||
@@ -426,7 +437,7 @@ module.exports = class CNode {
|
||||
Info.SendBytes = 0
|
||||
Info.SecretForReconnect = []
|
||||
Info.Reserv = []
|
||||
if (GrayConnect())
|
||||
if (global.GrayConnect())
|
||||
Info.GrayConnect = 1
|
||||
return Info;
|
||||
}
|
||||
@@ -480,7 +491,7 @@ global.CloseSocket = function(Socket, StrError?, bHide?) {
|
||||
function SetSocketStatus(Socket, Status) {
|
||||
if (Socket && Socket.SocketStatus !== Status) {
|
||||
if (Status === 100 && (Socket.SocketStatus !== 3 && Socket.SocketStatus !== 200)) {
|
||||
ToLogTrace("===================ERROR=================== " + Status);
|
||||
global.ToLogTrace("===================ERROR=================== " + Status);
|
||||
return;
|
||||
}
|
||||
if (Status === 100 && Socket.Node)
|
||||
@@ -494,7 +505,7 @@ function GetSocketStatus(Socket) {
|
||||
if (Socket && Socket.SocketStatus) {
|
||||
if (Socket.SocketStatus !== 100) {
|
||||
var Delta = Date.now() - Socket.TimeStatus;
|
||||
if (Delta > MAX_WAIT_PERIOD_FOR_STATUS) {
|
||||
if (Delta > global.MAX_WAIT_PERIOD_FOR_STATUS) {
|
||||
global.CloseSocket(Socket, "MAX_WAIT_PERIOD_FOR_STATUS = " + Socket.SocketStatus + " time = " + Delta);
|
||||
}
|
||||
}
|
||||
@@ -543,7 +554,7 @@ function NodeName(Node) {
|
||||
return "";
|
||||
if (Node.Name)
|
||||
return Node.Name;
|
||||
if (LOCAL_RUN)
|
||||
if (global.LOCAL_RUN)
|
||||
return "" + Node.port;
|
||||
else {
|
||||
return "" + Node.ip + ":" + Node.addrStr.substr(0, 6);
|
||||
@@ -583,7 +594,7 @@ function AddNodeInfo(Node, Str, bSet) {
|
||||
Node.Info = "";
|
||||
}
|
||||
{
|
||||
var timesend = GetStrOnlyTimeUTC();
|
||||
var timesend = global.GetStrOnlyTimeUTC();
|
||||
Str = timesend + " " + Str;
|
||||
Node.Info += Str + "\n";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user