-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
8,919 additions
and
6,924 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
// }); |
Oops, something went wrong.