transport

package
v0.0.0-...-c8fc2fc Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 2, 2018 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

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

func (t *RUDP) Close(ctx context.Context) error

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.

func (*RUDP) RecvFrom

func (t *RUDP) RecvFrom(ctx context.Context) (common.RawBytes, net.Addr, error)

RecvFrom returns the next non-ACK message.

func (*RUDP) SendMsgTo

func (t *RUDP) SendMsgTo(ctx context.Context, b common.RawBytes, a net.Addr) error

SendMsgTo sends a message and waits for an ACK. If no ACK is received for a set amount of time, the message is retransmitted. This process repeats while ctx is not canceled.

func (*RUDP) SendUnreliableMsgTo

func (t *RUDP) SendUnreliableMsgTo(ctx context.Context, b common.RawBytes, a net.Addr) error

SendUnreliableMsgTo sends a message and returns without waiting for an ACK.

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

func (*UDP) Close

func (u *UDP) Close(context.Context) error

func (*UDP) RecvFrom

func (u *UDP) RecvFrom(ctx context.Context) (common.RawBytes, net.Addr, error)

func (*UDP) SendMsgTo

func (u *UDP) SendMsgTo(ctx context.Context, b common.RawBytes, address net.Addr) error

func (*UDP) SendUnreliableMsgTo

func (u *UDP) SendUnreliableMsgTo(ctx context.Context, b common.RawBytes, address net.Addr) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL