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 ¶
Direction return the direction of the connection there are two types of link directions: Inbound and Outbound
func (*BasicStat) EstablishedTime ¶
EstablishedTime return the time the connection was established
func (*BasicStat) Extra ¶
func (s *BasicStat) Extra() map[interface{}]interface{}
Extra return information in the state
func (*BasicStat) IsClosed ¶
IsClosed return whether it is closed
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)
// SetDeadline used by the relay
SetDeadline(t time.Time) error
// SetReadDeadline used by the relay
SetReadDeadline(t time.Time) error
// SetWriteDeadline used by the relay
SetWriteDeadline(t time.Time) 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
// RelayListen continuously monitor relay communication
RelayListen(listener net.Listener)
}
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
// RelayDial using conn and addr of the relay peer, get the relay conn
RelayDial(conn Conn, rAddr ma.Multiaddr) (Conn, error)
// GetTempListenAddresses return the local addr dial success
GetTempListenAddresses() []ma.Multiaddr
// AddTempListenAddresses add the remote addr accept success
AddTempListenAddresses([]ma.Multiaddr)
// DirectListen listen without check and support listen repeat
DirectListen(ctx context.Context, addrs ...ma.Multiaddr) error
}
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 return the direction of the connection
Direction() Direction
// EstablishedTime return the time the connection was established
EstablishedTime() time.Time
// Extra return information in the state
Extra() map[interface{}]interface{}
// SetClosed set to close
SetClosed()
// IsClosed return whether it is closed
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.
Source Files
¶
- conn.go
- dialer.go
- listener.go
- network.go
- stat.go
- stream.go