rpt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2018 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

package rpt (Reliable Packet Transport) implements a simple packet-oriented protocol with ACKs on top of net.PacketConn.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RPT

type RPT struct {
	// contains filtered or unexported fields
}

RPT (Reliable Packet Transport) implements a simple packet-oriented protocol with ACKs on top of net.PacketConn.

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                           |
+--------+--------+--------+--------+--------+--------+--------+--------+

RPT 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 New

func New(conn net.PacketConn, logger log.Logger) *RPT

New creates a new RPT connection by wrapping around a PacketConn.

New also spawns a background receiving goroutine that continuously reads from conn and keeps track of ACKs and messages.

func (*RPT) Close

func (t *RPT) 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 (*RPT) RecvFrom

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

RecvFrom returns the next non-ACK message.

func (*RPT) SendMsgTo

func (t *RPT) 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 (*RPT) SendUnreliableMsgTo

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

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

Jump to

Keyboard shortcuts

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