@leofcoin/peernet 0.9.12 → 0.10.2

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.
@@ -33,10 +33,17 @@ var MultiWallet__default = /*#__PURE__*/_interopDefaultLegacy(MultiWallet);
33
33
  class PeernetPeer {
34
34
  constructor(id, connection) {
35
35
  this._events = {};
36
+ this.bw = {
37
+ up: 0,
38
+ down: 0,
39
+ };
36
40
  this.id = id;
37
41
  this.connection = connection;
38
42
 
39
- this.connection.on('data', (message) => pubsub.publish('peernet.data', JSON.parse(message.toString())));
43
+ this.connection.on('data', (message) => {
44
+ this.bw.down += message.length;
45
+ pubsub.publish('peernet.data', JSON.parse(message.toString()));
46
+ });
40
47
  }
41
48
 
42
49
  request(data) {
@@ -62,6 +69,8 @@ class PeernetPeer {
62
69
 
63
70
  write(data) {
64
71
  if (!Buffer.isBuffer(data)) data = Buffer.from(data);
72
+
73
+ this.bw.up += data.length;
65
74
  this.connection.write(data);
66
75
  }
67
76
 
@@ -280,7 +289,7 @@ class LeofcoinStorage$1 {
280
289
 
281
290
  }
282
291
 
283
- var version = "0.9.11";
292
+ var version = "0.10.1";
284
293
 
285
294
  var api$1 = {
286
295
  version: ({send}) => send({client: '@peernet/api/http', version}),
@@ -2007,6 +2016,10 @@ class Peernet {
2007
2016
  else options.root = `.${this.network}/peernet`;
2008
2017
  }
2009
2018
  globalThis.peernet = this;
2019
+ this.bw = {
2020
+ up: 0,
2021
+ down: 0
2022
+ };
2010
2023
  return this._init(options)
2011
2024
  }
2012
2025
 
@@ -2219,6 +2232,7 @@ class Peernet {
2219
2232
  */
2220
2233
  async _protoHandler(message, peer) {
2221
2234
  const {id, proto} = message;
2235
+ this.bw.down += message.encoded.length;
2222
2236
  if (proto.name === 'peernet-peer') {
2223
2237
  const from = proto.decoded.id;
2224
2238
  if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id]);
@@ -2233,6 +2247,7 @@ class Peernet {
2233
2247
  const node = await this.prepareMessage(from, data.encoded);
2234
2248
 
2235
2249
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2250
+ this.bw.up += node.encoded.length;
2236
2251
  } else if (proto.name === 'peernet-peer-response') {
2237
2252
  const from = proto.decoded.id;
2238
2253
  if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id]);
@@ -2248,9 +2263,10 @@ class Peernet {
2248
2263
  if (!from) {
2249
2264
  const data = new PeerMessage({id: this.id});
2250
2265
  const node = await this.prepareMessage(peer.id, data.encoded);
2251
-
2266
+ this.bw.up += node.encoded.length;
2252
2267
  let response = await peer.request(node.encoded);
2253
2268
  response = protoFor(response);
2269
+
2254
2270
  response = new PeerMessageResponse(response.decoded.data);
2255
2271
 
2256
2272
  from = response.decoded.id;
@@ -2278,6 +2294,7 @@ class Peernet {
2278
2294
  const node = await this.prepareMessage(from, data.encoded);
2279
2295
 
2280
2296
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2297
+ this.bw.up += node.encoded.length;
2281
2298
  } else if (proto.name === 'peernet-data') {
2282
2299
  let { hash, store } = proto.decoded;
2283
2300
  let data;
@@ -2297,6 +2314,7 @@ class Peernet {
2297
2314
 
2298
2315
  const node = await this.prepareMessage(from, data.encoded);
2299
2316
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2317
+ this.bw.up += node.encoded.length;
2300
2318
  }
2301
2319
  } else if (proto.name === 'peernet-peer') {
2302
2320
  const from = proto.decoded.id;
@@ -2310,6 +2328,7 @@ class Peernet {
2310
2328
  const node = await this.prepareMessage(from, data.encoded);
2311
2329
 
2312
2330
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2331
+ this.bw.up += node.encoded.length;
2313
2332
  } else if (proto.name === 'peernet-request') {
2314
2333
  // TODO: make dynamic
2315
2334
  // exposeddevapi[proto.decoded.request](proto.decoded.params)
@@ -2318,6 +2337,7 @@ class Peernet {
2318
2337
  const data = await method();
2319
2338
  const node = await this.prepareMessage(from, data.encoded);
2320
2339
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2340
+ this.bw.up += node.encoded.length;
2321
2341
  }
2322
2342
  } else if (proto.name === 'peernet-ps' &&
2323
2343
  this._getPeerId(peer.id) !== this.id.toString()) {
@@ -36,10 +36,17 @@ var MultiWallet__default = /*#__PURE__*/_interopDefaultLegacy(MultiWallet);
36
36
  class PeernetPeer {
37
37
  constructor(id, connection) {
38
38
  this._events = {};
39
+ this.bw = {
40
+ up: 0,
41
+ down: 0,
42
+ };
39
43
  this.id = id;
40
44
  this.connection = connection;
41
45
 
42
- this.connection.on('data', (message) => pubsub.publish('peernet.data', JSON.parse(message.toString())));
46
+ this.connection.on('data', (message) => {
47
+ this.bw.down += message.length;
48
+ pubsub.publish('peernet.data', JSON.parse(message.toString()));
49
+ });
43
50
  }
44
51
 
45
52
  request(data) {
@@ -65,6 +72,8 @@ class PeernetPeer {
65
72
 
66
73
  write(data) {
67
74
  if (!Buffer.isBuffer(data)) data = Buffer.from(data);
75
+
76
+ this.bw.up += data.length;
68
77
  this.connection.write(data);
69
78
  }
70
79
 
@@ -283,7 +292,7 @@ class LeofcoinStorage$1 {
283
292
 
284
293
  }
285
294
 
286
- var version = "0.9.11";
295
+ var version = "0.10.1";
287
296
 
288
297
  var api$1 = {
289
298
  version: ({send}) => send({client: '@peernet/api/http', version}),
@@ -1442,6 +1451,10 @@ class Peernet {
1442
1451
  else options.root = `.${this.network}/peernet`;
1443
1452
  }
1444
1453
  globalThis.peernet = this;
1454
+ this.bw = {
1455
+ up: 0,
1456
+ down: 0
1457
+ };
1445
1458
  return this._init(options)
1446
1459
  }
1447
1460
 
@@ -1654,6 +1667,7 @@ class Peernet {
1654
1667
  */
1655
1668
  async _protoHandler(message, peer) {
1656
1669
  const {id, proto} = message;
1670
+ this.bw.down += message.encoded.length;
1657
1671
  if (proto.name === 'peernet-peer') {
1658
1672
  const from = proto.decoded.id;
1659
1673
  if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id]);
@@ -1668,6 +1682,7 @@ class Peernet {
1668
1682
  const node = await this.prepareMessage(from, data.encoded);
1669
1683
 
1670
1684
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
1685
+ this.bw.up += node.encoded.length;
1671
1686
  } else if (proto.name === 'peernet-peer-response') {
1672
1687
  const from = proto.decoded.id;
1673
1688
  if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id]);
@@ -1683,9 +1698,10 @@ class Peernet {
1683
1698
  if (!from) {
1684
1699
  const data = new PeerMessage({id: this.id});
1685
1700
  const node = await this.prepareMessage(peer.id, data.encoded);
1686
-
1701
+ this.bw.up += node.encoded.length;
1687
1702
  let response = await peer.request(node.encoded);
1688
1703
  response = protoFor(response);
1704
+
1689
1705
  response = new PeerMessageResponse(response.decoded.data);
1690
1706
 
1691
1707
  from = response.decoded.id;
@@ -1713,6 +1729,7 @@ class Peernet {
1713
1729
  const node = await this.prepareMessage(from, data.encoded);
1714
1730
 
1715
1731
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
1732
+ this.bw.up += node.encoded.length;
1716
1733
  } else if (proto.name === 'peernet-data') {
1717
1734
  let { hash, store } = proto.decoded;
1718
1735
  let data;
@@ -1732,6 +1749,7 @@ class Peernet {
1732
1749
 
1733
1750
  const node = await this.prepareMessage(from, data.encoded);
1734
1751
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
1752
+ this.bw.up += node.encoded.length;
1735
1753
  }
1736
1754
  } else if (proto.name === 'peernet-peer') {
1737
1755
  const from = proto.decoded.id;
@@ -1745,6 +1763,7 @@ class Peernet {
1745
1763
  const node = await this.prepareMessage(from, data.encoded);
1746
1764
 
1747
1765
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
1766
+ this.bw.up += node.encoded.length;
1748
1767
  } else if (proto.name === 'peernet-request') {
1749
1768
  // TODO: make dynamic
1750
1769
  // exposeddevapi[proto.decoded.request](proto.decoded.params)
@@ -1753,6 +1772,7 @@ class Peernet {
1753
1772
  const data = await method();
1754
1773
  const node = await this.prepareMessage(from, data.encoded);
1755
1774
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
1775
+ this.bw.up += node.encoded.length;
1756
1776
  }
1757
1777
  } else if (proto.name === 'peernet-ps' &&
1758
1778
  this._getPeerId(peer.id) !== this.id.toString()) {
@@ -16,10 +16,17 @@ import MultiWallet from '@leofcoin/multi-wallet';
16
16
  class PeernetPeer {
17
17
  constructor(id, connection) {
18
18
  this._events = {};
19
+ this.bw = {
20
+ up: 0,
21
+ down: 0,
22
+ };
19
23
  this.id = id;
20
24
  this.connection = connection;
21
25
 
22
- this.connection.on('data', (message) => pubsub.publish('peernet.data', JSON.parse(message.toString())));
26
+ this.connection.on('data', (message) => {
27
+ this.bw.down += message.length;
28
+ pubsub.publish('peernet.data', JSON.parse(message.toString()));
29
+ });
23
30
  }
24
31
 
25
32
  request(data) {
@@ -45,6 +52,8 @@ class PeernetPeer {
45
52
 
46
53
  write(data) {
47
54
  if (!Buffer.isBuffer(data)) data = Buffer.from(data);
55
+
56
+ this.bw.up += data.length;
48
57
  this.connection.write(data);
49
58
  }
50
59
 
@@ -263,7 +272,7 @@ class LeofcoinStorage$1 {
263
272
 
264
273
  }
265
274
 
266
- var version = "0.9.11";
275
+ var version = "0.10.1";
267
276
 
268
277
  var api$1 = {
269
278
  version: ({send}) => send({client: '@peernet/api/http', version}),
@@ -1990,6 +1999,10 @@ class Peernet {
1990
1999
  else options.root = `.${this.network}/peernet`;
1991
2000
  }
1992
2001
  globalThis.peernet = this;
2002
+ this.bw = {
2003
+ up: 0,
2004
+ down: 0,
2005
+ };
1993
2006
  return this._init(options)
1994
2007
  }
1995
2008
 
@@ -2202,6 +2215,7 @@ class Peernet {
2202
2215
  */
2203
2216
  async _protoHandler(message, peer) {
2204
2217
  const {id, proto} = message;
2218
+ this.bw.down += message.encoded.length;
2205
2219
  if (proto.name === 'peernet-peer') {
2206
2220
  const from = proto.decoded.id;
2207
2221
  if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id]);
@@ -2216,6 +2230,7 @@ class Peernet {
2216
2230
  const node = await this.prepareMessage(from, data.encoded);
2217
2231
 
2218
2232
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2233
+ this.bw.up += node.encoded.length;
2219
2234
  } else if (proto.name === 'peernet-peer-response') {
2220
2235
  const from = proto.decoded.id;
2221
2236
  if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id]);
@@ -2231,9 +2246,10 @@ class Peernet {
2231
2246
  if (!from) {
2232
2247
  const data = new PeerMessage({id: this.id});
2233
2248
  const node = await this.prepareMessage(peer.id, data.encoded);
2234
-
2249
+ this.bw.up += node.encoded.length;
2235
2250
  let response = await peer.request(node.encoded);
2236
2251
  response = protoFor(response);
2252
+
2237
2253
  response = new PeerMessageResponse(response.decoded.data);
2238
2254
 
2239
2255
  from = response.decoded.id;
@@ -2261,6 +2277,7 @@ class Peernet {
2261
2277
  const node = await this.prepareMessage(from, data.encoded);
2262
2278
 
2263
2279
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2280
+ this.bw.up += node.encoded.length;
2264
2281
  } else if (proto.name === 'peernet-data') {
2265
2282
  let { hash, store } = proto.decoded;
2266
2283
  let data;
@@ -2280,6 +2297,7 @@ class Peernet {
2280
2297
 
2281
2298
  const node = await this.prepareMessage(from, data.encoded);
2282
2299
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2300
+ this.bw.up += node.encoded.length;
2283
2301
  }
2284
2302
  } else if (proto.name === 'peernet-peer') {
2285
2303
  const from = proto.decoded.id;
@@ -2293,6 +2311,7 @@ class Peernet {
2293
2311
  const node = await this.prepareMessage(from, data.encoded);
2294
2312
 
2295
2313
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2314
+ this.bw.up += node.encoded.length;
2296
2315
  } else if (proto.name === 'peernet-request') {
2297
2316
  // TODO: make dynamic
2298
2317
  // exposeddevapi[proto.decoded.request](proto.decoded.params)
@@ -2301,6 +2320,7 @@ class Peernet {
2301
2320
  const data = await method();
2302
2321
  const node = await this.prepareMessage(from, data.encoded);
2303
2322
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
2323
+ this.bw.up += node.encoded.length;
2304
2324
  }
2305
2325
  } else if (proto.name === 'peernet-ps' &&
2306
2326
  this._getPeerId(peer.id) !== this.id.toString()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leofcoin/peernet",
3
- "version": "0.9.12",
3
+ "version": "0.10.2",
4
4
  "description": "",
5
5
  "main": "dist/commonjs/peernet.js",
6
6
  "module": "dist/module/peernet.js",
package/src/peer.js CHANGED
@@ -1,10 +1,17 @@
1
1
  export default class PeernetPeer {
2
2
  constructor(id, connection) {
3
3
  this._events = {}
4
+ this.bw = {
5
+ up: 0,
6
+ down: 0,
7
+ }
4
8
  this.id = id
5
9
  this.connection = connection
6
10
 
7
- this.connection.on('data', (message) => pubsub.publish('peernet.data', JSON.parse(message.toString())))
11
+ this.connection.on('data', (message) => {
12
+ this.bw.down += message.length
13
+ pubsub.publish('peernet.data', JSON.parse(message.toString()))
14
+ })
8
15
  }
9
16
 
10
17
  request(data) {
@@ -30,6 +37,8 @@ export default class PeernetPeer {
30
37
 
31
38
  write(data) {
32
39
  if (!Buffer.isBuffer(data)) data = Buffer.from(data)
40
+
41
+ this.bw.up += data.length
33
42
  this.connection.write(data)
34
43
  }
35
44
 
package/src/peernet.js CHANGED
@@ -62,6 +62,10 @@ export default class Peernet {
62
62
  else options.root = `.${this.network}/peernet`
63
63
  }
64
64
  globalThis.peernet = this
65
+ this.bw = {
66
+ up: 0,
67
+ down: 0,
68
+ }
65
69
  return this._init(options)
66
70
  }
67
71
 
@@ -274,6 +278,7 @@ export default class Peernet {
274
278
  */
275
279
  async _protoHandler(message, peer) {
276
280
  const {id, proto} = message
281
+ this.bw.down += message.encoded.length
277
282
  if (proto.name === 'peernet-peer') {
278
283
  const from = proto.decoded.id
279
284
  if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id])
@@ -288,6 +293,7 @@ export default class Peernet {
288
293
  const node = await this.prepareMessage(from, data.encoded)
289
294
 
290
295
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})))
296
+ this.bw.up += node.encoded.length
291
297
  } else if (proto.name === 'peernet-peer-response') {
292
298
  const from = proto.decoded.id
293
299
  if (!this.peerMap.has(from)) this.peerMap.set(from, [peer.id])
@@ -303,9 +309,10 @@ export default class Peernet {
303
309
  if (!from) {
304
310
  const data = new PeerMessage({id: this.id})
305
311
  const node = await this.prepareMessage(peer.id, data.encoded)
306
-
312
+ this.bw.up += node.encoded.length
307
313
  let response = await peer.request(node.encoded)
308
314
  response = protoFor(response)
315
+
309
316
  response = new PeerMessageResponse(response.decoded.data)
310
317
 
311
318
  from = response.decoded.id
@@ -333,6 +340,7 @@ export default class Peernet {
333
340
  const node = await this.prepareMessage(from, data.encoded)
334
341
 
335
342
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})))
343
+ this.bw.up += node.encoded.length
336
344
  } else if (proto.name === 'peernet-data') {
337
345
  let { hash, store } = proto.decoded
338
346
  let data
@@ -352,6 +360,7 @@ export default class Peernet {
352
360
 
353
361
  const node = await this.prepareMessage(from, data.encoded)
354
362
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})))
363
+ this.bw.up += node.encoded.length
355
364
  }
356
365
  } else if (proto.name === 'peernet-peer') {
357
366
  const from = proto.decoded.id
@@ -365,6 +374,7 @@ export default class Peernet {
365
374
  const node = await this.prepareMessage(from, data.encoded)
366
375
 
367
376
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})))
377
+ this.bw.up += node.encoded.length
368
378
  } else if (proto.name === 'peernet-request') {
369
379
  // TODO: make dynamic
370
380
  // exposeddevapi[proto.decoded.request](proto.decoded.params)
@@ -373,6 +383,7 @@ export default class Peernet {
373
383
  const data = await method()
374
384
  const node = await this.prepareMessage(from, data.encoded)
375
385
  peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})))
386
+ this.bw.up += node.encoded.length
376
387
  }
377
388
  } else if (proto.name === 'peernet-ps' &&
378
389
  this._getPeerId(peer.id) !== this.id.toString()) {