Documentation
¶
Index ¶
- func MakeNetAddr(network, address string) (net.Addr, error)
- type PacketDialer
- type PacketDialerEndpoint
- type PacketEndpoint
- type PacketListener
- type PacketListenerDialer
- type StreamConn
- type StreamDialer
- type StreamDialerEndpoint
- type StreamEndpoint
- type TCPEndpoint
- type TCPStreamDialer
- type UDPEndpoint
- type UDPPacketDialer
- type UDPPacketListener
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MakeNetAddr ¶
MakeNetAddr returns a net.Addr based on the network and address. This is a helper for code that need to return or provide a net.Addr The address must be in host:port format, with the host being a domain name, IPv4 or IPv6. Network must be "tcp" or "udp". For IP hosts, the returned address will be of type *net.TCPAddr or *net.UDPAddr, based on the network argument. This is important because some of the standard library functions inspect the type of the address and may return an "invalid argument" error if the type is not the right one.
Types ¶
type PacketDialer ¶
type PacketDialer interface {
// Dial connects to `raddr`.
// `raddr` has the form `host:port`, where `host` can be a domain name or IP address.
Dial(ctx context.Context, addr string) (net.Conn, error)
}
PacketDialer provides a way to dial a destination and establish datagram connections.
type PacketDialerEndpoint ¶
type PacketDialerEndpoint struct {
Dialer PacketDialer
Address string
}
PacketDialerEndpoint is a PacketEndpoint that connects to the given address using the given PacketDialer.
func (*PacketDialerEndpoint) Connect ¶
Connect implements PacketEndpoint.Connect.
type PacketEndpoint ¶
type PacketEndpoint interface {
// Connect creates a connection bound to an endpoint, returning the connection.
Connect(ctx context.Context) (net.Conn, error)
}
PacketEndpoint represents an endpoint that can be used to established packet connections (like UDP) to a fixed destination.
type PacketListener ¶
type PacketListener interface {
// ListenPacket creates a PacketConn that can be used to relay packets (such as UDP) through some proxy.
ListenPacket(ctx context.Context) (net.PacketConn, error)
}
PacketListener provides a way to create a local unbound packet connection to send packets to different destinations.
type PacketListenerDialer ¶
type PacketListenerDialer struct {
// The PacketListener that is used to create the net.PacketConn to bind on Dial. Must be non nil.
Listener PacketListener
}
PacketListenerDialer is a PacketDialer that connects to the destination using the given PacketListener.
func (PacketListenerDialer) Dial ¶
Dial implements PacketDialer.Dial. The address is a host:port and the host must be a full IP address (not [::]) or a domain The address must be supported by the WriteTo call of the PacketConn returned by the PacketListener. For instance, a net.UDPConn only supports IP addresses, not domain names. If the host is a domain name, consider pre-resolving it to avoid resolution calls.
type StreamConn ¶
type StreamConn interface {
net.Conn
// Closes the Read end of the connection, allowing for the release of resources.
// No more reads should happen.
CloseRead() error
// Closes the Write end of the connection. An EOF or FIN signal may be
// sent to the connection target.
CloseWrite() error
}
StreamConn is a net.Conn that allows for closing only the reader or writer end of it, supporting half-open state.
func WrapConn ¶
func WrapConn(c StreamConn, r io.Reader, w io.Writer) StreamConn
WrapDuplexConn wraps an existing StreamConn with new Reader and Writer, but preserving the original [StreamConn.CloseRead] and [StreamConn.CloseWrite].
type StreamDialer ¶
type StreamDialer interface {
// Dial connects to `raddr`.
// `raddr` has the form `host:port`, where `host` can be a domain name or IP address.
Dial(ctx context.Context, raddr string) (StreamConn, error)
}
StreamDialer provides a way to dial a destination and establish stream connections.
type StreamDialerEndpoint ¶
type StreamDialerEndpoint struct {
Dialer StreamDialer
Address string
}
StreamDialerEndpoint is a StreamEndpoint that connects to the given address using the given StreamDialer.
func (*StreamDialerEndpoint) Connect ¶
func (e *StreamDialerEndpoint) Connect(ctx context.Context) (StreamConn, error)
Connect implements StreamEndpoint.Connect.
type StreamEndpoint ¶
type StreamEndpoint interface {
// Connect establishes a connection with the endpoint, returning the connection.
Connect(ctx context.Context) (StreamConn, error)
}
StreamEndpoint represents an endpoint that can be used to established stream connections (like TCP) to a fixed destination.
type TCPEndpoint ¶
type TCPEndpoint struct {
// The Dialer used to create the net.Conn on Connect().
Dialer net.Dialer
// The endpoint address (host:port) to pass to Dial.
// If the host is a domain name, consider pre-resolving it to avoid resolution calls.
Address string
}
TCPEndpoint is a StreamEndpoint that connects to the given address using the given StreamDialer.
func (*TCPEndpoint) Connect ¶
func (e *TCPEndpoint) Connect(ctx context.Context) (StreamConn, error)
Connect implements StreamEndpoint.Connect.
type TCPStreamDialer ¶
TCPStreamDialer is a StreamDialer that uses the standard net.Dialer to dial. It provides a convenient way to use a net.Dialer when you need a StreamDialer.
func (*TCPStreamDialer) Dial ¶
func (d *TCPStreamDialer) Dial(ctx context.Context, addr string) (StreamConn, error)
type UDPEndpoint ¶
type UDPEndpoint struct {
// The Dialer used to create the net.Conn on Connect().
Dialer net.Dialer
// The endpoint address (host:port) to pass to Dial.
// If the host is a domain name, consider pre-resolving it to avoid resolution calls.
Address string
}
UDPEndpoint is a PacketEndpoint that connects to the given address via UDP
func (UDPEndpoint) Connect ¶
Connect implements PacketEndpoint.Connect.
type UDPPacketDialer ¶
UDPPacketDialer is a PacketDialer that uses the standard net.Dialer to dial. It provides a convenient way to use a net.Dialer when you need a PacketDialer.
func (*UDPPacketDialer) Dial ¶
Dial implements PacketDialer.Dial.
type UDPPacketListener ¶
type UDPPacketListener struct {
net.ListenConfig
// The local address to bind to, as specified in [net.ListenPacket].
Address string
}
UDPPacketListener is a PacketListener that uses the standard net.ListenConfig.ListenPacket to listen.
func (UDPPacketListener) ListenPacket ¶
func (l UDPPacketListener) ListenPacket(ctx context.Context) (net.PacketConn, error)
ListenPacket implements PacketListener.ListenPacket