fix: add yamux interop tests (#1290)

Test stream compatibility with https://www.npmjs.com/package/@chainsafe/libp2p-yamux

Co-authored-by: achingbrain <alex@achingbrain.net>
This commit is contained in:
Cayman 2022-09-09 06:27:34 -04:00 committed by achingbrain
parent dd14f82ed5
commit b87632f97f
3 changed files with 17 additions and 5 deletions

View File

@ -168,16 +168,17 @@
},
"devDependencies": {
"@chainsafe/libp2p-noise": "^8.0.0",
"@chainsafe/libp2p-yamux": "^1.0.0",
"@libp2p/bootstrap": "^2.0.0",
"@libp2p/daemon-client": "^2.0.4",
"@libp2p/daemon-server": "^2.0.4",
"@libp2p/daemon-client": "^3.0.0",
"@libp2p/daemon-server": "^3.0.0",
"@libp2p/delegated-content-routing": "^2.0.1",
"@libp2p/delegated-peer-routing": "^2.0.1",
"@libp2p/floodsub": "^3.0.0",
"@libp2p/interface-compliance-tests": "^3.0.1",
"@libp2p/interface-connection-encrypter-compliance-tests": "^2.0.1",
"@libp2p/interface-mocks": "^4.0.1",
"@libp2p/interop": "^2.0.0",
"@libp2p/interop": "^3.0.0",
"@libp2p/kad-dht": "^3.0.4",
"@libp2p/mdns": "^3.0.0",
"@libp2p/mplex": "^5.2.1",

View File

@ -374,6 +374,10 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
return
}
// 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
// If a protocol stream has been successfully negotiated and is to be passed to the application,
@ -381,7 +385,7 @@ export class DefaultUpgrader extends EventEmitter<UpgraderEvents> implements Upg
this.components.getPeerStore().protoBook.add(remotePeer, [protocol]).catch(err => log.error(err))
connection.addStream(muxedStream)
this._onStream({ connection, stream: { ...muxedStream, ...stream }, protocol })
this._onStream({ connection, stream: muxedStream, protocol })
})
.catch(err => {
log.error(err)

View File

@ -12,6 +12,7 @@ import { execa } from 'execa'
import pDefer from 'p-defer'
import { logger } from '@libp2p/logger'
import { Mplex } from '@libp2p/mplex'
import { Yamux } from '@chainsafe/libp2p-yamux'
import fs from 'fs'
import { unmarshalPrivateKey } from '@libp2p/crypto/keys'
import type { PeerId } from '@libp2p/interface-peer-id'
@ -93,10 +94,16 @@ async function createJsPeer (options: SpawnOptions): Promise<Daemon> {
listen: ['/ip4/0.0.0.0/tcp/0']
},
transports: [new TCP()],
streamMuxers: [new Mplex()],
streamMuxers: [],
connectionEncryption: [new Noise()]
}
if (options.muxer === 'mplex') {
opts.streamMuxers?.push(new Mplex())
} else {
opts.streamMuxers?.push(new Yamux())
}
if (options.dht === true) {
// go-libp2p-daemon only has the older single-table DHT instead of the dual
// lan/wan version found in recent go-ipfs versions. unfortunately it's been