Skip to content

Commit beb0937

Browse files
authored
fix: update interface tests (#5)
The tests still fail but now they run with the new suite.
1 parent 676650e commit beb0937

File tree

6 files changed

+1929
-1485
lines changed

6 files changed

+1929
-1485
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@
5555
"dependencies": {
5656
"@libp2p/crypto": "^5.0.1",
5757
"@libp2p/interface": "^2.0.1",
58-
"@multiformats/mafmt": "^12.1.6",
5958
"@multiformats/multiaddr": "^12.3.1",
59+
"@multiformats/multiaddr-matcher": "^1.6.0",
6060
"it-stream-types": "^2.0.2",
6161
"uint8arraylist": "^2.4.8"
6262
},
6363
"devDependencies": {
64-
"@napi-rs/cli": "^3.0.0-alpha.64",
6564
"@libp2p/interface-compliance-tests": "^6.0.1",
6665
"@libp2p/logger": "^5.0.1",
66+
"@napi-rs/cli": "^3.0.0-alpha.64",
6767
"aegir": "^44.1.1"
6868
},
6969
"packageManager": "[email protected]+sha256.c17d3797fb9a9115bf375e31bfd30058cac6bc9c3b8807a3d8cb2094794b51ca"

src/filter.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Multiaddr } from "@multiformats/multiaddr"
2-
import * as mafmt from '@multiformats/mafmt'
2+
import { QUICV1 } from '@multiformats/multiaddr-matcher'
33

44
// p2p multi-address code
55
export const CODE_P2P = 421
@@ -8,11 +8,7 @@ export const CODE_UNIX = 400
88

99
export function listenFilter(multiaddrs: Multiaddr[]): Multiaddr[] {
1010
return multiaddrs.filter((ma) => {
11-
if (ma.protoCodes().includes(CODE_CIRCUIT)) {
12-
return false
13-
}
14-
15-
return mafmt.QUICV1.matches(ma.decapsulateCode(CODE_P2P))
11+
return QUICV1.exactMatch(ma)
1612
})
1713
}
1814

src/listener.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ type QuicListenerState = {
2626
listener: napi.Server
2727
listenAddr: Multiaddr
2828
controller: AbortController
29-
connections: Set<Connection>
29+
connections: Set<QuicConnection>
3030
} | {
3131
status: 'closed'
3232
}
@@ -143,7 +143,7 @@ export class QuicListener extends TypedEventEmitter<ListenerEvents> implements L
143143
})
144144

145145
try {
146-
const conn = await this.options.upgrader.upgradeInbound(maConn, {
146+
await this.options.upgrader.upgradeInbound(maConn, {
147147
skipEncryption: true,
148148
skipProtection: true,
149149
muxerFactory: new QuicStreamMuxerFactory({
@@ -152,15 +152,12 @@ export class QuicListener extends TypedEventEmitter<ListenerEvents> implements L
152152
}),
153153
})
154154

155-
this.state.connections.add(conn)
155+
this.state.connections.add(maConn)
156156
maConn.addEventListener('close', () => {
157157
if (this.state.status === 'listening') {
158-
this.state.connections.delete(conn)
158+
this.state.connections.delete(maConn)
159159
}
160160
}, { once: true })
161-
162-
this.safeDispatchEvent('connection', { detail: conn })
163-
this.options.handler?.(conn)
164161
} catch (err) {
165162
this.log.error('%s error handling inbound connection', this.state.listenAddr.toString(), err)
166163
maConn.abort(err as Error)

src/transport.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ export class QuicTransport implements Transport {
9797
connection,
9898
logger: this.components.logger,
9999
}),
100+
signal: options.signal
100101
})
101102
}
102103

test/compliance.spec.ts

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,70 @@
11
import transportCompliance from '@libp2p/interface-compliance-tests/transport'
2-
import { multiaddr } from '@multiformats/multiaddr'
3-
2+
import { QUICV1 } from '@multiformats/multiaddr-matcher'
43
import { quic } from '../src/index.js'
5-
import { QuicTransport } from '../src/transport.js'
6-
import { createComponents } from './util.js'
74

8-
describe.only('Interface compliance tests', () => {
5+
describe.only('Interface compliance tests (IPv4)', () => {
96
// Fails these listener tests:
107
// - close listener with connections, through timeout
118
// - should not handle connection if upgradeInbound throws
129
transportCompliance({
1310
async setup () {
14-
const transport = quic()(await createComponents())
15-
16-
const addrs = [
17-
multiaddr('/ip4/127.0.0.1/udp/9091/quic-v1'),
18-
multiaddr('/ip4/127.0.0.1/udp/9092/quic-v1'),
19-
multiaddr('/ip4/127.0.0.1/udp/9093/quic-v1'),
20-
multiaddr('/ip6/::/udp/9094/quic-v1'),
21-
]
11+
const dialer = {
12+
transports: [
13+
quic()
14+
],
15+
connectionMonitor: {
16+
enabled: false
17+
}
18+
}
2219

23-
const dial = QuicTransport.prototype.dial
24-
// Used by the dial tests to simulate a delayed connect
25-
const connector = {
26-
delay (delayMs: number) {
27-
QuicTransport.prototype.dial = async function (...args) {
28-
await new Promise((resolve) => setTimeout(resolve, delayMs))
29-
return dial.bind(this)(...args)
30-
}
20+
return {
21+
dialer,
22+
listener: {
23+
addresses: {
24+
listen: [
25+
'/ip4/127.0.0.1/udp/9091/quic-v1',
26+
'/ip4/127.0.0.1/udp/9092/quic-v1'
27+
]
28+
},
29+
...dialer
3130
},
32-
restore () {
33-
QuicTransport.prototype.dial = dial
31+
dialMultiaddrMatcher: QUICV1,
32+
listenMultiaddrMatcher: QUICV1
33+
}
34+
},
35+
async teardown () {}
36+
})
37+
})
38+
39+
describe('Interface compliance tests (IPv6)', () => {
40+
// Fails these listener tests:
41+
// - close listener with connections, through timeout
42+
// - should not handle connection if upgradeInbound throws
43+
transportCompliance({
44+
async setup () {
45+
const dialer = {
46+
transports: [
47+
quic()
48+
],
49+
connectionMonitor: {
50+
enabled: false
3451
}
3552
}
3653

37-
return { dialer: transport, listener: transport, listenAddrs: addrs, dialAddrs: addrs, connector }
54+
return {
55+
dialer,
56+
listener: {
57+
addresses: {
58+
listen: [
59+
'/ip6/::/udp/9091/quic-v1',
60+
'/ip6/::/udp/9092/quic-v1'
61+
]
62+
},
63+
...dialer
64+
},
65+
dialMultiaddrMatcher: QUICV1,
66+
listenMultiaddrMatcher: QUICV1
67+
}
3868
},
3969
async teardown () {}
4070
})

0 commit comments

Comments
 (0)