EPS Conduits  v0.0.2-2413
networking over networking
EPS::ClientHull Class Referencefinal

Client hull. More...

#include "ClientHull.hpp"

Inheritance diagram for EPS::ClientHull:
Collaboration diagram for EPS::ClientHull:

Public Member Functions

 ClientHull (int argc, char *argv[])
 Constructor. More...
 
virtual ~ClientHull (void)
 Destructor. More...
 
virtual void run_second_stage (void)
 Run EPS. More...
 
virtual void async_find_and_connect_to_server (void)
 Find the server and start one or more new TCP beams. More...
 
virtual void connection_failed (const EPS::TConnPtr &connection)
 Callback when a connection has failed and needs to be cleaned up. More...
 
virtual void processComm (const EPS::TConnPtr &connection, EPS::NetBuffer *nb, const EPS::CommHeader1 *header, const EPS::ECommType type)
 Called when a communication command is received. More...
 
std::string clean_hosts_file (std::string hosts="")
 Remove all of our entries from the hosts file. More...
 
void update_hosts_file (void)
 Add or remove the necessary entries into the hosts file. More...
 
void async_read_tun_tap (void)
 Asynchronous read from the TUN/TAP interface. More...
 
void process_tun_tap_packet (EPS::NetBuffer *nb)
 Called once a packet has been read from the TUN/TAP interface. More...
 
void stop_asio (void)
 Attempt to cleanly shutdown/close all ASIO activity. More...
 
void start_signal_handling (void)
 Start/initialize the signal handling for the hull. More...
 
void get_uuid (void)
 Get the UUID from the configuration file, or generate a new one if necessary. More...
 
void save_uuid (void)
 Save the UUID into the configuration file. More...
 
void write_blank_configuration_file (void)
 Create a new blank configuration file template with helpful comments. More...
 
void read_configuration_file (void)
 Read, parse, and store the configuration file. More...
 
void parse_options (void)
 Parse command-line options. More...
 
void run_first_stage (void)
 Called by main() to setup exception handling and calls run_second_stage(). More...
 
void setup_encryption_and_decryption (void)
 Initialize what we need for OpenSSL encryption/decryption. More...
 
void readComm (const EPS::TConnPtr &connection)
 Read (async) a communication command from the peer and act on it. More...
 
virtual void processComm (const EPS::TConnPtr &connection, EPS::NetBuffer *nb)
 Process a communication command that has already been read by readComm(). More...
 
void start_connect_timer (void)
 See if we have peers to which we want to connect. More...
 
void send_stats (void)
 Send the latest statistics to the server. More...
 
void start_stats_timer (void)
 Start an asynchronous wait on the stats timer. More...
 
void setup_listener (void)
 Setup socket listener. More...
 
void start_async_accept (void)
 Make the necessary calls to asynchronously accept a new TCP beam. More...
 
virtual void connection_failed (EPS::TCPConnection *connection)
 Callback when a connection has failed and needs to be cleaned up. More...
 
void validate_new_connection (const EPS::TConnPtr &connection)
 Exchange information and validate connection to peer. More...
 
void validate_new_connection (EPS::TCPConnection *connection)
 Exchange information and validate connection to peer. More...
 
void async_write (const EPS::TConnPtr &connection, EPS::NetBuffer *nb)
 Asynchronous write of the buffer. More...
 
void async_write (const EPS::TConnPtr &connection)
 Exchange information and validate connection to peer. More...
 

Static Public Member Functions

static Hullget (void)
 Returns the single instance of Hull, which is at time necessary since the asio service_io is part of the hull. More...
 

Public Attributes

std::string device_name
 TUN/TAP device name (such as "eps0") More...
 
FILE_HANDLE_DESCRIPTOR device_fd
 raw file handle or descriptor for TUN/TAP device More...
 
ASIO_STREAM tun_tap_stream
 TUN/TAP stream handle for ASIO read/write. More...
 
const EPS::EMode mode
 client or server mode More...
 
