transport

package
v0.0.0-...-b22b80b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 21, 2022 License: Apache-2.0 Imports: 8 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SplitHostPort

func SplitHostPort(hostport string) (host, port string, err error)

SplitHostPort is the same as net.SplitHostPort, except that it allows hostport to be host without port.

Types

type Address

type Address struct {
	Transport Transport
	Host      string
	Port      uint16
}

Address is a URI for a node

func NewAddress

func NewAddress(protocol, host string, port uint16, supportedTransports []Transport) (*Address, error)

NewAddress creates an Address struct with given protocol and address

func Parse

func Parse(rawAddr string, supportedTransports []Transport) (*Address, error)

Parse parses a raw addr string into an Address struct

func (*Address) ConnRemoteAddr

func (addr *Address) ConnRemoteAddr() string

ConnRemoteAddr returns the remote address string that transport can dial

func (*Address) Dial

func (addr *Address) Dial(dialTimeout time.Duration) (net.Conn, error)

Dial dials the remote address using local transport

func (*Address) String

func (addr *Address) String() string

type KCPTransport

type KCPTransport struct{}

KCPTransport is the transport layer based on KCP protocol

func NewKCPTransport

func NewKCPTransport() *KCPTransport

NewKCPTransport creates a new KCP transport layer

func (*KCPTransport) Dial

func (t *KCPTransport) Dial(addr string, dialTimeout time.Duration) (net.Conn, error)

Dial connects to the remote address on the network "udp"

func (*KCPTransport) GetNetwork

func (t *KCPTransport) GetNetwork() string

GetNetwork returns the network used (tcp or udp)

func (*KCPTransport) Listen

func (t *KCPTransport) Listen(port uint16) (net.Listener, error)

Listen listens for incoming packets to "port" on the network "udp"

func (*KCPTransport) String

func (t *KCPTransport) String() string

type TCPTransport

type TCPTransport struct{}

TCPTransport is the transport layer based on TCP protocol

func NewTCPTransport

func NewTCPTransport() *TCPTransport

NewTCPTransport creates a new TCP transport layer

func (*TCPTransport) Dial

func (t *TCPTransport) Dial(addr string, dialTimeout time.Duration) (net.Conn, error)

Dial connects to the remote address on the network "tcp"

func (*TCPTransport) GetNetwork

func (t *TCPTransport) GetNetwork() string

GetNetwork returns the network used (tcp or udp)

func (*TCPTransport) Listen

func (t *TCPTransport) Listen(port uint16) (net.Listener, error)

Listen listens for incoming packets to "port" on the network "tcp"

func (*TCPTransport) String

func (t *TCPTransport) String() string

type Transport

type Transport interface {
	Dial(addr string, dialTimeout time.Duration) (net.Conn, error)
	Listen(port uint16) (net.Listener, error)
	GetNetwork() string
	String() string
}

Transport is an abstract transport layer between local and remote nodes

func NewTransport

func NewTransport(protocol string, supportedTransports []Transport) (Transport, error)

NewTransport creates a transport based on conf

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL