ncp

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2024 License: Apache-2.0 Imports: 13 Imported by: 20

README

ncp-go

Go implementation of NCP (NKN Control Protocol), an ARQ protocol for NKN network.

Documentation

Index

Constants

View Source
const (
	MinSequenceID = 1
)

Variables

View Source
var (
	ErrSessionClosed         = NewGenericError("session closed", false, false)
	ErrSessionEstablished    = NewGenericError("session is already established", false, false)
	ErrSessionNotEstablished = NewGenericError("session not established yet", false, true)
	ErrReadDeadlineExceeded  = NewGenericError("read deadline exceeded", true, true)
	ErrWriteDeadlineExceeded = NewGenericError("write deadline exceeded", true, true)
	ErrBufferSizeTooSmall    = NewGenericError("read buffer size is less than data length in non-stream mode", false, true)
	ErrDataSizeTooLarge      = NewGenericError("data size is greater than session mtu", false, true)
	ErrInvalidPacket         = NewGenericError("invalid packet", false, true)
	ErrRecvWindowFull        = NewGenericError("receive window full", false, true)
	ErrNotHandshake          = NewGenericError("first packet is not handshake packet", false, true)
	ErrConnClosed            = NewGenericError("connection closed", false, false)
	ErrConnNotFound          = NewGenericError("connection not found", false, false)
)
View Source
var DefaultConfig = Config{
	NonStream:                    false,
	SessionWindowSize:            4 << 20,
	MTU:                          1024,
	MinConnectionWindowSize:      1,
	MaxAckSeqListSize:            32,
	FlushInterval:                10,
	Linger:                       1000,
	InitialRetransmissionTimeout: 5000,
	MaxRetransmissionTimeout:     10000,
	SendAckInterval:              50,
	CheckTimeoutInterval:         50,
	CheckBytesReadInterval:       100,
	SendBytesReadThreshold:       200,
	Verbose:                      false,
}

Functions

func CompareSeq

func CompareSeq(seq1, seq2 uint32) int

func NextSeq

func NextSeq(seq uint32, step int64) uint32

func SeqInBetween

func SeqInBetween(startSeq, endSeq, targetSeq uint32) bool

Types

type Config

type Config struct {
	NonStream                    bool
	SessionWindowSize            int32 // in bytes
	MTU                          int32 // in bytes
	MinConnectionWindowSize      int32 // in packets
	MaxAckSeqListSize            int32
	FlushInterval                int32 // in millisecond
	Linger                       int32 // in millisecond
	InitialRetransmissionTimeout int32 // in millisecond
	MaxRetransmissionTimeout     int32 // in millisecond
	SendAckInterval              int32 // in millisecond
	CheckTimeoutInterval         int32 // in millisecond
	CheckBytesReadInterval       int32 // in millisecond
	SendBytesReadThreshold       int32 // in millisecond
	Verbose                      bool
}

func MergeConfig

func MergeConfig(conf *Config) (*Config, error)

type Connection

type Connection struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewConnection

func NewConnection(session *Session, localClientID, remoteClientID string, initialWindowSize float64) (*Connection, error)

func (*Connection) ReceiveAck

func (conn *Connection) ReceiveAck(sequenceID uint32, isSentByMe bool)

func (*Connection) RetransmissionTimeout

func (conn *Connection) RetransmissionTimeout() time.Duration

func (*Connection) SendAck

func (conn *Connection) SendAck(sequenceID uint32)

func (*Connection) SendAckQueueLen

func (conn *Connection) SendAckQueueLen() int

func (*Connection) SendWindowUsed

func (conn *Connection) SendWindowUsed() uint32

func (*Connection) Start

func (conn *Connection) Start()

type GenericError

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

func NewGenericError

func NewGenericError(err string, timeout, temporary bool) *GenericError

func (GenericError) Error

func (e GenericError) Error() string

func (GenericError) Temporary

func (e GenericError) Temporary() bool

func (GenericError) Timeout

func (e GenericError) Timeout() bool

type SendWithFunc

type SendWithFunc func(localClientID, remoteClientID string, buf []byte, writeTimeout time.Duration) error

type SeqHeap

type SeqHeap []uint32

func (SeqHeap) Len

func (h SeqHeap) Len() int

func (SeqHeap) Less

func (h SeqHeap) Less(i, j int) bool

func (*SeqHeap) Pop

func (h *SeqHeap) Pop() interface{}

func (*SeqHeap) Push

func (h *SeqHeap) Push(x interface{})

func (SeqHeap) Swap

func (h SeqHeap) Swap(i, j int)

type Session

type Session struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewSession

func NewSession(localAddr, remoteAddr net.Addr, localClientIDs, remoteClientIDs []string, sendWith SendWithFunc, config *Config) (*Session, error)

func (*Session) Accept

func (session *Session) Accept() error

func (*Session) Close

func (session *Session) Close() error

func (*Session) Dial

func (session *Session) Dial(ctx context.Context) error

func (*Session) GetBytesRead

func (session *Session) GetBytesRead() uint64

func (*Session) GetConnWindowSize

func (session *Session) GetConnWindowSize() uint32

func (*Session) GetContext added in v1.0.6

func (session *Session) GetContext() context.Context

func (*Session) GetDataToSend

func (session *Session) GetDataToSend(sequenceID uint32) []byte

func (*Session) IsClosed

func (session *Session) IsClosed() bool

func (*Session) IsClosedByRemote added in v1.0.6

func (session *Session) IsClosedByRemote() bool

func (*Session) IsEstablished

func (session *Session) IsEstablished() bool

func (*Session) IsStream

func (session *Session) IsStream() bool

func (*Session) LocalAddr

func (session *Session) LocalAddr() net.Addr

func (*Session) Read

func (session *Session) Read(b []byte) (_ int, e error)

func (*Session) ReceiveWith

func (session *Session) ReceiveWith(localClientID, remoteClientID string, buf []byte) error

func (*Session) RecvWindowUsed

func (session *Session) RecvWindowUsed() uint32

func (*Session) RemoteAddr

func (session *Session) RemoteAddr() net.Addr

func (*Session) SendWindowUsed

func (session *Session) SendWindowUsed() uint32

func (*Session) SetDeadline

func (session *Session) SetDeadline(t time.Time) error

func (*Session) SetLinger

func (session *Session) SetLinger(t int32)

SetLinger sets session linger in unit of millisecond

func (*Session) SetReadDeadline

func (session *Session) SetReadDeadline(t time.Time) error

func (*Session) SetWriteDeadline

func (session *Session) SetWriteDeadline(t time.Time) error

func (*Session) Write

func (session *Session) Write(b []byte) (_ int, e error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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