const std::string mode_string
 client or server mode string More...
 
bool done
 EPS will exit when this is set to TRUE More...
 
int signal_number
 set by the signal handler for logging purposes if a fatal signal is raised More...
 
int ac
 argc More...
 
char ** av
 argv More...
 
const std::chrono::seconds seconds_between_retries
 
EC ec
 boost error code More...
 
EPS::StrMap configuration
 the content of the configuration file More...
 
UUID uuid
 uuid for this EPS instance More...
 
boost::asio::io_service io_service
 boost::asio's link to the operating system's I/O services More...
 
boost::asio::signal_set signal_set
 register (through asio) for signal handling More...
 
boost::asio::ip::tcp::resolver tcp_resolver
 tcp resolver for async name resolution More...
 
boost::asio::ip::tcp::acceptor acceptor
 accept incoming client connections More...
 
EPS::IPv4 address
 EPS address, e.g. 192.168.43.12. More...
 
EPS::IPv4 network
 EPS network, e.g. 192.168.43.0. More...
 
EPS::IPv4 netmask
 EPS netmask, e.g. 255.255.255.0. More...
 
EPS::Tracker tracker
 keep track of all clients, uuids, and ip addresses More...
 
EPS::IPv4Set local_addresses
 set of all interesting local addresses More...
 
boost::asio::system_timer connect_timer
 see if we have new connections to establish to create the mesh More...
 
boost::asio::system_timer stats_timer
 statistics timer which is triggered every 60 seconds More...
 
EPS::Stats stats
 statistics are updated every minute when stats_timer expires More...
 
IPv4Vec ipv4_pool
 pool of available addresses to give to clients More...
 
EPS::UUIDSet pending_uuids
 set of UUIDs to which we'd like to connect More...
 
EPS::TCPConns server_conns
 server connections More...
 
time_t start_time
 when EPS was started More...
 
boost::asio::system_timer upnp_renew_timer
 UPnP information. More...
 
EPS::IPv4 upnp_lan_address
 LAN ip address according to UPnP. More...
 
EPS::IPv4 upnp_wan_address
 WAN ip address according to UPnP. More...
 
uint16_t upnp_wan_port
 port opened up on WAN side of UPnP device More...
 
UPNPDev * upnp_dev
 structure used by libminiupnpc More...
 
UPNPUrls upnp_urls
 structure used by libminiupnpc More...
 
IGDdatas upnp_data
 structure used by libminiupnpc More...
 

Static Public Attributes

static std::string addr = ""
 Configuration item read from CLI or eps.conf file. More...
 
static uint16_t port = 0
 TCP/UDP port to which we'll connect. More...
 
static std::string network_str = ""
 network (with optional mask) to create for the EPS conduit network More...
 
static std::string scorecard = ""
 filename of the scorecard where stats are written More...
 
static bool sequential = false
 should IP addresses be assigned in a sequential manner to new clients More...
 
static std::string conf_filename = "/etc/eps.conf"
 name of the configuration file More...
 
static std::string log_filename = ""
 name of the file to which log entries will be written More...
 
static std::string gv_filename = ""
 name of the graphviz network diagram file More...
 
static bool upnp_enabled = false
 whether UPnP is enabled/disabled More...
 
static int upnp_timeout = 1000
 number of seconds to wait for UPnP (or -1 to disable) More...
 

Detailed Description

Client hull.

See also
EPS::Hull
EPS::ServerHull

Constructor & Destructor Documentation

◆ ClientHull()

EPS::ClientHull::ClientHull ( int  argc,
char *  argv[] 
)

Constructor.

◆ ~ClientHull()

EPS::ClientHull::~ClientHull ( void  )
virtual

Destructor.

Here is the call graph for this function:

Member Function Documentation

◆ async_find_and_connect_to_server()

void EPS::ClientHull::async_find_and_connect_to_server ( void  )
virtual

Find the server and start one or more new TCP beams.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ async_read_tun_tap()

void EPS::ClientHull::async_read_tun_tap ( void  )

