Documentation ¶
Index ¶
- Constants
- func UseLogger(logger btclog.Logger)
- type BackoffWaiter
- type GoBackNConn
- type IntervalAwareForceTicker
- func (t *IntervalAwareForceTicker) ForceTick()
- func (t *IntervalAwareForceTicker) IsActive() bool
- func (t *IntervalAwareForceTicker) LastTimedTick() time.Time
- func (t *IntervalAwareForceTicker) NextTickIn() time.Duration
- func (t *IntervalAwareForceTicker) Pause()
- func (t *IntervalAwareForceTicker) Reset()
- func (t *IntervalAwareForceTicker) ResetWithInterval(newInterval time.Duration)
- func (t *IntervalAwareForceTicker) Resume()
- func (t *IntervalAwareForceTicker) Stop()
- func (t *IntervalAwareForceTicker) Ticks() <-chan time.Time
- type Message
- type Option
- type PacketACK
- type PacketData
- type PacketFIN
- type PacketNACK
- type PacketSYN
- type PacketSYNACK
Constants ¶
const ( DefaultN = 20 DefaultSendTimeout = math.MaxInt64 DefaultRecvTimeout = math.MaxInt64 )
const ( SYN = 0x01 DATA = 0x02 ACK = 0x03 NACK = 0x04 FIN = 0x05 SYNACK = 0x06 FALSE = 0x00 TRUE = 0x01 )
const Subsystem = "GOBN"
Variables ¶
This section is empty.
Functions ¶
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.
func (*GoBackNConn) SetRecvTimeout ¶
func (g *GoBackNConn) SetRecvTimeout(timeout time.Duration)
SetRecvTimeout sets the timeout used in the Recv function.
func (*GoBackNConn) SetSendTimeout ¶
func (g *GoBackNConn) SetSendTimeout(timeout time.Duration)
SetSendTimeout sets the timeout used in the Send function.
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 ¶
func Deserialize ¶
type Option ¶
type Option func(conn *GoBackNConn)
func WithHandshakeTimeout ¶
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 ¶
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 ¶
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 ¶
WithTimeout is used to set the resend timeout. This is the time to wait for ACKs before resending the queue.
type PacketData ¶
func (*PacketData) Serialize ¶
func (m *PacketData) Serialize() ([]byte, error)
type PacketNACK ¶
type PacketNACK struct {
Seq uint8
}
func (*PacketNACK) Serialize ¶
func (m *PacketNACK) Serialize() ([]byte, error)
type PacketSYNACK ¶
type PacketSYNACK struct{}
func (*PacketSYNACK) Serialize ¶
func (m *PacketSYNACK) Serialize() ([]byte, error)