Add address methods to Conn

This commit is contained in:
Sasha Koshka 2025-01-21 21:07:52 -05:00
parent 19fa5983d6
commit f0753c5113

View File

@ -1,19 +1,38 @@
package hopp
import "io"
import "net"
// import "time"
// Conn is a HOPP connection.
type Conn interface {
io.Closer
// 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 {
io.Closer
// 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.