@leofcoin/peernet 0.9.2 → 0.9.5
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/README.md +26 -2
- package/dist/browser/peernet.js +651 -644
- package/dist/commonjs/codec-73adfc0f.js +205 -0
- package/dist/commonjs/codec-format-interface.js +5 -5
- package/dist/commonjs/codec.js +6 -199
- package/dist/commonjs/dht-response.js +1 -1
- package/dist/commonjs/dht.js +1 -1
- package/dist/commonjs/hash.js +4 -4
- package/dist/commonjs/peernet-message.js +1 -1
- package/dist/commonjs/peernet.js +653 -646
- package/dist/commonjs/request.js +1 -1
- package/dist/commonjs/response.js +1 -1
- package/dist/module/peernet.js +18 -11
- package/package.json +1 -1
- package/test/lastBlock.js +7 -0
package/dist/commonjs/request.js
CHANGED
package/dist/module/peernet.js
CHANGED
|
@@ -244,7 +244,7 @@ class LeofcoinStorage$1 {
|
|
|
244
244
|
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
var version = "0.9.
|
|
247
|
+
var version = "0.9.4";
|
|
248
248
|
|
|
249
249
|
var api$1 = {
|
|
250
250
|
version: ({send}) => send({client: '@peernet/api/http', version}),
|
|
@@ -1983,11 +1983,11 @@ class Peernet {
|
|
|
1983
1983
|
}
|
|
1984
1984
|
|
|
1985
1985
|
addProto(name, proto) {
|
|
1986
|
-
if (!
|
|
1986
|
+
if (!this.protos[name]) this.protos[name] = proto;
|
|
1987
1987
|
}
|
|
1988
1988
|
|
|
1989
|
-
addCodec(name,
|
|
1990
|
-
if (!
|
|
1989
|
+
addCodec(name, codec) {
|
|
1990
|
+
if (!this.codecs[name]) this.codecs[name] = codec;
|
|
1991
1991
|
}
|
|
1992
1992
|
|
|
1993
1993
|
async addStore(name, prefix, root, isPrivate = true) {
|
|
@@ -2045,6 +2045,7 @@ class Peernet {
|
|
|
2045
2045
|
*/
|
|
2046
2046
|
this.peerMap = new Map();
|
|
2047
2047
|
this.stores = [];
|
|
2048
|
+
this.requestProtos = {};
|
|
2048
2049
|
this.storePrefix = options.storePrefix;
|
|
2049
2050
|
this.root = options.root;
|
|
2050
2051
|
|
|
@@ -2070,7 +2071,9 @@ class Peernet {
|
|
|
2070
2071
|
'peernet-ps': PsMessage,
|
|
2071
2072
|
'chat-message': ChatMessage,
|
|
2072
2073
|
};
|
|
2074
|
+
|
|
2073
2075
|
this.protos = globalThis.peernet.protos;
|
|
2076
|
+
this.codecs = codecs;
|
|
2074
2077
|
|
|
2075
2078
|
this._messageHandler = new MessageHandler(this.network);
|
|
2076
2079
|
|
|
@@ -2169,6 +2172,10 @@ class Peernet {
|
|
|
2169
2172
|
}
|
|
2170
2173
|
}
|
|
2171
2174
|
|
|
2175
|
+
addRequestHandler(name, method) {
|
|
2176
|
+
this.requestProtos[name] = method;
|
|
2177
|
+
}
|
|
2178
|
+
|
|
2172
2179
|
/**
|
|
2173
2180
|
* @private
|
|
2174
2181
|
*
|
|
@@ -2271,14 +2278,10 @@ class Peernet {
|
|
|
2271
2278
|
} else if (proto.name === 'peernet-request') {
|
|
2272
2279
|
// TODO: make dynamic
|
|
2273
2280
|
// exposeddevapi[proto.decoded.request](proto.decoded.params)
|
|
2274
|
-
|
|
2275
|
-
if (
|
|
2276
|
-
const
|
|
2277
|
-
const hash = await chainStore.get('localBlock');
|
|
2278
|
-
response = JSON.stringify({ height: height.toString(), hash: hash.toString() });
|
|
2279
|
-
const data = new ResponseMessage({ response });
|
|
2281
|
+
const method = this.requestProtos[proto.decoded.request];
|
|
2282
|
+
if (method) {
|
|
2283
|
+
const data = await method();
|
|
2280
2284
|
const node = await this.prepareMessage(from, data.encoded);
|
|
2281
|
-
|
|
2282
2285
|
peer.write(Buffer.from(JSON.stringify({id, data: node.encoded})));
|
|
2283
2286
|
}
|
|
2284
2287
|
} else if (proto.name === 'peernet-ps' &&
|
|
@@ -2574,6 +2577,10 @@ class Peernet {
|
|
|
2574
2577
|
async removePeer(peer) {
|
|
2575
2578
|
connections.delete(peer.id);
|
|
2576
2579
|
}
|
|
2580
|
+
|
|
2581
|
+
get Buffer() {
|
|
2582
|
+
return Buffer
|
|
2583
|
+
}
|
|
2577
2584
|
// async block(index) {
|
|
2578
2585
|
// const _values = []
|
|
2579
2586
|
// for (const peer of this.peers) {
|
package/package.json
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
peernet.addRequestHandler('lastBlock', () => {
|
|
2
|
+
let response;
|
|
3
|
+
const height = await chainStore.get('localIndex')
|
|
4
|
+
const hash = await chainStore.get('localBlock')
|
|
5
|
+
response = JSON.stringify({ height: height.toString(), hash: hash.toString() })
|
|
6
|
+
return new peernet.protos['peernet-response']({ response })
|
|
7
|
+
})
|