Asynchronous read from the TUN/TAP interface.

Todo:
See this regression in kernel 3.19 and above: https://bugzilla.kernel.org/show_bug.cgi?id=96381 The problem is the tun/tap API is incorrectly returning 0 bytes instead of EAGAIN when nothing is available to read. To work around this, let's insert increasingly long pauses if the error is EOF.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ async_write() [1/2]

void EPS::Hull::async_write ( const EPS::TConnPtr connection,
EPS::NetBuffer nb 
)
inherited

Asynchronous write of the buffer.

The de-allocation of the NetBuffer parameter will be handled by this method once the write has completed. The NetBuffer must not be modified after this method is called.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ async_write() [2/2]

void EPS::Hull::async_write ( const EPS::TConnPtr connection)
inherited

Exchange information and validate connection to peer.

Here is the call graph for this function:

◆ clean_hosts_file()

std::string EPS::ClientHull::clean_hosts_file ( std::string  hosts = "")

Remove all of our entries from the hosts file.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connection_failed() [1/2]

void EPS::ClientHull::connection_failed ( const EPS::TConnPtr connection)
virtual

Callback when a connection has failed and needs to be cleaned up.

Implements EPS::Hull.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ connection_failed() [2/2]

void EPS::Hull::connection_failed ( EPS::TCPConnection connection)
virtualinherited

Callback when a connection has failed and needs to be cleaned up.

Here is the call graph for this function:

◆ get()

EPS::Hull & EPS::Hull::get ( void  )
staticinherited

Returns the single instance of Hull, which is at time necessary since the asio service_io is part of the hull.

Here is the caller graph for this function:

◆ get_uuid()

void EPS::Hull::get_uuid ( void  )
inherited

Get the UUID from the configuration file, or generate a new one if necessary.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_options()

void EPS::Hull::parse_options ( void  )
inherited

Parse command-line options.

For historical reasons, not all of the configuration settings are read/parsed using boost::program_options. For example, see the UUID values as well as cipher_iv and cipher_key in EPS::Hull::read_configuration_file().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_tun_tap_packet()

void EPS::ClientHull::process_tun_tap_packet ( EPS::NetBuffer nb)

Called once a packet has been read from the TUN/TAP interface.

Called once a packet/frame has been copied into the specified NetBuffer.

  • byte[0-1]: flags (network byte order)
  • byte[2-3]: proto (network byte order)
  • byte[4+...]: ethernet frame
  • byte[...]: ip packet ...etc...

Note that if IFF_NO_PI is specified when the TAP interface is created (which is what EPS does since v0.0.1-549) then the flags and proto bytes aren't included, and the read starts directly at the ethernet frame:

  • byte[0+.]: ethernet frame
  • byte[...]: ip packet ...etc...
Todo:
check to see if the UDP channel is up
Todo:
send this packet over UDP instead of TCP
Here is the call graph for this function:
Here is the caller graph for this function:

◆ processComm() [1/2]

void EPS::ClientHull::processComm ( const EPS::TConnPtr connection,
EPS::NetBuffer nb,
const EPS::CommHeader1 header,
const EPS::ECommType  type 
)
virtual

Called when a communication command is received.

Implements EPS::Hull.

Here is the call graph for this function:

◆ processComm() [2/2]

void EPS::Hull::processComm ( const EPS::TConnPtr connection,
EPS::NetBuffer nb 
)
virtualinherited

Process a communication command that has already been read by readComm().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ read_configuration_file()

void EPS::Hull::read_configuration_file ( void  )
inherited

Read, parse, and store the configuration file.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ readComm()

void EPS::Hull::readComm ( const EPS::TConnPtr connection)
inherited

Read (async) a communication command from the peer and act on it.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_first_stage()

void EPS::Hull::run_first_stage ( void  )
inherited

Called by main() to setup exception handling and calls run_second_stage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ run_second_stage()

void EPS::ClientHull::run_second_stage ( void  )
virtual

Run EPS.

Implements EPS::Hull.

