iosignal 5.2.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +163 -0
- package/dist/browser/esm/io.d.ts +17 -12
- package/dist/browser/esm/io.js +5 -5
- package/dist/browser/esm/io.js.map +1 -1
- package/dist/browser/iife/io.js +5 -5
- package/dist/browser/iife/io.js.map +1 -1
- package/dist/node/iosignal.cjs +195 -550
- package/dist/node/iosignal.js +193 -548
- package/dist/types/client/IOCore.d.ts +11 -5
- package/dist/types/client/browser/IOWebSocket.d.ts +4 -4
- package/dist/types/common/payload.d.ts +2 -2
- package/package.json +22 -4
- package/.vscode/settings.json +0 -3
- package/index.js +0 -26
- package/rollup.config.js +0 -59
- package/src/auth/BohoAuth.js +0 -196
- package/src/auth/key_providers/FileKeyProvider.js +0 -59
- package/src/auth/key_providers/RedisKeyProvider.js +0 -46
- package/src/auth/key_providers/StringKeyProvider.js +0 -54
- package/src/client/CongPacket.js +0 -143
- package/src/client/IOCongSocket.js +0 -92
- package/src/client/IOCore.js +0 -1202
- package/src/client/IOWS.js +0 -78
- package/src/client/browser/IOWebSocket.js +0 -202
- package/src/common/constants.js +0 -210
- package/src/common/payload.js +0 -82
- package/src/common/quotaTable.js +0 -68
- package/src/common/util.js +0 -64
- package/src/server/FileLogger.js +0 -30
- package/src/server/Manager.js +0 -450
- package/src/server/Metrics.js +0 -155
- package/src/server/Remote.js +0 -216
- package/src/server/RemoteCore.js +0 -427
- package/src/server/Server.js +0 -236
- package/src/server/serverOption.js +0 -56
- package/src/services/RedisService.js +0 -53
- package/src/services/constant.js +0 -7
- package/src/services/replyService.js +0 -39
- package/src/services/sudoService.js +0 -85
- package/tsconfig.json +0 -25
package/src/client/CongPacket.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { Transform } from 'stream'
|
|
2
|
-
import MBP from 'meta-buffer-pack'
|
|
3
|
-
|
|
4
|
-
export const CongType = {
|
|
5
|
-
TYPE_LEN1: 1,
|
|
6
|
-
TYPE_LEN2: 2,
|
|
7
|
-
TYPE_LEN3: 3,
|
|
8
|
-
TYPE_LEN4: 4
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// support LittleEndian system.
|
|
12
|
-
export function pack(payload) {
|
|
13
|
-
|
|
14
|
-
if( payload.byteLength == undefined ) payload = Buffer.from(payload)
|
|
15
|
-
|
|
16
|
-
if (payload.byteLength < 256) { //one byte len
|
|
17
|
-
return MBP.pack(
|
|
18
|
-
MBP.MB('#type', '8', CongType.TYPE_LEN1),
|
|
19
|
-
MBP.MB('#payloadLen1', '8', payload.byteLength),
|
|
20
|
-
MBP.MB('#payload', payload)
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
} else if (payload.byteLength < 65536) { // 2bytes len
|
|
24
|
-
return MBP.pack(
|
|
25
|
-
MBP.MB('#type', '8', CongType.TYPE_LEN2),
|
|
26
|
-
MBP.MB('#payloadLen2', '16L', payload.byteLength),
|
|
27
|
-
MBP.MB('#payload', payload)
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
} else if (payload.byteLength < 2 ** 24) { // 3bytes len
|
|
31
|
-
let len4Buffer = Buffer.alloc(4)
|
|
32
|
-
len4Buffer.writeUint32LE(payload.byteLength)
|
|
33
|
-
let cropLen3 = len4Buffer.subarray(0, 3)
|
|
34
|
-
return MBP.pack(
|
|
35
|
-
MBP.MB('#type', '8', CongType.TYPE_LEN3),
|
|
36
|
-
MBP.MB('#payloadLen3', cropLen3),
|
|
37
|
-
MBP.MB('#payload', payload)
|
|
38
|
-
)
|
|
39
|
-
|
|
40
|
-
} else { //use 4 bytes.
|
|
41
|
-
return MBP.pack(
|
|
42
|
-
MBP.MB('#type', '8', CongType.TYPE_LEN4),
|
|
43
|
-
MBP.MB('#payloadLen4', '32L', payload.byteLength),
|
|
44
|
-
MBP.MB('#payload', payload)
|
|
45
|
-
)
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export class CongRx extends Transform {
|
|
51
|
-
constructor(options) {
|
|
52
|
-
super(options)
|
|
53
|
-
this.buffer = Buffer.alloc(0)
|
|
54
|
-
this.frames = []
|
|
55
|
-
this.rxi = 0;
|
|
56
|
-
this.rxi_zero = 0;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
_transform(chunk, encoding, callback) {
|
|
62
|
-
this.addData(chunk)
|
|
63
|
-
if (this.frames.length > 0) {
|
|
64
|
-
this.frames.forEach(frame => {
|
|
65
|
-
this.push(frame)
|
|
66
|
-
})
|
|
67
|
-
this.frames = []
|
|
68
|
-
}
|
|
69
|
-
callback()
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
addData(chunk) {
|
|
74
|
-
let c = chunk.byteLength;
|
|
75
|
-
let i = 0;
|
|
76
|
-
while (c--) {
|
|
77
|
-
this.rxi++
|
|
78
|
-
if (chunk[i++] == 0) {
|
|
79
|
-
this.rxi_zero++
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (this.buffer.byteLength > 0) {
|
|
84
|
-
this.buffer = Buffer.concat([this.buffer, chunk])
|
|
85
|
-
} else {
|
|
86
|
-
this.buffer = chunk
|
|
87
|
-
}
|
|
88
|
-
this.parse()
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
parse() {
|
|
93
|
-
let head = this.buffer[0]
|
|
94
|
-
let headerLen;
|
|
95
|
-
let payloadSize;
|
|
96
|
-
|
|
97
|
-
if (head == CongType.TYPE_LEN1) {
|
|
98
|
-
headerLen = 2;
|
|
99
|
-
if (this.buffer.byteLength < headerLen) return;
|
|
100
|
-
payloadSize = this.buffer.readUint8(1)
|
|
101
|
-
|
|
102
|
-
} else if (head == CongType.TYPE_LEN2) {
|
|
103
|
-
headerLen = 3;
|
|
104
|
-
if (this.buffer.byteLength < headerLen) return;
|
|
105
|
-
payloadSize = this.buffer.readUint16LE(1)
|
|
106
|
-
|
|
107
|
-
} else if (head == CongType.TYPE_LEN3) {
|
|
108
|
-
headerLen = 4;
|
|
109
|
-
if (this.buffer.byteLength < headerLen) return;
|
|
110
|
-
payloadSize = this.buffer.readUint16LE(1) + this.buffer.readUint8(3) * 65536
|
|
111
|
-
|
|
112
|
-
} else if (head == CongType.TYPE_LEN4) {
|
|
113
|
-
headerLen = 5;
|
|
114
|
-
if (this.buffer.byteLength < headerLen) return;
|
|
115
|
-
payloadSize = this.buffer.readUint32LE(1)
|
|
116
|
-
|
|
117
|
-
} else {
|
|
118
|
-
this.emit('wrong', this.buffer)
|
|
119
|
-
this.buffer = Buffer.alloc(0)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (payloadSize == this.buffer.byteLength - headerLen) {
|
|
124
|
-
this.frames.push(this.buffer.subarray(headerLen))
|
|
125
|
-
this.buffer = Buffer.alloc(0)
|
|
126
|
-
return
|
|
127
|
-
} else if (payloadSize < this.buffer.byteLength - headerLen) {
|
|
128
|
-
this.frames.push(this.buffer.subarray(headerLen, headerLen + payloadSize))
|
|
129
|
-
this.buffer = this.buffer.subarray(headerLen + payloadSize)
|
|
130
|
-
this.parse()
|
|
131
|
-
} else {
|
|
132
|
-
// not ready
|
|
133
|
-
// console.log('+')
|
|
134
|
-
return
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { IOCore } from "./IOCore.js"
|
|
2
|
-
import { SIZE_LIMIT } from "../common/constants.js";
|
|
3
|
-
import { pack, CongRx } from './CongPacket.js'
|
|
4
|
-
import net from 'net'
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export class IOCongSocket extends IOCore {
|
|
8
|
-
constructor(url) {
|
|
9
|
-
super(url);
|
|
10
|
-
if (url) this.open();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Closes TCP socket and cleans resources.
|
|
15
|
-
*/
|
|
16
|
-
close() {
|
|
17
|
-
if (this.socket) {
|
|
18
|
-
if (this.congRx) {
|
|
19
|
-
this.socket.unpipe(this.congRx);
|
|
20
|
-
this.congRx.destroy(); // Use destroy() for complete stream cleanup
|
|
21
|
-
this.congRx = null;
|
|
22
|
-
}
|
|
23
|
-
this.socket.removeAllListeners();
|
|
24
|
-
if (!this.socket.destroyed) {
|
|
25
|
-
this.socket.destroy(); // destroy() is sufficient for forceful closing
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
super.close();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
keepConnection() {
|
|
34
|
-
if (!this.autoReconnect) return;
|
|
35
|
-
// Reconnect only if the socket is fully destroyed and the state is closed.
|
|
36
|
-
if ((!this.socket || this.socket.destroyed)) {
|
|
37
|
-
this.open();
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
createConnection(url) {
|
|
43
|
-
// TCP Socket
|
|
44
|
-
let urlObj = new URL(url)
|
|
45
|
-
if (urlObj.protocol != "cong:") {
|
|
46
|
-
urlObj = new URL('cong://' + url)
|
|
47
|
-
}
|
|
48
|
-
this.socket = net.createConnection(urlObj.port, urlObj.hostname)
|
|
49
|
-
this.stateChange('connecting','connecting')
|
|
50
|
-
|
|
51
|
-
this.socket.on('connect', () => {
|
|
52
|
-
this.congRx = new CongRx();
|
|
53
|
-
this.socket.pipe(this.congRx)
|
|
54
|
-
this.congRx.on("data", this.onTCPSocketMessage.bind(this));
|
|
55
|
-
this.emit('open')
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
this.socket.on('error', e => {
|
|
59
|
-
this.emit('error', e)
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
this.socket.on('close', () => {
|
|
63
|
-
this.emit('close');
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
onTCPSocketMessage(data) {
|
|
69
|
-
this.rxCounter++;
|
|
70
|
-
this.rxBytes += data.byteLength
|
|
71
|
-
this.lastTxRxTime = Date.now();
|
|
72
|
-
this.emit('socket_data', data);
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
socket_send(data) {
|
|
77
|
-
if (this.socket?.readyState === 'open') {
|
|
78
|
-
let packData = pack(data);
|
|
79
|
-
this.socket.write(packData)
|
|
80
|
-
this.txCounter++;
|
|
81
|
-
this.txBytes += packData.byteLength;
|
|
82
|
-
this.lastTxRxTime = Date.now();
|
|
83
|
-
} else {
|
|
84
|
-
console.log('.')
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|