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
- Variables
- func CurrentMs() uint32
- func Dial(raddr string) (net.Conn, error)
- func Listen(laddr string) (net.Listener, error)
- type Entropy
- type FecDecoder
- type FecEncoder
- type FecPacket
- type GFCP
- func (GFcp *GFCP) Check() uint32
- func (GFcp *GFCP) Flush(ackOnly bool) uint32
- func (GFcp *GFCP) Input(data []byte, regular, ackNoDelay bool) int
- func (GFcp *GFCP) NoDelay(nodelay, interval, resend, nc int) int
- func (GFcp *GFCP) PeekSize() (length int)
- func (GFcp *GFCP) Recv(buffer []byte) (n int)
- func (GFcp *GFCP) ReserveBytes(n int) bool
- func (GFcp *GFCP) Send(buffer []byte) int
- func (GFcp *GFCP) SetMtu(mtu int) int
- func (GFcp *GFCP) Update()
- func (GFcp *GFCP) WaitSnd() int
- func (GFcp *GFCP) WndSize(sndwnd, rcvwnd int) int
- type Listener
- func (l *Listener) Accept() (net.Conn, error)
- func (l *Listener) AcceptGFCP() (*UDPSession, error)
- func (l *Listener) Addr() net.Addr
- func (l *Listener) Close() error
- func (l *Listener) CloseSession(remote net.Addr) (ret bool)
- func (l *Listener) SetDSCP(dscp int) error
- func (l *Listener) SetDeadline(t time.Time) error
- func (l *Listener) SetReadBuffer(bytes int) error
- func (l *Listener) SetReadDeadline(t time.Time) error
- func (l *Listener) SetWriteBuffer(bytes int) error
- func (l *Listener) SetWriteDeadline(t time.Time) error
- type Nonce
- type Segment
- type Snsi
- type UDPSession
- func (s *UDPSession) Close() error
- func (s *UDPSession) GFcpInput(data []byte)
- func (s *UDPSession) GetConv() uint32
- func (s *UDPSession) LocalAddr() net.Addr
- func (s *UDPSession) Read(b []byte) (n int, err error)
- func (s *UDPSession) RemoteAddr() net.Addr
- func (s *UDPSession) SetACKNoDelay(nodelay bool)
- func (s *UDPSession) SetDSCP(dscp int) error
- func (s *UDPSession) SetDUP(dup int)
- func (s *UDPSession) SetDeadline(t time.Time) error
- func (s *UDPSession) SetMtu(mtu int) bool
- func (s *UDPSession) SetNoDelay(nodelay, interval, resend, nc int)
- func (s *UDPSession) SetReadBuffer(bytes int) error
- func (s *UDPSession) SetReadDeadline(t time.Time) error
- func (s *UDPSession) SetStreamMode(enable bool)
- func (s *UDPSession) SetWindowSize(sndwnd, rcvwnd int)
- func (s *UDPSession) SetWriteBuffer(bytes int) error
- func (s *UDPSession) SetWriteDeadline(t time.Time) error
- func (s *UDPSession) SetWriteDelay(delay bool)
- func (s *UDPSession) Write(b []byte) (n int, err error)
- func (s *UDPSession) WriteBuffers(v [][]byte) (n int, err error)
Constants ¶
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
const ( // KTypeData ... KTypeData = 0xf1 // KTypeParity ... KTypeParity = 0xf2 )
const (
// GFcpMtuLimit ...
GFcpMtuLimit = 1500
)
Variables ¶
KxmitBuf ...
Functions ¶
func Dial ¶
Dial connects to the remote address "raddr" 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 GFCP ¶
type GFCP struct { SndBuf []Segment // contains filtered or unexported fields }
GFCP primary structure
func NewGFCP ¶
NewGFCP creates a new GFcp control object.
func (*GFCP) Check ¶
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) Input ¶
Input receives a (low-level) UDP packet, and determinines if a full packet has been processsed (not by the FEC algorithm)
func (*GFCP) NoDelay ¶
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 ¶
PeekSize checks the size of next message in the receive queue.
func (*GFCP) Recv ¶
Recv is upper level recviver; returns size or EAGAIN on error.
func (*GFCP) ReserveBytes ¶
ReserveBytes keeps 'n' bytes from the beginning of buffering. Output callbacks use this to return 'false' if 'n' >= 'mss'.
func (*GFCP) Send ¶
Send is upper level sender, returns <0 on error.
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 ¶
WaitSnd shows how many packets are queued to be sent
type Listener ¶
type Listener struct { /// FecDecoder ... FecDecoder *FecDecoder // FEC mock initialization // contains filtered or unexported fields }
Listener ...
func ListenWithOptions ¶
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 ¶
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 ¶
Addr returns the listener's network address. The address returned is shared by all invocations of Addr - do not modify it.
func (*Listener) Close ¶
Close stops listening on the UDP address. Any already accepted connections will not be closed.
func (*Listener) CloseSession ¶
CloseSession notifies the Listener when a Session is Closed.
func (*Listener) SetDSCP ¶
SetDSCP sets the 6-bit DSCP field of IP header.
func (*Listener) SetDeadline ¶
SetDeadline sets the deadline associated with the Listener. A zero value will disable all deadlines.
func (*Listener) SetReadBuffer ¶
SetReadBuffer sets the socket read buffer for the Listener.
func (*Listener) SetReadDeadline ¶
SetReadDeadline implements the Conn SetReadDeadline method.
func (*Listener) SetWriteBuffer ¶
SetWriteBuffer sets the socket write buffer for the Listener.
type Segment ¶
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
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) 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 ...