gfcp

package module
v0.0.0-...-8d919a2 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2021 License: MIT Imports: 16 Imported by: 3

README

GFCP

Gridfinity Control Protocol

A high-speed variant of the KCP ARQ transport for Go

LicenseMIT PkgGoDev GoReportCard CodacyBadge LocCount GitHubCodeSize GitHubRelease DeepSourceActive TickgitTODOs


Availability
Go Modules
Source Code
Documentation
Issue Tracking
Security Policy
Original Authors
License

Documentation

Overview

Package gfcp - A Fast and Reliable ARQ Protocol

Copyright © 2015 Daniel Fu <daniel820313@gmail.com>. Copyright © 2019 Loki 'l0k18' Verloren <stalker.loki@protonmail.ch>. Copyright © 2021 Gridfinity, LLC. <admin@gridfinity.com>.

All rights reserved.

All use of this code is governed by the MIT license. The complete license is available in the LICENSE file.

Index

Constants

View Source
const (
	GfcpRtoNdl     = 20  // GfcpRtoNdl:	NoDelay min RTO
	GfcpRtoMin     = 120 // GfcpRtoMin:	Regular min RTO
	GfcpRtoDef     = 340
	GfcpRtoMax     = 60000
	GfcpCmdPush    = 81 // GfcpCmdPush:	Push data
	GfcpCmdAck     = 82 // GfcpCmdAck:	Ack
	GfcpCmdWask    = 83 // GfcpCmdWask:	Get Window Size
	GfcpCmdWins    = 84 // GfcpCmdWins:	Set window Size
	GfcpAskSend    = 1  // GfcpAskSend:	Need to send GfcpCmdWask
	GfcpAskTell    = 2  // GfcpAskTell:	Need to send GfcpCmdWins
	GfcpWndSnd     = 32
	GfcpWndRcv     = 32
	GfcpMtuDef     = 1480
	GfcpAckFast    = 3
	GfcpInterval   = 100
	GfcpOverhead   = 24
	GfcpDeadLink   = 20
	GfcpThreshInit = 2
	GfcpThreshMin  = 2
	GfcpProbeInit  = 7000   // 7s initial probe window
	GfcpProbeLimit = 102000 // 120s hard probe timeout
)

Gfcp protocol constants

View Source
const (

	// KTypeData ...
	KTypeData = 0xf1
	// KTypeParity ...
	KTypeParity = 0xf2
)
View Source
const (
	// GFcpMtuLimit ...
	GFcpMtuLimit = 1500
)

Variables

View Source
var KxmitBuf sync.Pool

KxmitBuf ...

Functions

func CurrentMs

func CurrentMs() uint32

CurrentMs ...

func Dial

func Dial(
	raddr string,
) (
	net.Conn,
	error,
)

Dial connects to the remote address "raddr" via "udp"

func Listen

func Listen(
	laddr string,
) (
	net.Listener,
	error,
)

Listen listens for incoming GFcp packets addressed to our local address (laddr) via "udp"

Types

type Entropy

type Entropy interface {
	Init()
	Fill(
		nonce []byte,
	)
}

Entropy defines a entropy source

type FecDecoder

type FecDecoder struct {
	DecodeCache [][]byte
	// contains filtered or unexported fields
}

FecDecoder ...

func NewFECDecoder

func NewFECDecoder(
	rxlimit,
	dataShards,
	parityShards int,
) *FecDecoder

NewFECDecoder ...

func (*FecDecoder) Decode

func (
	dec *FecDecoder,
) Decode(
	in FecPacket,
) (
	recovered [][]byte,
)

Decode ...

type FecEncoder

type FecEncoder struct {
	EncodeCache [][]byte
	// contains filtered or unexported fields
}

FecEncoder ...

func NewFECEncoder

func NewFECEncoder(
	dataShards,
	parityShards,
	offset int,
) *FecEncoder

NewFECEncoder ...

func (*FecEncoder) Encode

func (
	enc *FecEncoder,
) Encode(
	b []byte,
) (
	ps [][]byte,
)

Encode ...

type FecPacket

type FecPacket []byte

FecPacket ...

type GFCP

type GFCP struct {
	SndBuf []Segment
	// contains filtered or unexported fields
}

GFCP primary structure

func NewGFCP

func NewGFCP(
	conv uint32,
	output outputCallback,
) *GFCP

NewGFCP creates a new GFcp control object.

func (*GFCP) Check

