51 lines
1.5 KiB
Go
51 lines
1.5 KiB
Go
package hopp
|
|
|
|
import "io"
|
|
import "net"
|
|
// import "time"
|
|
|
|
const defaultSizeLimit = 1024 * 1024 // 1 megabyte
|
|
|
|
// 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)
|
|
|
|
// SetSizeLimit sets a limit (in bytes) for how large messages can be.
|
|
// By default, this limit is 1 megabyte.
|
|
SetSizeLimit(limit int)
|
|
}
|
|
|
|
// 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)
|
|
// ReceiveReader receives a message as an [io.Reader]. Any reader
|
|
// previously opened through this function will be discarded.
|
|
ReceiveReader() (method uint16, size int64, data io.Reader, err error)
|
|
}
|