Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: overwrite stream fields after handshake #1305

Merged
merged 5 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/delegated-routing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@libp2p/delegated-content-routing": "^2.0.1",
"@libp2p/delegated-peer-routing": "^2.0.1",
"@libp2p/kad-dht": "^3.0.0",
"@libp2p/mplex": "^5.0.0",
"@libp2p/mplex": "^5.2.1",
"@libp2p/webrtc-star": "^3.0.0",
"@libp2p/websockets": "^3.0.0",
"react": "^17.0.2",
Expand Down
2 changes: 1 addition & 1 deletion examples/libp2p-in-the-browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"dependencies": {
"@chainsafe/libp2p-noise": "^8.0.0",
"@libp2p/bootstrap": "^2.0.0",
"@libp2p/mplex": "^5.0.0",
"@libp2p/mplex": "^5.2.1",
"@libp2p/webrtc-star": "^3.0.0",
"@libp2p/websockets": "^3.0.0",
"libp2p": "../../"
Expand Down
2 changes: 1 addition & 1 deletion examples/webrtc-direct/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@libp2p/webrtc-direct": "^2.0.0",
"@chainsafe/libp2p-noise": "^8.0.0",
"@libp2p/bootstrap": "^2.0.0",
"@libp2p/mplex": "^5.0.0",
"@libp2p/mplex": "^5.2.1",
"libp2p": "../../",
"wrtc": "^0.4.7"
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
"@libp2p/interop": "^2.0.0",
"@libp2p/kad-dht": "^3.0.4",
"@libp2p/mdns": "^3.0.0",
"@libp2p/mplex": "^5.0.0",
"@libp2p/mplex": "^5.2.1",
"@libp2p/pubsub": "^3.0.1",
"@libp2p/tcp": "^3.0.5",
"@libp2p/topology": "^3.0.0",
Expand Down
17 changes: 7 additions & 10 deletions src/upgrader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,20 +440,17 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
throw err
}

muxedStream.stat.protocol = protocol

// If a protocol stream has been successfully negotiated and is to be passed to the application,
// the peerstore should ensure that the peer is registered with that protocol
this.components.getPeerStore().protoBook.add(remotePeer, [protocol]).catch(err => log.error(err))

return {
...muxedStream,
...stream,
stat: {
...muxedStream.stat,
protocol
}
}
// after the handshake the returned stream can have early data so override
// the souce/sink
muxedStream.source = stream.source
muxedStream.sink = stream.sink
muxedStream.stat.protocol = protocol

return muxedStream
} catch (err: any) {
log.error('could not create new stream', err)

Expand Down