Skip to content

Commit

Permalink
perf: express and local-core
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohaodu committed May 29, 2024
1 parent cd15bad commit 10cb946
Show file tree
Hide file tree
Showing 6 changed files with 320 additions and 249 deletions.
4 changes: 2 additions & 2 deletions packages/local-chat-x-core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ app.use(morgan("combined"));
app.get("/test", (_req, res) => {
res.send({
type: "message",
message: "you testing the local-webchat-x-core http://127.0.0.1:6666",
message: "you testing the local-webchat-x-core http://127.0.0.1:" + port,
});
});

Expand All @@ -24,6 +24,6 @@ app.get("/libp2p", async (_req, res) => {

app.listen(port, () => {
console.log(
`local relay node running with prot ${port},http://127.0.0.1:6666`
`local relay node running with prot ${port},http://127.0.0.1:${port}`
);
});
78 changes: 40 additions & 38 deletions packages/local-chat-x-core/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,23 @@ export default class Libp2pManager {
}),
pubsubPeerDiscovery({
interval: 10000,
topics: topics, // defaults to ['_peer-discovery._p2p._pubsub']
topics: topics,
listenOnly: false,
}),
],
peerId: peerId,
});
}
private handleListenEvent() {
// this.libp2p.addEventListener("connection:open", (connection) => {
// console.log("connection:open", connection.detail);
// });
// this.libp2p.addEventListener("connection:close", (connection) => {
// console.log("connection:open", connection.detail);
// });
// this.libp2p.addEventListener("connection:prune", (connection) => {
// console.log("connection:prune", connection.detail);
// });
this.libp2p.addEventListener("connection:open", (connection) => {
console.log("connection:open", connection.detail);
});
this.libp2p.addEventListener("connection:close", (connection) => {
console.log("connection:open", connection.detail);
});
this.libp2p.addEventListener("connection:prune", (connection) => {
console.log("connection:prune", connection.detail);
});
this.libp2p.addEventListener("peer:connect", (peerId) => {
console.log("peer:connect ", peerId.detail);
});
Expand All @@ -128,40 +128,42 @@ export default class Libp2pManager {
console.log("peer:discovery ", peerIdInfo.detail);
});

// this.libp2p.addEventListener("peer:identify", (identifyResult) => {
// console.log("peer:identify ", identifyResult.detail);
// });
// this.libp2p.addEventListener("peer:update", (peerUpdate) => {
// console.log("peer:update ", peerUpdate.detail);
// });
// this.libp2p.addEventListener("self:peer:update", (peerUpdate) => {
// console.log("self:peer:update ", peerUpdate.detail);
// console.log("self:peer:update protocols", libp2p?.getProtocols());
// console.log("self:peer:update multiaddrs", libp2p?.getMultiaddrs());
// libp2p?.getMultiaddrs().forEach((multiaddr, index) => {
// console.log(`self:peer:update multiaddr ${index} ${multiaddr.toString()}`);
// });
// console.log("self:peer:update dialQueue", libp2p?.getDialQueue());
// console.log("self:peer:update connections", libp2p?.getConnections());
// console.log("self:peer:update peers", libp2p?.getPeers());
// });
this.libp2p.addEventListener("peer:identify", (identifyResult) => {
console.log("peer:identify ", identifyResult.detail);
});
this.libp2p.addEventListener("peer:update", (peerUpdate) => {
console.log("peer:update ", peerUpdate.detail);
});
this.libp2p.addEventListener("self:peer:update", (peerUpdate) => {
console.log("self:peer:update ", peerUpdate.detail);
console.log("self:peer:update protocols", this.libp2p.getProtocols());
console.log("self:peer:update multiaddrs", this.libp2p.getMultiaddrs());
this.libp2p.getMultiaddrs().forEach((multiaddr, index) => {
console.log(
`self:peer:update multiaddr ${index} ${multiaddr.toString()}`
);
});
console.log("self:peer:update dialQueue", this.libp2p.getDialQueue());
console.log("self:peer:update connections", this.libp2p.getConnections());
console.log("self:peer:update peers", this.libp2p.getPeers());
});
this.libp2p.addEventListener("start", () => {
console.log("start");
// console.log("protocols", libp2p?.getProtocols());
// console.log("multiaddrs", libp2p?.getMultiaddrs());
// console.log("dialQueue", libp2p?.getDialQueue());
// console.log("connections", libp2p?.getConnections());
// console.log("peers", libp2p?.getPeers());
console.log("protocols", this.libp2p.getProtocols());
console.log("multiaddrs", this.libp2p.getMultiaddrs());
console.log("dialQueue", this.libp2p.getDialQueue());
console.log("connections", this.libp2p.getConnections());
console.log("peers", this.libp2p.getPeers());
});
this.libp2p.addEventListener("stop", () => {
console.log("stop");
});
// this.libp2p.addEventListener("transport:close", (listener) => {
// console.log("transport:close", listener.detail);
// });
// this.libp2p.addEventListener("transport:listening", (listener) => {
// console.log("transport:listening", listener.detail);
// });
this.libp2p.addEventListener("transport:close", (listener) => {
console.log("transport:close", listener.detail);
});
this.libp2p.addEventListener("transport:listening", (listener) => {
console.log("transport:listening", listener.detail);
});
}

private handleProtocol() {}
Expand Down
Loading

0 comments on commit 10cb946

Please sign in to comment.