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) EstablishedTime ¶
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 ¶
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 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 ¶
ReceiveStream is an interface defined a way to receive data.
type SendStream ¶
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.