js-tcp-tunnel 1.0.1 → 1.0.3

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/src/lib.test.js CHANGED
@@ -62,7 +62,7 @@ test('tunnel-tcp-socket-test', async () => {
62
62
  console.error(err.message)
63
63
  })
64
64
 
65
- let rec = null
65
+ let rec = ''
66
66
 
67
67
  await new Promise((resolve) => {
68
68
  socket.on('connect', async () => {
@@ -86,7 +86,8 @@ test('tunnel-tcp-socket-test', async () => {
86
86
  socketServer.close()
87
87
  })
88
88
 
89
- strictEqual(rec, 'qwertyuiop - 99')
89
+ let from = rec.length - 'qwertyuiop - 99'.length
90
+ strictEqual(rec.substring(from), 'qwertyuiop - 99')
90
91
 
91
92
  })
92
93
  console.info('over!')
package/src/types.ts ADDED
@@ -0,0 +1,114 @@
1
+ import net from 'node:net'
2
+ import { WritableStream } from "stream/web"
3
+
4
+
5
+ export type PromiseResolvers = {
6
+ promise: Promise<any>
7
+ resolve: (value: any | null) => void
8
+ reject: (reason: any | null) => void
9
+ }
10
+
11
+ export type TUNNEL_TCP_TYPE_INIT = 0xa9b398d5 // 链接建立后返回id
12
+ export type TUNNEL_TCP_TYPE_LISTEN = 0xe41957d3
13
+ export type TUNNEL_TCP_TYPE_ONLISTEN = 0x20993e38
14
+ export type TUNNEL_TCP_TYPE_CONNECT = 0x11d949f8
15
+ export type TUNNEL_TCP_TYPE_ONCONNECT = 0x377b2181
16
+ export type TUNNEL_TCP_TYPE_DATA = 0x48678f39
17
+ export type TUNNEL_TCP_TYPE_ERROR = 0x8117f762
18
+ export type TUNNEL_TCP_TYPE_CLOSE = 0x72fd6470
19
+ export type TUNNEL_TCP_TYPE_PING = 0x4768e1ba
20
+ export type TUNNEL_TCP_TYPE_PONG = 0x106f43fb
21
+ export type TUNNEL_TCP_TYPE_ACK = 0xc5870539
22
+
23
+ export type TUNNEL_TCP_TYPE = TUNNEL_TCP_TYPE_INIT |
24
+ TUNNEL_TCP_TYPE_LISTEN |
25
+ TUNNEL_TCP_TYPE_ONLISTEN |
26
+ TUNNEL_TCP_TYPE_CONNECT |
27
+ TUNNEL_TCP_TYPE_ONCONNECT |
28
+ TUNNEL_TCP_TYPE_DATA |
29
+ TUNNEL_TCP_TYPE_ERROR |
30
+ TUNNEL_TCP_TYPE_CLOSE |
31
+ TUNNEL_TCP_TYPE_PING |
32
+ TUNNEL_TCP_TYPE_PONG |
33
+ TUNNEL_TCP_TYPE_ACK
34
+
35
+ export type TCP_TUNNEL_DATA = {
36
+ type: TUNNEL_TCP_TYPE
37
+ srcId: number
38
+ dstId: number
39
+ srcChannel: number
40
+ dstChannel: number
41
+ buffer: Uint8Array
42
+ }
43
+
44
+ export type TUNNEL_TCP_DATA_LISTEN = {
45
+ key: string
46
+ }
47
+
48
+ export type TUNNEL_TCP_DATA_CONNECT = {
49
+ key: string
50
+ }
51
+
52
+ export type TUNNEL_TCP_DATA_PINGPONG = {
53
+ time: number
54
+ }
55
+
56
+ export type TUNNEL_TCP_SERVER = {
57
+ id: number
58
+ encodeWriter: WritableStreamDefaultWriter<Uint8Array>
59
+ }
60
+
61
+ export type TUNNEL_TCP_SERVER_HELPER = {
62
+ readable: ReadableStream<Uint8Array>
63
+ writable: WritableStream<Uint8Array>
64
+ reader: ReadableStreamDefaultReader<Uint8Array>
65
+ writer: WritableStreamDefaultWriter<Uint8Array>
66
+ dstId: number
67
+ }
68
+
69
+ export type TUNNEL_TCP_CLIENT_HELPER = {
70
+ readable: ReadableStream<Uint8Array>
71
+ writable: WritableStream<Uint8Array>
72
+ reader: ReadableStreamDefaultReader<Uint8Array>
73
+ writer: WritableStreamDefaultWriter<Uint8Array>
74
+ param: TunnelTcpClientHelperParam
75
+ listen: (param: {
76
+ clientKey?: string
77
+ tunnelKey: string
78
+ host?: string
79
+ port: number
80
+ }) => Promise<void>
81
+ connect: (param: {
82
+ clientKey?: string
83
+ tunnelKey: string
84
+ port: number
85
+ }) => Promise<void>
86
+ }
87
+
88
+
89
+ export type SocketChannel = {
90
+ writer: WritableStreamDefaultWriter<Uint8Array>
91
+ socket: net.Socket
92
+ srcId: number
93
+ dstId: number
94
+ srcChannel: number
95
+ dstChannel: number
96
+ notify: (size: number) => void
97
+ recvPackSize: number
98
+ key_iv: [CryptoKey, Uint8Array]
99
+ }
100
+
101
+
102
+ export type TunnelTcpServerHelperParam = {
103
+ uniqueId: number
104
+ listenMap: Map<string, number>
105
+ dstMap: Map<number, TUNNEL_TCP_SERVER>
106
+ serverKey?: string
107
+ }
108
+
109
+ export type TunnelTcpClientHelperParam = {
110
+ signal: AbortSignal
111
+ serverKey?: string
112
+ uniqueId: number
113
+ clientDataId: number
114
+ }