mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-05-02 10:53:11 +00:00
Concepts are being mixed up between the global network config (static vs auto sharding), that needs to be the same of all nodes in the network, individual node configuration (eg relay node subscribing to a given shard), and the routing characteristic of a specific message (eg pubsub topic, shard). This stops proper configuration of nwaku post 0.36.0 because we know need to be deliberate on whether nwaku nodes are running with auto or static sharding. It also included various back and forth conversions between shards, pubsub topics, etc. With this change, we tidy up the network configuration, and make it explicit whether it is static or auto sharded. We also introduce the concept of routing info, which is specific to a message, and tied to the overall network configuration. Routing info abstract pubsub topic, shard, and autosharding needs. Which should lead to easier tidy up of the pubsub concept at a later stage. # Conflicts: # packages/core/src/lib/connection_manager/connection_manager.ts # packages/core/src/lib/metadata/metadata.ts # packages/interfaces/src/metadata.ts # packages/interfaces/src/sharding.ts # packages/relay/src/create.ts # packages/sdk/src/filter/filter.ts # packages/sdk/src/filter/types.ts # packages/sdk/src/light_push/light_push.spec.ts # packages/tests/tests/sharding/auto_sharding.spec.ts # packages/tests/tests/sharding/static_sharding.spec.ts # Conflicts: # packages/sdk/src/store/store.ts
153 lines
4.0 KiB
TypeScript
153 lines
4.0 KiB
TypeScript
import { LightNode } from "@waku/interfaces";
|
|
import { expect } from "chai";
|
|
import type { Context } from "mocha";
|
|
|
|
import {
|
|
afterEachCustom,
|
|
beforeEachCustom,
|
|
runMultipleNodes,
|
|
ServiceNodesFleet,
|
|
teardownNodesWithRedundancy
|
|
} from "../../src/index.js";
|
|
|
|
import { TestRoutingInfo } from "./utils.js";
|
|
|
|
describe("Dialing", function () {
|
|
const ctx: Context = this.ctx;
|
|
let waku: LightNode;
|
|
let serviceNodes: ServiceNodesFleet;
|
|
|
|
beforeEachCustom(this, async () => {
|
|
[serviceNodes, waku] = await runMultipleNodes(
|
|
this.ctx,
|
|
TestRoutingInfo,
|
|
{ lightpush: true, filter: true, peerExchange: true },
|
|
false,
|
|
2,
|
|
true
|
|
);
|
|
|
|
await teardownNodesWithRedundancy(serviceNodes, []);
|
|
|
|
serviceNodes = await ServiceNodesFleet.createAndRun(
|
|
ctx,
|
|
2,
|
|
false,
|
|
TestRoutingInfo,
|
|
{
|
|
lightpush: true,
|
|
filter: true,
|
|
peerExchange: true
|
|
},
|
|
false
|
|
);
|
|
});
|
|
|
|
afterEachCustom(this, async () => {
|
|
await teardownNodesWithRedundancy(serviceNodes, [waku]);
|
|
});
|
|
|
|
it("should dial all peers on dial", async function () {
|
|
for (const node of serviceNodes.nodes) {
|
|
const addr = await node.getMultiaddrWithId();
|
|
await waku.dial(addr);
|
|
}
|
|
|
|
const peers = await waku.getConnectedPeers();
|
|
expect(peers.length).to.equal(
|
|
serviceNodes.nodes.length,
|
|
"Connection should be established"
|
|
);
|
|
});
|
|
|
|
it("should drop connection to all peers on hangUp", async function () {
|
|
for (const node of serviceNodes.nodes) {
|
|
const addr = await node.getMultiaddrWithId();
|
|
await waku.dial(addr);
|
|
}
|
|
|
|
let peers = await waku.getConnectedPeers();
|
|
expect(peers.length).to.equal(
|
|
serviceNodes.nodes.length,
|
|
"Connection should be established"
|
|
);
|
|
|
|
for (const node of serviceNodes.nodes) {
|
|
const peerId = await node.getPeerId();
|
|
await waku.hangUp(peerId);
|
|
}
|
|
|
|
peers = await waku.getConnectedPeers();
|
|
expect(peers.length).to.equal(0, "Connection should be dropped");
|
|
});
|
|
|
|
it("should dial one peer on dial", async function () {
|
|
const addr = await serviceNodes.nodes[0].getMultiaddrWithId();
|
|
await waku.dial(addr);
|
|
|
|
const peers = await waku.getConnectedPeers();
|
|
expect(peers.length).to.equal(1, "Connection should be established");
|
|
});
|
|
|
|
it("should drop connection to one peer on hangUp", async function () {
|
|
for (const node of serviceNodes.nodes) {
|
|
const addr = await node.getMultiaddrWithId();
|
|
await waku.dial(addr);
|
|
}
|
|
|
|
let peers = await waku.getConnectedPeers();
|
|
expect(peers.length).to.equal(
|
|
serviceNodes.nodes.length,
|
|
"Connection should be established"
|
|
);
|
|
|
|
const peerId = await serviceNodes.nodes[0].getPeerId();
|
|
await waku.hangUp(peerId);
|
|
|
|
peers = await waku.getConnectedPeers();
|
|
expect(peers.length).to.equal(
|
|
serviceNodes.nodes.length - 1,
|
|
"Connection should be dropped"
|
|
);
|
|
});
|
|
|
|
it("should drop connection via multiaddr with hangUp", async function () {
|
|
for (const node of serviceNodes.nodes) {
|
|
const addr = await node.getMultiaddrWithId();
|
|
await waku.dial(addr);
|
|
}
|
|
|
|
let peers = await waku.getConnectedPeers();
|
|
expect(peers.length).to.equal(
|
|
serviceNodes.nodes.length,
|
|
"Connection should be established"
|
|
);
|
|
|
|
const addr = await serviceNodes.nodes[0].getMultiaddrWithId();
|
|
await waku.hangUp(addr);
|
|
|
|
peers = await waku.getConnectedPeers();
|
|
expect(peers.length).to.equal(
|
|
serviceNodes.nodes.length - 1,
|
|
"Connection should be dropped"
|
|
);
|
|
});
|
|
|
|
it("should be able to dial TLS multiaddrs", async function () {
|
|
let tlsWorks = true;
|
|
|
|
const multiaddr = `/ip4/127.0.0.1/tcp/30303/tls/ws`;
|
|
try {
|
|
// dummy multiaddr, doesn't have to be valid
|
|
await waku.dial(multiaddr);
|
|
} catch (error) {
|
|
if (error instanceof Error) {
|
|
expect(error.message).to.eq(`Could not connect to ${multiaddr}`);
|
|
tlsWorks = !error.message.includes("Unsupported protocol tls");
|
|
}
|
|
}
|
|
|
|
expect(tlsWorks).to.eq(true);
|
|
});
|
|
});
|