This repository has been archived by the owner on Jun 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use transport manager getListeners to get listen addresses (#166)
- Loading branch information
1 parent
f0f4e7c
commit 2e144f9
Showing
5 changed files
with
53 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { createEd25519PeerId } from '@libp2p/peer-id-factory' | ||
import { multiaddr } from '@multiformats/multiaddr' | ||
import { expect } from 'aegir/chai' | ||
import { stubInterface } from 'sinon-ts' | ||
import { WebRTCPeerListener } from '../src/private-to-private/listener' | ||
import type { Listener, TransportManager } from '@libp2p/interface-transport' | ||
|
||
describe('webrtc private-to-private listener', () => { | ||
it('should only return relay addresses as webrtc listen addresses', async () => { | ||
const relayedAddress = '/ip4/127.0.0.1/tcp/4034/ws/p2p-circuit' | ||
const otherListenAddress = '/ip4/127.0.0.1/tcp/4001' | ||
const peerId = await createEd25519PeerId() | ||
const transportManager = stubInterface<TransportManager>() | ||
|
||
const listener = new WebRTCPeerListener({ | ||
peerId, | ||
transportManager | ||
}) | ||
|
||
const otherListener = stubInterface<Listener>({ | ||
getAddrs: [multiaddr(otherListenAddress)] | ||
}) | ||
|
||
const relayListener = stubInterface<Listener>({ | ||
getAddrs: [multiaddr(relayedAddress)] | ||
}) | ||
|
||
transportManager.getListeners.returns([ | ||
listener, | ||
otherListener, | ||
relayListener | ||
]) | ||
|
||
const addresses = listener.getAddrs() | ||
|
||
expect(addresses.map(ma => ma.toString())).to.deep.equal([ | ||
`${relayedAddress}/webrtc/p2p/${peerId}` | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters