network

package
v0.0.0-...-dae542e Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicStat

type BasicStat struct {
	// contains filtered or unexported fields
}

BasicStat stores metadata of a Conn or a Stream.

func NewStat

func NewStat(direction Direction, establishedTime time.Time, extra map[interface{}]interface{}) *BasicStat

NewStat create a new BasicStat instance.

func (*BasicStat) Direction

func (s *BasicStat) Direction() Direction

func (*BasicStat) EstablishedTime

func (s *BasicStat) EstablishedTime() time.Time

func (*BasicStat) Extra

func (s *BasicStat) Extra() map[interface{}]interface{}

func (*BasicStat) IsClosed

func (s *BasicStat) IsClosed() bool

func (*BasicStat) SetClosed

func (s *BasicStat) SetClosed()

type Conn

type Conn interface {
	io.Closer
	Stat
	// LocalAddr is the local net multi-address of the connection.
	LocalAddr() ma.Multiaddr
	// LocalNetAddr is the local net address of the connection.
	LocalNetAddr() net.Addr
	// LocalPeerID is the local peer id of the connection.
	LocalPeerID() peer.ID
	// RemoteAddr is the remote net multi-address of the connection.
	RemoteAddr() ma.Multiaddr
	// RemoteNetAddr is the remote net address of the connection.
	RemoteNetAddr() net.Addr
	// RemotePeerID is the remote peer id of the connection.
	RemotePeerID() peer.ID
	// Network is the network instance who create this connection.
	Network() Network
	// CreateSendStream try to open a sending stream with the connection.
	CreateSendStream() (SendStream, error)
	// AcceptReceiveStream accept a receiving stream with the connection.
	// It will block until a new receiving stream accepted or connection closed.
	AcceptReceiveStream() (ReceiveStream, error)
	// CreateBidirectionalStream try to open a bidirectional stream with the connection.
	CreateBidirectionalStream() (Stream, error)
	// AcceptBidirectionalStream accept a bidirectional stream with the connection.
	// It will block until a new bidirectional stream accepted or connection closed.
	AcceptBidirectionalStream() (Stream, error)
}

Conn defined a connection with remote peer.

type ConnHandler

type ConnHandler func(conn Conn) (bool, error)

ConnHandler is a function for handling connections.

type Dialer

type Dialer interface {
	// Dial try to establish an outbound connection with the remote address.
	Dial(ctx context.Context, remoteAddr ma.Multiaddr) (Conn, error)
}

Dialer provides a way to establish a connection with others.

type Direction

type Direction int

Direction of a connection or a stream.

const (
	// Unknown is the default direction.
	Unknown Direction = iota
	// Inbound is for when the remote peer initiated a connection.
	Inbound
	// Outbound is for when the local peer initiated a connection.
	Outbound
)

func (Direction) String

func (d Direction) String() string

type Listener

type Listener interface {
	io.Closer
	// Listen will run a task that start create listeners with the given
	// addresses waiting for accepting inbound connections.
	Listen(ctx context.Context, addresses ...ma.Multiaddr) error
	// ListenAddresses return the list of the local addresses for listeners.
	ListenAddresses() []ma.Multiaddr
}

Listener provides a way to accept connections established with others.

type Network

type Network interface {
	Dialer
	Listener
	io.Closer
	// SetNewConnHandler register a ConnHandler to handle the connection established.
	SetNewConnHandler(handler ConnHandler)
	// Disconnect a connection.
	Disconnect(conn Conn) error
	// Closed return whether network closed.
	Closed() bool
	// LocalPeerID return the local peer id.
	LocalPeerID() peer.ID
}

Network is a state machine interface provides a Dialer and a Listener to build a network.

type ReceiveStream

type ReceiveStream interface {
	io.Reader
	// contains filtered or unexported methods
}

ReceiveStream is an interface defined a way to receive data.

type SendStream

type SendStream interface {
	io.Writer
	// contains filtered or unexported methods
}

SendStream is an interface defined a way to send data.

type Stat

type Stat interface {
	Direction() Direction
	EstablishedTime() time.Time
	Extra() map[interface{}]interface{}
	SetClosed()
	IsClosed() bool
}

Stat is an interface for storing metadata of a Conn or a Stream.

type Stream

type Stream interface {
	SendStream
	ReceiveStream
}

Stream is an interface defined both ways to send and receive data.

Jump to

Keyboard shortcuts

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