Here is the call graph for this function:

◆ save_uuid()

void EPS::Hull::save_uuid ( void  )
inherited

Save the UUID into the configuration file.

Here is the caller graph for this function:

◆ send_stats()

void EPS::Hull::send_stats ( void  )
inherited

Send the latest statistics to the server.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_encryption_and_decryption()

void EPS::Hull::setup_encryption_and_decryption ( void  )
inherited

Initialize what we need for OpenSSL encryption/decryption.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setup_listener()

void EPS::Hull::setup_listener ( void  )
inherited

Setup socket listener.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_async_accept()

void EPS::Hull::start_async_accept ( void  )
inherited

Make the necessary calls to asynchronously accept a new TCP beam.

Todo:
fixme: even if the pool is empty, if this client has a reserved ip address we still need to accept it
Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_connect_timer()

void EPS::Hull::start_connect_timer ( void  )
inherited

See if we have peers to which we want to connect.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ start_signal_handling()

void EPS::Hull::start_signal_handling ( void  )
inherited

Start/initialize the signal handling for the hull.

Todo:
define our own error category derived from error_category
Here is the caller graph for this function:

◆ start_stats_timer()

void EPS::Hull::start_stats_timer ( void  )
inherited

Start an asynchronous wait on the stats timer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ stop_asio()

void EPS::Hull::stop_asio ( void  )
inherited

Attempt to cleanly shutdown/close all ASIO activity.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ update_hosts_file()

void EPS::ClientHull::update_hosts_file ( void  )

Add or remove the necessary entries into the hosts file.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validate_new_connection() [1/2]

void EPS::Hull::validate_new_connection ( const EPS::TConnPtr connection)
inherited

Exchange information and validate connection to peer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validate_new_connection() [2/2]

void EPS::Hull::validate_new_connection ( EPS::TCPConnection connection)
inherited

Exchange information and validate connection to peer.

Here is the call graph for this function:

◆ write_blank_configuration_file()

void EPS::Hull::write_blank_configuration_file ( void  )
inherited

Create a new blank configuration file template with helpful comments.

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ ac

int EPS::Hull::ac
inherited

argc

◆ acceptor

boost::asio::ip::tcp::acceptor EPS::Hull::acceptor
inherited

accept incoming client connections

◆ addr

std::string EPS::Hull::addr = ""
staticinherited

Configuration item read from CLI or eps.conf file.

name or ip address to which the client will connect

See also
--server

◆ address

EPS::IPv4 EPS::Hull::address
inherited

EPS address, e.g. 192.168.43.12.

◆ av

char** EPS::Hull::av
inherited

argv

◆ conf_filename

std::string EPS::Hull::conf_filename = "/etc/eps.conf"
staticinherited

name of the configuration file

See also
--conf

◆ configuration

EPS::StrMap EPS::Hull::configuration
inherited

the content of the configuration file

◆ connect_timer

boost::asio::system_timer EPS::Hull::connect_timer
inherited

see if we have new connections to establish to create the mesh

See also
pending_uuids

◆ device_fd

FILE_HANDLE_DESCRIPTOR EPS::ClientHull::device_fd

raw file handle or descriptor for TUN/TAP device

◆ device_name

std::string EPS::ClientHull::device_name

TUN/TAP device name (such as "eps0")

◆ done

bool EPS::Hull::done
inherited

EPS will exit when this is set to TRUE

◆ ec

EC EPS::Hull::ec
inherited

boost error code

◆ gv_filename

std::string EPS::Hull::gv_filename = ""
staticinherited

name of the graphviz network diagram file

See also
--graphviz

◆ io_service

boost::asio::io_service EPS::Hull::io_service
inherited

boost::asio's link to the operating system's I/O services

◆ ipv4_pool

IPv4Vec EPS::Hull::ipv4_pool
inherited

pool of available addresses to give to clients

◆ local_addresses

EPS::IPv4Set EPS::Hull::local_addresses
inherited

set of all interesting local addresses

◆ log_filename

