@leofcoin/peernet 0.9.10 → 0.10.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/dist/browser/peernet.js +20 -8
- package/dist/commonjs/peernet.js +20 -8
- package/dist/module/peernet.js +20 -8
- package/package.json +1 -1
- package/src/peer.js +10 -1
- package/src/peernet.js +15 -12
package/dist/browser/peernet.js
CHANGED
|
@@ -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) =>
|
|
43
|
+
this.connection.on('data', (message) => {
|
|
44
|
+
this.bw.down += data.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.
|
|
292
|
+
var version = "0.9.12";
|
|
284
293
|
|
|
285
294
|
var api$1 = {
|
|
286
295
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
|
@@ -2149,18 +2158,18 @@ class Peernet {
|
|
|
2149
2158
|
this.peerId = id;
|
|
2150
2159
|
|
|
2151
2160
|
pubsub.subscribe('peer:discovered', async (peer) => {
|
|
2152
|
-
this._peerHandler.discover(peer);
|
|
2153
2161
|
peer.on('peernet.data', async (message) => {
|
|
2154
2162
|
const id = message.id;
|
|
2155
2163
|
message = new PeernetMessage(Buffer.from(message.data.data));
|
|
2156
2164
|
const proto = protoFor(message.decoded.data);
|
|
2157
2165
|
await this._protoHandler({id, proto}, peer);
|
|
2158
|
-
const fulldId = this._getPeerId(peer.id);
|
|
2159
|
-
if (fulldId && this._discovered.indexOf(peer.id) === -1) {
|
|
2160
|
-
this._discovered.push(peer.id);
|
|
2161
|
-
pubsub.publish('peer:connected', peer);
|
|
2162
|
-
}
|
|
2163
2166
|
});
|
|
2167
|
+
await this._peerHandler.discover(peer);
|
|
2168
|
+
const fulldId = this._getPeerId(peer.id);
|
|
2169
|
+
if (fulldId && this._discovered.indexOf(peer.id) === -1) {
|
|
2170
|
+
this._discovered.push(peer.id);
|
|
2171
|
+
pubsub.publish('peer:connected', peer);
|
|
2172
|
+
}
|
|
2164
2173
|
});
|
|
2165
2174
|
pubsub.subscribe('peer:disconnected', async (peer) => {
|
|
2166
2175
|
let index = this._discovered.indexOf(peer.id);
|
|
@@ -2193,6 +2202,9 @@ class Peernet {
|
|
|
2193
2202
|
* @type {PeernetClient}
|
|
2194
2203
|
*/
|
|
2195
2204
|
this.client = new PeernetClient({...options, id});
|
|
2205
|
+
if (globalThis.onbeforeunload) {
|
|
2206
|
+
globalThis.addEventListener('beforeunload', async () => this.client.close());
|
|
2207
|
+
}
|
|
2196
2208
|
return this
|
|
2197
2209
|
}
|
|
2198
2210
|
|
package/dist/commonjs/peernet.js
CHANGED
|
@@ -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) =>
|
|
46
|
+
this.connection.on('data', (message) => {
|
|
47
|
+
this.bw.down += data.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.
|
|
295
|
+
var version = "0.9.12";
|
|
287
296
|
|
|
288
297
|
var api$1 = {
|
|
289
298
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
|
@@ -1584,18 +1593,18 @@ class Peernet {
|
|
|
1584
1593
|
this.peerId = id;
|
|
1585
1594
|
|
|
1586
1595
|
pubsub.subscribe('peer:discovered', async (peer) => {
|
|
1587
|
-
this._peerHandler.discover(peer);
|
|
1588
1596
|
peer.on('peernet.data', async (message) => {
|
|
1589
1597
|
const id = message.id;
|
|
1590
1598
|
message = new peernetMessage(Buffer.from(message.data.data));
|
|
1591
1599
|
const proto = protoFor(message.decoded.data);
|
|
1592
1600
|
await this._protoHandler({id, proto}, peer);
|
|
1593
|
-
const fulldId = this._getPeerId(peer.id);
|
|
1594
|
-
if (fulldId && this._discovered.indexOf(peer.id) === -1) {
|
|
1595
|
-
this._discovered.push(peer.id);
|
|
1596
|
-
pubsub.publish('peer:connected', peer);
|
|
1597
|
-
}
|
|
1598
1601
|
});
|
|
1602
|
+
await this._peerHandler.discover(peer);
|
|
1603
|
+
const fulldId = this._getPeerId(peer.id);
|
|
1604
|
+
if (fulldId && this._discovered.indexOf(peer.id) === -1) {
|
|
1605
|
+
this._discovered.push(peer.id);
|
|
1606
|
+
pubsub.publish('peer:connected', peer);
|
|
1607
|
+
}
|
|
1599
1608
|
});
|
|
1600
1609
|
pubsub.subscribe('peer:disconnected', async (peer) => {
|
|
1601
1610
|
let index = this._discovered.indexOf(peer.id);
|
|
@@ -1628,6 +1637,9 @@ class Peernet {
|
|
|
1628
1637
|
* @type {PeernetClient}
|
|
1629
1638
|
*/
|
|
1630
1639
|
this.client = new PeernetClient({...options, id});
|
|
1640
|
+
if (globalThis.onbeforeunload) {
|
|
1641
|
+
globalThis.addEventListener('beforeunload', async () => this.client.close());
|
|
1642
|
+
}
|
|
1631
1643
|
return this
|
|
1632
1644
|
}
|
|
1633
1645
|
|
package/dist/module/peernet.js
CHANGED
|
@@ -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) =>
|
|
26
|
+
this.connection.on('data', (message) => {
|
|
27
|
+
this.bw.down += data.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.
|
|
275
|
+
var version = "0.9.12";
|
|
267
276
|
|
|
268
277
|
var api$1 = {
|
|
269
278
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
|
@@ -2132,18 +2141,18 @@ class Peernet {
|
|
|
2132
2141
|
this.peerId = id;
|
|
2133
2142
|
|
|
2134
2143
|
pubsub.subscribe('peer:discovered', async (peer) => {
|
|
2135
|
-
this._peerHandler.discover(peer);
|
|
2136
2144
|
peer.on('peernet.data', async (message) => {
|
|
2137
2145
|
const id = message.id;
|
|
2138
2146
|
message = new PeernetMessage(Buffer.from(message.data.data));
|
|
2139
2147
|
const proto = protoFor(message.decoded.data);
|
|
2140
2148
|
await this._protoHandler({id, proto}, peer);
|
|
2141
|
-
const fulldId = this._getPeerId(peer.id);
|
|
2142
|
-
if (fulldId && this._discovered.indexOf(peer.id) === -1) {
|
|
2143
|
-
this._discovered.push(peer.id);
|
|
2144
|
-
pubsub.publish('peer:connected', peer);
|
|
2145
|
-
}
|
|
2146
2149
|
});
|
|
2150
|
+
await this._peerHandler.discover(peer);
|
|
2151
|
+
const fulldId = this._getPeerId(peer.id);
|
|
2152
|
+
if (fulldId && this._discovered.indexOf(peer.id) === -1) {
|
|
2153
|
+
this._discovered.push(peer.id);
|
|
2154
|
+
pubsub.publish('peer:connected', peer);
|
|
2155
|
+
}
|
|
2147
2156
|
});
|
|
2148
2157
|
pubsub.subscribe('peer:disconnected', async (peer) => {
|
|
2149
2158
|
let index = this._discovered.indexOf(peer.id);
|
|
@@ -2176,6 +2185,9 @@ class Peernet {
|
|
|
2176
2185
|
* @type {PeernetClient}
|
|
2177
2186
|
*/
|
|
2178
2187
|
this.client = new PeernetClient({...options, id});
|
|
2188
|
+
if (globalThis.onbeforeunload) {
|
|
2189
|
+
globalThis.addEventListener('beforeunload', async () => this.client.close());
|
|
2190
|
+
}
|
|
2179
2191
|
return this
|
|
2180
2192
|
}
|
|
2181
2193
|
|
package/package.json
CHANGED
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) =>
|
|
11
|
+
this.connection.on('data', (message) => {
|
|
12
|
+
this.bw.down += data.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
|
@@ -204,19 +204,19 @@ export default class Peernet {
|
|
|
204
204
|
this.peerId = id
|
|
205
205
|
|
|
206
206
|
pubsub.subscribe('peer:discovered', async (peer) => {
|
|
207
|
-
this._peerHandler.discover(peer)
|
|
208
207
|
peer.on('peernet.data', async (message) => {
|
|
209
|
-
const id = message.id
|
|
210
|
-
message = new PeernetMessage(Buffer.from(message.data.data))
|
|
211
|
-
const proto = protoFor(message.decoded.data)
|
|
212
|
-
await this._protoHandler({id, proto}, peer)
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
208
|
+
const id = message.id;
|
|
209
|
+
message = new PeernetMessage(Buffer.from(message.data.data));
|
|
210
|
+
const proto = protoFor(message.decoded.data);
|
|
211
|
+
await this._protoHandler({id, proto}, peer);
|
|
212
|
+
});
|
|
213
|
+
await this._peerHandler.discover(peer);
|
|
214
|
+
const fulldId = this._getPeerId(peer.id);
|
|
215
|
+
if (fulldId && this._discovered.indexOf(peer.id) === -1) {
|
|
216
|
+
this._discovered.push(peer.id);
|
|
217
|
+
pubsub.publish('peer:connected', peer);
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
220
|
pubsub.subscribe('peer:disconnected', async (peer) => {
|
|
221
221
|
let index = this._discovered.indexOf(peer.id)
|
|
222
222
|
if (index !== -1) this._discovered.splice(index, 1)
|
|
@@ -248,6 +248,9 @@ export default class Peernet {
|
|
|
248
248
|
* @type {PeernetClient}
|
|
249
249
|
*/
|
|
250
250
|
this.client = new Client({...options, id})
|
|
251
|
+
if (globalThis.onbeforeunload) {
|
|
252
|
+
globalThis.addEventListener('beforeunload', async () => this.client.close());
|
|
253
|
+
}
|
|
251
254
|
return this
|
|
252
255
|
}
|
|
253
256
|
|