@leofcoin/peernet 0.8.7 → 0.8.11

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.
@@ -0,0 +1,459 @@
1
+ TN:
2
+ SF:dist\commonjs\codec-format-interface.js
3
+ FN:11,_interopDefaultLegacy
4
+ FN:23,(anonymous_1)
5
+ FN:49,(anonymous_2)
6
+ FN:56,(anonymous_3)
7
+ FN:65,(anonymous_4)
8
+ FN:77,(anonymous_5)
9
+ FN:87,(anonymous_6)
10
+ FN:97,(anonymous_7)
11
+ FN:105,(anonymous_8)
12
+ FN:113,(anonymous_9)
13
+ FN:121,(anonymous_10)
14
+ FN:129,(anonymous_11)
15
+ FN:137,(anonymous_12)
16
+ FN:145,(anonymous_13)
17
+ FNF:14
18
+ FNH:9
19
+ FNDA:3,_interopDefaultLegacy
20
+ FNDA:3,(anonymous_1)
21
+ FNDA:5,(anonymous_2)
22
+ FNDA:5,(anonymous_3)
23
+ FNDA:2,(anonymous_4)
24
+ FNDA:1,(anonymous_5)
25
+ FNDA:1,(anonymous_6)
26
+ FNDA:0,(anonymous_7)
27
+ FNDA:1,(anonymous_8)
28
+ FNDA:0,(anonymous_9)
29
+ FNDA:0,(anonymous_10)
30
+ FNDA:0,(anonymous_11)
31
+ FNDA:0,(anonymous_12)
32
+ FNDA:1,(anonymous_13)
33
+ DA:3,1
34
+ DA:4,1
35
+ DA:5,1
36
+ DA:6,1
37
+ DA:7,1
38
+ DA:8,1
39
+ DA:9,1
40
+ DA:11,3
41
+ DA:13,1
42
+ DA:14,1
43
+ DA:15,1
44
+ DA:24,3
45
+ DA:25,3
46
+ DA:26,3
47
+ DA:27,3
48
+ DA:28,3
49
+ DA:29,1
50
+ DA:30,1
51
+ DA:31,1
52
+ DA:33,0
53
+ DA:36,2
54
+ DA:37,1
55
+ DA:38,1
56
+ DA:39,0
57
+ DA:40,1
58
+ DA:41,1
59
+ DA:50,5
60
+ DA:57,5
61
+ DA:58,5
62
+ DA:59,5
63
+ DA:66,2
64
+ DA:67,2
65
+ DA:68,2
66
+ DA:69,2
67
+ DA:70,2
68
+ DA:71,2
69
+ DA:78,1
70
+ DA:79,1
71
+ DA:80,1
72
+ DA:81,1
73
+ DA:88,1
74
+ DA:89,1
75
+ DA:90,1
76
+ DA:91,1
77
+ DA:98,0
78
+ DA:99,0
79
+ DA:106,1
80
+ DA:107,1
81
+ DA:114,0
82
+ DA:115,0
83
+ DA:122,0
84
+ DA:123,0
85
+ DA:130,0
86
+ DA:131,0
87
+ DA:138,0
88
+ DA:139,0
89
+ DA:146,1
90
+ DA:147,1
91
+ DA:151,1
92
+ LF:59
93
+ LH:47
94
+ BRDA:11,0,0,0
95
+ BRDA:11,0,1,3
96
+ BRDA:11,1,0,3
97
+ BRDA:11,1,1,3
98
+ BRDA:11,1,2,2
99
+ BRDA:23,2,0,0
100
+ BRDA:26,3,0,3
101
+ BRDA:26,3,1,0
102
+ BRDA:27,4,0,3
103
+ BRDA:27,4,1,3
104
+ BRDA:28,5,0,1
105
+ BRDA:28,5,1,2
106
+ BRDA:30,6,0,1
107
+ BRDA:30,6,1,0
108
+ BRDA:36,7,0,1
109
+ BRDA:36,7,1,1
110
+ BRDA:37,8,0,0
111
+ BRDA:37,8,1,1
112
+ BRDA:38,9,0,1
113
+ BRDA:38,9,1,0
114
+ BRDA:40,10,0,1
115
+ BRDA:40,10,1,0
116
+ BRDA:40,11,0,1
117
+ BRDA:40,11,1,1
118
+ BRDA:78,12,0,0
119
+ BRDA:78,12,1,1
120
+ BRDA:122,13,0,0
121
+ BRDA:122,13,1,0
122
+ BRDA:130,14,0,0
123
+ BRDA:130,14,1,0
124
+ BRDA:138,15,0,0
125
+ BRDA:138,15,1,0
126
+ BRF:32
127
+ BRH:18
128
+ end_of_record
129
+ TN:
130
+ SF:dist\commonjs\codec.js
131
+ FN:8,_interopDefaultLegacy
132
+ FN:91,(anonymous_1)
133
+ FN:94,(anonymous_2)
134
+ FN:118,(anonymous_3)
135
+ FN:126,(anonymous_4)
136
+ FN:131,(anonymous_5)
137
+ FN:136,(anonymous_6)
138
+ FN:141,(anonymous_7)
139
+ FN:145,(anonymous_8)
140
+ FN:146,(anonymous_9)
141
+ FN:152,(anonymous_10)
142
+ FN:156,(anonymous_11)
143
+ FN:164,(anonymous_12)
144
+ FN:172,(anonymous_13)
145
+ FN:177,(anonymous_14)
146
+ FN:182,(anonymous_15)
147
+ FN:186,(anonymous_16)
148
+ FN:192,(anonymous_17)
149
+ FNF:18
150
+ FNH:13
151
+ FNDA:4,_interopDefaultLegacy
152
+ FNDA:623,(anonymous_1)
153
+ FNDA:20,(anonymous_2)
154
+ FNDA:0,(anonymous_3)
155
+ FNDA:2,(anonymous_4)
156
+ FNDA:5,(anonymous_5)
157
+ FNDA:0,(anonymous_6)
158
+ FNDA:550,(anonymous_7)
159
+ FNDA:35,(anonymous_8)
160
+ FNDA:525,(anonymous_9)
161
+ FNDA:25,(anonymous_10)
162
+ FNDA:14,(anonymous_11)
163
+ FNDA:11,(anonymous_12)
164
+ FNDA:0,(anonymous_13)
165
+ FNDA:0,(anonymous_14)
166
+ FNDA:0,(anonymous_15)
167
+ FNDA:14,(anonymous_16)
168
+ FNDA:5,(anonymous_17)
169
+ DA:3,1
170
+ DA:4,1
171
+ DA:5,1
172
+ DA:6,1
173
+ DA:8,4
174
+ DA:10,1
175
+ DA:11,1
176
+ DA:12,1
177
+ DA:13,1
178
+ DA:15,1
179
+ DA:92,623
180
+ DA:95,20
181
+ DA:96,20
182
+ DA:97,7
183
+ DA:98,7
184
+ DA:100,7
185
+ DA:101,7
186
+ DA:102,7
187
+ DA:103,7
188
+ DA:105,0
189
+ DA:108,20
190
+ DA:109,13
191
+ DA:110,7
192
+ DA:111,5
193
+ DA:112,0
194
+ DA:114,20
195
+ DA:119,0
196
+ DA:120,0
197
+ DA:121,0
198
+ DA:122,0
199
+ DA:123,0
200
+ DA:127,2
201
+ DA:128,2
202
+ DA:132,5
203
+ DA:133,5
204
+ DA:137,0
205
+ DA:138,0
206
+ DA:142,550
207
+ DA:146,35
208
+ DA:147,525
209
+ DA:148,490
210
+ DA:153,25
211
+ DA:157,14
212
+ DA:158,14
213
+ DA:160,14
214
+ DA:161,14
215
+ DA:165,11
216
+ DA:166,11
217
+ DA:167,11
218
+ DA:168,11
219
+ DA:169,11
220
+ DA:173,0
221
+ DA:174,0
222
+ DA:178,0
223
+ DA:179,0
224
+ DA:183,0
225
+ DA:187,14
226
+ DA:188,14
227
+ DA:189,14
228
+ DA:193,5
229
+ DA:194,5
230
+ DA:195,5
231
+ DA:199,1
232
+ LF:63
233
+ LH:49
234
+ BRDA:8,0,0,0
235
+ BRDA:8,0,1,4
236
+ BRDA:8,1,0,4
237
+ BRDA:8,1,1,4
238
+ BRDA:8,1,2,3
239
+ BRDA:95,2,0,20
240
+ BRDA:95,2,1,0
241
+ BRDA:96,3,0,7
242
+ BRDA:96,3,1,13
243
+ BRDA:100,4,0,7
244
+ BRDA:100,4,1,0
245
+ BRDA:108,5,0,13
246
+ BRDA:108,5,1,7
247
+ BRDA:109,6,0,6
248
+ BRDA:109,6,1,7
249
+ BRDA:110,7,0,2
250
+ BRDA:110,7,1,5
251
+ BRDA:111,8,0,5
252
+ BRDA:111,8,1,0
253
+ BRDA:114,9,0,0
254
+ BRDA:114,9,1,20
255
+ BRDA:114,10,0,0
256
+ BRDA:114,10,1,0
257
+ BRDA:147,11,0,35
258
+ BRDA:147,11,1,490
259
+ BRF:25
260
+ BRH:18
261
+ end_of_record
262
+ TN:
263
+ SF:dist\commonjs\dht-response.js
264
+ FN:13,_interopDefaultLegacy
265
+ FN:26,(anonymous_1)
266
+ FN:30,(anonymous_2)
267
+ FNF:3
268
+ FNH:2
269
+ FNDA:1,_interopDefaultLegacy
270
+ FNDA:0,(anonymous_1)
271
+ FNDA:3,(anonymous_2)
272
+ DA:3,1
273
+ DA:4,1
274
+ DA:5,1
275
+ DA:6,1
276
+ DA:7,1
277
+ DA:8,1
278
+ DA:9,1
279
+ DA:10,1
280
+ DA:11,1
281
+ DA:13,1
282
+ DA:15,1
283
+ DA:17,1
284
+ DA:27,0
285
+ DA:31,3
286
+ DA:32,3
287
+ DA:36,1
288
+ LF:16
289
+ LH:15
290
+ BRDA:13,0,0,0
291
+ BRDA:13,0,1,1
292
+ BRDA:13,1,0,1
293
+ BRDA:13,1,1,1
294
+ BRDA:13,1,2,0
295
+ BRF:5
296
+ BRH:3
297
+ end_of_record
298
+ TN:
299
+ SF:dist\commonjs\hash.js
300
+ FN:10,_interopDefaultLegacy
301
+ FN:19,(anonymous_1)
302
+ FN:44,(anonymous_2)
303
+ FN:48,(anonymous_3)
304
+ FN:52,(anonymous_4)
305
+ FN:56,(anonymous_5)
306
+ FN:60,(anonymous_6)
307
+ FN:64,(anonymous_7)
308
+ FN:68,(anonymous_8)
309
+ FN:72,(anonymous_9)
310
+ FN:76,(anonymous_10)
311
+ FN:80,(anonymous_11)
312
+ FN:84,(anonymous_12)
313
+ FN:88,(anonymous_13)
314
+ FN:111,(anonymous_14)
315
+ FN:127,(anonymous_15)
316
+ FNF:16
317
+ FNH:7
318
+ FNDA:5,_interopDefaultLegacy
319
+ FNDA:5,(anonymous_1)
320
+ FNDA:5,(anonymous_2)
321
+ FNDA:5,(anonymous_3)
322
+ FNDA:0,(anonymous_4)
323
+ FNDA:0,(anonymous_5)
324
+ FNDA:0,(anonymous_6)
325
+ FNDA:5,(anonymous_7)
326
+ FNDA:5,(anonymous_8)
327
+ FNDA:0,(anonymous_9)
328
+ FNDA:0,(anonymous_10)
329
+ FNDA:0,(anonymous_11)
330
+ FNDA:0,(anonymous_12)
331
+ FNDA:5,(anonymous_13)
332
+ FNDA:0,(anonymous_14)
333
+ FNDA:0,(anonymous_15)
334
+ DA:3,1
335
+ DA:4,1
336
+ DA:5,1
337
+ DA:6,1
338
+ DA:7,1
339
+ DA:8,1
340
+ DA:10,5
341
+ DA:12,1
342
+ DA:13,1
343
+ DA:14,1
344
+ DA:15,1
345
+ DA:16,1
346
+ DA:20,5
347
+ DA:21,0
348
+ DA:22,5
349
+ DA:23,5
350
+ DA:24,5
351
+ DA:25,0
352
+ DA:26,0
353
+ DA:28,0
354
+ DA:29,0
355
+ DA:30,0
356
+ DA:32,0
357
+ DA:36,5
358
+ DA:37,0
359
+ DA:38,0
360
+ DA:39,0
361
+ DA:40,5
362
+ DA:45,5
363
+ DA:49,5
364
+ DA:53,0
365
+ DA:57,0
366
+ DA:61,0
367
+ DA:65,5
368
+ DA:69,5
369
+ DA:73,0
370
+ DA:77,0
371
+ DA:81,0
372
+ DA:85,0
373
+ DA:89,5
374
+ DA:90,5
375
+ DA:91,5
376
+ DA:92,5
377
+ DA:93,5
378
+ DA:94,5
379
+ DA:95,0
380
+ DA:96,0
381
+ DA:98,5
382
+ DA:99,5
383
+ DA:101,5
384
+ DA:102,5
385
+ DA:103,5
386
+ DA:108,5
387
+ DA:112,0
388
+ DA:113,0
389
+ DA:114,0
390
+ DA:115,0
391
+ DA:117,0
392
+ DA:120,0
393
+ DA:121,0
394
+ DA:122,0
395
+ DA:124,0
396
+ DA:128,0
397
+ DA:129,0
398
+ DA:131,0
399
+ DA:133,0
400
+ DA:134,0
401
+ DA:135,0
402
+ DA:136,0
403
+ DA:137,0
404
+ DA:142,0
405
+ DA:145,0
406
+ DA:147,0
407
+ DA:157,1
408
+ LF:74
409
+ LH:35
410
+ BRDA:10,0,0,0
411
+ BRDA:10,0,1,5
412
+ BRDA:10,1,0,5
413
+ BRDA:10,1,1,5
414
+ BRDA:10,1,2,3
415
+ BRDA:19,2,0,0
416
+ BRDA:20,3,0,5
417
+ BRDA:20,3,1,0
418
+ BRDA:22,4,0,0
419
+ BRDA:22,4,1,5
420
+ BRDA:23,5,0,5
421
+ BRDA:23,5,1,0
422
+ BRDA:24,6,0,0
423
+ BRDA:24,6,1,5
424
+ BRDA:28,7,0,0
425
+ BRDA:28,7,1,0
426
+ BRDA:36,8,0,0
427
+ BRDA:36,8,1,5
428
+ BRDA:37,9,0,0
429
+ BRDA:37,9,1,0
430
+ BRDA:38,10,0,0
431
+ BRDA:38,10,1,0
432
+ BRDA:40,11,0,5
433
+ BRDA:40,11,1,0
434
+ BRDA:84,12,0,0
435
+ BRDA:89,13,0,0
436
+ BRDA:89,13,1,5
437
+ BRDA:89,14,0,5
438
+ BRDA:89,14,1,0
439
+ BRDA:90,15,0,0
440
+ BRDA:90,15,1,5
441
+ BRDA:94,16,0,0
442
+ BRDA:94,16,1,5
443
+ BRDA:112,17,0,0
444
+ BRDA:112,17,1,0
445
+ BRDA:114,18,0,0
446
+ BRDA:114,18,1,0
447
+ BRDA:120,19,0,0
448
+ BRDA:120,19,1,0
449
+ BRDA:121,20,0,0
450
+ BRDA:121,20,1,0
451
+ BRDA:122,21,0,0
452
+ BRDA:122,21,1,0
453
+ BRDA:124,22,0,0
454
+ BRDA:124,22,1,0
455
+ BRDA:136,23,0,0
456
+ BRDA:136,23,1,0
457
+ BRF:47
458
+ BRH:14
459
+ end_of_record
@@ -86,10 +86,11 @@ globalThis.pubsub = globalThis.pubsub || new PubSub__default['default']({verbose
86
86
  class PeernetClient {
87
87
  constructor(options = {}) {
88
88
  if (!options.id) options.id = Buffer.from('00000000000000000000000000000000');
89
-
89
+ if (!options.networkVersion) options.networkVersion = 'v0.1.0';
90
+ if (!options.networkName) options.networkName = 'peernet';
90
91
  this.id = options.id;
91
92
 
92
- this.topic = Buffer.from(sha256__default['default']('peernet-v0.1.0').toString());
93
+ this.topic = Buffer.from(sha256__default['default'](`${options.networkName}-${options.networkVersion}`).toString());
93
94
 
94
95
  const trackers = [
95
96
  'wss://star.leofcoin.org:7575',
@@ -111,71 +112,6 @@ class PeernetClient {
111
112
 
112
113
  this.p2p.start();
113
114
 
114
-
115
- // this.sw.join(this.topic.slice(0, 32))
116
- //
117
- // const arrayOfPeers = this.sw.getPeers()
118
- //
119
- // this.sw.on('connection', async (connection, info) => {
120
- // // connected
121
- // const id = info.id.toString()
122
- // if (id === this.id.toString()) return
123
- //
124
- // const channel = connection.channelName
125
- // let channels = [channel]
126
- // let peer
127
- // if (connections.has(id)) {
128
- // const value = connections.get(id)
129
- // const _channels = value.channels
130
- // channels = [...channels, ..._channels]
131
- // peer = value.peer
132
- // } else {
133
- // peer = new PeernetPeer(id, connection)
134
- // pubsub.publish('peer:connected', peer)
135
- // }
136
- // connections.set(id, {channels, peer})
137
- // // connection.on('data', (data) => console.log({data}))
138
- // // connection.write('peerId')
139
- // });
140
- //
141
- // this.sw.on('candidates-updated', async (channel, candidates) => {
142
- // // TODO: Channels ...
143
- // for (const candidate of candidates) {
144
- // const id = candidate.toString()
145
- // let channels = [channel]
146
- // if (id === this.id.toString()) return
147
- //
148
- // if (!connections.has(id)) {
149
- // try {
150
- // const connection = await this.sw.connect(channel, candidate)
151
- // const peer = new PeernetPeer(id, connection)
152
- // connections.set(id, {channels, peer})
153
- // if (recentConnections.has(id)) {
154
- // setTimeout(() => {
155
- // pubsub.publish('peer:connected', peer)
156
- // }, 1000)
157
- // } else {
158
- // pubsub.publish('peer:connected', peer)
159
- // }
160
- // } catch (e) {
161
- // console.warn(e);
162
- // }
163
- // } else {
164
- // const value = connections.get(id)
165
- // const _channels = value.channels
166
- // channels = [...channels, ..._channels]
167
- // connections.set(id, {channels, peer: value.peer})
168
- // }
169
- // }
170
- // })
171
- //
172
- // this.sw.on('connection-closed', (connection, info) => {
173
- // if (!recentConnections.has(info.id.toString())) {
174
- // recentConnections.set(info.id.toString(), new Date().getTime())
175
- // }
176
- // if (connections.has(info.id.toString())) connections.delete(info.id.toString())
177
- // })
178
- //
179
115
  if (globalThis.process) {
180
116
  process.on('SIGINT', async () => {
181
117
  console.log('Caught interrupt signal');
@@ -325,7 +261,7 @@ class LeofcoinStorage$1 {
325
261
 
326
262
  }
327
263
 
328
- var version = "0.8.6";
264
+ var version = "0.8.10";
329
265
 
330
266
  var api$1 = {
331
267
  version: ({send}) => send({client: '@peernet/api/http', version}),
@@ -1729,14 +1665,10 @@ class PeerDiscovery {
1729
1665
  const connections = peernet.peerMap.get(id);
1730
1666
  if (connections.indexOf(peer.id) === -1) {
1731
1667
  connections.push(peer.id);
1732
- peernet.peerMap.set(id, connections);
1668
+ peernet.peerMap.set(from, connections);
1733
1669
  }
1734
1670
  }
1735
- return {peer, id}
1736
- }
1737
-
1738
- async _cleanedUpIfNeeded() {
1739
-
1671
+ return id
1740
1672
  }
1741
1673
 
1742
1674
  async discoverHandler(message, peer) {
@@ -2095,8 +2027,14 @@ class Peernet {
2095
2027
  * @property {Object} peer Instance of Peer
2096
2028
  */
2097
2029
  this.dht = new DhtEarth();
2030
+ /**
2031
+ * @type {Map}
2032
+ * @property {Object} peer Instance of Peer
2033
+ */
2098
2034
  this.peerMap = new Map();
2099
2035
  this.stores = [];
2036
+ this.storePrefix = options.storePrefix;
2037
+ this.root = options.root;
2100
2038
 
2101
2039
  /**
2102
2040
  * proto Object containing protos
@@ -2123,7 +2061,6 @@ class Peernet {
2123
2061
 
2124
2062
  this._messageHandler = new MessageHandler(this.network);
2125
2063
 
2126
-
2127
2064
  const {daemon, environment} = await target();
2128
2065
  this.hasDaemon = daemon;
2129
2066
 
@@ -2165,15 +2102,11 @@ class Peernet {
2165
2102
 
2166
2103
  pubsub.subscribe('peer:discovered', async (peer) => {
2167
2104
  this._peerHandler.discover(peer);
2168
-
2169
2105
  peer.on('peernet.data', async (message) => {
2170
2106
  const id = message.id;
2171
- message = new peernet.protos['peernet-message'](Buffer.from(message.data.data));
2172
- console.log(message);
2173
- // message = new PeernetMessage(Buffer.from(message.data.data))
2107
+ message = new PeernetMessage(Buffer.from(message.data.data));
2174
2108
  const proto = protoFor(message.decoded.data);
2175
2109
  await this._protoHandler({id, proto}, peer);
2176
-
2177
2110
  const fulldId = this._getPeerId(peer.id);
2178
2111
  if (fulldId && this._discovered.indexOf(peer.id) === -1) {
2179
2112
  this._discovered.push(peer.id);
@@ -2181,7 +2114,6 @@ class Peernet {
2181
2114
  }
2182
2115
  });
2183
2116
  });
2184
-
2185
2117
  pubsub.subscribe('peer:disconnected', async (peer) => {
2186
2118
  let index = this._discovered.indexOf(peer.id);
2187
2119
  if (index !== -1) this._discovered.splice(index, 1);
@@ -2242,40 +2174,40 @@ class Peernet {
2242
2174
  this.peerMap.set(from, connections);
2243
2175
  }
2244
2176
  }
2245
- const data = new peernet.protos['peernet-peer-response']({id: this.id});
2246
- const node = await this.prepareMessage(peer.id, data.encoded);
2177
+ const data = new PeerMessageResponse({id: this.id});
2178
+ const node = await this.prepareMessage(from, data.encoded);
2247
2179
 
2248
2180
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2249
- // } else if (proto.name === 'peernet-peer-response') {
2250
- // const from = proto.decoded.id
2251
- // if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id])
2252
- // else {
2253
- // const connections = this.peerMap.get(from)
2254
- // if (connections.indexOf(peer.id) === -1) {
2255
- // connections.push(peer.id)
2256
- // this.peerMap.set(from, connections)
2257
- // }
2258
- // }
2181
+ } else if (proto.name === 'peernet-peer-response') {
2182
+ const from = proto.decoded.id;
2183
+ if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id]);
2184
+ else {
2185
+ const connections = this.peerMap.get(from);
2186
+ if (connections.indexOf(peer.id) === -1) {
2187
+ connections.push(peer.id);
2188
+ this.peerMap.set(from, connections);
2189
+ }
2190
+ }
2259
2191
  } else {
2260
- const from = this._getPeerId(peer.id);
2261
- // if (!from) {
2262
- // const data = new PeerMessage({id: this.id})
2263
- // const node = await this.prepareMessage(peer.id, data.encoded)
2264
- //
2265
- // let response = await peer.request(node.encoded)
2266
- // response = protoFor(response)
2267
- // response = new PeerMessageResponse(response.decoded.data)
2268
- //
2269
- // from = response.decoded.id
2270
- // if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id])
2271
- // else {
2272
- // const connections = this.peerMap.get(from)
2273
- // if (connections.indexOf(peer.id) === -1) {
2274
- // connections.push(peer.id)
2275
- // this.peerMap.set(from, connections)
2276
- // }
2277
- // }
2278
- // }
2192
+ let from = this._getPeerId(peer.id);
2193
+ if (!from) {
2194
+ const data = new PeerMessage({id: this.id});
2195
+ const node = await this.prepareMessage(peer.id, data.encoded);
2196
+
2197
+ let response = await peer.request(node.encoded);
2198
+ response = protoFor(response);
2199
+ response = new PeerMessageResponse(response.decoded.data);
2200
+
2201
+ from = response.decoded.id;
2202
+ if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id]);
2203
+ else {
2204
+ const connections = this.peerMap.get(from);
2205
+ if (connections.indexOf(peer.id) === -1) {
2206
+ connections.push(peer.id);
2207
+ this.peerMap.set(from, connections);
2208
+ }
2209
+ }
2210
+ }
2279
2211
  if (proto.name === 'peernet-dht') {
2280
2212
  let { hash, store } = proto.decoded;
2281
2213
  let has;
@@ -2311,6 +2243,18 @@ class Peernet {
2311
2243
  const node = await this.prepareMessage(from, data.encoded);
2312
2244
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2313
2245
  }
2246
+ } else if (proto.name === 'peernet-peer') {
2247
+ const from = proto.decoded.id;
2248
+ if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id]);
2249
+ else {
2250
+ const connections = this.peerMap.get(from);
2251
+ connections.push(peer.id);
2252
+ this.peerMap.set(from, connections);
2253
+ }
2254
+ const data = new PeerMessage({id: this.id});
2255
+ const node = await this.prepareMessage(from, data.encoded);
2256
+
2257
+ peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2314
2258
  } else if (proto.name === 'peernet-request') {
2315
2259
  // TODO: make dynamic
2316
2260
  // exposeddevapi[proto.decoded.request](proto.decoded.params)