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 { TYPE_TRANSACTION } from '../constant/account';
|
||||
import { STreeBuffer } from './base';
|
||||
import { RBTree } from './library';
|
||||
//import * as crypto from 'crypto';
|
||||
require('./block-loader-const');
|
||||
const STAT_BLOCK_LOAD_PERIOD = global.CONSENSUS_PERIOD_TIME / 5;
|
||||
@ -1197,7 +1198,7 @@ export default class CBlock extends CRest {
|
||||
GetHistoryTree(typedata) {
|
||||
var Tree = global.HistoryBlockBuf.LoadValue(typedata, 1);
|
||||
if (!Tree) {
|
||||
Tree = new global.RBTree(global.CompareItemHash)
|
||||
Tree = new RBTree(global.CompareItemHash)
|
||||
global.HistoryBlockBuf.SaveValue(typedata, Tree)
|
||||
}
|
||||
return Tree;
|
||||
|
@ -17,8 +17,9 @@ import * as url from 'url'
|
||||
import * as fs from 'fs'
|
||||
import * as querystring from 'querystring'
|
||||
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 = {};
|
||||
ContenTypeMap["js"] = "application/javascript";
|
||||
ContenTypeMap["css"] = "text/css";
|
||||
|
@ -11,7 +11,7 @@
|
||||
"use strict";
|
||||
import "./library"
|
||||
import * as net from "net"
|
||||
import { secp256k1 } from '../core/library'
|
||||
import { secp256k1, RBTree } from '../core/library'
|
||||
var ConnectIDCount = 1;
|
||||
export default class CNode {
|
||||
addrStr
|
||||
@ -154,9 +154,9 @@ export default class CNode {
|
||||
this.CanHardTraffic = 0
|
||||
this.BufWriteLength = 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;
|
||||
})
|
||||
} as any)
|
||||
this.ConnectCount = 0
|
||||
this.TrafficArr = []
|
||||
this.SendTrafficCurrent = 0
|
||||
|
@ -15,7 +15,8 @@ import * as crypto from 'crypto';
|
||||
import "./library"
|
||||
import "./crypto-library"
|
||||
import CConnect from './connect'
|
||||
import { secp256k1 } from '../core/library'
|
||||
import { secp256k1, RBTree } from '../core/library'
|
||||
import { STreeBuffer } from './base';
|
||||
const HARD_PACKET_PERIOD = 20;
|
||||
global.BUF_TYPE = 1;
|
||||
global.STR_TYPE = 2;
|
||||
@ -87,7 +88,7 @@ export default class CTransport extends CConnect {
|
||||
this.port = RunPort
|
||||
this.CanSend = 0
|
||||
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)
|
||||
return b.Prioritet - a.Prioritet;
|
||||
return global.CompareArr(a.addrArr, b.addrArr);
|
||||
@ -96,7 +97,7 @@ export default class CTransport extends CConnect {
|
||||
this.LoadedPacketNum = 0
|
||||
this.LoadedSocketNum = 0
|
||||
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)
|
||||
return b.SocketPrioritet - a.SocketPrioritet;
|
||||
return a.SocketNum - b.SocketNum;
|
||||
@ -105,7 +106,7 @@ export default class CTransport extends CConnect {
|
||||
this.LastTimeHard = 0
|
||||
this.LastTimeHardOK = 0
|
||||
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)
|
||||
return a.PacketNum - b.PacketNum;
|
||||
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) {
|
||||
var arrSum = [arr[0]];
|
||||
|
@ -11,6 +11,7 @@
|
||||
"use strict";
|
||||
import CConsensus from './block-exchange'
|
||||
import { TYPE_TRANSACTION } from '../constant/account';
|
||||
import { RBTree } from './library';
|
||||
require("../system/dapp");
|
||||
require("../system/accounts");
|
||||
require("../system/smart");
|
||||
@ -26,7 +27,7 @@ export default class CSmartContract extends CConsensus {
|
||||
WasReloadSenderMapFromDB
|
||||
constructor(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.SenderBlockHashMap = {}
|
||||
this.SenderMap = {}
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
"use strict";
|
||||
import CSmartContract from './transaction-validator'
|
||||
import { RBTree } from './library';
|
||||
const MAX_MESSAGE_COUNT = 1000;
|
||||
export default class CMessages extends CSmartContract {
|
||||
MemPoolMsg
|
||||
@ -17,7 +18,7 @@ export default class CMessages extends CSmartContract {
|
||||
super(SetKeyPair, RunIP, RunPort, UseRNDHeader, bVirtual)
|
||||
this.MemPoolMsg = []
|
||||
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) {
|
||||
var Tree = this.MemPoolMsg[Msg.Level];
|
||||
|
@ -91,17 +91,18 @@ process.on('error' as any, function(err: TeraError) {
|
||||
});
|
||||
global.HTTP_PORT_NUMBER = 0;
|
||||
import CServerDB from '../core/transaction-validator'
|
||||
import { STreeBuffer } from '../core/base';
|
||||
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]));
|
||||
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() {
|
||||
if (global.SERVER) {
|
||||
global.SERVER.Close();
|
||||
}
|
||||
DoTXProcess();
|
||||
}, 10);
|
||||
var BlockTree = new global.STreeBuffer(30 * 1000, global.CompareItemHashSimple, "number");
|
||||
var BlockTree = new STreeBuffer(30 * 1000, global.CompareItemHashSimple, "number");
|
||||
global.bShowDetail = 0;
|
||||
var StopTxProcess = 0;
|
||||
var MinimalValidBlock = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user