Skip to content

Commit 1f20e21

Browse files
committed
update
1 parent a11a470 commit 1f20e21

File tree

6 files changed

+286
-32
lines changed

6 files changed

+286
-32
lines changed

package.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@conet.project/conet-proxy",
33

4-
"version": "0.20.3",
4+
"version": "1.0.2",
55

66
"license": "UNLICENSED",
77
"files": [
@@ -26,7 +26,7 @@
2626
"cors": "^2.8.5",
2727
"express": "^5.1.0",
2828
"fs-extra": "^11.3.0",
29-
"uuid": "^11.1.0",
29+
"uuid": "^13.0.0",
3030
"yargs": "18.0.0",
3131
"hexdump-nodejs": "^0.1.0",
3232
"ip": "^2.0.1",
@@ -38,24 +38,24 @@
3838
},
3939

4040
"devDependencies": {
41-
"@types/async": "^3.2.24",
41+
"@types/async": "^3.2.25",
4242
"@types/express": "^5.0.3",
4343
"@types/fs-extra": "^11.0.4",
4444
"@types/jest": "^30.0.0",
45-
"@types/node": "^24.1.0",
45+
"@types/node": "^24.5.2",
4646
"@types/pouchdb": "^6.4.2",
47-
"@types/uuid": "^10.0.0",
47+
"@types/uuid": "^11.0.0",
4848
"@types/openpgp": "^5.0.0",
49-
"@typescript-eslint/eslint-plugin": "^8.38.0",
50-
"@typescript-eslint/parser": "^8.38.0",
51-
"eslint": "^9.31.0",
49+
"@typescript-eslint/eslint-plugin": "^8.44.1",
50+
"@typescript-eslint/parser": "^8.44.1",
51+
"eslint": "^9.36.0",
5252
"eslint-config-airbnb-base": "^15.0.0",
5353
"eslint-config-prettier": "^10.1.8",
5454
"jszip": "^3.10.1",
5555
"pouchdb": "^9.0.0",
56-
"ts-jest": "^29.4.0",
56+
"ts-jest": "^29.4.4",
5757
"ts-node": "^10.9.2",
58-
"typescript": "^5.8.3",
58+
"typescript": "^5.9.2",
5959
"rimraf": "^6.0.1",
6060
"cpr": "^3.0.1",
6161
"copyfiles": "^2.4.1"

src/localServer/BandwidthCount.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,28 @@ export class BandwidthCount extends Transform {
1313

1414
constructor(private tab: string){
1515
super({
16-
readableHighWaterMark: 64 * 1024,
17-
writableHighWaterMark: 64 * 1024
16+
readableHighWaterMark: 8 * 1024,
17+
writableHighWaterMark: 8 * 1024
1818
})
1919
}
2020

21+
/**
22+
* 直接累加字节数(不经过 Transform 管道)。
23+
* 适用于你在自建泵里手工统计:counter.add(len)。
24+
*/
25+
public add(n: number): void {
26+
if (!n || n <= 0) return
27+
if (!this.startTime) this.startTime = Date.now()
28+
this.count += n
29+
}
30+
2131
public _transform(chunk: Buffer, encoding: BufferEncoding, callback: TransformCallback): void {
2232
if (!this.startTime) {
2333
this.startTime = Date.now()
2434
}
2535
this.count += chunk.length
26-
// logger(`${this.tab} start at ${this.startTime} BandwidthCount ${this.count} bytes`)
27-
this.push(chunk)
28-
callback()
36+
//logger(`${this.tab} start at ${this.startTime} BandwidthCount ${this.count} bytes`)
37+
callback(null, chunk)
2938
}
3039

3140
public _final(callback: (error?: Error | null | undefined) => void): void {
@@ -46,7 +55,7 @@ export class BandwidthCount extends Transform {
4655
return this.count
4756
}
4857

49-
private finishIfNeeded(kind: 'normal' | 'abnormal', reason?: string) {
58+
private finishIfNeeded(kind: 'normal' | 'abnormal' | '_flush', reason?: string) {
5059
if (this.printed) return
5160
this.printed = true
5261

@@ -63,7 +72,7 @@ export class BandwidthCount extends Transform {
6372
const avgHumanBytes = BandwidthCount.formatBytes(avgBytesPerSec)
6473
const avgMbps = (avgBitsPerSec / 1e6).toFixed(3)
6574

66-
const head = `${this.tab} ${kind === 'normal' ? 'end' : 'end(abnormal)'} at ${endTs}` +
75+
const head = `${this.tab} ${kind === 'normal'|| '_flush' ? kind : 'end(abnormal)'} at ${endTs}` +
6776
(reason ? ` reason=${reason}` : '')
6877

6978
if (!this.count) {

src/localServer/define.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,8 @@ interface UpdateInfo {
878878

879879
type makeConnectResult = {
880880
entryNode: string
881+
entryNode1?: string
881882
egressNode: string
882883
initialData: string
884+
initialData1?: string
883885
}

src/localServer/layerMinus.ts

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,72 @@ export class LayerMinus {
5959
egressNodes.forEach(async n => n.publicKeyObj = await openpgp.readKey ({ armoredKey: n.armoredPublicKey }))
6060
}
6161

62+
private getRandomEntryNodes = (node: nodes_info|null = null):nodes_info => {
63+
const randomIndex = Math.floor (Math.random() * (this.entryNodes.length))
64+
const retNode = this.entryNodes[randomIndex]
65+
if (!node || node.ip_addr !== retNode.ip_addr) {
66+
return retNode
67+
}
68+
69+
return this.getRandomEntryNodes(node)
70+
}
71+
72+
private getRandomeEressNodes = (node: nodes_info|null = null):nodes_info => {
73+
const randomIndex = Math.floor (Math.random() * (this.egressNodes.length))
74+
const retNode = this.egressNodes[randomIndex]
75+
if (!node || node.ip_addr !== retNode.ip_addr) {
76+
return retNode
77+
}
78+
79+
return this.getRandomeEressNodes(node)
80+
}
81+
82+
public makeConnectNew: (host: string, port: number, initialData: Buffer|null) => Promise<makeConnectResult> = async (host, port, initialData) => {
83+
logger(Colors.blue(`LayerMinus makeConnect ${host}:${port}`))
84+
const entryNode1 = this.getRandomEntryNodes()
85+
const entryNode2 = this.getRandomEntryNodes(entryNode1)
86+
const egressNode = this.getRandomeEressNodes()
87+
88+
const requestData : VE_IPptpStream[] = [{
89+
order: 0,
90+
host,
91+
port,
92+
buffer: initialData?.toString ( 'base64' )||''
93+
}]
94+
95+
const command: SICommandObj = {
96+
command: 'SaaS_Sock5_v2',
97+
algorithm: 'aes-256-cbc',
98+
Securitykey: Buffer.from(getRandomValues(new Uint8Array(16))).toString('base64'),
99+
requestData,
100+
walletAddress: this.wallet.address.toLowerCase()
101+
}
102+
103+
const hostInfo = `${host}:${port}`
104+
105+
const infoData: ITypeTransferCount = {
106+
hostInfo: hostInfo,
107+
startTime: new Date().getTime(),
108+
download: 0,
109+
upload: 0,
110+
nodeIpaddress: egressNode.ip_addr,
111+
endTime: 0
112+
}
113+
114+
const message =JSON.stringify(command)
115+
const signMessage = await this.wallet.signMessage(message)
116+
const encryptedCommand = await encrypt_Message( egressNode.publicKeyObj, { message, signMessage })
117+
const data = otherRequestForNet(JSON.stringify({data: encryptedCommand}), entryNode1.ip_addr, 80, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36')
118+
const data1 = otherRequestForNet(JSON.stringify({data: encryptedCommand}), entryNode1.ip_addr, 80, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36')
119+
120+
return {entryNode: entryNode1.ip_addr, egressNode: egressNode.ip_addr, initialData: data, entryNode1: entryNode2.ip_addr, initialData1: data1}
121+
}
62122

63123
public makeConnect: (host: string, port: number, initialData: Buffer|null) => Promise<makeConnectResult> = async (host, port, initialData) => {
64124
logger(Colors.blue(`LayerMinus makeConnect ${host}:${port}`))
65-
const entryNode = getRamdomNode(this.entryNodes)
66-
const egressNode = getRamdomNode(this.egressNodes)
125+
const entryNode = this.getRandomEntryNodes()
126+
const egressNode = this.getRandomeEressNodes()
127+
67128
const requestData : VE_IPptpStream[] = [{
68129
order: 0,
69130
host,

src/localServer/localServer.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,13 @@ export class Daemon {
483483
res.json(regions?? [])
484484
})
485485

486+
app.get('/switch',async (req, res) => {
487+
if (this._proxyServer) {
488+
this._proxyServer.protocolNew = !this._proxyServer.protocolNew
489+
}
490+
res.status(200).end()
491+
})
492+
486493

487494
app.post('/startSilentPass', async (req: any, res: any) => {
488495
const vpnObj: Native_StartVPNObj = req.body.vpnInfo

0 commit comments

Comments
 (0)