Documentation
¶
Index ¶
- Constants
- Variables
- type Addr
- type IPProtocol
- type Packet
- type Port
- func (up *Port) Close() error
- func (gp *Port) Input() chan<- *Packet
- func (gp *Port) LocalAddr() net.Addr
- func (gp *Port) Output() <-chan *Packet
- func (gp *Port) ReadFrom(buf []byte) (int, net.Addr, error)
- func (gp *Port) ReadPacket() (*Packet, error)
- func (gp *Port) RemoteAddr() net.Addr
- func (gp *Port) SetDeadline(t time.Time) error
- func (gp *Port) SetReadDeadline(t time.Time) error
- func (gp *Port) SetWriteDeadline(t time.Time) error
- func (gp *Port) Write(data []byte) (int, error)
- func (gp *Port) WritePacket(payload []byte, flags TCPFlags, raddr netip.AddrPort) error
- func (gp *Port) WriteTo(pkt []byte, addr net.Addr) (int, error)
- type PortAddr
- type PortStack
- type Stack
- func (ns *Stack) Addresses() []netip.Addr
- func (ns *Stack) Close() error
- func (ns *Stack) ClosePort(addr *PortAddr)
- func (ns *Stack) DialContext(ctx context.Context, network, address string) (net.Conn, error)
- func (ns *Stack) EOF() <-chan struct{}
- func (ns *Stack) FindLocalAddrFor(raddr netip.Addr) (netip.Addr, error)
- func (ns *Stack) Input() chan<- *Packet
- func (ns *Stack) Listen(ctx context.Context, network, address string) (net.Listener, error)
- func (ns *Stack) ListenPacket(ctx context.Context, network, address string) (net.PacketConn, error)
- func (ns *Stack) NewTCPConn(laddr, raddr netip.AddrPort) (*TCPConn, error)
- func (ns *Stack) Output() <-chan *Packet
- func (ns *Stack) SetResolvers(addrs ...netip.AddrPort)
- type TCPConn
- func (c *TCPConn) Accept() (err error)
- func (c *TCPConn) Close() error
- func (c *TCPConn) Connect(ctx context.Context) (err error)
- func (c *TCPConn) LocalAddr() net.Addr
- func (c *TCPConn) Read(buf []byte) (int, error)
- func (c *TCPConn) RemoteAddr() net.Addr
- func (c *TCPConn) SetDeadline(t time.Time) error
- func (c *TCPConn) SetReadDeadline(t time.Time) error
- func (c *TCPConn) SetWriteDeadline(t time.Time) error
- func (c *TCPConn) Write(data []byte) (int, error)
- type TCPFlags
- type TCPListener
- type TCPListenerStack
- type UDPConn
- func (c *UDPConn) Close() error
- func (c *UDPConn) LocalAddr() net.Addr
- func (c *UDPConn) Read(buf []byte) (int, error)
- func (c *UDPConn) ReadFrom(buf []byte) (int, net.Addr, error)
- func (c *UDPConn) RemoteAddr() net.Addr
- func (c *UDPConn) SetDeadline(t time.Time) error
- func (c *UDPConn) SetReadDeadline(t time.Time) error
- func (c *UDPConn) SetWriteDeadline(t time.Time) error
- func (c *UDPConn) Write(data []byte) (int, error)
- func (c *UDPConn) WriteTo(pkt []byte, addr net.Addr) (int, error)
Constants ¶
const ( // EADDRNOTAVAIL is the address not available error. EADDRNOTAVAIL = unix.EADDRNOTAVAIL // EADDRINUSE is the address in use error. EADDRINUSE = unix.EADDRINUSE // ECONNABORTED is the connection aborted error. ECONNABORTED = unix.ECONNABORTED // ECONNREFUSED is the connection refused error. ECONNREFUSED = unix.ECONNREFUSED // ECONNRESET is the connection reset by peer error. ECONNRESET = unix.ECONNRESET // EHOSTUNREACH is the host unreachable error. EHOSTUNREACH = unix.EHOSTUNREACH // EINVAL is the invalid argument error. EINVAL = unix.EINVAL // ENETDOWN is the network is down error. ENETDOWN = unix.ENETDOWN // ENOBUFS is the no buffer space available error. ENOBUFS = unix.ENOBUFS // ENOTCONN is the not connected error. ENOTCONN = unix.ENOTCONN // EPROTONOSUPPORT is the protocol not supported error. EPROTONOSUPPORT = unix.EPROTONOSUPPORT )
const ( IPProtocolTCP = packet.IPProtocolTCP IPProtocolUDP = packet.IPProtocolUDP TCPFlagFIN = packet.TCPFlagFIN TCPFlagSYN = packet.TCPFlagSYN TCPFlagRST = packet.TCPFlagRST TCPFlagPSH = packet.TCPFlagPSH TCPFlagACK = packet.TCPFlagACK )
Constant aliases
Variables ¶
var ErrNoConfiguredResolvers = errors.New("no configured resolvers")
ErrNoConfiguredResolvers is returned when there are no configured resolvers.
Functions ¶
This section is empty.
Types ¶
type Addr ¶
type Addr struct { // AddrPort is the endpoint address and port. AddrPort netip.AddrPort // Protocol is the endpoint protocol. Protocol IPProtocol }
Addr represents a TCP/UDP address.
type Port ¶
type Port struct {
// contains filtered or unexported fields
}
Port models an open TCP/UDP port.
func NewPort ¶
NewPort creates a *Port instance with the given *PortAddr.
Leave the *PortAddr `RemoteAddr` field zero when you want to create a port that is not connected to a peer (i.e., a TCP/UDP listener).
func (*Port) ReadFrom ¶
ReadFrom implements net.PacketConn.
func (*Port) ReadPacket ¶
ReadPacket receives a packet from a remote endpoint.
We discard packets that do not match the remote address unless the remote address is not set, in which case we accept all packets.
The following errors are possible:
1. nil if we receive a packet from the `Input` channel.
2. net.ErrClosed if the port is closed before we receive a packet;
3. os.ErrDeadlineExceeded if the read deadline is exceeded.
func (*Port) RemoteAddr ¶
RemoteAddr returns the remote address of this *Port.
func (*Port) SetDeadline ¶
SetDeadline sets the read and write deadlines.
func (*Port) SetReadDeadline ¶
SetReadDeadline sets the read deadline.
func (*Port) SetWriteDeadline ¶
SetWriteDeadline sets the write deadline.
func (*Port) WritePacket ¶
WritePacket creates and writes a packet to a remote endpoint using the given payload, TCP flags, and remote address.
If the `raddr` field is a zero value, we use the `RemoteAddr` field of the *PortAddr. If also such a field is a zero value, we return ENOTCONN to indicate we don't know the peer addr.
Also, we copy the payload to avoid issues with buffer pools, which occur, for example, when using the crypto/tls package.
The following errors are possible:
1. ENOTCONN if the port is not connected to a peer and the raddr is zero;
2. nil if the packet is sent (i.e., delivered to the `Output` channel);
3. net.ErrClosed if the port is closed before we send the packet;
4. os.ErrDeadlineExceeded if the write deadline is exceeded.
type PortAddr ¶
type PortAddr struct { // LocalAddr is the local address. This field must // always have valid address and port. LocalAddr netip.AddrPort // Protocol is the port protocol. Protocol IPProtocol // RemoteAddr is the remote address. This field // may be zero for non-connected ports. RemoteAddr netip.AddrPort }
PortAddr is the *Port address.
type PortStack ¶
type PortStack interface { // ClosePort closes the given port. ClosePort(addr *PortAddr) // FindLocalAddrFor finds the first local address with the // same family of the given remote address. FindLocalAddrFor(raddr netip.Addr) (netip.Addr, error) }
PortStack is the stack to which a *Port is attached.
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack models a network stack.
func New ¶
New creates a new *Stack instance and starts a goroutine demuxing incoming traffic. Remember to invoke Close to stop any muxing/demuxing goroutine.
func (*Stack) DialContext ¶
DialContext dials a network address.
func (*Stack) EOF ¶
func (ns *Stack) EOF() <-chan struct{}
EOF returns the channel to wait for the stack to close.
func (*Stack) FindLocalAddrFor ¶
FindLocalAddrFor returns the first local address that has the same IP version as the remote address.
func (*Stack) Listen ¶
Listen creates a new listening net.Listener.
func (*Stack) ListenPacket ¶
ListenPacket creates a new listening net.PacketConn.
func (*Stack) NewTCPConn ¶
NewTCPConn implements TCPListenerStack.
func (*Stack) SetResolvers ¶
SetResolvers sets the resolvers endpoints to use.
Note that this method IS NOT goroutine safe.
type TCPConn ¶
type TCPConn struct {
// contains filtered or unexported fields
}
TCPConn is a TCP connection.
The zero value is invalid; construct using NewTCPConn.
func (*TCPConn) RemoteAddr ¶
RemoteAddr implements net.Conn.
func (*TCPConn) SetDeadline ¶
SetDeadline implements net.Conn.
func (*TCPConn) SetReadDeadline ¶
SetReadDeadline implements net.Conn.
func (*TCPConn) SetWriteDeadline ¶
SetWriteDeadline implements net.Conn.
type TCPListener ¶
type TCPListener struct { *Port // contains filtered or unexported fields }
TCPListener is a TCP listener.
The zero value is invalid; construct using NewTCPListener.
func NewTCPListener ¶
func NewTCPListener(stack TCPListenerStack, p *Port) *TCPListener
NewTCPListener creates a new TCP connection.
func (*TCPListener) Accept ¶
func (tl *TCPListener) Accept() (net.Conn, error)
Accept implements net.Listener.
type TCPListenerStack ¶
TCPListenerStack is the stack to which a *TCPListener is attached.
type UDPConn ¶
type UDPConn struct {
// contains filtered or unexported fields
}
UDPConn is a UDP connection.
The zero value is invalid; construct using NewUDPConn.
func (*UDPConn) LocalAddr ¶
LocalAddr implements net.PacketConn.
func (*UDPConn) ReadFrom ¶
ReadFrom implements net.PacketConn.
func (*UDPConn) RemoteAddr ¶
RemoteAddr implements net.Conn.
func (*UDPConn) SetDeadline ¶
SetDeadline implements net.PacketConn.
func (*UDPConn) SetReadDeadline ¶
SetReadDeadline implements net.PacketConn.
func (*UDPConn) SetWriteDeadline ¶
SetWriteDeadline implements net.PacketConn.