turbotunnel

package
v0.0.0-...-0a4c363 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package turbotunnel provides support for overlaying a virtual net.PacketConn on some other network carrier.

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

Index

Constants

This section is empty.

Variables

View Source
var Token = [8]byte{0x12, 0x93, 0x60, 0x5d, 0x27, 0x81, 0x75, 0xf5}

This magic prefix is how a client opts into turbo tunnel mode. It is just a randomly generated byte string.

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 ClientMap

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

ClientMap manages a mapping of live clients (keyed by address, which will be a ClientID) to their respective send queues. ClientMap's functions are safe to call from multiple goroutines.

func NewClientMap

func NewClientMap(timeout time.Duration) *ClientMap

NewClientMap creates a ClientMap that expires clients after a timeout.

The timeout does not have to be kept in sync with QUIC's internal idle timeout. If a client is removed from the client map while the QUIC session is still live, the worst that can happen is a loss of whatever packets were in the send queue at the time. If QUIC later decides to send more packets to the same client, we'll instantiate a new send queue, and if the client ever connects again with the proper client ID, we'll deliver them.

func (*ClientMap) SendQueue

func (m *ClientMap) SendQueue(addr net.Addr) chan []byte

SendQueue returns the send queue corresponding to addr, creating it if necessary.

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 client that sent them). There are many outgoing queues, one for each client 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 clients 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) ReadFrom

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

ReadFrom returns a packet and address previously stored by QueueIncoming.

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) 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.

type RedialPacketConn

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

RedialPacketConn implements a long-lived net.PacketConn atop a sequence of other, transient net.PacketConns. RedialPacketConn creates a new net.PacketConn by calling a provided dialContext function. Whenever the net.PacketConn experiences a ReadFrom or WriteTo error, RedialPacketConn calls the dialContext function again and starts sending and receiving packets on the new net.PacketConn. RedialPacketConn's own ReadFrom and WriteTo methods return an error only when the dialContext function returns an error.

RedialPacketConn uses static local and remote addresses that are independent of those of any dialed net.PacketConn.

func NewRedialPacketConn

func NewRedialPacketConn(
	localAddr, remoteAddr net.Addr,
	dialContext func(context.Context) (net.PacketConn, error),
) *RedialPacketConn

NewQueuePacketConn makes a new RedialPacketConn, with the given static local and remote addresses, and dialContext function.

func (*RedialPacketConn) Close

func (c *RedialPacketConn) Close() error

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

func (*RedialPacketConn) LocalAddr

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

LocalAddr returns the localAddr value that was passed to NewRedialPacketConn.

func (*RedialPacketConn) ReadFrom

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

ReadFrom reads a packet from the currently active net.PacketConn. The packet's original remote address is replaced with the RedialPacketConn's own remote address.

func (*RedialPacketConn) SetDeadline

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

func (*RedialPacketConn) SetReadDeadline

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

func (*RedialPacketConn) SetWriteDeadline

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

func (*RedialPacketConn) WriteTo

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

WriteTo writes a packet to the currently active net.PacketConn. The addr argument is ignored and instead replaced with the RedialPacketConn's own remote address.

Jump to

Keyboard shortcuts

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