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: #2902 #2903

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 4 additions & 4 deletions packages/libp2p/src/transport-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ export class DefaultTransportManager implements TransportManager, Startable {
return this.started
}

start (): void {
async start (): Promise<void> {
this.started = true
}

async afterStart (): Promise<void> {
// Listen on the provided transports for the provided addresses
const addrs = this.components.addressManager.getListenAddrs()

await this.listen(addrs)
}

async afterStart (): Promise<void> {
}

/**
* Stops all listeners
*/
Expand Down
46 changes: 45 additions & 1 deletion packages/transport-websockets/test/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { multiaddr } from '@multiformats/multiaddr'
import { WebSockets, WebSocketsSecure } from '@multiformats/multiaddr-matcher'
import { expect } from 'aegir/chai'
import { isLoopbackAddr } from 'is-loopback-addr'
import { createLibp2p } from 'libp2p'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This module doesn't depend on libp2p but adding this test here would mean the dependency would need to be added.

This is intentional as it creates weird dependency loops that mean (among other things) a patch release of @libp2p/websockets would also cause a patch release of libp2p even if no changes were made there.

If you need to do integration-style testing, tests should be added to the integration-tests module, this won't cause any cascading releases.

import { pEvent } from 'p-event'
import pWaitFor from 'p-wait-for'
import Sinon from 'sinon'
import { stubInterface } from 'sinon-ts'
import * as filters from '../src/filters.js'
import { webSockets } from '../src/index.js'
import type { Connection, Libp2pEvents, Listener, Transport, Upgrader, TLSCertificate } from '@libp2p/interface'
import type { Connection, Libp2pEvents, Listener, Transport, Upgrader, TLSCertificate, PeerDiscoveryEvents, PeerDiscovery, Startable } from '@libp2p/interface'
import type { AddressManager } from '@libp2p/interface-internal'
import type { StubbedInstance } from 'sinon-ts'

describe('instantiate the transport', () => {
Expand Down Expand Up @@ -746,3 +748,45 @@ describe('auto-tls (IPv6)', () => {
expect(wsOptions.port).to.equal(wssOptions.port)
})
})

class TestPeerDiscovery extends TypedEventEmitter<PeerDiscoveryEvents> implements PeerDiscovery, Startable {
private readonly addressManager: AddressManager

constructor (components: {
addressManager: AddressManager
}) {
super()
this.addressManager = components.addressManager
}

async start (): Promise<void> {
}

async stop (): Promise<void> { }

afterStart (): void {
this.addressManager.getAddresses()
}

readonly [Symbol.toStringTag] = '@libp2p/test-peer-discovery'
}

describe('discovery-websockets', () => {
it('should discover peers over websockets', async () => {
const libp2p = await createLibp2p({
addresses: {
listen: [
'/ip4/0.0.0.0/tcp/0/ws'
]
},
peerDiscovery: [(component: {
addressManager: AddressManager
}) => new TestPeerDiscovery(component)],
transports: [
webSockets()
]
})

await libp2p.start()
})
})
Loading