Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

Commit 88fcf02

Browse files
author
Akim
authored
fix(libp2p): Add fluence protocol to local peer store protocols [fixes DXJ-471] (#343)
Add fluence protocol to local peer store protocols
1 parent 31dab07 commit 88fcf02

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

packages/core/js-client/src/connection/RelayConnection.ts

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export class RelayConnection implements IConnection {
104104
return;
105105
}
106106

107-
const lib2p2Peer = await createLibp2p({
107+
this.lib2p2Peer = await createLibp2p({
108108
peerId: this.config.peerId,
109109
transports: [
110110
webSockets({
@@ -121,15 +121,16 @@ export class RelayConnection implements IConnection {
121121
denyDialMultiaddr: () => Promise.resolve(false)
122122
},
123123
services: {
124-
identify: identifyService({
125-
runOnConnectionOpen: false,
126-
}),
124+
identify: identifyService(),
127125
ping: pingService()
128126
}
129127
});
130128

131-
this.lib2p2Peer = lib2p2Peer;
132-
this.lib2p2Peer.start();
129+
const supportedProtocols = (await this.lib2p2Peer.peerStore.get(this.lib2p2Peer.peerId)).protocols;
130+
await this.lib2p2Peer.peerStore.patch(this.lib2p2Peer.peerId, {
131+
protocols: [...supportedProtocols, PROTOCOL_NAME]
132+
});
133+
133134
await this.connect();
134135
}
135136

@@ -156,16 +157,8 @@ export class RelayConnection implements IConnection {
156157
);
157158
}
158159

159-
/*
160-
TODO:: find out why this doesn't work and a new connection has to be established each time
161-
if (this._connection.streams.length !== 1) {
162-
throw new Error('Incorrect number of streams in FluenceConnection');
163-
}
164-
165-
const sink = this._connection.streams[0].sink;
166-
*/
167-
168160
log.trace('sending particle...');
161+
// Reusing active connection here
169162
const stream = await this.lib2p2Peer.dialProtocol(this.relayAddress, PROTOCOL_NAME);
170163
log.trace('created stream with id ', stream.id);
171164
const sink = stream.sink;

0 commit comments

Comments
 (0)