UDP-WG Implementation
Loading...
Searching...
No Matches
network Namespace Reference

The core networking namespace. More...

Classes

class  queue
 A thread-safe queue. More...
 

Functions

void thread (port_t port, wireguard::config wg={})
 The Network Thread.
 

Variables

queue in
 
queue out
 

Detailed Description

The core networking namespace.

Remarks
This namespace contains all the low level networking code that UDP-WG are built on. It presents an easy to use, seamless interface for the Main Thread, where it need only provide a destination, and then enqueue packets to the out queue to be sent, and read from the in queue for messages sent by others. The queue is a relatively straight-forward object, it's just a collection of packets to which access is mediated but a mutex to allow for multiple threads to access it at once. The Network Thread is a complicated function; it drives the network stack.

Function Documentation

◆ thread()

void network::thread ( port_t port,
wireguard::config wg = {} )

The Network Thread.

Parameters
portThe port to bind to: 0 = randomized.
wgAn optional WireGuard configuration.

Send a packet across a FD.

Parameters
pThe packet to send.
fdThe FD to send across.
Exceptions
runtime_errorIf the packet failed to send.

Open a socket at the specified port.

Parameters
portThe port.
Returns
The socket FD.
Warning
This function can teardown the thread if the socket cannot be initialized.

Establish a new connection.

Parameters
destThe destination.
Returns
The FD of the connection.
Remarks
One function of the Network Thread is that it should transparently handle new connections, maintain existing connections, and remove dead connections. When a unknown destination is specified in a UDP packet, we call this lambda to reach out and establish a FD to communicate over. Network Threads are cooperative in the sense that they willingly exchange this information.

Cleanup the thread.

Remarks
This closes the listening socket and all active connections, and flushes the queues.
Only the Network Threads sets stat to TERMINATE.

Wait for a connection of a specific type.

Parameters
fdThe FD to listen on.
tagThe tag at the start of the packet data.
Returns
The UDP packet.
Remarks
This is for re-keying. See that section for a more apt explanation.