Skip to content

Commit

Permalink
fix: libp2p
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaohaodu committed May 22, 2024
1 parent 9f72915 commit 08000b1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
10 changes: 10 additions & 0 deletions packages/web-chat-x-express/src/controllers/libp2p.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import { parsePrivateKeySecret } from "../utils/parseSecret.js";
import { mdns } from "@libp2p/mdns";
import { gossipsub } from "@chainsafe/libp2p-gossipsub";
import { Server } from "https";
import { pubsubPeerDiscovery } from "@libp2p/pubsub-peer-discovery";
// import { bootstrap } from "@libp2p/bootstrap";
const topics = [
`webChatX._peer-discovery._p2p._pubsub`, // It's recommended but not required to extend the global space
// "_peer-discovery._p2p._pubsub", // Include if you want to participate in the global space
];
/**
* 定义 RelayServiceOptions 类型,用于配置启动和停止回调函数
* */
Expand Down Expand Up @@ -90,6 +95,11 @@ async function createRelayNode(_server?: Server): Promise<Libp2p> {
// bootstrap({
// list: [],
// }),
pubsubPeerDiscovery({
interval: 10000,
topics: topics, // defaults to ['_peer-discovery._p2p._pubsub']
listenOnly: false,
}),
],
peerId: peerId,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/web-chat-x-vue/src/classes/Libp2pManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { Multiaddr, multiaddr } from "@multiformats/multiaddr";
import { GossipsubEvents, gossipsub } from "@chainsafe/libp2p-gossipsub";
import ChatUser from "./ChatUser";
// import { pubsubPeerDiscovery } from "@libp2p/pubsub-peer-discovery";
import { pubsubPeerDiscovery } from "@libp2p/pubsub-peer-discovery";
import { pipe } from "it-pipe";
import { DatabaseManager } from "./DatabaseManager";
import ChatMessageAggregation from "./ChatMessageAggregation";
Expand Down Expand Up @@ -211,7 +211,7 @@ export class Libp2pManager {
listen: ["/webrtc"],
},
transports: [
webSockets({ filter: filters.all }),
webSockets({ filter: filters.dnsWsOrWss }),
webRTC({
rtcConfiguration: {
iceServers: [
Expand All @@ -230,7 +230,7 @@ export class Libp2pManager {
},
}),
circuitRelayTransport({
discoverRelays: 100,
discoverRelays: 1,
}),
],
connectionEncryption: [noise()],
Expand Down
1 change: 1 addition & 0 deletions packages/web-chat-x-vue/src/views/StartChatting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ async function friendRequest() {
privateChatFormData.userId
);
const remotePeerId = peerIdFromString(remotePeerIdString);
// "/dns/webchatx.mayuan.work/tcp/10000/ws/p2p/12D3KooWFzsY7wUBHwbrz6m9nFfLCDwqLD4LS9JykKxSZ4zqG7Pg/p2p-circuit/p2p/"
await libp2pManager.requestFriend(
remotePeerId,
privateChatFormData.validationMessage ||
Expand Down

0 comments on commit 08000b1

Please sign in to comment.