Documentation ¶
Index ¶
- type RUDP
- func (t *RUDP) Close(ctx context.Context) error
- func (t *RUDP) RecvFrom(ctx context.Context) (common.RawBytes, net.Addr, error)
- func (t *RUDP) SendMsgTo(ctx context.Context, b common.RawBytes, a net.Addr) error
- func (t *RUDP) SendUnreliableMsgTo(ctx context.Context, b common.RawBytes, a net.Addr) error
- type Transport
- type UDP
- func (u *UDP) Close(context.Context) error
- func (u *UDP) RecvFrom(ctx context.Context) (common.RawBytes, net.Addr, error)
- func (u *UDP) SendMsgTo(ctx context.Context, b common.RawBytes, address net.Addr) error
- func (u *UDP) SendUnreliableMsgTo(ctx context.Context, b common.RawBytes, address net.Addr) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RUDP ¶
type RUDP struct {
// contains filtered or unexported fields
}
RUDP (Reliable UDP) implements a simple UDP protocol with ACKs on top of SCION/UDP.
Two sending primitives are available:
SendUnreliableMsgTo sends a message and returns without waiting for an ACK.
SendMsgTo sends a message and waits for a limited amount of time for an ACK; if time allows, also resends the message. Once the parent context is canceled, the function returns immediately with an error.
Header format:
0B 1 2 3 4 5 6 7 +--------+--------+--------+--------+--------+--------+--------+--------+ | Flags | PacketID | +--------+--------+--------+--------+--------+--------+--------+--------+
RUDP can be safely used by concurrent goroutines.
All methods receive a context argument. If the context is canceled prior to completing work, ErrContextDone is returned. If the net.PacketConn connection is closed, running functions terminate with ErrClosed.
func NewRUDP ¶
func NewRUDP(conn net.PacketConn, logger log.Logger) *RUDP
NewRUDP creates a new RUDP connection by wrapping around a PacketConn.
NewRUDP also spawns a background receiving goroutine that continuously reads from conn and keeps track of ACKs and messages.
func (*RUDP) Close ¶
Close closes the net.PacketConn connection and shuts down the background goroutine. If Close blocks for too long while waiting for the goroutine to terminate, it returns ErrContextDone.
type Transport ¶
type Transport interface { // Send an unreliable message. Unreliable transport layers do not request // an ACK. For reliable transport layers, this is the same as SendMsgTo. SendUnreliableMsgTo(context.Context, common.RawBytes, net.Addr) error // Send a reliable message. Unreliable transport layers block here waiting // for the message to be ACK'd. Reliable transport layers return // immediately. SendMsgTo(context.Context, common.RawBytes, net.Addr) error // Receive a message. RecvFrom(context.Context) (common.RawBytes, net.Addr, error) // Clean up. Close(context.Context) error }
Transport layers must be safe for concurrent use by multiple goroutines.
type UDP ¶
type UDP struct {
// contains filtered or unexported fields
}
UDP implements interface Transport by wrapping around *snet.Conn. For UDP, SendMsgTo is equivalent to SendUnreliableMsgTo and provides no guarantees of reliability.
func NewUDP ¶
func NewUDP(conn net.PacketConn) *UDP