forked from circlecloud/tera
refactor: replace global new
Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
parent
5fd017eaf1
commit
efb60e3d0d
@ -13,6 +13,7 @@ import * as fs from 'fs'
|
|||||||
import CRest from './rest-loader'
|
import CRest from './rest-loader'
|
||||||
import { TYPE_TRANSACTION } from '../constant/account';
|
import { TYPE_TRANSACTION } from '../constant/account';
|
||||||
import { STreeBuffer } from './base';
|
import { STreeBuffer } from './base';
|
||||||
|
import { RBTree } from './library';
|
||||||
//import * as crypto from 'crypto';
|
//import * as crypto from 'crypto';
|
||||||
require('./block-loader-const');
|
require('./block-loader-const');
|
||||||
const STAT_BLOCK_LOAD_PERIOD = global.CONSENSUS_PERIOD_TIME / 5;
|
const STAT_BLOCK_LOAD_PERIOD = global.CONSENSUS_PERIOD_TIME / 5;
|
||||||
@ -1197,7 +1198,7 @@ export default class CBlock extends CRest {
|
|||||||
GetHistoryTree(typedata) {
|
GetHistoryTree(typedata) {
|
||||||
var Tree = global.HistoryBlockBuf.LoadValue(typedata, 1);
|
var Tree = global.HistoryBlockBuf.LoadValue(typedata, 1);
|
||||||
if (!Tree) {
|
if (!Tree) {
|
||||||
Tree = new global.RBTree(global.CompareItemHash)
|
Tree = new RBTree(global.CompareItemHash)
|
||||||
global.HistoryBlockBuf.SaveValue(typedata, Tree)
|
global.HistoryBlockBuf.SaveValue(typedata, Tree)
|
||||||
}
|
}
|
||||||
return Tree;
|
return Tree;
|
||||||
|
@ -17,8 +17,9 @@ import * as url from 'url'
|
|||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
import * as querystring from 'querystring'
|
import * as querystring from 'querystring'
|
||||||
import * as crypto from 'crypto';
|
import * as crypto from 'crypto';
|
||||||
|
import { STreeBuffer } from './base';
|
||||||
|
|
||||||
var BlockTree = new global.STreeBuffer(300 * 1000, global.CompareItemHashSimple, "number");
|
var BlockTree = new STreeBuffer(300 * 1000, global.CompareItemHashSimple, "number");
|
||||||
var ContenTypeMap = {};
|
var ContenTypeMap = {};
|
||||||
ContenTypeMap["js"] = "application/javascript";
|
ContenTypeMap["js"] = "application/javascript";
|
||||||
ContenTypeMap["css"] = "text/css";
|
ContenTypeMap["css"] = "text/css";
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
import "./library"
|
import "./library"
|
||||||
import * as net from "net"
|
import * as net from "net"
|
||||||
import { secp256k1 } from '../core/library'
|
import { secp256k1, RBTree } from '../core/library'
|
||||||
var ConnectIDCount = 1;
|
var ConnectIDCount = 1;
|
||||||
export default class CNode {
|
export default class CNode {
|
||||||
addrStr
|
addrStr
|
||||||
@ -154,9 +154,9 @@ export default class CNode {
|
|||||||
this.CanHardTraffic = 0
|
this.CanHardTraffic = 0
|
||||||
this.BufWriteLength = 0
|
this.BufWriteLength = 0
|
||||||
this.BufWrite = Buffer.alloc(0)
|
this.BufWrite = Buffer.alloc(0)
|
||||||
this.SendPacket = new global.RBTree(function(a, b) {
|
this.SendPacket = new RBTree(function(a, b) {
|
||||||
return b.PacketNum - a.PacketNum;
|
return b.PacketNum - a.PacketNum;
|
||||||
})
|
} as any)
|
||||||
this.ConnectCount = 0
|
this.ConnectCount = 0
|
||||||
this.TrafficArr = []
|
this.TrafficArr = []
|
||||||
this.SendTrafficCurrent = 0
|
this.SendTrafficCurrent = 0
|
||||||
|
@ -15,7 +15,8 @@ import * as crypto from 'crypto';
|
|||||||
import "./library"
|
import "./library"
|
||||||
import "./crypto-library"
|
import "./crypto-library"
|
||||||
import CConnect from './connect'
|
import CConnect from './connect'
|
||||||
import { secp256k1 } from '../core/library'
|
import { secp256k1, RBTree } from '../core/library'
|
||||||
|
import { STreeBuffer } from './base';
|
||||||
const HARD_PACKET_PERIOD = 20;
|
const HARD_PACKET_PERIOD = 20;
|
||||||
global.BUF_TYPE = 1;
|
global.BUF_TYPE = 1;
|
||||||
global.STR_TYPE = 2;
|
global.STR_TYPE = 2;
|
||||||
@ -87,7 +88,7 @@ export default class CTransport extends CConnect {
|
|||||||
this.port = RunPort
|
this.port = RunPort
|
||||||
this.CanSend = 0
|
this.CanSend = 0
|
||||||
this.SendFormatMap = {}
|
this.SendFormatMap = {}
|
||||||
this.ActualNodes = new global.RBTree(function(a, b) {
|
this.ActualNodes = new RBTree(function(a: any, b: any): number {
|
||||||
if (b.Prioritet !== a.Prioritet)
|
if (b.Prioritet !== a.Prioritet)
|
||||||
return b.Prioritet - a.Prioritet;
|
return b.Prioritet - a.Prioritet;
|
||||||
return global.CompareArr(a.addrArr, b.addrArr);
|
return global.CompareArr(a.addrArr, b.addrArr);
|
||||||
@ -96,7 +97,7 @@ export default class CTransport extends CConnect {
|
|||||||
this.LoadedPacketNum = 0
|
this.LoadedPacketNum = 0
|
||||||
this.LoadedSocketNum = 0
|
this.LoadedSocketNum = 0
|
||||||
setInterval(this.DoLoadBuf.bind(this), 1)
|
setInterval(this.DoLoadBuf.bind(this), 1)
|
||||||
this.LoadBufSocketList = new global.RBTree(function(a, b) {
|
this.LoadBufSocketList = new RBTree(function(a: any, b: any): number {
|
||||||
if (b.SocketPrioritet !== a.SocketPrioritet)
|
if (b.SocketPrioritet !== a.SocketPrioritet)
|
||||||
return b.SocketPrioritet - a.SocketPrioritet;
|
return b.SocketPrioritet - a.SocketPrioritet;
|
||||||
return a.SocketNum - b.SocketNum;
|
return a.SocketNum - b.SocketNum;
|
||||||
@ -105,7 +106,7 @@ export default class CTransport extends CConnect {
|
|||||||
this.LastTimeHard = 0
|
this.LastTimeHard = 0
|
||||||
this.LastTimeHardOK = 0
|
this.LastTimeHardOK = 0
|
||||||
setInterval(this.DoHardPacketForSend.bind(this), HARD_PACKET_PERIOD)
|
setInterval(this.DoHardPacketForSend.bind(this), HARD_PACKET_PERIOD)
|
||||||
this.HardPacketForSend = new global.RBTree(function(a, b) {
|
this.HardPacketForSend = new RBTree(function(a: any, b: any): number {
|
||||||
if (b.BlockProcessCount === a.BlockProcessCount)
|
if (b.BlockProcessCount === a.BlockProcessCount)
|
||||||
return a.PacketNum - b.PacketNum;
|
return a.PacketNum - b.PacketNum;
|
||||||
else
|
else
|
||||||
@ -1036,7 +1037,7 @@ export default class CTransport extends CConnect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
global.ContextPackets = new global.STreeBuffer(10 * 1000, global.CompareItemHash32, "object");
|
global.ContextPackets = new STreeBuffer(10 * 1000, global.CompareItemHash32, "object");
|
||||||
|
|
||||||
function CalcStatArr(arr, arrAvg, arrNext, Period) {
|
function CalcStatArr(arr, arrAvg, arrNext, Period) {
|
||||||
var arrSum = [arr[0]];
|
var arrSum = [arr[0]];
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
import CConsensus from './block-exchange'
|
import CConsensus from './block-exchange'
|
||||||
import { TYPE_TRANSACTION } from '../constant/account';
|
import { TYPE_TRANSACTION } from '../constant/account';
|
||||||
|
import { RBTree } from './library';
|
||||||
require("../system/dapp");
|
require("../system/dapp");
|
||||||
require("../system/accounts");
|
require("../system/accounts");
|
||||||
require("../system/smart");
|
require("../system/smart");
|
||||||
@ -26,7 +27,7 @@ export default class CSmartContract extends CConsensus {
|
|||||||
WasReloadSenderMapFromDB
|
WasReloadSenderMapFromDB
|
||||||
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
constructor(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual) {
|
||||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||||
this.BufHashTree = new global.RBTree(global.CompareArr)
|
this.BufHashTree = new RBTree(global.CompareArr)
|
||||||
this.BufHashTree.LastAddNum = 0
|
this.BufHashTree.LastAddNum = 0
|
||||||
this.SenderBlockHashMap = {}
|
this.SenderBlockHashMap = {}
|
||||||
this.SenderMap = {}
|
this.SenderMap = {}
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
import CSmartContract from './transaction-validator'
|
import CSmartContract from './transaction-validator'
|
||||||
|
import { RBTree } from './library';
|
||||||
const MAX_MESSAGE_COUNT = 1000;
|
const MAX_MESSAGE_COUNT = 1000;
|
||||||
export default class CMessages extends CSmartContract {
|
export default class CMessages extends CSmartContract {
|
||||||
MemPoolMsg
|
MemPoolMsg
|
||||||
@ -17,7 +18,7 @@ export default class CMessages extends CSmartContract {
|
|||||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||||
this.MemPoolMsg = []
|
this.MemPoolMsg = []
|
||||||
for (var i = 0; i <= global.MAX_LEVEL_SPECIALIZATION; i++)
|
for (var i = 0; i <= global.MAX_LEVEL_SPECIALIZATION; i++)
|
||||||
this.MemPoolMsg[i] = new global.RBTree(global.CompareItemTimePow)
|
this.MemPoolMsg[i] = new RBTree(global.CompareItemTimePow)
|
||||||
}
|
}
|
||||||
AddMsgToQuote(Msg) {
|
AddMsgToQuote(Msg) {
|
||||||
var Tree = this.MemPoolMsg[Msg.Level];
|
var Tree = this.MemPoolMsg[Msg.Level];
|
||||||
|
@ -91,17 +91,18 @@ process.on('error' as any, function(err: TeraError) {
|
|||||||
});
|
});
|
||||||
global.HTTP_PORT_NUMBER = 0;
|
global.HTTP_PORT_NUMBER = 0;
|
||||||
import CServerDB from '../core/transaction-validator'
|
import CServerDB from '../core/transaction-validator'
|
||||||
|
import { STreeBuffer } from '../core/base';
|
||||||
var KeyPair = crypto.createECDH('secp256k1');
|
var KeyPair = crypto.createECDH('secp256k1');
|
||||||
KeyPair.setPrivateKey(Buffer.from([77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]));
|
KeyPair.setPrivateKey(Buffer.from([77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77, 77]));
|
||||||
global.SERVER = new CServerDB(KeyPair, undefined, undefined, false, true);
|
global.SERVER = new CServerDB(KeyPair, undefined, undefined, false, true);
|
||||||
global.TreeFindTX = new global.STreeBuffer(30 * 1000, global.CompareItemHashSimple, "string");
|
global.TreeFindTX = new STreeBuffer(30 * 1000, global.CompareItemHashSimple, "string");
|
||||||
setInterval(function() {
|
setInterval(function() {
|
||||||
if (global.SERVER) {
|
if (global.SERVER) {
|
||||||
global.SERVER.Close();
|
global.SERVER.Close();
|
||||||
}
|
}
|
||||||
DoTXProcess();
|
DoTXProcess();
|
||||||
}, 10);
|
}, 10);
|
||||||
var BlockTree = new global.STreeBuffer(30 * 1000, global.CompareItemHashSimple, "number");
|
var BlockTree = new STreeBuffer(30 * 1000, global.CompareItemHashSimple, "number");
|
||||||
global.bShowDetail = 0;
|
global.bShowDetail = 0;
|
||||||
var StopTxProcess = 0;
|
var StopTxProcess = 0;
|
||||||
var MinimalValidBlock = 0;
|
var MinimalValidBlock = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user