libp2p 0.37.3-3c0fb13 → 0.37.3-4199042
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/dist/src/circuit/circuit/hop.d.ts +2 -1
- package/dist/src/circuit/circuit/hop.d.ts.map +1 -1
- package/dist/src/circuit/circuit/hop.js.map +1 -1
- package/dist/src/circuit/circuit/stop.d.ts +3 -2
- package/dist/src/circuit/circuit/stop.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stop.js.map +1 -1
- package/dist/src/circuit/circuit/stream-handler.d.ts +2 -1
- package/dist/src/circuit/circuit/stream-handler.d.ts.map +1 -1
- package/dist/src/circuit/circuit/stream-handler.js +2 -2
- package/dist/src/circuit/circuit/stream-handler.js.map +1 -1
- package/dist/src/circuit/pb/index.d.ts +5 -4
- package/dist/src/circuit/pb/index.d.ts.map +1 -1
- package/dist/src/circuit/pb/index.js +107 -11
- package/dist/src/circuit/pb/index.js.map +1 -1
- package/dist/src/circuit/transport.d.ts.map +1 -1
- package/dist/src/circuit/transport.js +5 -5
- package/dist/src/circuit/transport.js.map +1 -1
- package/dist/src/connection-manager/index.d.ts.map +1 -1
- package/dist/src/connection-manager/index.js +3 -0
- package/dist/src/connection-manager/index.js.map +1 -1
- package/dist/src/fetch/pb/proto.d.ts +4 -3
- package/dist/src/fetch/pb/proto.d.ts.map +1 -1
- package/dist/src/fetch/pb/proto.js +88 -8
- package/dist/src/fetch/pb/proto.js.map +1 -1
- package/dist/src/identify/index.d.ts.map +1 -1
- package/dist/src/identify/index.js +1 -1
- package/dist/src/identify/index.js.map +1 -1
- package/dist/src/identify/pb/message.d.ts +2 -1
- package/dist/src/identify/pb/message.d.ts.map +1 -1
- package/dist/src/identify/pb/message.js +94 -10
- package/dist/src/identify/pb/message.js.map +1 -1
- package/dist/src/insecure/index.d.ts.map +1 -1
- package/dist/src/insecure/index.js +7 -3
- package/dist/src/insecure/index.js.map +1 -1
- package/dist/src/insecure/pb/proto.d.ts +4 -3
- package/dist/src/insecure/pb/proto.d.ts.map +1 -1
- package/dist/src/insecure/pb/proto.js +89 -9
- package/dist/src/insecure/pb/proto.js.map +1 -1
- package/dist/src/metrics/index.d.ts +1 -2
- package/dist/src/metrics/index.d.ts.map +1 -1
- package/dist/src/metrics/index.js +3 -4
- package/dist/src/metrics/index.js.map +1 -1
- package/dist/src/ping/index.js +1 -1
- package/dist/src/ping/index.js.map +1 -1
- package/dist/src/pnet/index.d.ts.map +1 -1
- package/dist/src/pnet/index.js +2 -1
- package/dist/src/pnet/index.js.map +1 -1
- package/dist/src/upgrader.d.ts.map +1 -1
- package/dist/src/upgrader.js +24 -16
- package/dist/src/upgrader.js.map +1 -1
- package/package.json +45 -45
- package/src/circuit/README.md +2 -2
- package/src/circuit/circuit/hop.ts +5 -3
- package/src/circuit/circuit/stop.ts +2 -1
- package/src/circuit/circuit/stream-handler.ts +5 -4
- package/src/circuit/pb/index.ts +133 -15
- package/src/circuit/transport.ts +8 -6
- package/src/connection-manager/index.ts +3 -0
- package/src/fetch/pb/proto.ts +109 -11
- package/src/identify/index.ts +4 -5
- package/src/identify/pb/message.ts +111 -11
- package/src/insecure/index.ts +8 -3
- package/src/insecure/pb/proto.ts +111 -12
- package/src/metrics/index.ts +4 -7
- package/src/ping/index.ts +1 -1
- package/src/pnet/index.ts +2 -0
- package/src/upgrader.ts +26 -16
- package/src/version.ts +1 -1
package/src/circuit/pb/index.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* eslint-disable import/export */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
3
|
|
|
4
|
-
import { enumeration, encodeMessage, decodeMessage, message
|
|
4
|
+
import { enumeration, encodeMessage, decodeMessage, message } from 'protons-runtime'
|
|
5
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
5
6
|
import type { Codec } from 'protons-runtime'
|
|
6
7
|
|
|
7
8
|
export interface CircuitRelay {
|
|
@@ -52,7 +53,7 @@ export namespace CircuitRelay {
|
|
|
52
53
|
|
|
53
54
|
export namespace Status {
|
|
54
55
|
export const codec = () => {
|
|
55
|
-
return enumeration<
|
|
56
|
+
return enumeration<Status>(__StatusValues)
|
|
56
57
|
}
|
|
57
58
|
}
|
|
58
59
|
|
|
@@ -72,7 +73,7 @@ export namespace CircuitRelay {
|
|
|
72
73
|
|
|
73
74
|
export namespace Type {
|
|
74
75
|
export const codec = () => {
|
|
75
|
-
return enumeration<
|
|
76
|
+
return enumeration<Type>(__TypeValues)
|
|
76
77
|
}
|
|
77
78
|
}
|
|
78
79
|
|
|
@@ -82,36 +83,153 @@ export namespace CircuitRelay {
|
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
export namespace Peer {
|
|
86
|
+
let _codec: Codec<Peer>
|
|
87
|
+
|
|
85
88
|
export const codec = (): Codec<Peer> => {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
if (_codec == null) {
|
|
90
|
+
_codec = message<Peer>((obj, writer, opts = {}) => {
|
|
91
|
+
if (opts.lengthDelimited !== false) {
|
|
92
|
+
writer.fork()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (obj.id != null) {
|
|
96
|
+
writer.uint32(10)
|
|
97
|
+
writer.bytes(obj.id)
|
|
98
|
+
} else {
|
|
99
|
+
throw new Error('Protocol error: required field "id" was not found in object')
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (obj.addrs != null) {
|
|
103
|
+
for (const value of obj.addrs) {
|
|
104
|
+
writer.uint32(18)
|
|
105
|
+
writer.bytes(value)
|
|
106
|
+
}
|
|
107
|
+
} else {
|
|
108
|
+
throw new Error('Protocol error: required field "addrs" was not found in object')
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
if (opts.lengthDelimited !== false) {
|
|
112
|
+
writer.ldelim()
|
|
113
|
+
}
|
|
114
|
+
}, (reader, length) => {
|
|
115
|
+
const obj: any = {}
|
|
116
|
+
|
|
117
|
+
const end = length == null ? reader.len : reader.pos + length
|
|
118
|
+
|
|
119
|
+
while (reader.pos < end) {
|
|
120
|
+
const tag = reader.uint32()
|
|
121
|
+
|
|
122
|
+
switch (tag >>> 3) {
|
|
123
|
+
case 1:
|
|
124
|
+
obj.id = reader.bytes()
|
|
125
|
+
break
|
|
126
|
+
case 2:
|
|
127
|
+
obj.addrs = obj.addrs ?? []
|
|
128
|
+
obj.addrs.push(reader.bytes())
|
|
129
|
+
break
|
|
130
|
+
default:
|
|
131
|
+
reader.skipType(tag & 7)
|
|
132
|
+
break
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
obj.addrs = obj.addrs ?? []
|
|
137
|
+
|
|
138
|
+
if (obj.id == null) {
|
|
139
|
+
throw new Error('Protocol error: value for required field "id" was not found in protobuf')
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (obj.addrs == null) {
|
|
143
|
+
throw new Error('Protocol error: value for required field "addrs" was not found in protobuf')
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return obj
|
|
147
|
+
})
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return _codec
|
|
90
151
|
}
|
|
91
152
|
|
|
92
153
|
export const encode = (obj: Peer): Uint8Array => {
|
|
93
154
|
return encodeMessage(obj, Peer.codec())
|
|
94
155
|
}
|
|
95
156
|
|
|
96
|
-
export const decode = (buf: Uint8Array): Peer => {
|
|
157
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): Peer => {
|
|
97
158
|
return decodeMessage(buf, Peer.codec())
|
|
98
159
|
}
|
|
99
160
|
}
|
|
100
161
|
|
|
162
|
+
let _codec: Codec<CircuitRelay>
|
|
163
|
+
|
|
101
164
|
export const codec = (): Codec<CircuitRelay> => {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
165
|
+
if (_codec == null) {
|
|
166
|
+
_codec = message<CircuitRelay>((obj, writer, opts = {}) => {
|
|
167
|
+
if (opts.lengthDelimited !== false) {
|
|
168
|
+
writer.fork()
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (obj.type != null) {
|
|
172
|
+
writer.uint32(8)
|
|
173
|
+
CircuitRelay.Type.codec().encode(obj.type, writer)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (obj.srcPeer != null) {
|
|
177
|
+
writer.uint32(18)
|
|
178
|
+
CircuitRelay.Peer.codec().encode(obj.srcPeer, writer)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
if (obj.dstPeer != null) {
|
|
182
|
+
writer.uint32(26)
|
|
183
|
+
CircuitRelay.Peer.codec().encode(obj.dstPeer, writer)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (obj.code != null) {
|
|
187
|
+
writer.uint32(32)
|
|
188
|
+
CircuitRelay.Status.codec().encode(obj.code, writer)
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (opts.lengthDelimited !== false) {
|
|
192
|
+
writer.ldelim()
|
|
193
|
+
}
|
|
194
|
+
}, (reader, length) => {
|
|
195
|
+
const obj: any = {}
|
|
196
|
+
|
|
197
|
+
const end = length == null ? reader.len : reader.pos + length
|
|
198
|
+
|
|
199
|
+
while (reader.pos < end) {
|
|
200
|
+
const tag = reader.uint32()
|
|
201
|
+
|
|
202
|
+
switch (tag >>> 3) {
|
|
203
|
+
case 1:
|
|
204
|
+
obj.type = CircuitRelay.Type.codec().decode(reader)
|
|
205
|
+
break
|
|
206
|
+
case 2:
|
|
207
|
+
obj.srcPeer = CircuitRelay.Peer.codec().decode(reader, reader.uint32())
|
|
208
|
+
break
|
|
209
|
+
case 3:
|
|
210
|
+
obj.dstPeer = CircuitRelay.Peer.codec().decode(reader, reader.uint32())
|
|
211
|
+
break
|
|
212
|
+
case 4:
|
|
213
|
+
obj.code = CircuitRelay.Status.codec().decode(reader)
|
|
214
|
+
break
|
|
215
|
+
default:
|
|
216
|
+
reader.skipType(tag & 7)
|
|
217
|
+
break
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return obj
|
|
222
|
+
})
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return _codec
|
|
108
226
|
}
|
|
109
227
|
|
|
110
228
|
export const encode = (obj: CircuitRelay): Uint8Array => {
|
|
111
229
|
return encodeMessage(obj, CircuitRelay.codec())
|
|
112
230
|
}
|
|
113
231
|
|
|
114
|
-
export const decode = (buf: Uint8Array): CircuitRelay => {
|
|
232
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): CircuitRelay => {
|
|
115
233
|
return decodeMessage(buf, CircuitRelay.codec())
|
|
116
234
|
}
|
|
117
235
|
}
|
package/src/circuit/transport.ts
CHANGED
|
@@ -21,6 +21,8 @@ import type { RelayConfig } from '../index.js'
|
|
|
21
21
|
import { abortableDuplex } from 'abortable-iterator'
|
|
22
22
|
import { TimeoutController } from 'timeout-abort-controller'
|
|
23
23
|
import { setMaxListeners } from 'events'
|
|
24
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
25
|
+
import type { Duplex } from 'it-stream-types'
|
|
24
26
|
|
|
25
27
|
const log = logger('libp2p:circuit')
|
|
26
28
|
|
|
@@ -90,7 +92,7 @@ export class Circuit implements Transport, Initializable {
|
|
|
90
92
|
return
|
|
91
93
|
}
|
|
92
94
|
|
|
93
|
-
let virtualConnection
|
|
95
|
+
let virtualConnection: Duplex<Uint8ArrayList, Uint8ArrayList | Uint8Array> | undefined
|
|
94
96
|
|
|
95
97
|
switch (request.type) {
|
|
96
98
|
case CircuitPB.Type.CAN_HOP: {
|
|
@@ -100,7 +102,7 @@ export class Circuit implements Transport, Initializable {
|
|
|
100
102
|
}
|
|
101
103
|
case CircuitPB.Type.HOP: {
|
|
102
104
|
log('received HOP request from %p', connection.remotePeer)
|
|
103
|
-
|
|
105
|
+
await handleHop({
|
|
104
106
|
connection,
|
|
105
107
|
request,
|
|
106
108
|
streamHandler,
|
|
@@ -130,10 +132,10 @@ export class Circuit implements Transport, Initializable {
|
|
|
130
132
|
}
|
|
131
133
|
|
|
132
134
|
if (virtualConnection != null) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const localAddr = new Multiaddr(request.srcPeer
|
|
135
|
+
const remoteAddr = connection.remoteAddr
|
|
136
|
+
.encapsulate('/p2p-circuit')
|
|
137
|
+
.encapsulate(new Multiaddr(request.dstPeer?.addrs[0]))
|
|
138
|
+
const localAddr = new Multiaddr(request.srcPeer?.addrs[0])
|
|
137
139
|
const maConn = streamToMaConnection({
|
|
138
140
|
stream: virtualConnection,
|
|
139
141
|
remoteAddr,
|
package/src/fetch/pb/proto.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* eslint-disable import/export */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
3
|
|
|
4
|
-
import { encodeMessage, decodeMessage, message,
|
|
4
|
+
import { encodeMessage, decodeMessage, message, enumeration } from 'protons-runtime'
|
|
5
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
5
6
|
import type { Codec } from 'protons-runtime'
|
|
6
7
|
|
|
7
8
|
export interface FetchRequest {
|
|
@@ -9,17 +10,59 @@ export interface FetchRequest {
|
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
export namespace FetchRequest {
|
|
13
|
+
let _codec: Codec<FetchRequest>
|
|
14
|
+
|
|
12
15
|
export const codec = (): Codec<FetchRequest> => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
if (_codec == null) {
|
|
17
|
+
_codec = message<FetchRequest>((obj, writer, opts = {}) => {
|
|
18
|
+
if (opts.lengthDelimited !== false) {
|
|
19
|
+
writer.fork()
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (obj.identifier != null) {
|
|
23
|
+
writer.uint32(10)
|
|
24
|
+
writer.string(obj.identifier)
|
|
25
|
+
} else {
|
|
26
|
+
throw new Error('Protocol error: required field "identifier" was not found in object')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (opts.lengthDelimited !== false) {
|
|
30
|
+
writer.ldelim()
|
|
31
|
+
}
|
|
32
|
+
}, (reader, length) => {
|
|
33
|
+
const obj: any = {}
|
|
34
|
+
|
|
35
|
+
const end = length == null ? reader.len : reader.pos + length
|
|
36
|
+
|
|
37
|
+
while (reader.pos < end) {
|
|
38
|
+
const tag = reader.uint32()
|
|
39
|
+
|
|
40
|
+
switch (tag >>> 3) {
|
|
41
|
+
case 1:
|
|
42
|
+
obj.identifier = reader.string()
|
|
43
|
+
break
|
|
44
|
+
default:
|
|
45
|
+
reader.skipType(tag & 7)
|
|
46
|
+
break
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (obj.identifier == null) {
|
|
51
|
+
throw new Error('Protocol error: value for required field "identifier" was not found in protobuf')
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return obj
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return _codec
|
|
16
59
|
}
|
|
17
60
|
|
|
18
61
|
export const encode = (obj: FetchRequest): Uint8Array => {
|
|
19
62
|
return encodeMessage(obj, FetchRequest.codec())
|
|
20
63
|
}
|
|
21
64
|
|
|
22
|
-
export const decode = (buf: Uint8Array): FetchRequest => {
|
|
65
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): FetchRequest => {
|
|
23
66
|
return decodeMessage(buf, FetchRequest.codec())
|
|
24
67
|
}
|
|
25
68
|
}
|
|
@@ -44,22 +87,77 @@ export namespace FetchResponse {
|
|
|
44
87
|
|
|
45
88
|
export namespace StatusCode {
|
|
46
89
|
export const codec = () => {
|
|
47
|
-
return enumeration<
|
|
90
|
+
return enumeration<StatusCode>(__StatusCodeValues)
|
|
48
91
|
}
|
|
49
92
|
}
|
|
50
93
|
|
|
94
|
+
let _codec: Codec<FetchResponse>
|
|
95
|
+
|
|
51
96
|
export const codec = (): Codec<FetchResponse> => {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
97
|
+
if (_codec == null) {
|
|
98
|
+
_codec = message<FetchResponse>((obj, writer, opts = {}) => {
|
|
99
|
+
if (opts.lengthDelimited !== false) {
|
|
100
|
+
writer.fork()
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (obj.status != null) {
|
|
104
|
+
writer.uint32(8)
|
|
105
|
+
FetchResponse.StatusCode.codec().encode(obj.status, writer)
|
|
106
|
+
} else {
|
|
107
|
+
throw new Error('Protocol error: required field "status" was not found in object')
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (obj.data != null) {
|
|
111
|
+
writer.uint32(18)
|
|
112
|
+
writer.bytes(obj.data)
|
|
113
|
+
} else {
|
|
114
|
+
throw new Error('Protocol error: required field "data" was not found in object')
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (opts.lengthDelimited !== false) {
|
|
118
|
+
writer.ldelim()
|
|
119
|
+
}
|
|
120
|
+
}, (reader, length) => {
|
|
121
|
+
const obj: any = {}
|
|
122
|
+
|
|
123
|
+
const end = length == null ? reader.len : reader.pos + length
|
|
124
|
+
|
|
125
|
+
while (reader.pos < end) {
|
|
126
|
+
const tag = reader.uint32()
|
|
127
|
+
|
|
128
|
+
switch (tag >>> 3) {
|
|
129
|
+
case 1:
|
|
130
|
+
obj.status = FetchResponse.StatusCode.codec().decode(reader)
|
|
131
|
+
break
|
|
132
|
+
case 2:
|
|
133
|
+
obj.data = reader.bytes()
|
|
134
|
+
break
|
|
135
|
+
default:
|
|
136
|
+
reader.skipType(tag & 7)
|
|
137
|
+
break
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (obj.status == null) {
|
|
142
|
+
throw new Error('Protocol error: value for required field "status" was not found in protobuf')
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (obj.data == null) {
|
|
146
|
+
throw new Error('Protocol error: value for required field "data" was not found in protobuf')
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return obj
|
|
150
|
+
})
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return _codec
|
|
56
154
|
}
|
|
57
155
|
|
|
58
156
|
export const encode = (obj: FetchResponse): Uint8Array => {
|
|
59
157
|
return encodeMessage(obj, FetchResponse.codec())
|
|
60
158
|
}
|
|
61
159
|
|
|
62
|
-
export const decode = (buf: Uint8Array): FetchResponse => {
|
|
160
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): FetchResponse => {
|
|
63
161
|
return decodeMessage(buf, FetchResponse.codec())
|
|
64
162
|
}
|
|
65
163
|
}
|
package/src/identify/index.ts
CHANGED
|
@@ -26,7 +26,6 @@ import type { Components } from '@libp2p/components'
|
|
|
26
26
|
import { TimeoutController } from 'timeout-abort-controller'
|
|
27
27
|
import type { AbortOptions } from '@libp2p/interfaces'
|
|
28
28
|
import { abortableDuplex } from 'abortable-iterator'
|
|
29
|
-
import type { Duplex } from 'it-stream-types'
|
|
30
29
|
import { setMaxListeners } from 'events'
|
|
31
30
|
|
|
32
31
|
const log = logger('libp2p:identify')
|
|
@@ -179,7 +178,7 @@ export class IdentifyService implements Startable {
|
|
|
179
178
|
})
|
|
180
179
|
|
|
181
180
|
// make stream abortable
|
|
182
|
-
const source
|
|
181
|
+
const source = abortableDuplex(stream, timeoutController.signal)
|
|
183
182
|
|
|
184
183
|
await pipe(
|
|
185
184
|
[Identify.encode({
|
|
@@ -404,7 +403,7 @@ export class IdentifyService implements Startable {
|
|
|
404
403
|
|
|
405
404
|
const envelope = await RecordEnvelope.seal(peerRecord, this.components.getPeerId())
|
|
406
405
|
await this.components.getPeerStore().addressBook.consumePeerRecord(envelope)
|
|
407
|
-
signedPeerRecord = envelope.marshal()
|
|
406
|
+
signedPeerRecord = envelope.marshal().subarray()
|
|
408
407
|
}
|
|
409
408
|
|
|
410
409
|
const message = Identify.encode({
|
|
@@ -418,7 +417,7 @@ export class IdentifyService implements Startable {
|
|
|
418
417
|
})
|
|
419
418
|
|
|
420
419
|
// make stream abortable
|
|
421
|
-
const source
|
|
420
|
+
const source = abortableDuplex(stream, timeoutController.signal)
|
|
422
421
|
|
|
423
422
|
await pipe(
|
|
424
423
|
[message],
|
|
@@ -449,7 +448,7 @@ export class IdentifyService implements Startable {
|
|
|
449
448
|
let message: Identify | undefined
|
|
450
449
|
try {
|
|
451
450
|
// make stream abortable
|
|
452
|
-
const source
|
|
451
|
+
const source = abortableDuplex(stream, timeoutController.signal)
|
|
453
452
|
|
|
454
453
|
const data = await pipe(
|
|
455
454
|
[],
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/* eslint-disable import/export */
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-namespace */
|
|
3
3
|
|
|
4
|
-
import { encodeMessage, decodeMessage, message
|
|
4
|
+
import { encodeMessage, decodeMessage, message } from 'protons-runtime'
|
|
5
|
+
import type { Uint8ArrayList } from 'uint8arraylist'
|
|
5
6
|
import type { Codec } from 'protons-runtime'
|
|
6
7
|
|
|
7
8
|
export interface Identify {
|
|
@@ -15,23 +16,122 @@ export interface Identify {
|
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
export namespace Identify {
|
|
19
|
+
let _codec: Codec<Identify>
|
|
20
|
+
|
|
18
21
|
export const codec = (): Codec<Identify> => {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
if (_codec == null) {
|
|
23
|
+
_codec = message<Identify>((obj, writer, opts = {}) => {
|
|
24
|
+
if (opts.lengthDelimited !== false) {
|
|
25
|
+
writer.fork()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (obj.protocolVersion != null) {
|
|
29
|
+
writer.uint32(42)
|
|
30
|
+
writer.string(obj.protocolVersion)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (obj.agentVersion != null) {
|
|
34
|
+
writer.uint32(50)
|
|
35
|
+
writer.string(obj.agentVersion)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (obj.publicKey != null) {
|
|
39
|
+
writer.uint32(10)
|
|
40
|
+
writer.bytes(obj.publicKey)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (obj.listenAddrs != null) {
|
|
44
|
+
for (const value of obj.listenAddrs) {
|
|
45
|
+
writer.uint32(18)
|
|
46
|
+
writer.bytes(value)
|
|
47
|
+
}
|
|
48
|
+
} else {
|
|
49
|
+
throw new Error('Protocol error: required field "listenAddrs" was not found in object')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (obj.observedAddr != null) {
|
|
53
|
+
writer.uint32(34)
|
|
54
|
+
writer.bytes(obj.observedAddr)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (obj.protocols != null) {
|
|
58
|
+
for (const value of obj.protocols) {
|
|
59
|
+
writer.uint32(26)
|
|
60
|
+
writer.string(value)
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
throw new Error('Protocol error: required field "protocols" was not found in object')
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (obj.signedPeerRecord != null) {
|
|
67
|
+
writer.uint32(66)
|
|
68
|
+
writer.bytes(obj.signedPeerRecord)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (opts.lengthDelimited !== false) {
|
|
72
|
+
writer.ldelim()
|
|
73
|
+
}
|
|
74
|
+
}, (reader, length) => {
|
|
75
|
+
const obj: any = {}
|
|
76
|
+
|
|
77
|
+
const end = length == null ? reader.len : reader.pos + length
|
|
78
|
+
|
|
79
|
+
while (reader.pos < end) {
|
|
80
|
+
const tag = reader.uint32()
|
|
81
|
+
|
|
82
|
+
switch (tag >>> 3) {
|
|
83
|
+
case 5:
|
|
84
|
+
obj.protocolVersion = reader.string()
|
|
85
|
+
break
|
|
86
|
+
case 6:
|
|
87
|
+
obj.agentVersion = reader.string()
|
|
88
|
+
break
|
|
89
|
+
case 1:
|
|
90
|
+
obj.publicKey = reader.bytes()
|
|
91
|
+
break
|
|
92
|
+
case 2:
|
|
93
|
+
obj.listenAddrs = obj.listenAddrs ?? []
|
|
94
|
+
obj.listenAddrs.push(reader.bytes())
|
|
95
|
+
break
|
|
96
|
+
case 4:
|
|
97
|
+
obj.observedAddr = reader.bytes()
|
|
98
|
+
break
|
|
99
|
+
case 3:
|
|
100
|
+
obj.protocols = obj.protocols ?? []
|
|
101
|
+
obj.protocols.push(reader.string())
|
|
102
|
+
break
|
|
103
|
+
case 8:
|
|
104
|
+
obj.signedPeerRecord = reader.bytes()
|
|
105
|
+
break
|
|
106
|
+
default:
|
|
107
|
+
reader.skipType(tag & 7)
|
|
108
|
+
break
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
obj.listenAddrs = obj.listenAddrs ?? []
|
|
113
|
+
obj.protocols = obj.protocols ?? []
|
|
114
|
+
|
|
115
|
+
if (obj.listenAddrs == null) {
|
|
116
|
+
throw new Error('Protocol error: value for required field "listenAddrs" was not found in protobuf')
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
if (obj.protocols == null) {
|
|
120
|
+
throw new Error('Protocol error: value for required field "protocols" was not found in protobuf')
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return obj
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return _codec
|
|
28
128
|
}
|
|
29
129
|
|
|
30
130
|
export const encode = (obj: Identify): Uint8Array => {
|
|
31
131
|
return encodeMessage(obj, Identify.codec())
|
|
32
132
|
}
|
|
33
133
|
|
|
34
|
-
export const decode = (buf: Uint8Array): Identify => {
|
|
134
|
+
export const decode = (buf: Uint8Array | Uint8ArrayList): Identify => {
|
|
35
135
|
return decodeMessage(buf, Identify.codec())
|
|
36
136
|
}
|
|
37
137
|
}
|
package/src/insecure/index.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { PeerId } from '@libp2p/interface-peer-id'
|
|
|
7
7
|
import { peerIdFromBytes, peerIdFromKeys } from '@libp2p/peer-id'
|
|
8
8
|
import type { ConnectionEncrypter, SecuredConnection } from '@libp2p/interface-connection-encrypter'
|
|
9
9
|
import type { Duplex } from 'it-stream-types'
|
|
10
|
+
import map from 'it-map'
|
|
10
11
|
|
|
11
12
|
const log = logger('libp2p:plaintext')
|
|
12
13
|
const PROTOCOL = '/plaintext/2.0.0'
|
|
@@ -39,7 +40,7 @@ async function encrypt (localId: PeerId, conn: Duplex<Uint8Array>, remoteId?: Pe
|
|
|
39
40
|
Type: type,
|
|
40
41
|
Data: localId.publicKey ?? new Uint8Array(0)
|
|
41
42
|
}
|
|
42
|
-
}).
|
|
43
|
+
}).subarray()
|
|
43
44
|
)
|
|
44
45
|
|
|
45
46
|
log('write pubkey exchange to peer %p', remoteId)
|
|
@@ -47,7 +48,7 @@ async function encrypt (localId: PeerId, conn: Duplex<Uint8Array>, remoteId?: Pe
|
|
|
47
48
|
// Get the Exchange message
|
|
48
49
|
// @ts-expect-error needs to be generator
|
|
49
50
|
const response = (await lp.decode.fromReader(shake.reader).next()).value
|
|
50
|
-
const id = Exchange.decode(response
|
|
51
|
+
const id = Exchange.decode(response)
|
|
51
52
|
log('read pubkey exchange from peer %p', remoteId)
|
|
52
53
|
|
|
53
54
|
let peerId
|
|
@@ -81,8 +82,12 @@ async function encrypt (localId: PeerId, conn: Duplex<Uint8Array>, remoteId?: Pe
|
|
|
81
82
|
log('plaintext key exchange completed successfully with peer %p', peerId)
|
|
82
83
|
|
|
83
84
|
shake.rest()
|
|
85
|
+
|
|
84
86
|
return {
|
|
85
|
-
conn:
|
|
87
|
+
conn: {
|
|
88
|
+
sink: shake.stream.sink,
|
|
89
|
+
source: map(shake.stream.source, (buf) => buf.subarray())
|
|
90
|
+
},
|
|
86
91
|
remotePeer: peerId,
|
|
87
92
|
remoteEarlyData: new Uint8Array()
|
|
88
93
|
}
|