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.
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 send stream with the connection.
CreateSendStream() (SendStream, error)
// AcceptReceiveStream accept a receive stream with the connection.
// It will block until a new receive 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 a 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, addrs ...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 a interface defined a way to receive data.
type SendStream ¶
SendStream is a 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 a interface for storing metadata of a Conn or a Stream.
type Stream ¶
type Stream interface {
SendStream
ReceiveStream
}
Stream is a interface defined both ways to send and receive data.
Source Files
¶
- conn.go
- dialer.go
- listener.go
- network.go
- stat.go
- stream.go
Click to show internal directories.
Click to hide internal directories.