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

Commit

Permalink
chore!: update deps (#76)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: update to simpler connection api
  • Loading branch information
achingbrain authored Jun 16, 2022
1 parent f602e26 commit 50d1a5f
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,13 @@
"release": "aegir release"
},
"dependencies": {
"@libp2p/components": "^1.0.0",
"@libp2p/components": "^2.0.0",
"@libp2p/crypto": "^1.0.0",
"@libp2p/interfaces": "^3.0.2",
"@libp2p/logger": "^1.1.0",
"@libp2p/logger": "^2.0.0",
"@libp2p/peer-collections": "^1.0.0",
"@libp2p/peer-id": "^1.1.0",
"@libp2p/topology": "^2.0.0",
"@libp2p/topology": "^3.0.0",
"@multiformats/multiaddr": "^10.2.0",
"abortable-iterator": "^4.0.2",
"err-code": "^3.0.1",
Expand All @@ -191,10 +191,10 @@
"uint8arrays": "^3.0.0"
},
"devDependencies": {
"@libp2p/interface-connection": "^1.0.1",
"@libp2p/interface-connection": "^2.0.0",
"@libp2p/interface-peer-id": "^1.0.2",
"@libp2p/interface-pubsub": "^1.0.1",
"@libp2p/interface-registrar": "^1.0.0",
"@libp2p/interface-registrar": "^2.0.0",
"@libp2p/peer-id-factory": "^1.0.0",
"aegir": "^37.2.0",
"delay": "^5.0.0",
Expand Down
20 changes: 16 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,15 @@ export abstract class PubSubBaseProtocol<Events = PubSubEvents> extends EventEmi
* On an inbound stream opened
*/
protected _onIncomingStream (data: IncomingStreamData) {
const { protocol, stream, connection } = data
const { stream, connection } = data
const peerId = connection.remotePeer
const peer = this.addPeer(peerId, protocol)

if (stream.stat.protocol == null) {
stream.abort(new Error('Stream was not multiplexed'))
return
}

const peer = this.addPeer(peerId, stream.stat.protocol)
const inboundStream = peer.attachInboundStream(stream)

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

void Promise.resolve().then(async () => {
try {
const { stream, protocol } = await conn.newStream(this.multicodecs)
const peer = this.addPeer(peerId, protocol)
const stream = await conn.newStream(this.multicodecs)

if (stream.stat.protocol == null) {
stream.abort(new Error('Stream was not multiplexed'))
return
}

const peer = this.addPeer(peerId, stream.stat.protocol)
await peer.attachOutboundStream(stream)
} catch (err: any) {
log.error(err)
Expand Down
14 changes: 9 additions & 5 deletions test/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,23 +132,27 @@ export const ConnectionPair = (): [Connection, Connection] => {
{
// @ts-expect-error incomplete implementation
newStream: async (protocol: string[]) => await Promise.resolve({
protocol: protocol[0],
stream: d0
...d0,
stat: {
protocol: protocol[0]
}
})
},
{
// @ts-expect-error incomplete implementation
newStream: async (protocol: string[]) => await Promise.resolve({
protocol: protocol[0],
stream: d1
...d1,
stat: {
protocol: protocol[0]
}
})
}
]
}

export async function mockIncomingStreamEvent (protocol: string, conn: Connection, remotePeer: PeerId): Promise<IncomingStreamData> {
return {
...await conn.newStream([protocol]),
stream: await conn.newStream([protocol]),
// @ts-expect-error incomplete implementation
connection: {
remotePeer
Expand Down

0 comments on commit 50d1a5f

Please sign in to comment.