-
Notifications
You must be signed in to change notification settings - Fork 73
fix(dcutr): preserve QUIC server role during hole punching #2838
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ import std/[hashes, sets, sequtils] | |
| import chronos, chronicles, metrics, results | ||
| import lsquic | ||
| import | ||
| ../crypto/rng, | ||
| ../wire, | ||
| ../connmanager, | ||
| ../multiaddress, | ||
|
|
@@ -350,11 +351,15 @@ proc new*( | |
| _: type QuicTransport, | ||
| u: Upgrade, | ||
| privateKey: PrivateKey, | ||
| rng: Rng, | ||
|
richard-ramos marked this conversation as resolved.
|
||
| connManager: ConnManager = nil, | ||
| ): QuicTransport = | ||
| doAssert not rng.isNil, "Rng is nil" | ||
|
|
||
| let self = QuicTransport( | ||
| upgrader: QuicUpgrade(ms: u.ms, connManager: connManager.toOpt()), | ||
| privateKey: privateKey, | ||
| rng: rng, | ||
| certGenerator: defaultCertGenerator, | ||
| ) | ||
| procCall Transport(self).initialize() | ||
|
|
@@ -364,12 +369,16 @@ proc new*( | |
| _: type QuicTransport, | ||
| u: Upgrade, | ||
| privateKey: PrivateKey, | ||
| rng: Rng, | ||
| certGenerator: CertGenerator, | ||
| connManager: ConnManager = nil, | ||
| ): QuicTransport = | ||
| doAssert not rng.isNil, "Rng is nil" | ||
|
|
||
| let self = QuicTransport( | ||
| upgrader: QuicUpgrade(ms: u.ms, connManager: connManager.toOpt()), | ||
| privateKey: privateKey, | ||
| rng: rng, | ||
| certGenerator: certGenerator, | ||
| ) | ||
| procCall Transport(self).initialize() | ||
|
|
@@ -576,6 +585,7 @@ method dial*( | |
| hostname: string, | ||
| address: MultiAddress, | ||
| peerId: Opt[PeerId] = Opt.none(PeerId), | ||
| dir: Direction = Direction.Out, | ||
| ): Future[RawConn] {.async: (raises: [transport.TransportError, CancelledError]).} = | ||
| let taAddress = | ||
| try: | ||
|
|
@@ -586,6 +596,23 @@ method dial*( | |
| ) | ||
|
|
||
| try: | ||
| if dir == Direction.In: | ||
| let endpoint = self.listenerEndpointFor(taAddress) | ||
| if endpoint.isNone(): | ||
| raise newException( | ||
| QuicTransportDialError, | ||
| "error in QUIC hole punch: no unique listener for address family", | ||
| ) | ||
|
|
||
| # The Sync sender is the QUIC server. Open its NAT mapping with random | ||
| # UDP packets from the listener socket and let the expected inbound | ||
| # connection complete the DCUtR attempt. | ||
| while true: | ||
| let payload = self.rng.generateBytes(64) | ||
| await endpoint.get().datagramTransport().sendTo(taAddress, payload) | ||
| let delay = self.rng.rand(10, 200) | ||
| await sleepAsync(delay.milliseconds) | ||
|
Comment on lines
+612
to
+616
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. understood, but it feels strange. for transport to implement this logic. it also needs better explanation:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fyi @rlve, ^ this is blind spot in unit tests, there should be test that assert what happens when server is dialing. code needs to be the same for every transport.
vladopajic marked this conversation as resolved.
richard-ramos marked this conversation as resolved.
|
||
|
|
||
| let endpoint = self.dialEndpointFor(taAddress) | ||
| let quicConnection = await endpoint.dial(taAddress) | ||
| peerId.withValue(expectedPeerId): | ||
|
|
@@ -606,6 +633,8 @@ method dial*( | |
| ) | ||
| except TransportOsError as e: | ||
| raise newException(QuicTransportDialError, "error in quic dial:" & e.msg, e) | ||
| except chronos.TransportError as e: | ||
| raise newException(QuicTransportDialError, "error in quic dial: " & e.msg, e) | ||
| except DialError as e: | ||
| raise newException(QuicTransportDialError, "error in quic dial:" & e.msg, e) | ||
| except QuicError as e: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.