Documentation ¶
Index ¶
- Constants
- func ParsePortRange(desiredPort string) (desiredPortLow, desiredPortHigh int, ok bool)
- type Compressor
- type Connection
- type Direction
- type Fragment
- type FragmentAssembly
- type Fragmenter
- type Packet
- type State
- type TimestampedState
- type Transport
- func (t *Transport[S, R]) Awaken(now int64) (ret bool)
- func (t *Transport[S, R]) Close()
- func (t *Transport[S, R]) CounterpartyShutdownAckSent() bool
- func (t *Transport[S, R]) GetConnection() *Connection
- func (t *Transport[S, R]) GetCurrentState() S
- func (t *Transport[S, R]) GetKey() string
- func (t *Transport[S, R]) GetLatestRemoteState() TimestampedState[R]
- func (t *Transport[S, R]) GetRemoteAddr() net.Addr
- func (t *Transport[S, R]) GetRemoteDiff() string
- func (t *Transport[S, R]) GetRemoteStateNum() uint64
- func (t *Transport[S, R]) GetSentStateAcked() uint64
- func (t *Transport[S, R]) GetSentStateAckedTimestamp() int64
- func (t *Transport[S, R]) GetSentStateLast() uint64
- func (t *Transport[S, R]) GetSentStateLastTimestamp() int64
- func (t *Transport[S, R]) GetServerPort() string
- func (t *Transport[S, R]) HasRemoteAddr() bool
- func (t *Transport[S, R]) InitSize(nCols, nRows int)
- func (t *Transport[S, R]) ProcessPayload(s string) error
- func (t *Transport[S, R]) Recv() error
- func (t *Transport[S, R]) SentInterval() uint
- func (t *Transport[S, R]) SetCurrentState(x S)
- func (t *Transport[S, R]) SetSendDelay(delay uint)
- func (t *Transport[S, R]) SetVerbose(verbose uint)
- func (t *Transport[S, R]) ShutdownAckTimedout() bool
- func (t *Transport[S, R]) ShutdownAcknowledged() bool
- func (t *Transport[S, R]) ShutdownInProgress() bool
- func (t *Transport[S, R]) StartShutdown()
- func (t *Transport[S, R]) Tick() error
- func (t *Transport[S, R]) WaitTime() int
- type TransportSender
Constants ¶
const ( DIRECTION_MASK uint64 = uint64(1) << 63 SEQUENCE_MASK uint64 = ^DIRECTION_MASK )
const ( /* * For IPv4, guess the typical (minimum) header length; * fragmentation is not dangerous, just inefficient. */ IPV4_HEADER_LEN = 20 + 8 // base IP header + UDP /* * For IPv6, we don't want to ever have MTU issues, so make a * conservative guess about header size. */ IPV6_HEADER_LEN = 40 + 16 + 8 // base IPv6 header + 2 minimum-sized extension headers + UDP */ /* Application datagram MTU. For constructors and fallback. */ DEFAULT_SEND_MTU = 500 /* * IPv4 MTU. Don't use full Ethernet-derived MTU, * mobile networks have high tunneling overhead. * * As of July 2016, VPN traffic over Amtrak Acela wifi seems to be * dropped if tunnelled packets are 1320 bytes or larger. Use a * 1280-byte IPv4 MTU for now. * * We may have to implement ICMP-less PMTUD (RFC 4821) eventually. */ DEFAULT_IPV4_MTU = 1280 /* IPv6 MTU. Use the guaranteed minimum to avoid fragmentation. */ DEFAULT_IPV6_MTU = 1280 MIN_RTO int64 = 50 // ms MAX_RTO int64 = 1000 // ms PORT_RANGE_LOW = 60001 PORT_RANGE_HIGH = 60999 SERVER_ASSOCIATION_TIMEOUT = 40000 PORT_HOP_INTERVAL = 10000 MAX_PORTS_OPEN = 10 MAX_OLD_SOCKET_AGE = 60000 CONGESTION_TIMESTAMP_PENALTY = 500 // ms NETWORK = "udp" // IPv6 is only supported on Docker daemons running on Linux hosts. // Network transport overhead. ADDED_BYTES = 8 + 4 /* timestamps */ )
const ( SEND_INTERVAL_MIN = 20 /* ms between frames */ SEND_INTERVAL_MAX = 250 /* ms between frames */ ACK_INTERVAL = 3000 /* ms between empty acks */ ACK_DELAY = 100 /* ms before delayed ack */ SHUTDOWN_RETRIES = 16 /* number of shutdown packets to send before giving up */ ACTIVE_RETRY_TIMEOUT = 10000 /* attempt to resend at frame rate */ )
Variables ¶
This section is empty.
Functions ¶
func ParsePortRange ¶
parse "port" or "portlow:porthigh"
Types ¶
type Compressor ¶
type Compressor struct {
// contains filtered or unexported fields
}
func GetCompressor ¶
func GetCompressor() *Compressor
func (*Compressor) Uncompress ¶
func (c *Compressor) Uncompress(input []byte) ([]byte, error)
type Connection ¶
type Connection struct { SRTT float64 // smoothed round-trip time RTTVAR float64 // round-trip time variation sync.RWMutex RTTHit bool // contains filtered or unexported fields }
func NewConnection ¶
func NewConnection(desiredIp string, desiredPort string) *Connection
func NewConnectionClient ¶
func NewConnectionClient(keyStr string, ip, port string) *Connection
func (*Connection) Close ¶
func (c *Connection) Close()
type Fragment ¶
type Fragment struct {
// contains filtered or unexported fields
}
func NewFragment ¶
func NewFragmentFrom ¶
convert network order string into Fragment
type FragmentAssembly ¶
type FragmentAssembly struct {
// contains filtered or unexported fields
}
func NewFragmentAssembly ¶
func NewFragmentAssembly() *FragmentAssembly
type Fragmenter ¶
type Fragmenter struct {
// contains filtered or unexported fields
}
func NewFragmenter ¶
func NewFragmenter() *Fragmenter
type Packet ¶
type Packet struct {
// contains filtered or unexported fields
}
Packet is used for RTT calculation
func NewPacketFrom ¶
type State ¶
type State[C any] interface { // interface for Network::Transport Subtract(x C) DiffFrom(x C) string InitDiff() string ApplyString(diff string) error Equal(x C) bool EqualTrace(x C) bool // for test purpose // interface from code ResetInput() Reset() InitSize(y, x int) Clone() C }
State is implemented by UserSteam or CompleteTerminal. The type parameter is required to meet the requirement: the concrete type, such as UserSteam or CompleteTerminal, can use the concrete type for method parameter or return type instead of interface. self reference in method parameter and return type is not common, pay attention to it. [ref](https://appliedgo.com/blog/generic-interface-functions) The meaning of [C any]: the following methods requires a quite unspecified type C - basically, it can be anything.
type TimestampedState ¶
type TimestampedState[T State[T]] struct { // contains filtered or unexported fields }
timestamp int64 num uint64 state T
func (*TimestampedState[T]) GetState ¶
func (t *TimestampedState[T]) GetState() T
func (*TimestampedState[T]) GetTimestamp ¶
func (t *TimestampedState[T]) GetTimestamp() int64
type Transport ¶
type S or R that must implement the State[T] interface - that is, for itself.
func NewTransportClient ¶
func NewTransportServer ¶
func (*Transport[S, R]) Awaken ¶
detect computer awaken from hibernate based on receivedState and sentStates.
func (*Transport[S, R]) CounterpartyShutdownAckSent ¶
Other side has requested shutdown and we have sent one ACK
func (*Transport[S, R]) GetConnection ¶
func (t *Transport[S, R]) GetConnection() *Connection
func (*Transport[S, R]) GetCurrentState ¶
func (t *Transport[S, R]) GetCurrentState() S
func (*Transport[S, R]) GetLatestRemoteState ¶
func (t *Transport[S, R]) GetLatestRemoteState() TimestampedState[R]
func (*Transport[S, R]) GetRemoteAddr ¶
func (*Transport[S, R]) GetRemoteDiff ¶
func (*Transport[S, R]) GetRemoteStateNum ¶
func (*Transport[S, R]) GetSentStateAcked ¶
func (*Transport[S, R]) GetSentStateAckedTimestamp ¶
func (*Transport[S, R]) GetSentStateLast ¶
func (*Transport[S, R]) GetSentStateLastTimestamp ¶
func (*Transport[S, R]) GetServerPort ¶
func (*Transport[S, R]) HasRemoteAddr ¶
func (*Transport[S, R]) ProcessPayload ¶
func (*Transport[S, R]) SentInterval ¶
func (*Transport[S, R]) SetCurrentState ¶
func (t *Transport[S, R]) SetCurrentState(x S)
func (*Transport[S, R]) SetSendDelay ¶
func (*Transport[S, R]) SetVerbose ¶
func (*Transport[S, R]) ShutdownAckTimedout ¶
return true if retries reach times limit or retries time out
func (*Transport[S, R]) ShutdownAcknowledged ¶
return true if the firt sent state num is -1, otherwise false.
func (*Transport[S, R]) ShutdownInProgress ¶
return true if shutdown is started, otherwise false.
func (*Transport[S, R]) StartShutdown ¶
func (t *Transport[S, R]) StartShutdown()
Other side has requested shutdown and we have sent one ACK
Illegal to change current_state after this.
type TransportSender ¶
type TransportSender[T State[T]] struct { SEND_MINDELAY uint // ms to collect all input // contains filtered or unexported fields }
func NewTransportSender ¶
func NewTransportSender[T State[T]](connection *Connection, initialState T) *TransportSender[T]