Cross-platform mechanism to set socket options #313
Replies: 3 comments
-
We can also simplify and just make Though technically |
Beta Was this translation helpful? Give feedback.
-
For the simpler proposal, we probably need to define an interface for TCP and UDP Dialers with |
Beta Was this translation helpful? Give feedback.
-
See #316 for an implementation of TCPOptions. |
Beta Was this translation helpful? Give feedback.
-
We need a cross-platform and reusable mechanism to set the TTL on TCP and UDP connections.
That is needed in some strategies, for example:
The ipv6 and ipv4 packages help, but it would be nicer to have a more unified API and interfaces we can use.
Current Proposal: TCPConn interface
Define a new TCP dialer and connection interfaces:
Note that this will require renaming the existing
transport.TCPDialer
, perhaps back toTCPStreamDialer
The
TCPConn
type can then have all the IP and TCP options we want to support. It may be helpful to breakdown theStreamConn
andTCPConn
interfaces in order to better allow for wrapping:Note that the new
transport.TCPConn
implementsnet.Conn
andtransport.StreamConn
.However,
net.TCPConn
does not implementtransport.TCPConn
. We will need to wrap it. But that is easy with the broken down interfaces:We can consider extracting an
IPOptions
fromTCPOptions
.One additional note: by having a
transport.TCPConn
interface, rather than usingnet.TCPConn
, we can provide alternative implementations of TCP. For example, using GVisor or lwip, which in turn can plug to a TUN device, Wireguard or OpenVPN service, etc.In the config providers, the
disorder
factory function can check if the inputtransport.StreamDialer
is of typetransport.TCPDialer
, validating the input type at creation time. Alternatively we can define an explicitTCPDialer
provider.The fake strategy needs a way to send data, and then edit it. It will need an interface that describes that behavior. But it also needs to work with the hop limits. So we need to think how we can extend it to support the sendfile hack, even though it's not supported on all platforms. We also need to figure out the interface for
oob
.Previous Proposal: Option interfaces
I propose we create a new interface:
Then connections can explicitly provide an implementation. We should have functions to create a
HasHopLimit
from aTCPConn
orUDPConn
, or perhaps justnet.Conn
.For the disorder
Writer
, it could take aninnerWriter
and aHasHopLimit
as inputs:To implement a Dialer, it needs a special inner Dialer that can return something with
HopLimit
. We can define a new interface:In the config providers, we will need to have a new provider for
StreamWithHopLimitDialer
s. The disorder factory function will create a StreamWithHopLimitDialer, not a StreamDialer, when processing its BaseConfig.This ensures type safety, without obscure casting.
It may be worth investigating ways to make this a bit more extensible perhaps.
The fake strategy needs a way to send data, and then edit it. It will need an interface that describes that behavior. But it also needs to work with the hop limits. So we need both. oob will need an interface to set the OOB. How do we make that scalable?
Thoughts?
Beta Was this translation helpful? Give feedback.
All reactions