std::string EPS::Hull::log_filename = ""
staticinherited

name of the file to which log entries will be written

See also
--log

◆ mode

const EPS::EMode EPS::Hull::mode
inherited

client or server mode

◆ mode_string

const std::string EPS::Hull::mode_string
inherited

client or server mode string

See also
EPS::mode_to_string()

◆ netmask

EPS::IPv4 EPS::Hull::netmask
inherited

EPS netmask, e.g. 255.255.255.0.

◆ network

EPS::IPv4 EPS::Hull::network
inherited

EPS network, e.g. 192.168.43.0.

◆ network_str

std::string EPS::Hull::network_str = ""
staticinherited

network (with optional mask) to create for the EPS conduit network

See also
--network

◆ pending_uuids

EPS::UUIDSet EPS::Hull::pending_uuids
inherited

set of UUIDs to which we'd like to connect

See also
connect_timer

◆ port

uint16_t EPS::Hull::port = 0
staticinherited

TCP/UDP port to which we'll connect.

See also
--port

◆ scorecard

std::string EPS::Hull::scorecard = ""
staticinherited

filename of the scorecard where stats are written

See also
--scorecard

◆ seconds_between_retries

const std::chrono::seconds EPS::Hull::seconds_between_retries
inherited

◆ sequential

bool EPS::Hull::sequential = false
staticinherited

should IP addresses be assigned in a sequential manner to new clients

See also
--sequential

◆ server_conns

EPS::TCPConns EPS::Hull::server_conns
inherited

server connections

◆ signal_number

int EPS::Hull::signal_number
inherited

set by the signal handler for logging purposes if a fatal signal is raised

◆ signal_set

boost::asio::signal_set EPS::Hull::signal_set
inherited

register (through asio) for signal handling

◆ start_time

time_t EPS::Hull::start_time
inherited

when EPS was started

◆ stats

EPS::Stats EPS::Hull::stats
inherited

statistics are updated every minute when stats_timer expires

◆ stats_timer

boost::asio::system_timer EPS::Hull::stats_timer
inherited

statistics timer which is triggered every 60 seconds

◆ tcp_resolver

boost::asio::ip::tcp::resolver EPS::Hull::tcp_resolver
inherited

tcp resolver for async name resolution

◆ tracker

EPS::Tracker EPS::Hull::tracker
inherited

keep track of all clients, uuids, and ip addresses

◆ tun_tap_stream

ASIO_STREAM EPS::ClientHull::tun_tap_stream

TUN/TAP stream handle for ASIO read/write.

◆ upnp_data

IGDdatas EPS::Hull::upnp_data
inherited

structure used by libminiupnpc

◆ upnp_dev

UPNPDev* EPS::Hull::upnp_dev
inherited

structure used by libminiupnpc

◆ upnp_enabled

bool EPS::Hull::upnp_enabled = false
staticinherited

whether UPnP is enabled/disabled

See also
--upnptimeout

◆ upnp_lan_address

EPS::IPv4 EPS::Hull::upnp_lan_address
inherited

LAN ip address according to UPnP.

◆ upnp_renew_timer

boost::asio::system_timer EPS::Hull::upnp_renew_timer
inherited

UPnP information.

timer used to regularly attempt to renew any UPnP port mappings

◆ upnp_timeout

int EPS::Hull::upnp_timeout = 1000
staticinherited

number of seconds to wait for UPnP (or -1 to disable)

in milliseconds

See also
--upnptimeout

◆ upnp_urls

UPNPUrls EPS::Hull::upnp_urls
inherited

structure used by libminiupnpc

◆ upnp_wan_address

EPS::IPv4 EPS::Hull::upnp_wan_address
inherited

WAN ip address according to UPnP.

◆ upnp_wan_port

uint16_t EPS::Hull::upnp_wan_port
inherited

port opened up on WAN side of UPnP device

◆ uuid

UUID EPS::Hull::uuid
inherited

uuid for this EPS instance


The documentation for this class was generated from the following files: