Compare commits
No commits in common. "v0.1.0-develop.65" and "v0.1.0-develop.64" have entirely different histories.
v0.1.0-dev
...
v0.1.0-dev
|
@ -1,10 +1,3 @@
|
||||||
# [0.1.0-develop.65](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.64...v0.1.0-develop.65) (2023-11-18)
|
|
||||||
|
|
||||||
|
|
||||||
### Features
|
|
||||||
|
|
||||||
* add hashQuery protocol method ([5391666](https://git.lumeweb.com/LumeWeb/libs5/commit/53916663886b54f4adf5192f17f79e72c457d4be))
|
|
||||||
|
|
||||||
# [0.1.0-develop.64](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.63...v0.1.0-develop.64) (2023-11-18)
|
# [0.1.0-develop.64](https://git.lumeweb.com/LumeWeb/libs5/compare/v0.1.0-develop.63...v0.1.0-develop.64) (2023-11-18)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/libs5",
|
"name": "@lumeweb/libs5",
|
||||||
"version": "0.1.0-develop.65",
|
"version": "0.1.0-develop.64",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@lumeweb/libs5",
|
"name": "@lumeweb/libs5",
|
||||||
"version": "0.1.0-develop.65",
|
"version": "0.1.0-develop.64",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@noble/curves": "^1.1.0",
|
"@noble/curves": "^1.1.0",
|
||||||
"@noble/hashes": "^1.3.1",
|
"@noble/hashes": "^1.3.1",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/libs5",
|
"name": "@lumeweb/libs5",
|
||||||
"version": "0.1.0-develop.65",
|
"version": "0.1.0-develop.64",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
|
@ -1,48 +0,0 @@
|
||||||
import { S5Node } from "#node.js";
|
|
||||||
import { Peer } from "#types.js";
|
|
||||||
import Unpacker from "#serialization/unpack.js";
|
|
||||||
import { Multihash } from "#multihash.js";
|
|
||||||
|
|
||||||
export default async function (
|
|
||||||
node: S5Node,
|
|
||||||
peer: Peer,
|
|
||||||
data: Unpacker,
|
|
||||||
rawData: Uint8Array,
|
|
||||||
) {
|
|
||||||
const hash = new Multihash(data.unpackBinary());
|
|
||||||
const types = data.unpackList().map((item) => Number(item));
|
|
||||||
|
|
||||||
try {
|
|
||||||
const map = await node.getCachedStorageLocations(hash, types);
|
|
||||||
|
|
||||||
if (Object.keys(map).length > 0) {
|
|
||||||
const availableNodes = [...map.keys()];
|
|
||||||
node.services.p2p.sortNodesByScore(availableNodes);
|
|
||||||
|
|
||||||
const entry = map.get(availableNodes[0]);
|
|
||||||
|
|
||||||
peer.sendMessage(entry?.providerMessage as Uint8Array);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
node.logger.catched(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
const hashCode = hash.hashCode;
|
|
||||||
|
|
||||||
if (node.hashQueryRoutingTable.has(hashCode)) {
|
|
||||||
if (!node.hashQueryRoutingTable[hashCode].includes(peer.id)) {
|
|
||||||
node.hashQueryRoutingTable[hashCode].push(peer.id);
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
node.hashQueryRoutingTable.set(hashCode, new Set([peer.id]));
|
|
||||||
for (const p of node.services.p2p.peers.values()) {
|
|
||||||
if (p.id !== peer.id) {
|
|
||||||
p.sendMessage(rawData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
|
@ -2,7 +2,6 @@ import { P2PMessageHandler } from "#types.js";
|
||||||
import handshakeOpen from "#messages/handshakeOpen.js";
|
import handshakeOpen from "#messages/handshakeOpen.js";
|
||||||
import {
|
import {
|
||||||
protocolMethodHandshakeOpen,
|
protocolMethodHandshakeOpen,
|
||||||
protocolMethodHashQuery,
|
|
||||||
protocolMethodRegistryQuery,
|
protocolMethodRegistryQuery,
|
||||||
protocolMethodSignedMessage,
|
protocolMethodSignedMessage,
|
||||||
recordTypeRegistryEntry,
|
recordTypeRegistryEntry,
|
||||||
|
@ -12,7 +11,6 @@ import registryQuery from "#messages/registryQuery.js";
|
||||||
import registryEntry from "#messages/registryEntry.js";
|
import registryEntry from "#messages/registryEntry.js";
|
||||||
import storageLocation from "#messages/storageLocation.js";
|
import storageLocation from "#messages/storageLocation.js";
|
||||||
import signedMessage from "#messages/signedMessage.js";
|
import signedMessage from "#messages/signedMessage.js";
|
||||||
import hashQuery from "#messages/hashQuery.js";
|
|
||||||
|
|
||||||
const messages = new Map<number, P2PMessageHandler>(
|
const messages = new Map<number, P2PMessageHandler>(
|
||||||
Object.entries({
|
Object.entries({
|
||||||
|
@ -21,7 +19,6 @@ const messages = new Map<number, P2PMessageHandler>(
|
||||||
[recordTypeRegistryEntry]: registryEntry,
|
[recordTypeRegistryEntry]: registryEntry,
|
||||||
[recordTypeStorageLocation]: storageLocation,
|
[recordTypeStorageLocation]: storageLocation,
|
||||||
[protocolMethodSignedMessage]: signedMessage,
|
[protocolMethodSignedMessage]: signedMessage,
|
||||||
[protocolMethodHashQuery]: hashQuery,
|
|
||||||
}).map(([key, value]) => [Number(key), value]),
|
}).map(([key, value]) => [Number(key), value]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -57,8 +57,7 @@ export default async function (
|
||||||
config: node.config,
|
config: node.config,
|
||||||
});
|
});
|
||||||
|
|
||||||
const list =
|
const list = p2p.hashQueryRoutingTable.get(hash) || new Set<NodeId>();
|
||||||
node.hashQueryRoutingTable.get(hash.hashCode) || new Set<NodeId>();
|
|
||||||
for (const peerId of list) {
|
for (const peerId of list) {
|
||||||
if (peerId.equals(nodeId)) {
|
if (peerId.equals(nodeId)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -75,5 +74,5 @@ export default async function (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
node.hashQueryRoutingTable.delete(hash.hashCode);
|
p2p.hashQueryRoutingTable.delete(hash);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,12 +50,6 @@ export class S5Node {
|
||||||
|
|
||||||
private _started = false;
|
private _started = false;
|
||||||
|
|
||||||
private _hashQueryRoutingTable: Map<number, Set<NodeId>> = new Map();
|
|
||||||
|
|
||||||
get hashQueryRoutingTable(): Map<number, Set<NodeId>> {
|
|
||||||
return this._hashQueryRoutingTable;
|
|
||||||
}
|
|
||||||
|
|
||||||
get started(): boolean {
|
get started(): boolean {
|
||||||
return this._started;
|
return this._started;
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,13 @@ export class P2PService extends EventEmitter {
|
||||||
|
|
||||||
node.services.p2p = this;
|
node.services.p2p = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _hashQueryRoutingTable: Map<Multihash, Set<NodeId>> = new Map();
|
||||||
|
|
||||||
|
get hashQueryRoutingTable(): Map<Multihash, Set<NodeId>> {
|
||||||
|
return this._hashQueryRoutingTable;
|
||||||
|
}
|
||||||
|
|
||||||
private _networkId?: string;
|
private _networkId?: string;
|
||||||
|
|
||||||
get networkId(): string {
|
get networkId(): string {
|
||||||
|
|
Loading…
Reference in New Issue