func (
	GFcp *GFCP,
) Check() uint32

Check function helps determine when to invoke an gfcp_update. It returns when you should invoke gfcp_update, in milliseconds, if there is no gfcp_input or _send calling. You may repeatdly call gfcp_update instead of update, to reduce most unnacessary gfcp_update invocations. This function may be used to schedule gfcp_updates, when implementing an epoll-like mechanism, or for optimizing an gfcp_update loop handling massive GFcp connections.

func (*GFCP) Flush

func (
	GFcp *GFCP,
) Flush(
	ackOnly bool,
) uint32

Flush ...

func (*GFCP) Input

func (
	GFcp *GFCP,
) Input(
	data []byte,
	regular,
	ackNoDelay bool,
) int

Input receives a (low-level) UDP packet, and determinines if a full packet has been processsed (not by the FEC algorithm)

func (*GFCP) NoDelay

func (
	GFcp *GFCP,
) NoDelay(
	nodelay,
	interval,
	resend,
	nc int,
) int

NoDelay options: * fastest: gfcp_nodelay(GFcp, 1, 20, 2, 1) * nodelay: 0: disable (default), 1: enable * interval: internal update timer interval in milliseconds, defaults to 100ms * resend: 0: disable fast resends (default), 1: enable fast resends * nc: 0: normal congestion control (default), 1: disable congestion control

func (*GFCP) PeekSize

func (
	GFcp *GFCP,
) PeekSize() (
	length int,
)

PeekSize checks the size of next message in the receive queue.

func (*GFCP) Recv

func (
	GFcp *GFCP,
) Recv(
	buffer []byte,
) (
	n int,
)

Recv is upper level recviver; returns size or EAGAIN on error.

func (*GFCP) ReserveBytes

func (
	GFcp *GFCP,
) ReserveBytes(
	n int,
) bool

ReserveBytes keeps 'n' bytes from the beginning of buffering. Output callbacks use this to return 'false' if 'n' >= 'mss'.

func (*GFCP) Send

func (
	GFcp *GFCP,
) Send(
	buffer []byte,
) int

Send is upper level sender, returns <0 on error.

func (*GFCP) SetMtu

func (
	GFcp *GFCP,
) SetMtu(
	mtu int,
) int

SetMtu changes MTU size.

func (*GFCP) Update

func (
	GFcp *GFCP,
) Update()

Update is called repeatedly, 10ms to 100ms, queried via gfcp_check without gfcp_input or _send executing, returning timestamp in ms.

func (*GFCP) WaitSnd

func (
	GFcp *GFCP,
) WaitSnd() int

WaitSnd shows how many packets are queued to be sent

func (*GFCP) WndSize

func (
	GFcp *GFCP,
) WndSize(
	sndwnd,
	rcvwnd int,
) int

WndSize sets maximum window size (efaults: sndwnd=32 and rcvwnd=32)

type Listener

type Listener struct {

	/// FecDecoder ...
	FecDecoder *FecDecoder // FEC mock initialization
	// contains filtered or unexported fields
}

Listener ...

func ListenWithOptions

func ListenWithOptions(
	laddr string,
	dataShards,
	parityShards int,
) (
	*Listener,
	error,
)

ListenWithOptions listens for incoming GFcp packets addressed to our local address (laddr) via "udp" Porvides for encryption, sharding, parity, and RS coding parameters to be specified.

func ServeConn

func ServeConn(
	dataShards,
	parityShards int,
	conn net.PacketConn,
) (
	*Listener,
	error,
)

ServeConn serves the GFcp protocol - a single packet is processed.

func (*Listener) Accept

func (
	l *Listener,
) Accept() (
	net.Conn,
	error,
)

Accept implements the Accept method in the Listener interface. It waits until the next call, then returns a generic 'Conn'.

func (*Listener) AcceptGFCP

func (
	l *Listener,
) AcceptGFCP() (
	*UDPSession,
	error,
)

AcceptGFCP accepts a GFcp connection

func (*Listener) Addr

func (
	l *Listener,
) Addr() net.Addr

Addr returns the listener's network address. The address returned is shared by all invocations of Addr - do not modify it.

func (*Listener) Close

func (
	l *Listener,
) Close() error

Close stops listening on the UDP address. Any already accepted connections will not be closed.

func (*Listener) CloseSession

func (
	l *Listener,
) CloseSession(
	remote net.Addr,
) (
	ret bool,
)

CloseSession notifies the Listener when a Session is Closed.

func (*Listener) SetDSCP

func (
	l *Listener,
) SetDSCP(
	dscp int,
) error

SetDSCP sets the 6-bit DSCP field of IP header.

func (*Listener) SetDeadline

func (
	l *Listener,
) SetDeadline(
	t time.Time,
) error

SetDeadline sets the deadline associated with the Listener. A zero value will disable all deadlines.

func (*Listener) SetReadBuffer

func (
	l *Listener,
) SetReadBuffer(
	bytes int,
) error

SetReadBuffer sets the socket read buffer for the Listener.

func (*Listener) SetReadDeadline

func (
	l *Listener,
) SetReadDeadline(
	t time.Time,
) error

SetReadDeadline implements the Conn SetReadDeadline method.

func (*Listener) SetWriteBuffer

func (
	l *Listener,
) SetWriteBuffer(
	bytes int,
) error

SetWriteBuffer sets the socket write buffer for the Listener.

func (*Listener) SetWriteDeadline

func (
	l *Listener,
) SetWriteDeadline(
	t time.Time,
) error

SetWriteDeadline implements the Conn SetWriteDeadline method.

type Nonce

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

Nonce ...

func (*Nonce) Fill

func (
	n *Nonce,
) Fill(
	nonce []byte,
)

Fill ...

func (*Nonce) Init

func (
	n *Nonce,
) Init()

Init ...

type Segment

type Segment struct {
	Kxmit        uint32
	GFcpResendTs uint32
	// contains filtered or unexported fields
}

Segment structure

type Snsi

type Snsi struct {
	GFcpBytesSent                   uint64 // Bytes sent from upper level
	GFcpBytesReceived               uint64 // Bytes received to upper level
	GFcpMaxConn                     uint64 // Max number of connections ever reached
	GFcpActiveOpen                  uint64 // Accumulated active open connections
	GFcpPassiveOpen                 uint64 // Accumulated passive open connections
	GFcpNowEstablished              uint64 // Current number of established connections
	GFcpPreInputErrors              uint64 // UDP read errors reported from net.PacketConn
	GFcpChecksumFailures            uint64 // Checksum errors from CRC32
	GFcpInputErrors                 uint64 // Packet input errors reported from GFCP
	GFcpInputPackets                uint64 // Incoming packets count
	GFcpOutputPackets               uint64 // Outgoing packets count
	GFcpInputSegments               uint64 // Incoming GFCP KSegments
	GFcpOutputSegments              uint64 // Outgoing GFCP KSegments
	GFcpInputBytes                  uint64 // UDP bytes received
	GFcpOutputBytes                 uint64 // UDP bytes sent
	GFcpRestransmittedSegments      uint64 // Accmulated retransmited KSegments
	FastGFcpRestransmittedSegments  uint64 // Accmulated fast retransmitted KSegments
	EarlyGFcpRestransmittedSegments uint64 // Accmulated early retransmitted KSegments
	GFcpLostSegments                uint64 // Number of segs inferred as lost
	GFcpDupSegments                 uint64 // Number of segs duplicated
	GFcpFECRecovered                uint64 // Correct packets recovered from FEC
	GFcpFailures                    uint64 // Incorrect packets recovered from FEC
	GFcpFECParityShards             uint64 // FEC KSegments received
	GFcpFECRuntShards               uint64 // Number of data shards insufficient for recovery
}

Snsi == Simple Network Statistics Indicators

var (
	DefaultSnsi *Snsi
)

DefaultSnsi is the GFCP default statistics collector

func (*Snsi) Copy

func (
	s *Snsi,
) Copy() *Snsi

Copy makes a copy of current Snsi snapshot

func (*Snsi) Header

func (
	s *Snsi,
) Header() []string

Header returns all field names

func (*Snsi) Reset

func (s *Snsi) Reset()

Reset sets all Snsi values to zero

func (*Snsi) ToSlice

func (
	s *Snsi,
) ToSlice() []string

ToSlice returns current Snsi info as a slice

type UDPSession

type UDPSession struct {
	GFcp *GFCP // GFCP ARQ protocol

	// FecDecoder ...
	FecDecoder *FecDecoder
	// FecEncoder ...
	FecEncoder *FecEncoder
	// contains filtered or unexported fields
}

UDPSession ...

func DialWithOptions

