hopp/connection.go

41 lines
1.1 KiB
Go

package hopp
import "net"
// import "time"
// Conn is a HOPP connection.
type Conn interface {
// Close closes the connection. Any blocked operations on the connection
// or its transactions will be unblocked and return errors.
Close() error
// See documentation for [net.Conn]
LocalAddr() net.Addr
RemoteAddr() net.Addr
// OpenTrans opens a transaction. The other party will not know about
// this until the first message is sent.
OpenTrans() (Trans, error)
// AcceptTrans accepts a transaction from the other party. This must
// be called in a loop to avoid the connection locking up.
AcceptTrans() (Trans, error)
}
// Trans is a HOPP transaction.
type Trans interface {
// Close closes the transaction. Any blocked operations will be
// unblocked and return errors.
Close() error
// ID returns the transaction ID. This must not change, and it must be
// unique within the connection.
ID() int64
// TODO: add methods for setting send and receive deadlines
// Send sends a message.
Send(method uint16, data []byte) error
// Receive receives a message.
Receive() (method uint16, data []byte, err error)
}