1
0
forked from circlecloud/tera

fix: sync error

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
2019-07-11 15:52:17 +08:00
parent 13607ba157
commit f8fcab7929
21 changed files with 195 additions and 142 deletions

View File

@@ -15,12 +15,13 @@ import * as crypto from 'crypto';
import "./library"
import "./crypto-library"
import CConnect from './connect'
import { secp256k1 } from '../core/library'
const HARD_PACKET_PERIOD = 20;
global.BUF_TYPE = 1;
global.STR_TYPE = 2;
global.MAX_STR_BUF_DATA = 200;
global.MAX_CONNECTION_ACTIVE = 40;
// var MAX_CONNECTION_ANOTHER = 40;
var MAX_CONNECTION_ANOTHER = 40;
const TRAFIC_LIMIT_NODE_1S = global.MAX_BLOCK_SIZE * 1.25;
const TRAFIC_LIMIT_1S = 8 * TRAFIC_LIMIT_NODE_1S;
global.STAT_PERIOD = global.CONSENSUS_PERIOD_TIME / 5;
@@ -713,13 +714,13 @@ export default class CTransport extends CConnect {
}
DoSendBuf() {
this.RecalcSendStatictic()
// var CountNodeSend = 0;
var CountNodeSend = 0;
var it = this.ActualNodes.iterator(), Node;
NEXT_NODE:
while ((Node = it.next()) !== null)
if (Node.Socket && Node.ConnectStatus() === 100)
if (Node.BufWrite.length > 0) {
// CountNodeSend++
CountNodeSend++
var CountSend = Math.min(BUF_PACKET_SIZE, Node.BufWrite.length);
var Value = CountSend / 1024;
if (global.LIMIT_SEND_TRAFIC) {
@@ -810,7 +811,7 @@ export default class CTransport extends CConnect {
}
let Result = false;
if (Info.PubKeyType === 2 || Info.PubKeyType === 3)
Result = global.secp256k1.verify(Buffer.from(Hash), Buffer.from(Info.Sign), Buffer.from([Info.PubKeyType].concat(Info.addrArr)))
Result = secp256k1.verify(Buffer.from(Hash), Buffer.from(Info.Sign), Buffer.from([Info.PubKeyType].concat(Info.addrArr)))
if (!Result) {
global.AddNodeInfo(Node, "SERV: ERROR_SIGN_CLIENT")
Socket.end(this.GetBufFromData("POW_CONNECT8", "ERROR_SIGN_CLIENT", 2))
@@ -959,9 +960,8 @@ export default class CTransport extends CConnect {
if (SELF.CanSend < 2)
global.ToLogClient("Run TCP server on " + SELF.ip + ":" + SELF.port)
SELF.CanSend++
var Hash;
Hash = global.sha3(SELF.addrStr)
SELF.ServerSign = global.secp256k1.sign(Buffer.from(Hash), SELF.KeyPair.getPrivateKey('')).signature
var Hash = global.sha3(SELF.addrStr)
SELF.ServerSign = secp256k1.sign(Buffer.from(Hash), SELF.KeyPair.getPrivateKey('')).signature
})
}
FindInternetIP() {