Compare commits
3 Commits
d572e39a65
...
f875cd116f
Author | SHA1 | Date |
---|---|---|
Derrick Hammer | f875cd116f | |
Derrick Hammer | 065934461e | |
Derrick Hammer | e9e25b2573 |
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"network.d.ts","sourceRoot":"","sources":["../src/network.ts"],"names":[],"mappings":"AAEA,OAAO,sBAAsB,MAAM,kBAAkB,CAAC;AAItD,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B,OAAO,CAAC,uBAAuB,CAAC,CAAgB;IAChD,OAAO,CAAC,uBAAuB,CAAC,CAAW;gBAC/B,KAAK,MAAmB;IAKpC,OAAO,CAAC,QAAQ,CAA4D;IAE5E,IAAI,OAAO,IAAI,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAEtC;IAED,OAAO,CAAC,QAAQ,CAAoC;IAEpD,IAAI,OAAO,IAAI,sBAAsB,CAEpC;IAED,OAAO,CAAC,MAAM,CAAoB;IAElC,IAAI,KAAK,QAER;IAED,OAAO,CAAC,kBAAkB,CAAQ;IAElC,IAAI,iBAAiB,IAAI,MAAM,CAE9B;IAED,IAAI,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAElC;IAED,OAAO,CAAC,aAAa,CAAM;IAE3B,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,EAE7B;IAED,OAAO,CAAC,aAAa,CAAK;IAE1B,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED,IAAI,YAAY,CAAC,KAAK,EAAE,MAAM,EAE7B;IAED,OAAO,CAAC,OAAO,CAAiD;IAEhE,IAAI,MAAM,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAElC;IAED,OAAO,CAAC,MAAM,CAAC,CAAgB;IAE/B,IAAI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAMzB;IAED,IAAI,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAEnC;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AO,CAAC,MAAM,CAAC,CAAgB;IAE/B,IAAI,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAMzB;IAED,IAAI,eAAe,IAAI,OAAO,CAAC,IAAI,CAAC,CAEnC;IAED,OAAO,CAAC,YAAY,CAAkB;IAEtC,IAAI,WAAW,IAAI,OAAO,CAEzB;IAED,IAAI,WAAW,CAAC,KAAK,EAAE,OAAO,EAE7B;IAEM,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAYhD,QAAQ,CAAC,MAAM,EAAE,MAAM;IAQ9B,OAAO,CAAC,IAAI;IAwCZ,OAAO,CAAC,iBAAiB;CAK1B"}
|
|
@ -82,22 +82,8 @@ export default class RpcNetwork {
|
||||||
this._swarm.join(createHash("lumeweb"));
|
this._swarm.join(createHash("lumeweb"));
|
||||||
this.setupRelayPromise();
|
this.setupRelayPromise();
|
||||||
this._swarm.on("connection", async (relay) => {
|
this._swarm.on("connection", async (relay) => {
|
||||||
const query = this._factory.simple({
|
|
||||||
relay,
|
|
||||||
query: { module: "core", method: "get_methods", data: null },
|
|
||||||
});
|
|
||||||
const resp = await query.result;
|
|
||||||
const pubkey = b4a.from(relay.remotePublicKey).toString("hex");
|
const pubkey = b4a.from(relay.remotePublicKey).toString("hex");
|
||||||
if (resp.data) {
|
relay.once("close", () => {
|
||||||
this._relays.set(pubkey, relay);
|
|
||||||
resp.data.forEach((item) => {
|
|
||||||
const methods = this._methods.get(item) ?? new Set();
|
|
||||||
methods.add(pubkey);
|
|
||||||
this._methods.set(item, methods);
|
|
||||||
});
|
|
||||||
this._relaysAvailableResolve?.();
|
|
||||||
}
|
|
||||||
relay.on("close", () => {
|
|
||||||
this._methods.forEach((item) => {
|
this._methods.forEach((item) => {
|
||||||
if (item.has(pubkey)) {
|
if (item.has(pubkey)) {
|
||||||
item.delete(pubkey);
|
item.delete(pubkey);
|
||||||
|
@ -108,6 +94,20 @@ export default class RpcNetwork {
|
||||||
this.setupRelayPromise();
|
this.setupRelayPromise();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
const query = this._factory.simple({
|
||||||
|
relay,
|
||||||
|
query: { module: "core", method: "get_methods", data: null },
|
||||||
|
});
|
||||||
|
const resp = await query.result;
|
||||||
|
if (resp.data) {
|
||||||
|
this._relays.set(pubkey, relay);
|
||||||
|
resp.data.forEach((item) => {
|
||||||
|
const methods = this._methods.get(item) ?? new Set();
|
||||||
|
methods.add(pubkey);
|
||||||
|
this._methods.set(item, methods);
|
||||||
|
});
|
||||||
|
this._relaysAvailableResolve?.();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
setupRelayPromise() {
|
setupRelayPromise() {
|
||||||
|
|
|
@ -115,14 +115,26 @@ export default class RpcNetwork {
|
||||||
this.setupRelayPromise();
|
this.setupRelayPromise();
|
||||||
|
|
||||||
this._swarm.on("connection", async (relay: any) => {
|
this._swarm.on("connection", async (relay: any) => {
|
||||||
|
const pubkey = b4a.from(relay.remotePublicKey).toString("hex");
|
||||||
|
relay.once("close", () => {
|
||||||
|
this._methods.forEach((item) => {
|
||||||
|
if (item.has(pubkey)) {
|
||||||
|
item.delete(pubkey);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.relays.delete(pubkey);
|
||||||
|
|
||||||
|
if (!this._relays.size) {
|
||||||
|
this.setupRelayPromise();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
const query = this._factory.simple({
|
const query = this._factory.simple({
|
||||||
relay,
|
relay,
|
||||||
query: { module: "core", method: "get_methods", data: null },
|
query: { module: "core", method: "get_methods", data: null },
|
||||||
});
|
});
|
||||||
const resp = await query.result;
|
const resp = await query.result;
|
||||||
|
|
||||||
const pubkey = b4a.from(relay.remotePublicKey).toString("hex");
|
|
||||||
|
|
||||||
if (resp.data) {
|
if (resp.data) {
|
||||||
this._relays.set(pubkey, relay);
|
this._relays.set(pubkey, relay);
|
||||||
|
|
||||||
|
@ -135,19 +147,6 @@ export default class RpcNetwork {
|
||||||
});
|
});
|
||||||
this._relaysAvailableResolve?.();
|
this._relaysAvailableResolve?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
relay.on("close", () => {
|
|
||||||
this._methods.forEach((item) => {
|
|
||||||
if (item.has(pubkey)) {
|
|
||||||
item.delete(pubkey);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.relays.delete(pubkey);
|
|
||||||
|
|
||||||
if (!this._relays.size) {
|
|
||||||
this.setupRelayPromise();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue