@leofcoin/peernet 0.12.2 → 0.12.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/dist/browser/messages.js +11 -88
- package/dist/browser/peernet.js +70 -43
- package/dist/commonjs/dht-response.js +23 -3
- package/dist/commonjs/dht.js +34 -3
- package/dist/commonjs/{messages-bcb02ee9.js → messages-d7de0e2e.js} +16 -46
- package/dist/commonjs/peernet.js +11 -12
- package/dist/commonjs/peernet2.js +25 -3
- package/dist/commonjs/request.js +22 -3
- package/dist/commonjs/response.js +22 -3
- package/dist/module/{messages-421f88db.js → messages-1168ade4.js} +1 -56
- package/dist/module/peernet.js +9 -11
- package/package.json +2 -2
- package/src/messages.js +11 -11
- package/src/peernet.js +8 -10
- package/test.js +3 -3
- package/dist/commonjs/dht-6a1b6246.js +0 -45
- package/dist/commonjs/dht-response-e4a603ea.js +0 -34
- package/dist/commonjs/peernet-6eef77d5.js +0 -36
- package/dist/commonjs/request-95ed03ec.js +0 -33
- package/dist/commonjs/response-bae4e2a2.js +0 -33
package/dist/browser/messages.js
CHANGED
|
@@ -8,94 +8,17 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
8
8
|
|
|
9
9
|
// EXPORTS
|
|
10
10
|
__webpack_require__.d(__webpack_exports__, {
|
|
11
|
-
"ChatMessage": function() { return /* reexport */
|
|
12
|
-
"DHTMessage": function() { return /* reexport */
|
|
13
|
-
"DHTMessageResponse": function() { return /* reexport */
|
|
14
|
-
"DataMessage": function() { return /* reexport */
|
|
15
|
-
"DataMessageResponse": function() { return /* reexport */
|
|
16
|
-
"PeerMessage": function() { return /* reexport */
|
|
17
|
-
"PeerMessageResponse": function() { return /* reexport */
|
|
18
|
-
"PeernetMessage": function() { return /* reexport */
|
|
19
|
-
"PsMessage": function() { return /* reexport */
|
|
20
|
-
"RequestMessage": function() { return /* reexport */
|
|
21
|
-
"ResponseMessage": function() { return /* reexport */
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// NAMESPACE OBJECT: ./src/messages/peernet.js
|
|
25
|
-
var peernet_namespaceObject = {};
|
|
26
|
-
__webpack_require__.r(peernet_namespaceObject);
|
|
27
|
-
__webpack_require__.d(peernet_namespaceObject, {
|
|
28
|
-
"default": function() { return PeernetMessage; }
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// NAMESPACE OBJECT: ./src/messages/dht.js
|
|
32
|
-
var dht_namespaceObject = {};
|
|
33
|
-
__webpack_require__.r(dht_namespaceObject);
|
|
34
|
-
__webpack_require__.d(dht_namespaceObject, {
|
|
35
|
-
"default": function() { return DHTMessage; }
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// NAMESPACE OBJECT: ./src/messages/dht-response.js
|
|
39
|
-
var dht_response_namespaceObject = {};
|
|
40
|
-
__webpack_require__.r(dht_response_namespaceObject);
|
|
41
|
-
__webpack_require__.d(dht_response_namespaceObject, {
|
|
42
|
-
"default": function() { return DHTMessageResponse; }
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// NAMESPACE OBJECT: ./src/messages/data.js
|
|
46
|
-
var data_namespaceObject = {};
|
|
47
|
-
__webpack_require__.r(data_namespaceObject);
|
|
48
|
-
__webpack_require__.d(data_namespaceObject, {
|
|
49
|
-
"default": function() { return DataMessage; }
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
// NAMESPACE OBJECT: ./src/messages/ps.js
|
|
53
|
-
var ps_namespaceObject = {};
|
|
54
|
-
__webpack_require__.r(ps_namespaceObject);
|
|
55
|
-
__webpack_require__.d(ps_namespaceObject, {
|
|
56
|
-
"default": function() { return PsMessage; }
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
// NAMESPACE OBJECT: ./src/messages/peer.js
|
|
60
|
-
var peer_namespaceObject = {};
|
|
61
|
-
__webpack_require__.r(peer_namespaceObject);
|
|
62
|
-
__webpack_require__.d(peer_namespaceObject, {
|
|
63
|
-
"default": function() { return PeerMessage; }
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
// NAMESPACE OBJECT: ./src/messages/request.js
|
|
67
|
-
var request_namespaceObject = {};
|
|
68
|
-
__webpack_require__.r(request_namespaceObject);
|
|
69
|
-
__webpack_require__.d(request_namespaceObject, {
|
|
70
|
-
"default": function() { return RequestMessage; }
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
// NAMESPACE OBJECT: ./src/messages/response.js
|
|
74
|
-
var response_namespaceObject = {};
|
|
75
|
-
__webpack_require__.r(response_namespaceObject);
|
|
76
|
-
__webpack_require__.d(response_namespaceObject, {
|
|
77
|
-
"default": function() { return ResponseMessage; }
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
// NAMESPACE OBJECT: ./src/messages/peer-response.js
|
|
81
|
-
var peer_response_namespaceObject = {};
|
|
82
|
-
__webpack_require__.r(peer_response_namespaceObject);
|
|
83
|
-
__webpack_require__.d(peer_response_namespaceObject, {
|
|
84
|
-
"default": function() { return PeerMessageResponse; }
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
// NAMESPACE OBJECT: ./src/messages/data-response.js
|
|
88
|
-
var data_response_namespaceObject = {};
|
|
89
|
-
__webpack_require__.r(data_response_namespaceObject);
|
|
90
|
-
__webpack_require__.d(data_response_namespaceObject, {
|
|
91
|
-
"default": function() { return DataMessageResponse; }
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// NAMESPACE OBJECT: ./src/messages/chat.js
|
|
95
|
-
var chat_namespaceObject = {};
|
|
96
|
-
__webpack_require__.r(chat_namespaceObject);
|
|
97
|
-
__webpack_require__.d(chat_namespaceObject, {
|
|
98
|
-
"default": function() { return ChatMessage; }
|
|
11
|
+
"ChatMessage": function() { return /* reexport */ ChatMessage; },
|
|
12
|
+
"DHTMessage": function() { return /* reexport */ DHTMessage; },
|
|
13
|
+
"DHTMessageResponse": function() { return /* reexport */ DHTMessageResponse; },
|
|
14
|
+
"DataMessage": function() { return /* reexport */ DataMessage; },
|
|
15
|
+
"DataMessageResponse": function() { return /* reexport */ DataMessageResponse; },
|
|
16
|
+
"PeerMessage": function() { return /* reexport */ PeerMessage; },
|
|
17
|
+
"PeerMessageResponse": function() { return /* reexport */ PeerMessageResponse; },
|
|
18
|
+
"PeernetMessage": function() { return /* reexport */ PeernetMessage; },
|
|
19
|
+
"PsMessage": function() { return /* reexport */ PsMessage; },
|
|
20
|
+
"RequestMessage": function() { return /* reexport */ RequestMessage; },
|
|
21
|
+
"ResponseMessage": function() { return /* reexport */ ResponseMessage; }
|
|
99
22
|
});
|
|
100
23
|
|
|
101
24
|
;// CONCATENATED MODULE: ./src/proto/peernet.proto.js
|
package/dist/browser/peernet.js
CHANGED
|
@@ -6,42 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
// EXPORTS
|
|
8
8
|
__webpack_require__.d(__webpack_exports__, {
|
|
9
|
-
"V9": function() { return /* reexport */
|
|
10
|
-
"N6": function() { return /* reexport */
|
|
11
|
-
"L1": function() { return /* reexport */
|
|
12
|
-
"QB": function() { return /* reexport */
|
|
9
|
+
"V9": function() { return /* reexport */ PeernetCodec; },
|
|
10
|
+
"N6": function() { return /* reexport */ CodecHash; },
|
|
11
|
+
"L1": function() { return /* reexport */ FormatInterface; },
|
|
12
|
+
"QB": function() { return /* reexport */ codecs; }
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
// UNUSED EXPORTS: BasicInterface
|
|
16
16
|
|
|
17
|
-
// NAMESPACE OBJECT: ./node_modules/@leofcoin/codec-format-interface/src/codecs.js
|
|
18
|
-
var codecs_namespaceObject = {};
|
|
19
|
-
__webpack_require__.r(codecs_namespaceObject);
|
|
20
|
-
__webpack_require__.d(codecs_namespaceObject, {
|
|
21
|
-
"default": function() { return codecs; }
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
// NAMESPACE OBJECT: ./node_modules/@leofcoin/codec-format-interface/src/codec.js
|
|
25
|
-
var codec_namespaceObject = {};
|
|
26
|
-
__webpack_require__.r(codec_namespaceObject);
|
|
27
|
-
__webpack_require__.d(codec_namespaceObject, {
|
|
28
|
-
"default": function() { return PeernetCodec; }
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
// NAMESPACE OBJECT: ./node_modules/@leofcoin/codec-format-interface/src/codec-hash.js
|
|
32
|
-
var codec_hash_namespaceObject = {};
|
|
33
|
-
__webpack_require__.r(codec_hash_namespaceObject);
|
|
34
|
-
__webpack_require__.d(codec_hash_namespaceObject, {
|
|
35
|
-
"default": function() { return CodecHash; }
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
// NAMESPACE OBJECT: ./node_modules/@leofcoin/codec-format-interface/src/codec-format-interface.js
|
|
39
|
-
var codec_format_interface_namespaceObject = {};
|
|
40
|
-
__webpack_require__.r(codec_format_interface_namespaceObject);
|
|
41
|
-
__webpack_require__.d(codec_format_interface_namespaceObject, {
|
|
42
|
-
"default": function() { return FormatInterface; }
|
|
43
|
-
});
|
|
44
|
-
|
|
45
17
|
;// CONCATENATED MODULE: ./node_modules/@vandeurenglenn/base-x/src/base-x.js
|
|
46
18
|
// base-x encoding / decoding
|
|
47
19
|
// Copyright (c) 2018 base-x contributors
|
|
@@ -8460,6 +8432,63 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
8460
8432
|
|
|
8461
8433
|
// EXTERNAL MODULE: ./node_modules/@vandeurenglenn/debug/debug.js
|
|
8462
8434
|
var debug_debug = __webpack_require__(307);
|
|
8435
|
+
;// CONCATENATED MODULE: ./node_modules/@vandeurenglenn/little-pubsub/src/index.js
|
|
8436
|
+
class LittlePubSub {
|
|
8437
|
+
|
|
8438
|
+
/**
|
|
8439
|
+
* Creates handlers
|
|
8440
|
+
*/
|
|
8441
|
+
constructor(verbose = true) {
|
|
8442
|
+
this.subscribers = {};
|
|
8443
|
+
this.verbose = verbose
|
|
8444
|
+
}
|
|
8445
|
+
|
|
8446
|
+
/**
|
|
8447
|
+
* @param {String} event
|
|
8448
|
+
* @param {Method} handler
|
|
8449
|
+
* @param {HTMLElement} context
|
|
8450
|
+
*/
|
|
8451
|
+
subscribe(event, handler, context) {
|
|
8452
|
+
if (typeof context === 'undefined') {
|
|
8453
|
+
context = handler;
|
|
8454
|
+
}
|
|
8455
|
+
this.subscribers[event] = this.subscribers[event] || { handlers: [], value: null};
|
|
8456
|
+
this.subscribers[event].handlers.push(handler.bind(context))
|
|
8457
|
+
}
|
|
8458
|
+
|
|
8459
|
+
/**
|
|
8460
|
+
* @param {String} event
|
|
8461
|
+
* @param {Method} handler
|
|
8462
|
+
* @param {HTMLElement} context
|
|
8463
|
+
*/
|
|
8464
|
+
unsubscribe(event, handler, context) {
|
|
8465
|
+
if (typeof context === 'undefined') {
|
|
8466
|
+
context = handler;
|
|
8467
|
+
}
|
|
8468
|
+
if (this.subscribers[event]) {
|
|
8469
|
+
const index = this.subscribers[event].handlers.indexOf(handler.bind(context));
|
|
8470
|
+
this.subscribers[event].handlers.splice(index);
|
|
8471
|
+
if (this.subscribers[event].handlers.length === 0) delete this.subscribers[event];
|
|
8472
|
+
}
|
|
8473
|
+
|
|
8474
|
+
}
|
|
8475
|
+
|
|
8476
|
+
/**
|
|
8477
|
+
* @param {String} event
|
|
8478
|
+
* @param {String|Number|Boolean|Object|Array} change
|
|
8479
|
+
*/
|
|
8480
|
+
publish(event, change) {
|
|
8481
|
+
if (this.subscribers[event]) {
|
|
8482
|
+
if (this.verbose || this.subscribers[event].value !== change) {
|
|
8483
|
+
this.subscribers[event].value = change;
|
|
8484
|
+
this.subscribers[event].handlers.forEach(handler => {
|
|
8485
|
+
handler(change, this.subscribers[event].value)
|
|
8486
|
+
})
|
|
8487
|
+
}
|
|
8488
|
+
}
|
|
8489
|
+
}
|
|
8490
|
+
}
|
|
8491
|
+
|
|
8463
8492
|
// EXTERNAL MODULE: ./node_modules/node-fetch/browser.js
|
|
8464
8493
|
var browser = __webpack_require__(3300);
|
|
8465
8494
|
var browser_default = /*#__PURE__*/__webpack_require__.n(browser);
|
|
@@ -8840,8 +8869,10 @@ const nothingFoundError = (hash) => {
|
|
|
8840
8869
|
|
|
8841
8870
|
|
|
8842
8871
|
|
|
8872
|
+
|
|
8843
8873
|
globalThis.leofcoin = globalThis.leofcoin || {}
|
|
8844
|
-
globalThis.
|
|
8874
|
+
globalThis.pubsub = globalThis.pubsub || new LittlePubSub()
|
|
8875
|
+
globalThis.globalSub = globalThis.globalSub || new LittlePubSub({verbose: true})
|
|
8845
8876
|
|
|
8846
8877
|
/**
|
|
8847
8878
|
* @access public
|
|
@@ -8887,16 +8918,12 @@ class Peernet {
|
|
|
8887
8918
|
return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message']
|
|
8888
8919
|
}
|
|
8889
8920
|
|
|
8890
|
-
get protos() {
|
|
8891
|
-
return globalThis.peernet.protos
|
|
8892
|
-
}
|
|
8893
|
-
|
|
8894
8921
|
get codecs() {
|
|
8895
8922
|
return src/* codecs */.QB
|
|
8896
8923
|
}
|
|
8897
8924
|
|
|
8898
8925
|
addProto(name, proto) {
|
|
8899
|
-
if (!
|
|
8926
|
+
if (!globalThis.peernet.protos[name]) globalThis.peernet.protos[name] = proto
|
|
8900
8927
|
}
|
|
8901
8928
|
|
|
8902
8929
|
addCodec(name, codec) {
|
|
@@ -9126,7 +9153,7 @@ class Peernet {
|
|
|
9126
9153
|
if (store.private) has = false
|
|
9127
9154
|
else has = await store.has(hash)
|
|
9128
9155
|
}
|
|
9129
|
-
const data = await new
|
|
9156
|
+
const data = await new globalThis.peernet.protos['peernet-dht-response']({hash, has})
|
|
9130
9157
|
const node = await this.prepareMessage(from, data.encoded)
|
|
9131
9158
|
|
|
9132
9159
|
this.sendMessage(peer, id, node.encoded)
|
|
@@ -9142,7 +9169,7 @@ class Peernet {
|
|
|
9142
9169
|
data = await store.get(hash)
|
|
9143
9170
|
|
|
9144
9171
|
if (data) {
|
|
9145
|
-
data = await new
|
|
9172
|
+
data = await new globalThis.peernet.protos['peernet-data-response']({hash, data});
|
|
9146
9173
|
|
|
9147
9174
|
const node = await this.prepareMessage(from, data.encoded)
|
|
9148
9175
|
this.sendMessage(peer, id, node.encoded)
|
|
@@ -9171,7 +9198,7 @@ class Peernet {
|
|
|
9171
9198
|
*/
|
|
9172
9199
|
async walk(hash) {
|
|
9173
9200
|
if (!hash) throw new Error('hash expected, received undefined')
|
|
9174
|
-
const data = await new
|
|
9201
|
+
const data = await new globalThis.peernet.protos['peernet-dht']({hash})
|
|
9175
9202
|
const clientId = this.client.id
|
|
9176
9203
|
const walk = async peer => {
|
|
9177
9204
|
const node = await this.prepareMessage(peer.peerId, data.encoded)
|
|
@@ -9279,7 +9306,7 @@ class Peernet {
|
|
|
9279
9306
|
if (peer.peerId === id) return peer
|
|
9280
9307
|
})
|
|
9281
9308
|
|
|
9282
|
-
let data = await new
|
|
9309
|
+
let data = await new globalThis.peernet.protos['peernet-data']({hash, store: store?.name ? store?.name : store});
|
|
9283
9310
|
|
|
9284
9311
|
const node = await this.prepareMessage(id, data.encoded)
|
|
9285
9312
|
if (closest[0]) data = await closest[0].request(node.encoded)
|
|
@@ -9425,7 +9452,7 @@ class Peernet {
|
|
|
9425
9452
|
if (topic instanceof Uint8Array === false) topic = new TextEncoder().encode(topic)
|
|
9426
9453
|
if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data))
|
|
9427
9454
|
const id = Math.random().toString(36).slice(-12)
|
|
9428
|
-
data = await new
|
|
9455
|
+
data = await new globalThis.peernet.protos['peernet-ps']({data, topic})
|
|
9429
9456
|
for (const peer of this.connections) {
|
|
9430
9457
|
if (peer.peerId !== this.peerId) {
|
|
9431
9458
|
const node = await this.prepareMessage(peer.peerId, data.encoded)
|
|
@@ -1,8 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('@leofcoin/codec-format-interface');
|
|
3
|
+
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
5
4
|
|
|
5
|
+
var proto = `
|
|
6
|
+
// PeernetDHTMessageResponse
|
|
7
|
+
message PeernetDHTMessageResponse {
|
|
8
|
+
required string hash = 1;
|
|
9
|
+
required bool has = 2;
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
6
12
|
|
|
13
|
+
class DHTMessageResponse extends codecFormatInterface.FormatInterface {
|
|
14
|
+
get keys() {
|
|
15
|
+
return ['hash', 'has']
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get messageName() {
|
|
19
|
+
return 'PeernetDHTMessageResponse'
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
constructor(data) {
|
|
23
|
+
const name = 'peernet-dht-response';
|
|
24
|
+
super(data, proto, {name});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
7
27
|
|
|
8
|
-
module.exports =
|
|
28
|
+
module.exports = DHTMessageResponse;
|
package/dist/commonjs/dht.js
CHANGED
|
@@ -1,8 +1,39 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('@leofcoin/codec-format-interface');
|
|
3
|
+
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
5
4
|
|
|
5
|
+
var proto = `
|
|
6
|
+
// PeernetDHTMessage
|
|
7
|
+
message PeernetDHTMessage {
|
|
8
|
+
required string hash = 1;
|
|
9
|
+
optional string store = 2;
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
6
12
|
|
|
13
|
+
/**
|
|
14
|
+
* @example `
|
|
15
|
+
new DHTMessage(hash, store)
|
|
16
|
+
// store = optional if not set, peernet checks every store
|
|
17
|
+
let message = new DHTMessage('hashmvbs124xcfd...', 'transaction')
|
|
18
|
+
message = new DHTMessage('hashmvbs124xcfd...', 'block')
|
|
19
|
+
`
|
|
20
|
+
*/
|
|
21
|
+
class DHTMessage extends codecFormatInterface.FormatInterface {
|
|
22
|
+
/**
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
get keys() {
|
|
26
|
+
return ['hash', 'store']
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
get messageName() {
|
|
30
|
+
return 'PeernetDHTMessage'
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
constructor(data) {
|
|
34
|
+
const name = 'peernet-dht';
|
|
35
|
+
super(data, proto, {name});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
7
38
|
|
|
8
|
-
module.exports =
|
|
39
|
+
module.exports = DHTMessage;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var peernet = require('./
|
|
4
|
-
var dht = require('./dht
|
|
5
|
-
var dhtResponse = require('./dht-response
|
|
3
|
+
var peernet = require('./peernet2.js');
|
|
4
|
+
var dht = require('./dht.js');
|
|
5
|
+
var dhtResponse = require('./dht-response.js');
|
|
6
6
|
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
7
|
-
var request = require('./request
|
|
8
|
-
var response = require('./response
|
|
7
|
+
var request = require('./request.js');
|
|
8
|
+
var response = require('./response.js');
|
|
9
9
|
|
|
10
10
|
var proto$5 = `
|
|
11
11
|
// PeernetDataMessage
|
|
@@ -34,11 +34,6 @@ class DataMessage extends codecFormatInterface.FormatInterface {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
var data = /*#__PURE__*/Object.freeze({
|
|
38
|
-
__proto__: null,
|
|
39
|
-
'default': DataMessage
|
|
40
|
-
});
|
|
41
|
-
|
|
42
37
|
var proto$4 = `
|
|
43
38
|
// PsMessage
|
|
44
39
|
message PsMessage {
|
|
@@ -61,11 +56,6 @@ class PsMessage extends codecFormatInterface.FormatInterface {
|
|
|
61
56
|
}
|
|
62
57
|
}
|
|
63
58
|
|
|
64
|
-
var ps = /*#__PURE__*/Object.freeze({
|
|
65
|
-
__proto__: null,
|
|
66
|
-
'default': PsMessage
|
|
67
|
-
});
|
|
68
|
-
|
|
69
59
|
var proto$3 = `
|
|
70
60
|
// PeernetPeerMessage
|
|
71
61
|
message PeernetPeerMessage {
|
|
@@ -88,11 +78,6 @@ class PeerMessage extends codecFormatInterface.FormatInterface {
|
|
|
88
78
|
}
|
|
89
79
|
}
|
|
90
80
|
|
|
91
|
-
var peer = /*#__PURE__*/Object.freeze({
|
|
92
|
-
__proto__: null,
|
|
93
|
-
'default': PeerMessage
|
|
94
|
-
});
|
|
95
|
-
|
|
96
81
|
var proto$2 = `
|
|
97
82
|
// PeernetPeerMessageResponse
|
|
98
83
|
message PeernetPeerMessageResponse {
|
|
@@ -115,11 +100,6 @@ class PeerMessageResponse extends codecFormatInterface.FormatInterface {
|
|
|
115
100
|
}
|
|
116
101
|
}
|
|
117
102
|
|
|
118
|
-
var peerResponse = /*#__PURE__*/Object.freeze({
|
|
119
|
-
__proto__: null,
|
|
120
|
-
'default': PeerMessageResponse
|
|
121
|
-
});
|
|
122
|
-
|
|
123
103
|
var proto$1 = `
|
|
124
104
|
// PeernetDataMessageResponse
|
|
125
105
|
message PeernetDataMessageResponse {
|
|
@@ -143,11 +123,6 @@ class DataMessageResponse extends codecFormatInterface.FormatInterface {
|
|
|
143
123
|
}
|
|
144
124
|
}
|
|
145
125
|
|
|
146
|
-
var dataResponse = /*#__PURE__*/Object.freeze({
|
|
147
|
-
__proto__: null,
|
|
148
|
-
'default': DataMessageResponse
|
|
149
|
-
});
|
|
150
|
-
|
|
151
126
|
var proto = `
|
|
152
127
|
message ChatMessage {
|
|
153
128
|
required string value = 1;
|
|
@@ -171,19 +146,14 @@ class ChatMessage extends codecFormatInterface.FormatInterface {
|
|
|
171
146
|
}
|
|
172
147
|
}
|
|
173
148
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
exports.
|
|
180
|
-
exports.
|
|
181
|
-
exports.
|
|
182
|
-
exports.
|
|
183
|
-
exports.
|
|
184
|
-
exports.
|
|
185
|
-
exports.DataMessage = data;
|
|
186
|
-
exports.DataMessageResponse = dataResponse;
|
|
187
|
-
exports.PeerMessage = peer;
|
|
188
|
-
exports.PeerMessageResponse = peerResponse;
|
|
189
|
-
exports.PsMessage = ps;
|
|
149
|
+
exports.PeernetMessage = peernet;
|
|
150
|
+
exports.DHTMessage = dht;
|
|
151
|
+
exports.DHTMessageResponse = dhtResponse;
|
|
152
|
+
exports.RequestMessage = request;
|
|
153
|
+
exports.ResponseMessage = response;
|
|
154
|
+
exports.ChatMessage = ChatMessage;
|
|
155
|
+
exports.DataMessage = DataMessage;
|
|
156
|
+
exports.DataMessageResponse = DataMessageResponse;
|
|
157
|
+
exports.PeerMessage = PeerMessage;
|
|
158
|
+
exports.PeerMessageResponse = PeerMessageResponse;
|
|
159
|
+
exports.PsMessage = PsMessage;
|
package/dist/commonjs/peernet.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
require('@vandeurenglenn/debug');
|
|
4
|
+
var PubSub = require('@vandeurenglenn/little-pubsub');
|
|
4
5
|
var fetch = require('node-fetch');
|
|
5
6
|
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
6
7
|
var MultiWallet = require('@leofcoin/multi-wallet');
|
|
@@ -25,6 +26,7 @@ function _interopNamespace(e) {
|
|
|
25
26
|
return Object.freeze(n);
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
var PubSub__default = /*#__PURE__*/_interopDefaultLegacy(PubSub);
|
|
28
30
|
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
|
|
29
31
|
var MultiWallet__default = /*#__PURE__*/_interopDefaultLegacy(MultiWallet);
|
|
30
32
|
|
|
@@ -352,7 +354,8 @@ const nothingFoundError = (hash) => {
|
|
|
352
354
|
};
|
|
353
355
|
|
|
354
356
|
globalThis.leofcoin = globalThis.leofcoin || {};
|
|
355
|
-
globalThis.
|
|
357
|
+
globalThis.pubsub = globalThis.pubsub || new PubSub__default["default"]();
|
|
358
|
+
globalThis.globalSub = globalThis.globalSub || new PubSub__default["default"]({verbose: true});
|
|
356
359
|
|
|
357
360
|
/**
|
|
358
361
|
* @access public
|
|
@@ -398,16 +401,12 @@ class Peernet {
|
|
|
398
401
|
return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message']
|
|
399
402
|
}
|
|
400
403
|
|
|
401
|
-
get protos() {
|
|
402
|
-
return globalThis.peernet.protos
|
|
403
|
-
}
|
|
404
|
-
|
|
405
404
|
get codecs() {
|
|
406
405
|
return codecFormatInterface.codecs
|
|
407
406
|
}
|
|
408
407
|
|
|
409
408
|
addProto(name, proto) {
|
|
410
|
-
if (!
|
|
409
|
+
if (!globalThis.peernet.protos[name]) globalThis.peernet.protos[name] = proto;
|
|
411
410
|
}
|
|
412
411
|
|
|
413
412
|
addCodec(name, codec) {
|
|
@@ -503,7 +502,7 @@ class Peernet {
|
|
|
503
502
|
DataMessageResponse,
|
|
504
503
|
PsMessage,
|
|
505
504
|
ChatMessage
|
|
506
|
-
} = await Promise.resolve().then(function () { return require(/* webpackChunkName: "messages" */ './messages-
|
|
505
|
+
} = await Promise.resolve().then(function () { return require(/* webpackChunkName: "messages" */ './messages-d7de0e2e.js'); });
|
|
507
506
|
|
|
508
507
|
/**
|
|
509
508
|
* proto Object containing protos
|
|
@@ -634,7 +633,7 @@ class Peernet {
|
|
|
634
633
|
if (store.private) has = false;
|
|
635
634
|
else has = await store.has(hash);
|
|
636
635
|
}
|
|
637
|
-
const data = await new
|
|
636
|
+
const data = await new globalThis.peernet.protos['peernet-dht-response']({hash, has});
|
|
638
637
|
const node = await this.prepareMessage(from, data.encoded);
|
|
639
638
|
|
|
640
639
|
this.sendMessage(peer, id, node.encoded);
|
|
@@ -650,7 +649,7 @@ class Peernet {
|
|
|
650
649
|
data = await store.get(hash);
|
|
651
650
|
|
|
652
651
|
if (data) {
|
|
653
|
-
data = await new
|
|
652
|
+
data = await new globalThis.peernet.protos['peernet-data-response']({hash, data});
|
|
654
653
|
|
|
655
654
|
const node = await this.prepareMessage(from, data.encoded);
|
|
656
655
|
this.sendMessage(peer, id, node.encoded);
|
|
@@ -677,7 +676,7 @@ class Peernet {
|
|
|
677
676
|
*/
|
|
678
677
|
async walk(hash) {
|
|
679
678
|
if (!hash) throw new Error('hash expected, received undefined')
|
|
680
|
-
const data = await new
|
|
679
|
+
const data = await new globalThis.peernet.protos['peernet-dht']({hash});
|
|
681
680
|
this.client.id;
|
|
682
681
|
const walk = async peer => {
|
|
683
682
|
const node = await this.prepareMessage(peer.peerId, data.encoded);
|
|
@@ -785,7 +784,7 @@ class Peernet {
|
|
|
785
784
|
if (peer.peerId === id) return peer
|
|
786
785
|
});
|
|
787
786
|
|
|
788
|
-
let data = await new
|
|
787
|
+
let data = await new globalThis.peernet.protos['peernet-data']({hash, store: store?.name ? store?.name : store});
|
|
789
788
|
|
|
790
789
|
const node = await this.prepareMessage(id, data.encoded);
|
|
791
790
|
if (closest[0]) data = await closest[0].request(node.encoded);
|
|
@@ -930,7 +929,7 @@ class Peernet {
|
|
|
930
929
|
if (topic instanceof Uint8Array === false) topic = new TextEncoder().encode(topic);
|
|
931
930
|
if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data));
|
|
932
931
|
const id = Math.random().toString(36).slice(-12);
|
|
933
|
-
data = await new
|
|
932
|
+
data = await new globalThis.peernet.protos['peernet-ps']({data, topic});
|
|
934
933
|
for (const peer of this.connections) {
|
|
935
934
|
if (peer.peerId !== this.peerId) {
|
|
936
935
|
const node = await this.prepareMessage(peer.peerId, data.encoded);
|
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('@leofcoin/codec-format-interface');
|
|
3
|
+
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
5
4
|
|
|
5
|
+
var proto = `
|
|
6
|
+
// PeernetMessage
|
|
7
|
+
message PeernetMessage {
|
|
8
|
+
required bytes data = 1;
|
|
9
|
+
required bytes signature = 2;
|
|
10
|
+
optional string from = 3;
|
|
11
|
+
optional string to = 4;
|
|
12
|
+
optional string id = 5;
|
|
13
|
+
}`;
|
|
6
14
|
|
|
15
|
+
class PeernetMessage extends codecFormatInterface.FormatInterface {
|
|
16
|
+
get keys() {
|
|
17
|
+
return ['data', 'signature', 'from', 'to', 'id']
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get messageName() {
|
|
21
|
+
return 'PeernetMessage'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
constructor(buffer) {
|
|
25
|
+
const name = 'peernet-message';
|
|
26
|
+
super(buffer, proto, {name});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
7
29
|
|
|
8
|
-
module.exports =
|
|
30
|
+
module.exports = PeernetMessage;
|
package/dist/commonjs/request.js
CHANGED
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('@leofcoin/codec-format-interface');
|
|
3
|
+
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
5
4
|
|
|
5
|
+
var proto = `
|
|
6
|
+
// PeernetRequestMessage
|
|
7
|
+
message PeernetRequestMessage {
|
|
8
|
+
required string request = 1;
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
6
11
|
|
|
12
|
+
class RequestMessage extends codecFormatInterface.FormatInterface {
|
|
13
|
+
get keys() {
|
|
14
|
+
return ['request']
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get messageName() {
|
|
18
|
+
return 'PeernetRequestMessage'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(data) {
|
|
22
|
+
const name = 'peernet-request';
|
|
23
|
+
super(data, proto, {name});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
7
26
|
|
|
8
|
-
module.exports =
|
|
27
|
+
module.exports = RequestMessage;
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
require('@leofcoin/codec-format-interface');
|
|
3
|
+
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
5
4
|
|
|
5
|
+
var proto = `
|
|
6
|
+
// PeernetResponseMessage
|
|
7
|
+
message PeernetResponseMessage {
|
|
8
|
+
required bytes response = 1;
|
|
9
|
+
}
|
|
10
|
+
`;
|
|
6
11
|
|
|
12
|
+
class ResponseMessage extends codecFormatInterface.FormatInterface {
|
|
13
|
+
get keys() {
|
|
14
|
+
return ['response']
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
get messageName() {
|
|
18
|
+
return 'PeernetResponseMessage'
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
constructor(data) {
|
|
22
|
+
const name = 'peernet-response';
|
|
23
|
+
super(data, proto, {name});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
7
26
|
|
|
8
|
-
module.exports =
|
|
27
|
+
module.exports = ResponseMessage;
|
|
@@ -25,11 +25,6 @@ class PeernetMessage extends FormatInterface {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
var peernet = /*#__PURE__*/Object.freeze({
|
|
29
|
-
__proto__: null,
|
|
30
|
-
'default': PeernetMessage
|
|
31
|
-
});
|
|
32
|
-
|
|
33
28
|
var proto$9 = `
|
|
34
29
|
// PeernetDHTMessage
|
|
35
30
|
message PeernetDHTMessage {
|
|
@@ -64,11 +59,6 @@ class DHTMessage extends FormatInterface {
|
|
|
64
59
|
}
|
|
65
60
|
}
|
|
66
61
|
|
|
67
|
-
var dht = /*#__PURE__*/Object.freeze({
|
|
68
|
-
__proto__: null,
|
|
69
|
-
'default': DHTMessage
|
|
70
|
-
});
|
|
71
|
-
|
|
72
62
|
var proto$8 = `
|
|
73
63
|
// PeernetDHTMessageResponse
|
|
74
64
|
message PeernetDHTMessageResponse {
|
|
@@ -92,11 +82,6 @@ class DHTMessageResponse extends FormatInterface {
|
|
|
92
82
|
}
|
|
93
83
|
}
|
|
94
84
|
|
|
95
|
-
var dhtResponse = /*#__PURE__*/Object.freeze({
|
|
96
|
-
__proto__: null,
|
|
97
|
-
'default': DHTMessageResponse
|
|
98
|
-
});
|
|
99
|
-
|
|
100
85
|
var proto$7 = `
|
|
101
86
|
// PeernetDataMessage
|
|
102
87
|
message PeernetDataMessage {
|
|
@@ -124,11 +109,6 @@ class DataMessage extends FormatInterface {
|
|
|
124
109
|
}
|
|
125
110
|
}
|
|
126
111
|
|
|
127
|
-
var data = /*#__PURE__*/Object.freeze({
|
|
128
|
-
__proto__: null,
|
|
129
|
-
'default': DataMessage
|
|
130
|
-
});
|
|
131
|
-
|
|
132
112
|
var proto$6 = `
|
|
133
113
|
// PsMessage
|
|
134
114
|
message PsMessage {
|
|
@@ -151,11 +131,6 @@ class PsMessage extends FormatInterface {
|
|
|
151
131
|
}
|
|
152
132
|
}
|
|
153
133
|
|
|
154
|
-
var ps = /*#__PURE__*/Object.freeze({
|
|
155
|
-
__proto__: null,
|
|
156
|
-
'default': PsMessage
|
|
157
|
-
});
|
|
158
|
-
|
|
159
134
|
var proto$5 = `
|
|
160
135
|
// PeernetPeerMessage
|
|
161
136
|
message PeernetPeerMessage {
|
|
@@ -178,11 +153,6 @@ class PeerMessage extends FormatInterface {
|
|
|
178
153
|
}
|
|
179
154
|
}
|
|
180
155
|
|
|
181
|
-
var peer = /*#__PURE__*/Object.freeze({
|
|
182
|
-
__proto__: null,
|
|
183
|
-
'default': PeerMessage
|
|
184
|
-
});
|
|
185
|
-
|
|
186
156
|
var proto$4 = `
|
|
187
157
|
// PeernetRequestMessage
|
|
188
158
|
message PeernetRequestMessage {
|
|
@@ -205,11 +175,6 @@ class RequestMessage extends FormatInterface {
|
|
|
205
175
|
}
|
|
206
176
|
}
|
|
207
177
|
|
|
208
|
-
var request = /*#__PURE__*/Object.freeze({
|
|
209
|
-
__proto__: null,
|
|
210
|
-
'default': RequestMessage
|
|
211
|
-
});
|
|
212
|
-
|
|
213
178
|
var proto$3 = `
|
|
214
179
|
// PeernetResponseMessage
|
|
215
180
|
message PeernetResponseMessage {
|
|
@@ -232,11 +197,6 @@ class ResponseMessage extends FormatInterface {
|
|
|
232
197
|
}
|
|
233
198
|
}
|
|
234
199
|
|
|
235
|
-
var response = /*#__PURE__*/Object.freeze({
|
|
236
|
-
__proto__: null,
|
|
237
|
-
'default': ResponseMessage
|
|
238
|
-
});
|
|
239
|
-
|
|
240
200
|
var proto$2 = `
|
|
241
201
|
// PeernetPeerMessageResponse
|
|
242
202
|
message PeernetPeerMessageResponse {
|
|
@@ -259,11 +219,6 @@ class PeerMessageResponse extends FormatInterface {
|
|
|
259
219
|
}
|
|
260
220
|
}
|
|
261
221
|
|
|
262
|
-
var peerResponse = /*#__PURE__*/Object.freeze({
|
|
263
|
-
__proto__: null,
|
|
264
|
-
'default': PeerMessageResponse
|
|
265
|
-
});
|
|
266
|
-
|
|
267
222
|
var proto$1 = `
|
|
268
223
|
// PeernetDataMessageResponse
|
|
269
224
|
message PeernetDataMessageResponse {
|
|
@@ -287,11 +242,6 @@ class DataMessageResponse extends FormatInterface {
|
|
|
287
242
|
}
|
|
288
243
|
}
|
|
289
244
|
|
|
290
|
-
var dataResponse = /*#__PURE__*/Object.freeze({
|
|
291
|
-
__proto__: null,
|
|
292
|
-
'default': DataMessageResponse
|
|
293
|
-
});
|
|
294
|
-
|
|
295
245
|
var proto = `
|
|
296
246
|
message ChatMessage {
|
|
297
247
|
required string value = 1;
|
|
@@ -315,9 +265,4 @@ class ChatMessage extends FormatInterface {
|
|
|
315
265
|
}
|
|
316
266
|
}
|
|
317
267
|
|
|
318
|
-
|
|
319
|
-
__proto__: null,
|
|
320
|
-
'default': ChatMessage
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
export { chat as ChatMessage, dht as DHTMessage, dhtResponse as DHTMessageResponse, data as DataMessage, dataResponse as DataMessageResponse, peer as PeerMessage, peerResponse as PeerMessageResponse, peernet as PeernetMessage, ps as PsMessage, request as RequestMessage, response as ResponseMessage };
|
|
268
|
+
export { ChatMessage, DHTMessage, DHTMessageResponse, DataMessage, DataMessageResponse, PeerMessage, PeerMessageResponse, PeernetMessage, PsMessage, RequestMessage, ResponseMessage };
|
package/dist/module/peernet.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import '@vandeurenglenn/debug';
|
|
2
|
+
import PubSub from '@vandeurenglenn/little-pubsub';
|
|
2
3
|
import { Codec, CodecHash, codecs } from '@leofcoin/codec-format-interface';
|
|
3
4
|
import MultiWallet from '@leofcoin/multi-wallet';
|
|
4
5
|
|
|
@@ -326,6 +327,7 @@ const nothingFoundError = (hash) => {
|
|
|
326
327
|
};
|
|
327
328
|
|
|
328
329
|
globalThis.leofcoin = globalThis.leofcoin || {};
|
|
330
|
+
globalThis.pubsub = globalThis.pubsub || new PubSub();
|
|
329
331
|
globalThis.globalSub = globalThis.globalSub || new PubSub({verbose: true});
|
|
330
332
|
|
|
331
333
|
/**
|
|
@@ -372,16 +374,12 @@ class Peernet {
|
|
|
372
374
|
return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message']
|
|
373
375
|
}
|
|
374
376
|
|
|
375
|
-
get protos() {
|
|
376
|
-
return globalThis.peernet.protos
|
|
377
|
-
}
|
|
378
|
-
|
|
379
377
|
get codecs() {
|
|
380
378
|
return codecs
|
|
381
379
|
}
|
|
382
380
|
|
|
383
381
|
addProto(name, proto) {
|
|
384
|
-
if (!
|
|
382
|
+
if (!globalThis.peernet.protos[name]) globalThis.peernet.protos[name] = proto;
|
|
385
383
|
}
|
|
386
384
|
|
|
387
385
|
addCodec(name, codec) {
|
|
@@ -477,7 +475,7 @@ class Peernet {
|
|
|
477
475
|
DataMessageResponse,
|
|
478
476
|
PsMessage,
|
|
479
477
|
ChatMessage
|
|
480
|
-
} = await import(/* webpackChunkName: "messages" */ './messages-
|
|
478
|
+
} = await import(/* webpackChunkName: "messages" */ './messages-1168ade4.js');
|
|
481
479
|
|
|
482
480
|
/**
|
|
483
481
|
* proto Object containing protos
|
|
@@ -608,7 +606,7 @@ class Peernet {
|
|
|
608
606
|
if (store.private) has = false;
|
|
609
607
|
else has = await store.has(hash);
|
|
610
608
|
}
|
|
611
|
-
const data = await new
|
|
609
|
+
const data = await new globalThis.peernet.protos['peernet-dht-response']({hash, has});
|
|
612
610
|
const node = await this.prepareMessage(from, data.encoded);
|
|
613
611
|
|
|
614
612
|
this.sendMessage(peer, id, node.encoded);
|
|
@@ -624,7 +622,7 @@ class Peernet {
|
|
|
624
622
|
data = await store.get(hash);
|
|
625
623
|
|
|
626
624
|
if (data) {
|
|
627
|
-
data = await new
|
|
625
|
+
data = await new globalThis.peernet.protos['peernet-data-response']({hash, data});
|
|
628
626
|
|
|
629
627
|
const node = await this.prepareMessage(from, data.encoded);
|
|
630
628
|
this.sendMessage(peer, id, node.encoded);
|
|
@@ -651,7 +649,7 @@ class Peernet {
|
|
|
651
649
|
*/
|
|
652
650
|
async walk(hash) {
|
|
653
651
|
if (!hash) throw new Error('hash expected, received undefined')
|
|
654
|
-
const data = await new
|
|
652
|
+
const data = await new globalThis.peernet.protos['peernet-dht']({hash});
|
|
655
653
|
this.client.id;
|
|
656
654
|
const walk = async peer => {
|
|
657
655
|
const node = await this.prepareMessage(peer.peerId, data.encoded);
|
|
@@ -759,7 +757,7 @@ class Peernet {
|
|
|
759
757
|
if (peer.peerId === id) return peer
|
|
760
758
|
});
|
|
761
759
|
|
|
762
|
-
let data = await new
|
|
760
|
+
let data = await new globalThis.peernet.protos['peernet-data']({hash, store: store?.name ? store?.name : store});
|
|
763
761
|
|
|
764
762
|
const node = await this.prepareMessage(id, data.encoded);
|
|
765
763
|
if (closest[0]) data = await closest[0].request(node.encoded);
|
|
@@ -904,7 +902,7 @@ class Peernet {
|
|
|
904
902
|
if (topic instanceof Uint8Array === false) topic = new TextEncoder().encode(topic);
|
|
905
903
|
if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data));
|
|
906
904
|
const id = Math.random().toString(36).slice(-12);
|
|
907
|
-
data = await new
|
|
905
|
+
data = await new globalThis.peernet.protos['peernet-ps']({data, topic});
|
|
908
906
|
for (const peer of this.connections) {
|
|
909
907
|
if (peer.peerId !== this.peerId) {
|
|
910
908
|
const node = await this.prepareMessage(peer.peerId, data.encoded);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leofcoin/peernet",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/commonjs/peernet.js",
|
|
6
6
|
"module": "src/module/peernet.js",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"browserslist": "> 0.5%, last 2 versions, not dead",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@leofcoin/codec-format-interface": "^1.2.
|
|
25
|
+
"@leofcoin/codec-format-interface": "^1.2.2",
|
|
26
26
|
"@leofcoin/generate-account": "^1.0.4",
|
|
27
27
|
"@leofcoin/multi-wallet": "^2.1.2",
|
|
28
28
|
"@leofcoin/peernet-swarm": "^0.3.3",
|
package/src/messages.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
1
|
+
export { default as PeernetMessage } from './messages/peernet.js'
|
|
2
|
+
export { default as DHTMessage } from './messages/dht.js'
|
|
3
|
+
export { default as DHTMessageResponse } from './messages/dht-response.js'
|
|
4
|
+
export { default as DataMessage } from './messages/data.js'
|
|
5
|
+
export { default as PsMessage } from './messages/ps.js'
|
|
6
|
+
export { default as PeerMessage } from './messages/peer.js'
|
|
7
|
+
export { default as RequestMessage } from './messages/request.js'
|
|
8
|
+
export { default as ResponseMessage } from './messages/response.js'
|
|
9
|
+
export { default as PeerMessageResponse } from './messages/peer-response.js'
|
|
10
|
+
export { default as DataMessageResponse } from './messages/data-response.js'
|
|
11
|
+
export { default as ChatMessage } from './messages/chat.js'
|
package/src/peernet.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import '@vandeurenglenn/debug'
|
|
2
|
+
import PubSub from '@vandeurenglenn/little-pubsub'
|
|
2
3
|
import PeerDiscovery from './discovery/peer-discovery'
|
|
3
4
|
import DHT from './dht/dht.js'
|
|
4
5
|
import { CodecHash, codecs} from '@leofcoin/codec-format-interface'
|
|
@@ -9,6 +10,7 @@ import { encapsulatedError, dhtError,
|
|
|
9
10
|
nothingFoundError } from './errors/errors.js'
|
|
10
11
|
|
|
11
12
|
globalThis.leofcoin = globalThis.leofcoin || {}
|
|
13
|
+
globalThis.pubsub = globalThis.pubsub || new PubSub()
|
|
12
14
|
globalThis.globalSub = globalThis.globalSub || new PubSub({verbose: true})
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -55,16 +57,12 @@ export default class Peernet {
|
|
|
55
57
|
return ['account', 'wallet', 'block', 'transaction', 'chain', 'data', 'message']
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
get protos() {
|
|
59
|
-
return globalThis.peernet.protos
|
|
60
|
-
}
|
|
61
|
-
|
|
62
60
|
get codecs() {
|
|
63
61
|
return codecs
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
addProto(name, proto) {
|
|
67
|
-
if (!
|
|
65
|
+
if (!globalThis.peernet.protos[name]) globalThis.peernet.protos[name] = proto
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
addCodec(name, codec) {
|
|
@@ -294,7 +292,7 @@ export default class Peernet {
|
|
|
294
292
|
if (store.private) has = false
|
|
295
293
|
else has = await store.has(hash)
|
|
296
294
|
}
|
|
297
|
-
const data = await new
|
|
295
|
+
const data = await new globalThis.peernet.protos['peernet-dht-response']({hash, has})
|
|
298
296
|
const node = await this.prepareMessage(from, data.encoded)
|
|
299
297
|
|
|
300
298
|
this.sendMessage(peer, id, node.encoded)
|
|
@@ -310,7 +308,7 @@ export default class Peernet {
|
|
|
310
308
|
data = await store.get(hash)
|
|
311
309
|
|
|
312
310
|
if (data) {
|
|
313
|
-
data = await new
|
|
311
|
+
data = await new globalThis.peernet.protos['peernet-data-response']({hash, data});
|
|
314
312
|
|
|
315
313
|
const node = await this.prepareMessage(from, data.encoded)
|
|
316
314
|
this.sendMessage(peer, id, node.encoded)
|
|
@@ -339,7 +337,7 @@ export default class Peernet {
|
|
|
339
337
|
*/
|
|
340
338
|
async walk(hash) {
|
|
341
339
|
if (!hash) throw new Error('hash expected, received undefined')
|
|
342
|
-
const data = await new
|
|
340
|
+
const data = await new globalThis.peernet.protos['peernet-dht']({hash})
|
|
343
341
|
const clientId = this.client.id
|
|
344
342
|
const walk = async peer => {
|
|
345
343
|
const node = await this.prepareMessage(peer.peerId, data.encoded)
|
|
@@ -447,7 +445,7 @@ export default class Peernet {
|
|
|
447
445
|
if (peer.peerId === id) return peer
|
|
448
446
|
})
|
|
449
447
|
|
|
450
|
-
let data = await new
|
|
448
|
+
let data = await new globalThis.peernet.protos['peernet-data']({hash, store: store?.name ? store?.name : store});
|
|
451
449
|
|
|
452
450
|
const node = await this.prepareMessage(id, data.encoded)
|
|
453
451
|
if (closest[0]) data = await closest[0].request(node.encoded)
|
|
@@ -593,7 +591,7 @@ export default class Peernet {
|
|
|
593
591
|
if (topic instanceof Uint8Array === false) topic = new TextEncoder().encode(topic)
|
|
594
592
|
if (data instanceof Uint8Array === false) data = new TextEncoder().encode(JSON.stringify(data))
|
|
595
593
|
const id = Math.random().toString(36).slice(-12)
|
|
596
|
-
data = await new
|
|
594
|
+
data = await new globalThis.peernet.protos['peernet-ps']({data, topic})
|
|
597
595
|
for (const peer of this.connections) {
|
|
598
596
|
if (peer.peerId !== this.peerId) {
|
|
599
597
|
const node = await this.prepareMessage(peer.peerId, data.encoded)
|
package/test.js
CHANGED
|
@@ -4,7 +4,7 @@ const client = new Client({root: '.peernet/test'})
|
|
|
4
4
|
|
|
5
5
|
pubsub.subscribe('peer:connected', async peer => {
|
|
6
6
|
chainStore.put('localBlock', '00000')
|
|
7
|
-
const request = new globalThis.peernet.protos['peernet-request']({
|
|
7
|
+
const request = await new globalThis.peernet.protos['peernet-request']({
|
|
8
8
|
request:'lastBlock'
|
|
9
9
|
})
|
|
10
10
|
const to = peer.id
|
|
@@ -19,9 +19,9 @@ pubsub.subscribe('peer:connected', async peer => {
|
|
|
19
19
|
for (const key of keys) {
|
|
20
20
|
uint8Array[Number(key)] = response[key]
|
|
21
21
|
}
|
|
22
|
-
const proto = new globalThis.peernet.protos['peernet-message'](uint8Array)
|
|
22
|
+
const proto = await new globalThis.peernet.protos['peernet-message'](uint8Array)
|
|
23
23
|
console.log(proto.decoded.data);
|
|
24
|
-
response = new globalThis.peernet.protos['peernet-response'](proto.decoded.data)
|
|
24
|
+
response = await new globalThis.peernet.protos['peernet-response'](proto.decoded.data)
|
|
25
25
|
console.log({response});
|
|
26
26
|
|
|
27
27
|
const block = new TextDecoder().decode(response.decoded.response)
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
4
|
-
|
|
5
|
-
var proto = `
|
|
6
|
-
// PeernetDHTMessage
|
|
7
|
-
message PeernetDHTMessage {
|
|
8
|
-
required string hash = 1;
|
|
9
|
-
optional string store = 2;
|
|
10
|
-
}
|
|
11
|
-
`;
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @example `
|
|
15
|
-
new DHTMessage(hash, store)
|
|
16
|
-
// store = optional if not set, peernet checks every store
|
|
17
|
-
let message = new DHTMessage('hashmvbs124xcfd...', 'transaction')
|
|
18
|
-
message = new DHTMessage('hashmvbs124xcfd...', 'block')
|
|
19
|
-
`
|
|
20
|
-
*/
|
|
21
|
-
class DHTMessage extends codecFormatInterface.FormatInterface {
|
|
22
|
-
/**
|
|
23
|
-
*
|
|
24
|
-
*/
|
|
25
|
-
get keys() {
|
|
26
|
-
return ['hash', 'store']
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
get messageName() {
|
|
30
|
-
return 'PeernetDHTMessage'
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
constructor(data) {
|
|
34
|
-
const name = 'peernet-dht';
|
|
35
|
-
super(data, proto, {name});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
var dht = /*#__PURE__*/Object.freeze({
|
|
40
|
-
__proto__: null,
|
|
41
|
-
'default': DHTMessage
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
exports.DHTMessage = DHTMessage;
|
|
45
|
-
exports.dht = dht;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
4
|
-
|
|
5
|
-
var proto = `
|
|
6
|
-
// PeernetDHTMessageResponse
|
|
7
|
-
message PeernetDHTMessageResponse {
|
|
8
|
-
required string hash = 1;
|
|
9
|
-
required bool has = 2;
|
|
10
|
-
}
|
|
11
|
-
`;
|
|
12
|
-
|
|
13
|
-
class DHTMessageResponse extends codecFormatInterface.FormatInterface {
|
|
14
|
-
get keys() {
|
|
15
|
-
return ['hash', 'has']
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get messageName() {
|
|
19
|
-
return 'PeernetDHTMessageResponse'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
constructor(data) {
|
|
23
|
-
const name = 'peernet-dht-response';
|
|
24
|
-
super(data, proto, {name});
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
var dhtResponse = /*#__PURE__*/Object.freeze({
|
|
29
|
-
__proto__: null,
|
|
30
|
-
'default': DHTMessageResponse
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
exports.DHTMessageResponse = DHTMessageResponse;
|
|
34
|
-
exports.dhtResponse = dhtResponse;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
4
|
-
|
|
5
|
-
var proto = `
|
|
6
|
-
// PeernetMessage
|
|
7
|
-
message PeernetMessage {
|
|
8
|
-
required bytes data = 1;
|
|
9
|
-
required bytes signature = 2;
|
|
10
|
-
optional string from = 3;
|
|
11
|
-
optional string to = 4;
|
|
12
|
-
optional string id = 5;
|
|
13
|
-
}`;
|
|
14
|
-
|
|
15
|
-
class PeernetMessage extends codecFormatInterface.FormatInterface {
|
|
16
|
-
get keys() {
|
|
17
|
-
return ['data', 'signature', 'from', 'to', 'id']
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
get messageName() {
|
|
21
|
-
return 'PeernetMessage'
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
constructor(buffer) {
|
|
25
|
-
const name = 'peernet-message';
|
|
26
|
-
super(buffer, proto, {name});
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
var peernet = /*#__PURE__*/Object.freeze({
|
|
31
|
-
__proto__: null,
|
|
32
|
-
'default': PeernetMessage
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
exports.PeernetMessage = PeernetMessage;
|
|
36
|
-
exports.peernet = peernet;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
4
|
-
|
|
5
|
-
var proto = `
|
|
6
|
-
// PeernetRequestMessage
|
|
7
|
-
message PeernetRequestMessage {
|
|
8
|
-
required string request = 1;
|
|
9
|
-
}
|
|
10
|
-
`;
|
|
11
|
-
|
|
12
|
-
class RequestMessage extends codecFormatInterface.FormatInterface {
|
|
13
|
-
get keys() {
|
|
14
|
-
return ['request']
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get messageName() {
|
|
18
|
-
return 'PeernetRequestMessage'
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
constructor(data) {
|
|
22
|
-
const name = 'peernet-request';
|
|
23
|
-
super(data, proto, {name});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
var request = /*#__PURE__*/Object.freeze({
|
|
28
|
-
__proto__: null,
|
|
29
|
-
'default': RequestMessage
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
exports.RequestMessage = RequestMessage;
|
|
33
|
-
exports.request = request;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var codecFormatInterface = require('@leofcoin/codec-format-interface');
|
|
4
|
-
|
|
5
|
-
var proto = `
|
|
6
|
-
// PeernetResponseMessage
|
|
7
|
-
message PeernetResponseMessage {
|
|
8
|
-
required bytes response = 1;
|
|
9
|
-
}
|
|
10
|
-
`;
|
|
11
|
-
|
|
12
|
-
class ResponseMessage extends codecFormatInterface.FormatInterface {
|
|
13
|
-
get keys() {
|
|
14
|
-
return ['response']
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
get messageName() {
|
|
18
|
-
return 'PeernetResponseMessage'
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
constructor(data) {
|
|
22
|
-
const name = 'peernet-response';
|
|
23
|
-
super(data, proto, {name});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
var response = /*#__PURE__*/Object.freeze({
|
|
28
|
-
__proto__: null,
|
|
29
|
-
'default': ResponseMessage
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
exports.ResponseMessage = ResponseMessage;
|
|
33
|
-
exports.response = response;
|