Skip to content

Commit

Permalink
feat-beta: bootstrap
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohaodu committed May 29, 2024
1 parent f91f149 commit e94937d
Show file tree
Hide file tree
Showing 12 changed files with 8,919 additions and 6,924 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
"@commitlint/config-conventional": "^19.2.2",
"copyfiles": "^2.4.1",
"husky": "^9.0.11",
"nodemon": "^3.1.0",
"ts-node": "^10.9.2",
"typescript": "5.4.2",
"vitest": "^1.3.1"
"vitest": "^1.3.1",
"pm2": "^5.3.1",
"supertest": "^6.3.4"
}
}
9 changes: 0 additions & 9 deletions packages/local-chat-x-core/index.html

This file was deleted.

84 changes: 24 additions & 60 deletions packages/local-chat-x-core/index.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,29 @@
import { Libp2p } from "libp2p";
import { startRelayService } from "./libp2p.js";
import express from "express";
const app = express();
const port = 6666;

const libp2p = (await startRelayService({
onStarted: (listenMultiaddrArray) => {
console.log("Relay service started on:");
listenMultiaddrArray.forEach((addr) => {
console.log("-> ", addr.toString());
});
},
onStopped: () => console.log("Relay service stopped"),
})) as Libp2p;
// libp2p.addEventListener("connection:open", (connection) => {
// console.log("connection:open", connection.detail);
// });
// libp2p.addEventListener("connection:close", (connection) => {
// console.log("connection:open", connection.detail);
// });
// libp2p.addEventListener("connection:prune", (connection) => {
// console.log("connection:prune", connection.detail);
// });
libp2p.addEventListener("peer:connect", (peerId) => {
console.log("peer:connect ", peerId.detail);
});
libp2p.addEventListener("peer:disconnect", (peerId) => {
console.log("peer:disconnect ", peerId.detail);
});
libp2p.addEventListener("peer:discovery", (peerIdInfo) => {
console.log("peer:discovery ", peerIdInfo.detail);
import Libp2pManager from "./libp2p.js";
const libp2pManager = new Libp2pManager();
libp2pManager.startRelayService();

import morgan from "morgan";

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",
});
});

// libp2p.addEventListener("peer:identify", (identifyResult) => {
// console.log("peer:identify ", identifyResult.detail);
// });
// libp2p.addEventListener("peer:update", (peerUpdate) => {
// console.log("peer:update ", peerUpdate.detail);
// });
// 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());
// });
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());
app.get("/libp2p", async (_req, res) => {
const peerStore = await libp2pManager.libp2p.peerStore.all();
res.send(peerStore);
});
libp2p.addEventListener("stop", () => {
console.log("stop");

app.listen(port, () => {
console.log(
`local relay node running with prot ${port},http://127.0.0.1:6666`
);
});
// libp2p.addEventListener("transport:close", (listener) => {
// console.log("transport:close", listener.detail);
// });
// libp2p.addEventListener("transport:listening", (listener) => {
// console.log("transport:listening", listener.detail);
// });
Loading

0 comments on commit e94937d

Please sign in to comment.