Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
MaxMessageSize uint64
MsgToIDFunc func(m any) (uint64, error)
IDToMsgFunc func(id uint64) (any, error)
}
Config is the configuration of connection.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection allows to communicate with the peer.
func NewConnection ¶
func NewConnection(peer io.ReadWriter, config Config) *Connection
NewConnection creates new connection.
func (*Connection) Ping ¶
func (c *Connection) Ping() error
Ping sends the 0x00 byte to ensure connection works.
func (*Connection) Receive ¶
func (c *Connection) Receive() (any, error)
Receive receives message from the peer.
func (*Connection) Send ¶
func (c *Connection) Send(msg Marshalable) error
Send sends message to the peer.
type Marshalable ¶
Marshalable is the interface for messages.
type PeerBuffer ¶
type PeerBuffer struct {
// contains filtered or unexported fields
}
PeerBuffer simulates the network connection from the peer's view.
func (PeerBuffer) OtherPeer ¶
func (b PeerBuffer) OtherPeer() PeerBuffer
OtherPeer returns the corresponding buffer for the other peer in the connection.
func (PeerBuffer) Read ¶
func (b PeerBuffer) Read(buf []byte) (n int, err error)
Read reads data from the read buffer.
func (PeerBuffer) ReadByte ¶
func (b PeerBuffer) ReadByte() (byte, error)
ReadByte reads byte from the read buffer.
Click to show internal directories.
Click to hide internal directories.