[go: up one dir, main page]

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

feat: add webtransport listener #2422

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c722ce1
feat: add webtransport listener
achingbrain Feb 23, 2024
e7c33fb
Merge remote-tracking branch 'origin/main' into feat/add-webtransport…
achingbrain Apr 3, 2024
016da0a
chore: fix up tests
achingbrain Apr 3, 2024
19e5dd0
chore: fix deps
achingbrain Apr 3, 2024
c31c054
chore: most tests passing
achingbrain Apr 8, 2024
1f6f0f1
chore: remove log
achingbrain Apr 8, 2024
dac49e6
Merge remote-tracking branch 'origin/main' into feat/add-webtransport…
achingbrain Apr 8, 2024
2581673
chore: update go version
achingbrain Apr 8, 2024
74d0a7d
chore: update go version
achingbrain Apr 8, 2024
a9ffb09
Merge remote-tracking branch 'origin/main' into feat/add-webtransport…
achingbrain Apr 28, 2024
0eadc67
chore: update version
achingbrain Apr 28, 2024
825a297
chore: missed merge
achingbrain Apr 28, 2024
c9df7a2
chore: consistent logging
achingbrain Apr 28, 2024
5f35c6a
chore: install go on node runners
achingbrain Apr 28, 2024
9fe17b0
chore: install go on electron runners
achingbrain Apr 28, 2024
8b5e9b7
chore: generate certs on listen
achingbrain Apr 28, 2024
0b4ec75
Merge branch 'main' into feat/add-webtransport-listener
achingbrain Apr 29, 2024
c7a552f
Merge branch 'main' into feat/add-webtransport-listener
achingbrain Apr 30, 2024
f453592
chore: run webtransport integration tests
achingbrain Apr 30, 2024
7862f36
Merge remote-tracking branch 'origin/main' into feat/add-webtransport…
achingbrain May 1, 2024
670e96f
chore: unskip tests
achingbrain May 1, 2024
ec7add6
Merge remote-tracking branch 'origin/main' into feat/add-webtransport…
achingbrain May 17, 2024
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
Prev Previous commit
Next Next commit
chore: fix up tests
  • Loading branch information
achingbrain committed Apr 3, 2024
commit 016da0afdfef8dc70b9c1b807f8c87a64d965454
1 change: 1 addition & 0 deletions packages/transport-webtransport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"@libp2p/peer-id": "^4.0.8",
"@multiformats/multiaddr": "^12.2.1",
"@multiformats/multiaddr-matcher": "^1.2.0",
"browser-readablestream-to-it": "^2.0.5",
"it-stream-types": "^2.0.1",
"multiformats": "^13.1.0",
"race-signal": "^1.0.2",
Expand Down
3 changes: 2 additions & 1 deletion packages/transport-webtransport/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import { noise } from '@chainsafe/libp2p-noise'
import { AbortError, transportSymbol } from '@libp2p/interface'
import { WebTransport as WebTransportMatcher } from '@multiformats/multiaddr-matcher'
import { raceSignal } from 'race-signal'
import createListener from './listener.js'
import { webtransportMuxer } from './muxer.js'
import { inertDuplex } from './utils/inert-duplex.js'
Expand Down Expand Up @@ -104,8 +105,8 @@

async dial (ma: Multiaddr, options: DialOptions): Promise<Connection> {
if (options?.signal?.aborted === true) {
throw new AbortError()
}

Check warning on line 109 in packages/transport-webtransport/src/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/transport-webtransport/src/index.ts#L108-L109

Added lines #L108 - L109 were not covered by tests

this.log('dialing %s', ma)
const localPeer = this.components.peerId
Expand Down Expand Up @@ -193,13 +194,13 @@
cleanUpWTSession('remote_close')
})

if (!await this.authenticateWebTransport(wt, localPeer, remotePeer, certhashes)) {
if (!await raceSignal(this.authenticateWebTransport(wt, localPeer, remotePeer, certhashes), options.signal)) {
throw new Error('Failed to authenticate webtransport')
}

if (options?.signal?.aborted === true) {
throw new AbortError()
}

Check warning on line 203 in packages/transport-webtransport/src/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/transport-webtransport/src/index.ts#L202-L203

Added lines #L202 - L203 were not covered by tests

this.metrics?.dialerEvents.increment({ open: true })

Expand Down Expand Up @@ -300,10 +301,10 @@
}

createListener (options: CreateListenerOptions): Listener {
return createListener(this.components, {
...options,
certificates: this.config.certificates
})

Check warning on line 307 in packages/transport-webtransport/src/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/transport-webtransport/src/index.ts#L304-L307

Added lines #L304 - L307 were not covered by tests
}

/**
Expand Down
12 changes: 9 additions & 3 deletions packages/transport-webtransport/src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ class WebTransportStream extends AbstractStream {

Promise.resolve().then(async () => {
while (true) {
init.log('readData waiting for reader to be ready')
const result = await this.reader.read()

init.log('readData read', result)

if (result.done) {
init.log('remote closed read')
this.remoteCloseRead()
init.log('remote closed write')
this.remoteCloseWrite()
return
}

if (result.value != null) {
init.log('push valud', new Uint8ArrayList(result.value))
this.sourcePush(new Uint8ArrayList(result.value))
}
}
Expand All @@ -45,7 +49,7 @@ class WebTransportStream extends AbstractStream {
init.log('writer close promise rejected', err)
})
.finally(() => {
this.remoteCloseWrite()
this.remoteCloseRead()
})
}

Expand All @@ -55,7 +59,9 @@ class WebTransportStream extends AbstractStream {

async sendData (buf: Uint8ArrayList, options?: AbortOptions): Promise<void> {
for await (const chunk of buf) {
this.log('sendData waiting for writer to be ready')
await raceSignal(this.writer.ready, options?.signal)
this.log('sendData sending data', chunk)
await raceSignal(this.writer.write(chunk), options?.signal)
}
}
Expand Down
13 changes: 12 additions & 1 deletion packages/transport-webtransport/test/webtransport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { expect } from 'aegir/chai'
import map from 'it-map'
import toBuffer from 'it-to-buffer'
import { createLibp2p, type Libp2p } from 'libp2p'
import pWaitFor from 'p-wait-for'
import { webTransport } from '../src/index.js'
import { randomBytes } from './fixtures/random-bytes.js'

Expand All @@ -19,6 +20,9 @@ describe('libp2p-webtransport', () => {
connectionEncryption: [noise()],
connectionGater: {
denyDialMultiaddr: async () => false
},
connectionManager: {
minConnections: 0
}
})
})
Expand Down Expand Up @@ -111,7 +115,7 @@ describe('libp2p-webtransport', () => {
expect(err.toString()).to.contain('aborted')
})

it('connects to ipv6 addresses', async function () {
it.skip('connects to ipv6 addresses', async function () {
if (process.env.disableIp6 === 'true') {
return this.skip()
}
Expand Down Expand Up @@ -153,6 +157,13 @@ describe('libp2p-webtransport', () => {

await stream.sink(gen())

// closing takes a little bit of time
await pWaitFor(() => {
return stream.writeStatus === 'closed'
}, {
interval: 100
})

expect(stream.writeStatus).to.equal('closed')
expect(stream.timeline.closeWrite).to.be.greaterThan(0)

Expand Down
Loading