Documentation ¶
Index ¶
- Variables
- func Dial(network, address string) (net.Conn, error)
- func DialContext(ctx context.Context, network, address string) (net.Conn, error)
- func DialOptions(network, address string, options ...ConnectOption) (net.Conn, error)
- func DialTLS(network, addr string, config *tls.Config) (*tls.Conn, error)
- func DialTLSOptions(network, addr string, config *tls.Config, options ...ConnectOption) (*tls.Conn, error)
- func DialUTP(network string, localAddr, remoteAddr *Addr) (net.Conn, error)
- func DialUTPOptions(network string, localAddr, remoteAddr *Addr, options ...ConnectOption) (net.Conn, error)
- func Listen(network string, addr string) (net.Listener, error)
- func ListenOptions(network, addr string, options ...ConnectOption) (net.Listener, error)
- func ListenTLS(network, laddr string, config *tls.Config) (net.Listener, error)
- func ListenTLSOptions(network, laddr string, config *tls.Config, options ...ConnectOption) (net.Listener, error)
- func NewConnIdGenerator() libutp.ConnIdGenerator
- type AcceptReq
- type Addr
- type Conn
- func (c *Conn) Close() error
- func (u *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(buf []byte) (n int, err error)
- func (c *Conn) ReadContext(ctx context.Context, buf []byte) (n int, err error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetLogger(logger *zap.Logger)
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Write(buf []byte) (n int, err error)
- func (c *Conn) WriteContext(ctx context.Context, buf []byte) (n int, err error)
- type ConnectOption
- func WithBufferSize(readSize int, writeSize int) ConnectOption
- func WithConnId(connId uint16) ConnectOption
- func WithContext(ctx context.Context) ConnectOption
- func WithLogger(logger *zap.Logger) ConnectOption
- func WithMaxPacketSize(size int) ConnectOption
- func WithPacketRouter(pr *PacketRouter) ConnectOption
- func WithSocketManager(sm *SocketManager) ConnectOption
- func WithTLS(tlsConfig *tls.Config) ConnectOption
- type Listener
- func (l *Listener) Accept() (net.Conn, error)
- func (l *Listener) AcceptContext(ctx context.Context) (net.Conn, error)
- func (l *Listener) AcceptUTP() (*Conn, error)
- func (l *Listener) AcceptUTPContext(ctx context.Context, id enode.ID, connId *libutp.ConnId) (c *Conn, err error)
- func (l *Listener) AcceptUTPWithConnId(id enode.ID, connId *libutp.ConnId) (*Conn, error)
- func (l *Listener) Addr() net.Addr
- func (l *Listener) Close() error
- func (u *Listener) LocalAddr() net.Addr
- type MessageWriter
- type NodeInfo
- type PacketRouter
- type PendingAcceptConn
- type SocketManager
Constants ¶
This section is empty.
Variables ¶
var ErrReceiveBufferOverflow = fmt.Errorf("receive buffer overflow")
Functions ¶
func Dial ¶
Dial attempts to make an outgoing µTP connection to the given address. It is analogous to net.Dial.
func DialContext ¶
DialContext attempts to make an outgoing µTP connection to the given address.
func DialOptions ¶
func DialOptions(network, address string, options ...ConnectOption) (net.Conn, error)
DialOptions attempts to make an outgoing µTP connection to the given address with the given options.
func DialTLS ¶
DialTLS connects to the given network address using net.Dial or utp.Dial as appropriate and then initiates a TLS handshake, returning the resulting TLS connection. DialTLS interprets a nil configuration as equivalent to the zero configuration; see the documentation of tls.Config for the details.
func DialTLSOptions ¶
func DialTLSOptions(network, addr string, config *tls.Config, options ...ConnectOption) (*tls.Conn, error)
DialTLSOptions connects to the given network address using net.Dial or utp.Dial as appropriate and then initiates a TLS handshake, returning the resulting TLS connection. DialTLS interprets a nil configuration as equivalent to the zero configuration; see the documentation of tls.Config for the details.
func DialUTP ¶
DialUTP attempts to make an outgoing µTP connection with the given local and remote address endpoints. It is analogous to net.DialUDP.
func DialUTPOptions ¶
func DialUTPOptions(network string, localAddr, remoteAddr *Addr, options ...ConnectOption) (net.Conn, error)
DialUTPOptions attempts to make an outgoing µTP connection with the given local and remote address endpoints and the given options.
func Listen ¶
Listen creates a listening µTP socket on the local network address. It is analogous to net.Listen.
func ListenOptions ¶
func ListenOptions(network, addr string, options ...ConnectOption) (net.Listener, error)
ListenOptions creates a listening µTP socket on the local network address with the given options.
func ListenTLS ¶
ListenTLS creates a TLS listener accepting connections on the given network address using net.Listen or utp.Listen as appropriate. The configuration config must be non-nil and must include at least one certificate or else set GetCertificate.
func ListenTLSOptions ¶
func ListenTLSOptions(network, laddr string, config *tls.Config, options ...ConnectOption) (net.Listener, error)
ListenTLSOptions creates a TLS listener accepting connections on the given network address using net.Listen or utp.Listen as appropriate. The configuration config must be non-nil and must include at least one certificate or else set GetCertificate.
func NewConnIdGenerator ¶
func NewConnIdGenerator() libutp.ConnIdGenerator
Types ¶
type Addr ¶
Addr represents a µTP address.
func ResolveUTPAddr ¶
ResolveUTPAddr resolves a µTP address. It is analogous to net.ResolveUDPAddr.
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a µTP connection.
func (*Conn) ReadContext ¶
ReadContext reads from a Conn.
func (*Conn) RemoteAddr ¶
RemoteAddr returns the address of the connection peer.
func (*Conn) SetDeadline ¶
SetDeadline sets a deadline for future read and write operations.
func (*Conn) SetLogger ¶
SetLogger sets the logger to be used by a connection. The logger will receive debugging information about the socket.
func (*Conn) SetReadDeadline ¶
SetReadDeadline sets a read deadline for future read operations.
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline sets a write deadline for future write operations.
type ConnectOption ¶
type ConnectOption func(state *utpDialState)
ConnectOption is the interface which connection options should implement.
func WithBufferSize ¶
func WithBufferSize(readSize int, writeSize int) ConnectOption
WithBufferSize Will set the write buffer size and read buffer size for connection
func WithConnId ¶
func WithConnId(connId uint16) ConnectOption
WithConnId Connect or Accept with certain connection id.If not specified, a random connection id will be generated.
func WithContext ¶
func WithContext(ctx context.Context) ConnectOption
WithContext creates a connection option which specifies a context to be attached to the connection. If the context is closed, the dial operation will be canceled.
func WithLogger ¶
func WithLogger(logger *zap.Logger) ConnectOption
WithLogger creates a connection option which specifies a logger to be attached to the connection. The logger will receive debugging messages about the socket.
func WithMaxPacketSize ¶
func WithMaxPacketSize(size int) ConnectOption
WithMaxPacketSize Will set the maximum packet size for the connection which will send out size of packet.
func WithPacketRouter ¶
func WithPacketRouter(pr *PacketRouter) ConnectOption
func WithSocketManager ¶
func WithSocketManager(sm *SocketManager) ConnectOption
WithSocketManager can share SocketManager with other conn
func WithTLS ¶
func WithTLS(tlsConfig *tls.Config) ConnectOption
WithTLS creates a connection option which specifies a TLS configuration structure to be attached to the connection. If specified, a TLS layer will be established on the connection before Dial returns.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener represents a listening µTP socket.
func ListenUTP ¶
ListenUTP creates a listening µTP socket on the local network address. It is analogous to net.ListenUDP.
func ListenUTPOptions ¶
func ListenUTPOptions(network string, localAddr *Addr, options ...ConnectOption) (*Listener, error)
ListenUTPOptions creates a listening µTP socket on the given local network address and with the given options.
func (*Listener) AcceptContext ¶
AcceptContext accepts a new µTP connection on a listening socket.
func (*Listener) AcceptUTPContext ¶
func (l *Listener) AcceptUTPContext(ctx context.Context, id enode.ID, connId *libutp.ConnId) (c *Conn, err error)
AcceptUTPContext accepts a new µTP connection on a listening socket.
func (*Listener) AcceptUTPWithConnId ¶
AcceptUTPWithConnId accepts a new µTP connection with special connection id on a listening socket.
type MessageWriter ¶
type PacketRouter ¶
type PacketRouter struct {
// contains filtered or unexported fields
}
func NewPacketRouter ¶
func NewPacketRouter(mw MessageWriter) *PacketRouter
func NewPacketRouterWithChannelLength ¶
func NewPacketRouterWithChannelLength(mw MessageWriter, length int) *PacketRouter
func (*PacketRouter) ReceiveMessage ¶
func (pr *PacketRouter) ReceiveMessage(buf []byte, nodeInfo *NodeInfo)
type PendingAcceptConn ¶
type PendingAcceptConn struct {
// contains filtered or unexported fields
}
type SocketManager ¶
type SocketManager struct {
// contains filtered or unexported fields
}
func NewSocketManagerWithOptions ¶
func NewSocketManagerWithOptions(network string, localAddr *net.UDPAddr, options ...ConnectOption) (*SocketManager, error)
func (*SocketManager) LocalAddr ¶
func (sm *SocketManager) LocalAddr() net.Addr
func (*SocketManager) RemoteAddr ¶
func (sm *SocketManager) RemoteAddr() net.Addr