queuepacketconn

package
v0.7.10 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package queuepacketconn is facilities for embedding packet-based reliability protocols inside other protocols.

https://github.com/net4people/bbs/issues/9

Index

Constants

View Source
const QueueSize = 128

QueueSize is the size of send and receive queues in QueuePacketConn and RemoteMap.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientID

type ClientID [8]byte

ClientID is an abstract identifier that binds together all the communications belonging to a single client session, even though those communications may arrive from multiple IP addresses or over multiple lower-level connections. It plays the same role that an (IP address, port number) tuple plays in a net.UDPConn: it's the return address pertaining to a long-lived abstract client session. The client attaches its ClientID to each of its communications, enabling the server to disambiguate requests among its many clients. ClientID implements the net.Addr interface.

func NewClientID

func NewClientID() ClientID

func (ClientID) Network

func (id ClientID) Network() string

func (ClientID) String

func (id ClientID) String() string

type DummyAddr

type DummyAddr struct{}

DummyAddr is a placeholder net.Addr, for when a programming interface requires a net.Addr but there is none relevant. All DummyAddrs compare equal to each other.

func (DummyAddr) Network

func (addr DummyAddr) Network() string

func (DummyAddr) String

func (addr DummyAddr) String() string

type QueuePacketConn

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

QueuePacketConn implements net.PacketConn by storing queues of packets. There is one incoming queue (where packets are additionally tagged by the source address of the peer that sent them). There are many outgoing queues, one for each remote peer address that has been recently seen. The QueueIncoming method inserts a packet into the incoming queue, to eventually be returned by ReadFrom. WriteTo inserts a packet into an address-specific outgoing queue, which can later by accessed through the OutgoingQueue method.

func NewQueuePacketConn

func NewQueuePacketConn(localAddr net.Addr, timeout time.Duration) *QueuePacketConn

NewQueuePacketConn makes a new QueuePacketConn, set to track recent peers for at least a duration of timeout.

func (*QueuePacketConn) Close

func (c *QueuePacketConn) Close() error

Close unblocks pending operations and makes future operations fail with a "closed connection" error.

func (*QueuePacketConn) LocalAddr

func (c *QueuePacketConn) LocalAddr() net.Addr

LocalAddr returns the localAddr value that was passed to NewQueuePacketConn.

func (*QueuePacketConn) OutgoingQueue

func (c *QueuePacketConn) OutgoingQueue(addr net.Addr) <-chan []byte

OutgoingQueue returns the queue of outgoing packets corresponding to addr, creating it if necessary. The contents of the queue will be packets that are written to the address in question using WriteTo.

func (*QueuePacketConn) QueueIncoming

func (c *QueuePacketConn) QueueIncoming(p []byte, addr net.Addr)

QueueIncoming queues and incoming packet and its source address, to be returned in a future call to ReadFrom.

func (*QueuePacketConn) Read

func (c *QueuePacketConn) Read(b []byte) (int, error)

Read calls ReadFrom to read a packet. Created to implement net.Conn interface. Should be only used by stream-oriented transports (DoH, DoT), will return error if this is not the case.

func (*QueuePacketConn) ReadFrom

func (c *QueuePacketConn) ReadFrom(p []byte) (int, net.Addr, error)

ReadFrom returns a packet and address previously stored by QueueIncoming.

func (*QueuePacketConn) RemoteAddr

func (c *QueuePacketConn) RemoteAddr() net.Addr

RemoteAddr returns a stub addr. Created to implement net.Conn interface. This should be only used by stream-oriented transports (DoH, DoT).

func (*QueuePacketConn) SetDeadline

func (c *QueuePacketConn) SetDeadline(t time.Time) error

func (*QueuePacketConn) SetReadDeadline

func (c *QueuePacketConn) SetReadDeadline(t time.Time) error

func (*QueuePacketConn) SetWriteDeadline

func (c *QueuePacketConn) SetWriteDeadline(t time.Time) error

func (*QueuePacketConn) Write

func (c *QueuePacketConn) Write(b []byte) (int, error)

Write calls WriteTo to read a packet. Created to implement net.Conn interface. This should be only used by stream-oriented transports (DoH, DoT).

func (*QueuePacketConn) WriteTo

func (c *QueuePacketConn) WriteTo(p []byte, addr net.Addr) (int, error)

WriteTo queues an outgoing packet for the given address. The queue can later be retrieved using the OutgoingQueue method.

Jump to

Keyboard shortcuts

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