Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 50d1a5f

Browse files
authored
chore!: update deps (#76)
BREAKING CHANGE: update to simpler connection api
1 parent f602e26 commit 50d1a5f

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -172,13 +172,13 @@
172172
"release": "aegir release"
173173
},
174174
"dependencies": {
175-
"@libp2p/components": "^1.0.0",
175+
"@libp2p/components": "^2.0.0",
176176
"@libp2p/crypto": "^1.0.0",
177177
"@libp2p/interfaces": "^3.0.2",
178-
"@libp2p/logger": "^1.1.0",
178+
"@libp2p/logger": "^2.0.0",
179179
"@libp2p/peer-collections": "^1.0.0",
180180
"@libp2p/peer-id": "^1.1.0",
181-
"@libp2p/topology": "^2.0.0",
181+
"@libp2p/topology": "^3.0.0",
182182
"@multiformats/multiaddr": "^10.2.0",
183183
"abortable-iterator": "^4.0.2",
184184
"err-code": "^3.0.1",
@@ -191,10 +191,10 @@
191191
"uint8arrays": "^3.0.0"
192192
},
193193
"devDependencies": {
194-
"@libp2p/interface-connection": "^1.0.1",
194+
"@libp2p/interface-connection": "^2.0.0",
195195
"@libp2p/interface-peer-id": "^1.0.2",
196196
"@libp2p/interface-pubsub": "^1.0.1",
197-
"@libp2p/interface-registrar": "^1.0.0",
197+
"@libp2p/interface-registrar": "^2.0.0",
198198
"@libp2p/peer-id-factory": "^1.0.0",
199199
"aegir": "^37.2.0",
200200
"delay": "^5.0.0",

src/index.ts

+16-4
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,15 @@ export abstract class PubSubBaseProtocol<Events = PubSubEvents> extends EventEmi
165165
* On an inbound stream opened
166166
*/
167167
protected _onIncomingStream (data: IncomingStreamData) {
168-
const { protocol, stream, connection } = data
168+
const { stream, connection } = data
169169
const peerId = connection.remotePeer
170-
const peer = this.addPeer(peerId, protocol)
170+
171+
if (stream.stat.protocol == null) {
172+
stream.abort(new Error('Stream was not multiplexed'))
173+
return
174+
}
175+
176+
const peer = this.addPeer(peerId, stream.stat.protocol)
171177
const inboundStream = peer.attachInboundStream(stream)
172178

173179
this.processMessages(peerId, inboundStream, peer)
@@ -182,8 +188,14 @@ export abstract class PubSubBaseProtocol<Events = PubSubEvents> extends EventEmi
182188

183189
void Promise.resolve().then(async () => {
184190
try {
185-
const { stream, protocol } = await conn.newStream(this.multicodecs)
186-
const peer = this.addPeer(peerId, protocol)
191+
const stream = await conn.newStream(this.multicodecs)
192+
193+
if (stream.stat.protocol == null) {
194+
stream.abort(new Error('Stream was not multiplexed'))
195+
return
196+
}
197+
198+
const peer = this.addPeer(peerId, stream.stat.protocol)
187199
await peer.attachOutboundStream(stream)
188200
} catch (err: any) {
189201
log.error(err)

test/utils/index.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -132,23 +132,27 @@ export const ConnectionPair = (): [Connection, Connection] => {
132132
{
133133
// @ts-expect-error incomplete implementation
134134
newStream: async (protocol: string[]) => await Promise.resolve({
135-
protocol: protocol[0],
136-
stream: d0
135+
...d0,
136+
stat: {
137+
protocol: protocol[0]
138+
}
137139
})
138140
},
139141
{
140142
// @ts-expect-error incomplete implementation
141143
newStream: async (protocol: string[]) => await Promise.resolve({
142-
protocol: protocol[0],
143-
stream: d1
144+
...d1,
145+
stat: {
146+
protocol: protocol[0]
147+
}
144148
})
145149
}
146150
]
147151
}
148152

149153
export async function mockIncomingStreamEvent (protocol: string, conn: Connection, remotePeer: PeerId): Promise<IncomingStreamData> {
150154
return {
151-
...await conn.newStream([protocol]),
155+
stream: await conn.newStream([protocol]),
152156
// @ts-expect-error incomplete implementation
153157
connection: {
154158
remotePeer

0 commit comments

Comments
 (0)