gbn

package
v0.1.6-alpha Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: MIT Imports: 12 Imported by: 4

Documentation

Index

Constants

View Source
const (
	SYN    = 0x01
	DATA   = 0x02
	ACK    = 0x03
	NACK   = 0x04
	FIN    = 0x05
	SYNACK = 0x06

	FALSE = 0x00
	TRUE  = 0x01
)
View Source
const (
	DefaultN = 20
)
View Source
const Subsystem = "GOBN"

Variables

This section is empty.

Functions

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

Types

type BackoffWaiter

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

func NewBackoffWaiter

func NewBackoffWaiter(initial, min, max time.Duration) *BackoffWaiter

func (*BackoffWaiter) Wait

func (b *BackoffWaiter) Wait()

type GoBackNConn

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

func NewClientConn

func NewClientConn(n uint8, sendFunc sendBytesFunc, receiveFunc recvBytesFunc,
	opts ...Option) (*GoBackNConn, error)

NewClientConn creates a new bidirectional Go-Back-N client. The sendStream function must write to the underlying transport stream. The receiveStream function must read from an underlying transport stream. The resendTimeout parameter defines the duration to wait before resending data if the corresponding ACK for the data is not received.

func NewServerConn

func NewServerConn(ctx context.Context, sendFunc sendBytesFunc,
	recvFunc recvBytesFunc, opts ...Option) (*GoBackNConn, error)

NewServerConn creates a new bidirectional Go-Back-N server. The sendStream function must write to the underlying transport stream. The receiveStream function must read from an underlying transport stream. The resendTimeout parameter defines the duration to wait before resending data if the corresponding ACK for the data is not received.

func (*GoBackNConn) Close

func (g *GoBackNConn) Close() error

Close attempts to cleanly close the connection by sending a FIN message.

func (*GoBackNConn) Recv

func (g *GoBackNConn) Recv() ([]byte, error)

Recv blocks until it gets a recv with the correct sequence it was expecting.

func (*GoBackNConn) Send

func (g *GoBackNConn) Send(data []byte) error

Send blocks until an ack is received for the packet sent N packets before.

type IntervalAwareForceTicker

type IntervalAwareForceTicker struct {

	// Force is used to force-feed a ticks into the ticker. Useful for
	// debugging when trying to wake an event.
	Force chan time.Time
	// contains filtered or unexported fields
}

IntervalAwareForceTicker implements the Ticker interface, and provides a method of force-feeding ticks, even while paused. This is a copy of lnd's ticker.Force that is also aware when the last timed tick happened and how long approximately it takes until the next timed tick happens.

func NewIntervalAwareForceTicker

func NewIntervalAwareForceTicker(interval time.Duration) *IntervalAwareForceTicker

NewIntervalAwareForceTicker returns a IntervalAwareForceTicker ticker, used for testing and debugging. It supports the ability to force-feed events that get output by the channel returned by Ticks().

func (*IntervalAwareForceTicker) ForceTick

func (t *IntervalAwareForceTicker) ForceTick()

ForceTick force feeds an event into the ticker channel and resets the internal clock ticker causing the next clock tick to occur in the configured interval.

func (*IntervalAwareForceTicker) IsActive

func (t *IntervalAwareForceTicker) IsActive() bool

IsActive returns true if the timed ticks are currently forwarded to the Force channel.

func (*IntervalAwareForceTicker) LastTimedTick

func (t *IntervalAwareForceTicker) LastTimedTick() time.Time

LastTimedTick returns the timestamp when the last tick occurred that was fired by the underlying clock. This does not mean that the tick was necessarily also forwarded to the Force channel. If we are paused, this timestamp is still updated but no ticks are sent to the channel.

func (*IntervalAwareForceTicker) NextTickIn

func (t *IntervalAwareForceTicker) NextTickIn() time.Duration

NextTickIn returns the approximate duration until the next timed tick will occur.

func (*IntervalAwareForceTicker) Pause

func (t *IntervalAwareForceTicker) Pause()

Pause suspends the underlying ticker, such that Ticks() stops signaling at regular intervals.

NOTE: Part of the Ticker interface.

func (*IntervalAwareForceTicker) Reset

func (t *IntervalAwareForceTicker) Reset()

Reset restarts the ticker interval, causing the next clock tick to occur in the configured interval.

func (*IntervalAwareForceTicker) ResetWithInterval

func (t *IntervalAwareForceTicker) ResetWithInterval(newInterval time.Duration)

ResetWithInterval restarts the ticker with the given interval, causing the next clock tick to occur in the given interval.

func (*IntervalAwareForceTicker) Resume

func (t *IntervalAwareForceTicker) Resume()

Resume starts underlying time.Ticker and causes the ticker to begin delivering scheduled events.

NOTE: Part of the Ticker interface.

func (*IntervalAwareForceTicker) Stop

func (t *IntervalAwareForceTicker) Stop()

Stop suspends the underlying ticker, such that Ticks() stops signaling at regular intervals, and permanently frees up any resources.

NOTE: Part of the Ticker interface.

func (*IntervalAwareForceTicker) Ticks

func (t *IntervalAwareForceTicker) Ticks() <-chan time.Time

Ticks returns a receive-only channel that delivers times at the ticker's prescribed interval when active. Force-fed ticks can be delivered at any time.

NOTE: Part of the Ticker interface.

type Message

type Message interface {
	Serialize() ([]byte, error)
}

func Deserialize

func Deserialize(b []byte) (Message, error)

type Option

type Option func(conn *GoBackNConn)

func WithHandshakeTimeout

func WithHandshakeTimeout(timeout time.Duration) Option

WithHandshakeTimeout is used to set the timeout used during the handshake. If the timeout is reached without response from the peer then the handshake will be aborted and restarted.

func WithKeepalivePing

func WithKeepalivePing(duration time.Duration) Option

WithKeepalivePing is used to send a ping packet if no packets have been received from the other side for the given duration. This helps keep the connection alive and also ensures that the connection is closed if the other side does not respond to the ping in a timely manner. After the ping the connection will be closed if the other side does not respond within time duration.

func WithMaxSendSize

func WithMaxSendSize(size int) Option

WithMaxSendSize is used to set the maximum payload size in bytes per packet. If set and a large payload comes through then it will be split up into multiple packets with payloads no larger than the given maximum size. A size of zero will disable splitting.

func WithTimeout

func WithTimeout(timeout time.Duration) Option

WithTimeout is used to set the resend timeout. This is the time to wait for ACKs before resending the queue.

type PacketACK

type PacketACK struct {
	Seq uint8
}

func (*PacketACK) Serialize

func (m *PacketACK) Serialize() ([]byte, error)

type PacketData

type PacketData struct {
	Seq        uint8
	FinalChunk bool
	IsPing     bool
	Payload    []byte
}

func (*PacketData) Serialize

func (m *PacketData) Serialize() ([]byte, error)

type PacketFIN

type PacketFIN struct {
}

func (*PacketFIN) Serialize

func (m *PacketFIN) Serialize() ([]byte, error)

type PacketNACK

type PacketNACK struct {
	Seq uint8
}

func (*PacketNACK) Serialize

func (m *PacketNACK) Serialize() ([]byte, error)

type PacketSYN

type PacketSYN struct {
	N uint8
}

func (*PacketSYN) Serialize

func (m *PacketSYN) Serialize() ([]byte, error)

type PacketSYNACK

type PacketSYNACK struct{}

func (*PacketSYNACK) Serialize

func (m *PacketSYNACK) Serialize() ([]byte, error)

Jump to

Keyboard shortcuts

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