func DialWithOptions(
	raddr string,
	dataShards,
	parityShards int,
) (
	*UDPSession,
	error,
)

DialWithOptions connects to the remote address "raddr" via "udp" with encryption options.

func NewConn

func NewConn(
	raddr string,
	dataShards,
	parityShards int,
	conn net.PacketConn,
) (
	*UDPSession,
	error,
)

NewConn establishes a session, talking GFcp over a packet connection.

func (*UDPSession) Close

func (
	s *UDPSession,
) Close() error

Close ...

func (*UDPSession) GFcpInput

func (
	s *UDPSession,
) GFcpInput(
	data []byte,
)

GFcpInput ...

func (*UDPSession) GetConv

func (
	s *UDPSession,
) GetConv() uint32

GetConv ...

func (*UDPSession) LocalAddr

func (
	s *UDPSession,
) LocalAddr() net.Addr

LocalAddr returns the local network address. The address returned is shared by all invocations of LocalAddr - do not modify it.

func (*UDPSession) Read

func (
	s *UDPSession,
) Read(
	b []byte,
) (
	n int,
	err error,
)

Read implements net.Conn Function is safe for concurrent access.

func (*UDPSession) RemoteAddr

func (
	s *UDPSession,
) RemoteAddr() net.Addr

RemoteAddr returns the remote network address. The address returned is shared by all invocations of RemoteAddr - do not modify it.

func (*UDPSession) SetACKNoDelay

func (
	s *UDPSession,
) SetACKNoDelay(
	nodelay bool,
)

SetACKNoDelay changes the ACK flushing option. If set to true, ACKs are flusghed immediately,

func (*UDPSession) SetDSCP

func (
	s *UDPSession,
) SetDSCP(
	dscp int,
) error

SetDSCP sets the 6-bit DSCP field of IP header. Has no effect, unless accepted by your Listener.

func (*UDPSession) SetDUP

func (
	s *UDPSession,
) SetDUP(
	dup int,
)

SetDUP duplicates UDP packets for GFcp output. Useful for testing, not for normal use.

func (*UDPSession) SetDeadline

func (
	s *UDPSession,
) SetDeadline(
	t time.Time,
) error

SetDeadline sets a deadline associated with the listener. A zero time value disables a deadline.

func (*UDPSession) SetMtu

func (
	s *UDPSession,
) SetMtu(
	mtu int,
) bool

SetMtu sets the maximum transmission unit This size does not including UDP header itself.

func (*UDPSession) SetNoDelay

func (
	s *UDPSession,
) SetNoDelay(
	nodelay,
	interval,
	resend,
	nc int,
)

SetNoDelay sets TCP_DELAY, for GFcp.

func (*UDPSession) SetReadBuffer

func (
	s *UDPSession,
) SetReadBuffer(
	bytes int,
) error

SetReadBuffer sets the socket read buffer. Has no effect, unless it's accepted by your Listener.

func (*UDPSession) SetReadDeadline

func (
	s *UDPSession,
) SetReadDeadline(
	t time.Time,
) error

SetReadDeadline implements the Conn SetReadDeadline method.

func (*UDPSession) SetStreamMode

func (s *UDPSession) SetStreamMode(
	enable bool,
)

SetStreamMode toggles the streaming mode on or off

func (*UDPSession) SetWindowSize

func (
	s *UDPSession,
) SetWindowSize(
	sndwnd,
	rcvwnd int,
)

SetWindowSize sets the maximum window size

func (*UDPSession) SetWriteBuffer

func (
	s *UDPSession,
) SetWriteBuffer(
	bytes int,
) error

SetWriteBuffer sets the socket write buffer. Has no effect, unless it's accepted by your Listener.

func (*UDPSession) SetWriteDeadline

func (
	s *UDPSession,
) SetWriteDeadline(
	t time.Time,
) error

SetWriteDeadline implements the Conn SetWriteDeadline method.

func (*UDPSession) SetWriteDelay

func (
	s *UDPSession,
) SetWriteDelay(
	delay bool,
)

SetWriteDelay delays writes for bulk transfers, until the next update interval.

func (*UDPSession) Write

func (
	s *UDPSession,
) Write(
	b []byte,
) (
	n int,
	err error,
)

func (*UDPSession) WriteBuffers

func (
	s *UDPSession,
) WriteBuffers(
	v [][]byte,
) (
	n int,
	err error,
)

WriteBuffers ...

Jump to

Keyboard shortcuts

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