Skip to content

Commit

Permalink
refactor: update libp2p-yamux and fix breaking changes
Browse files Browse the repository at this point in the history
 - Passing a logger to MuxerInit is now required
 - Passing a logger to yamux()({logger:...}) is now required

See: #120

Update dependencies and fix various breaking changes introduced by those
dependency updates:

- Change type of Conn to Duplex<Uint8Array | Uint8ArrayList>
- Pass default logger to yamux as it's now required.

Related:

- ChainSafe/js-libp2p-yamux#69
- libp2p/js-libp2p#2275
- ChainSafe/js-libp2p-yamux#70

Signed-off-by: Christian Stewart <christian@aperture.us>
  • Loading branch information
paralin committed Feb 7, 2024
1 parent e64b3ac commit 53619e7
Show file tree
Hide file tree
Showing 6 changed files with 337 additions and 278 deletions.
2 changes: 1 addition & 1 deletion .github/renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"enabled": false
},
{
"matchPackageNames": ["@chainsafe/libp2p-yamux", "@libp2p/interface", "uint8arraylist"],
"matchPackageNames": ["uint8arraylist"],
"enabled": false
}
]
Expand Down
2 changes: 1 addition & 1 deletion hack/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ replace google.golang.org/protobuf => github.com/aperturerobotics/protobuf-go v1

require (
github.com/golangci/golangci-lint v1.55.2 // latest
github.com/planetscale/vtprotobuf v0.6.0 // main
github.com/planetscale/vtprotobuf v0.6.0 // latest
github.com/psampaz/go-mod-outdated v0.9.0
google.golang.org/protobuf v1.32.0
)
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@
},
"dependencies": {
"@aptre/it-ws": "^1.0.0",
"@chainsafe/libp2p-yamux": "^5.0.0",
"@libp2p/interface": "^0.1.2",
"@chainsafe/libp2p-yamux": "^6.0.1",
"@libp2p/interface": "^1.0.1",
"@libp2p/logger": "^4.0.5",
"event-iterator": "^2.0.0",
"is-promise": "^4.0.0",
"isomorphic-ws": "^5.0.0",
Expand Down
12 changes: 9 additions & 3 deletions srpc/conn.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { yamux } from '@chainsafe/libp2p-yamux'
import type { Direction, Stream } from '@libp2p/interface/connection'
import type {
Direction,
Stream,
StreamMuxer,
StreamMuxerFactory,
} from '@libp2p/interface/stream-muxer'
} from '@libp2p/interface'
import { pipe } from 'it-pipe'
import type { Duplex, Source } from 'it-stream-types'
import { Uint8ArrayList } from 'uint8arraylist'
import isPromise from 'is-promise'
import { pushable, Pushable } from 'it-pushable'
import { defaultLogger } from '@libp2p/logger'

import type { OpenStreamFunc, Stream as SRPCStream } from './stream.js'
import { Client } from './client.js'
Expand Down Expand Up @@ -73,7 +75,11 @@ export class Conn
if (server) {
this.server = server
}
const muxerFactory = connParams?.muxerFactory ?? yamux()()
const muxerFactory =
connParams?.muxerFactory ??
yamux()({
logger: defaultLogger(),
})
this.muxer = muxerFactory.createStreamMuxer({
onIncomingStream: this.handleIncomingStream.bind(this),
direction: connParams?.direction || 'outbound',
Expand Down
2 changes: 1 addition & 1 deletion srpc/websocket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { pipe } from 'it-pipe'
import { Direction } from '@libp2p/interface/connection'
import { Direction } from '@libp2p/interface'

import duplex from '@aptre/it-ws/duplex'
import type WebSocket from '@aptre/it-ws/web-socket'
Expand Down
Loading

0 comments on commit 53619e7

Please sign in to comment.