EPS Conduits  v0.0.2-2413
networking over networking
EPS Namespace Reference

Namespaces

 Cipher
 Cipher takes care of calling OpenSSL to encrypt and decrypt NetBuffer objects.
 

Classes

class  ClientHull
 Client hull. More...
 
struct  CommAddress1
 Communication header: send a number of important addresses sent by the server to the clients on startup. More...
 
struct  CommData1
 Communication header: data packet. More...
 
struct  CommHeader1
 Communication header: common fields to all communication commands. More...
 
struct  CommHello2
 Communication header: initial "hello" sent between clients and servers when they first connect. More...
 
struct  CommList2
 Communication header: list all devices. More...
 
struct  CommList2Data
 Represents a single EPS client. More...
 
struct  CommStats1
 Communication header: send stats information. More...
 
class  Connection
 Base class for TCP and UDP connections between peer devices. More...
 
struct  EthernetHeader
 typical 14-byte ethernet header. (Ignores 802.1Q.) More...
 
class  Hull
 The Hull is the base class for both the client and server. More...
 
struct  Ipv4Header
 typical 20-byte IPV4 header. More...
 
class  NetBuffer
 NetBuffer objects manage blocks of buffer bytes used for either reading from, and writing to sockets. More...
 
class  Packet
 Simple class to dissect a packet and look for a few key identifiers, such as is_ipv4() and is_ipv4_tcp(). More...
 
class  ServerHull
 Server hull. More...
 
struct  Statistics
 Track all of the transfer and bandwidth statistics. More...
 
class  Stats
 Manage the EPS::Statistics structure. Differentiate between total statistics, and those gathered in the last minute. More...
 
class  TCPConnection
 TCP connection. More...
 
class  Tracker
 Manage all tracker records. More...
 
struct  TrackerData
 Used to track everything we know about a particular EPS client. More...
 
class  UDPConnection
 UDP connection. More...
 

Typedefs

typedef std::map< std::string, std::string > StrMap
 Map of string-to-string. More...
 
typedef boost::asio::ip::tcp::endpoint TCPEP
 Convenient alias for boost TCP endpoint. More...
 
typedef boost::asio::ip::address_v4 IPv4
 Convenient alias for boost IPv4 address. More...
 
typedef boost::system::error_code EC
 Convenient alias for boost error codes. More...
 
typedef boost::uuids::uuid UUID
 Convenient alias for boost UUIDs. More...
 
typedef uint8_t UUID16[16]
 UUID POD (uuid data) More...
 
typedef std::set< UUIDUUIDSet
 Set of UUIDs. More...
 
typedef std::set< EPS::IPv4IPv4Set
 Set of IPv4 addresses. More...
 
typedef std::vector< EPS::IPv4IPv4Vec
 Vector of IPv4 addresses. More...
 
typedef boost::asio::posix::stream_descriptor ASIO_STREAM
 TUN/TAP stream descriptor. More...
 
typedef int FILE_HANDLE_DESCRIPTOR
 native file descriptor More...
 
typedef std::deque< EPS::NetBuffer * > NBDeque
 Asio async_write() calls cannot overlap, so store pending buffers to send in a deque. More...
 
typedef uint8_t MAC[6]
 
typedef std::shared_ptr< EPS::TCPConnectionTConnPtr
 TCP connections are dynamically allocated when a socket is needed, so this type allows us to easily manage the lifespan of all connections. More...
 
typedef std::set< TConnPtrTCPConns
 When multiple TCP connections need to be grouped. More...
 
typedef std::map< UUID, EPS::TrackerDataTrackerMap
 Map between client UUIDs and a tracker record. This is the central "database" that makes up the Tracker functionality. More...
 
typedef std::map< IPv4, UUIDDestinationMap
 Map between an IP address and the corresponding UUID. This is a secondary index to quickly find an entry given an IP address. More...
 
typedef std::map< EPS::UUID, CommStats1MUuidStats
 forward declaration More...
 
typedef std::map< EPS::UUID, EPS::UUIDSetMUuidMesh
 

Enumerations

enum  EMode {
  kInvalid = 0,
  kClient = 1,
  kServer = 2
}
 Enum to let some of the common code know if it is working in client or server mode. More...
 
enum  ECommType {
  kUnknown = 0,
  kMinValid = 1,
  kHello1 = kMinValid,
  kAddress1 = 2,
  kData1 = 3,
  kList1 = 4,
  kStats1 = 5,
  kHello2 = 6,
  kList2 = 7,
  kMax
}
 Communication structure types. More...
 

Functions

bool validate_network_against_existing_routes (const uint32_t &eps_network_in_host_order, const uint32_t &eps_netmask_in_host_order)
 Verify that the network doesn't conflict with any existing network setting. More...
 
void raise_tun_tap_interface (const uint32_t ip_address_in_network_order, std::string &device_name, FILE_HANDLE_DESCRIPTOR &device_fd)
 Raise the expected TUN/TAP interface. More...
 
void set_tun_tap_routes (const uint32_t &network_in_network_order, const uint32_t &netmask_in_network_order, const std::string &device_name)
 Setup a route for the TUN/TAP interface. More...
 
void close_tun_tap_interface (std::string &device_name, FILE_HANDLE_DESCRIPTOR &device_fd)
 Cleanly shut down the TUN/TAP interface. More...
 
std::string ipset_to_string (const IPv4Set &s)
 Convert a set of IPv4 addresses to a debug string. More...
 
std::string mode_to_string (const EPS::EMode mode)
 Convert the mode to a text string. More...
 
std::string cpp_demangle (const std::string &str)
 Demangle the given C++ name. This is compiler-specific. More...
 
void parse_network_and_mask (const std::string &str, IPv4 &network, IPv4 &netmask)
 Parse the network+mask string. More...
 
int get_random (const int min_val=0, const int max_val=99)
 Get a random int value between the specified range (inclusive). More...
 
std::string read_file (const std::string &filename)
 Read the entire file and return it as a text string. More...
 
void write_file (const std::string &filename, const std::string &text)
 Overwrite the filename with this content. More...
 
std::string hex_out (const uint8_t *data, const size_t len, const int number_of_rows_to_display=4)
 Produce hex output for the given data. More...
 
std::string get_utc_timestamp (time_t tt=0)
 Format the given time (or now) into a UTC timestamp. More...
 
std::string get_local_timestamp (time_t tt=0)
 Format the given time (or now) into a local timestamp. More...
 
std::string to_hex_string (const uint8_t *data, const size_t len)
 Format the given bytes to a hex string. More...
 
void from_hex_string (uint8_t *data, const size_t len, std::string str)
 Parse the given hex string and populate data. More...
 
std::string get_eps_conf_template (void)
 Get the content of the template/default eps.conf file. More...
 
std::string get_os_name (void)
 Get a "pretty" text string that describes the OS name. More...
 
std::string get_approximate_time (const time_t timestamp)
 Pretty-print a timestamp (in reference to now). More...
 
time_t get_boot_timestamp (void)
 Return a timestamp representing when the system was last rebooted. More...
 
void initialize_logging (const EPS::EMode mode)
 Initialize boost::log for EPS client/server. More...
 
void initialize_file_logging (const std::string &filename)
 Add the specified filename to the logging output. More...
 
void reset_logging (void)
 Reset boost::log and disable logging. More...
 
void log_backtrace (void)
 Log a line for every function name in the call stack. More...
 
size_t number_of_pkcs_padding_bytes (const size_t &len)
 PKCS padding adds between 1 and 16 bytes to our own length. More...
 
size_t length_including_pkcs_padding (const size_t &len)
 
std::string proto_to_string (const uint16_t proto_in_host_order)
 Convert the protocol field in the TAP packets to a readable string. More...
 
std::string proto_to_string (const EPS::CommData1 *cd1)
 Convert the protocol field in the TAP packets to a readable string. More...
 
std::string format (const long double &value, std::string &postfix)
 Format the value similar to KBytes or KBytes/sec. More...
 
std::string format_bytes (const uint64_t &value)
 Format the value similar to KBytes or KBytes/sec. More...
 
std::string format_bps (const uint64_t &value, int seconds)
 Format the value similar to KBytes or KBytes/sec. More...
 
std::string & trim (std::string &str)
 Trim whitespace from string. More...
 
std::string trim (const std::string &str)
 Trim whitespace from string. More...
 
std::string comm_type_to_string (const uint8_t type)
 Convert EPS::ECommType to a user-readable text string. More...
 
std::string comm_type_to_string (const EPS::ECommType type)
 Convert EPS::ECommType to a user-readable text string. More...
 

Variables

static const size_t cipher_block_size = 16
 the size of blocks required for encryption/decryption More...
 
static const size_t bps_string_size = 32
 the size of the character-based BPS text fields More...
 
static const size_t network_buffer_size = 2048
 the size of arrays to allocate for incoming, outgoing, encryption and decryption network buffers More...
 

Typedef Documentation

◆ ASIO_STREAM

typedef boost::asio::posix::stream_descriptor EPS::ASIO_STREAM

TUN/TAP stream descriptor.

◆ DestinationMap

typedef std::map<IPv4, UUID> EPS::DestinationMap

Map between an IP address and the corresponding UUID. This is a secondary index to quickly find an entry given an IP address.

◆ EC

typedef boost::system::error_code EPS::EC

Convenient alias for boost error codes.

◆ FILE_HANDLE_DESCRIPTOR

native file descriptor

◆ IPv4

typedef boost::asio::ip::address_v4 EPS::IPv4

Convenient alias for boost IPv4 address.

◆ IPv4Set

typedef std::set<EPS::IPv4> EPS::IPv4Set

Set of IPv4 addresses.

◆ IPv4Vec

typedef std::vector<EPS::IPv4> EPS::IPv4Vec

Vector of IPv4 addresses.

◆ MAC

typedef uint8_t EPS::MAC[6]

◆ MUuidMesh

◆ MUuidStats

typedef std::map<EPS::UUID, CommStats1> EPS::MUuidStats

forward declaration

◆ NBDeque

typedef std::deque<EPS::NetBuffer*> EPS::NBDeque

Asio async_write() calls cannot overlap, so store pending buffers to send in a deque.

◆ StrMap

typedef std::map<std::string, std::string> EPS::StrMap

Map of string-to-string.

◆ TConnPtr

typedef std::shared_ptr<EPS::TCPConnection> EPS::TConnPtr

TCP connections are dynamically allocated when a socket is needed, so this type allows us to easily manage the lifespan of all connections.

See also
EPS::UConnPtr

◆ TCPConns

typedef std::set<TConnPtr> EPS::TCPConns

When multiple TCP connections need to be grouped.

◆ TCPEP

typedef boost::asio::ip::tcp::endpoint EPS::TCPEP

Convenient alias for boost TCP endpoint.

◆ TrackerMap

Map between client UUIDs and a tracker record. This is the central "database" that makes up the Tracker functionality.

◆ UUID

typedef boost::uuids::uuid EPS::UUID

Convenient alias for boost UUIDs.

◆ UUID16

typedef uint8_t EPS::UUID16[16]

UUID POD (uuid data)

◆ UUIDSet

typedef std::set<UUID> EPS::UUIDSet

Set of UUIDs.

Enumeration Type Documentation

◆ ECommType

Communication structure types.

Enumerator
kUnknown 
kMinValid 
kHello1 

see EPS::CommHello1 (no longer supported, replaced by EPS:CommHello2)

kAddress1 

see EPS::CommAddress1

kData1 

see EPS::CommData1

kList1 

see EPS::CommList1 (no longer supported, replaced by EPS::CommList2)

kStats1 

see EPS::CommStats1

kHello2 

see EPS::CommHello2 (introduced in protocol version 4)

kList2 

see EPS::CommList2 (introduced in protocol version 4)

kMax 

remember to update EPS::comm_type_to_string() if you add a new comm type

◆ EMode

enum EPS::EMode

Enum to let some of the common code know if it is working in client or server mode.

Enumerator
kInvalid 
kClient 

EPS client mode

kServer 

EPS server mode

Function Documentation

◆ close_tun_tap_interface()

void EPS::close_tun_tap_interface ( std::string &  device_name,
FILE_HANDLE_DESCRIPTOR device_fd 
)

Cleanly shut down the TUN/TAP interface.

Here is the caller graph for this function:

◆ comm_type_to_string() [1/2]

std::string EPS::comm_type_to_string ( const uint8_t  type)

Convert EPS::ECommType to a user-readable text string.

◆ comm_type_to_string() [2/2]

std::string EPS::comm_type_to_string ( const EPS::ECommType  type)

Convert EPS::ECommType to a user-readable text string.

◆ cpp_demangle()

std::string EPS::cpp_demangle ( const std::string &  str)

Demangle the given C++ name. This is compiler-specific.

Here is the caller graph for this function:

◆ format()

std::string EPS::format ( const long double &  value,
std::string &  postfix 
)

Format the value similar to KBytes or KBytes/sec.

Here is the caller graph for this function:

◆ format_bps()

std::string EPS::format_bps ( const uint64_t &  value,
int  seconds 
)

Format the value similar to KBytes or KBytes/sec.

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

◆ format_bytes()

std::string EPS::format_bytes ( const uint64_t &  value)

Format the value similar to KBytes or KBytes/sec.

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

◆ from_hex_string()

void EPS::from_hex_string ( uint8_t *  data,
const size_t  len,
std::string  str 
)

Parse the given hex string and populate data.

See also
EPS::to_hex_string()
Here is the caller graph for this function:

◆ get_approximate_time()

std::string EPS::get_approximate_time ( const time_t  timestamp)

Pretty-print a timestamp (in reference to now).

Figure out how long ago was "timestamp". Return an approximate text string, not a precise value. As the timestamp gets older, the precision is eroded. For example, valid strings returned could be "3 minutes ago" or "3 months ago".

Here is the caller graph for this function:

◆ get_boot_timestamp()

time_t EPS::get_boot_timestamp ( void  )

Return a timestamp representing when the system was last rebooted.

Here is the caller graph for this function:

◆ get_eps_conf_template()

std::string EPS::get_eps_conf_template ( void  )

Get the content of the template/default eps.conf file.

The contents of the template eps.conf file are generated from eps.ini using xxd.

See also
eps_conf.ini
CMakeLists.txt
Here is the caller graph for this function:

◆ get_local_timestamp()

std::string EPS::get_local_timestamp ( time_t  tt = 0)

Format the given time (or now) into a local timestamp.

Here is the caller graph for this function:

◆ get_os_name()

std::string EPS::get_os_name ( void  )

Get a "pretty" text string that describes the OS name.

From the /etc/os-release text file, try and extract PRETTY_NAME. For example:

   VERSION_ID="7"
   PRETTY_NAME="CentOS Linux 7 (Core)"
   ANSI_COLOR="0;31"

or:

    ID_LIKE=debian
    PRETTY_NAME="Ubuntu 14.04.1 LTS"
    VERSION_ID="14.04"

or:

    VERSION_ID=20
    PRETTY_NAME="Fedora 20 (Heisenbug)"
    ANSI_COLOR="0;34"

If os-release doesn't yield a usable name, see if /etc/issue has something we can use.

Otherwise, the name used will be the output from running uname -sr, such as "Linux 3.13.0-37-generic".

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

◆ get_random()

int EPS::get_random ( const int  min_val = 0,
const int  max_val = 99 
)

Get a random int value between the specified range (inclusive).

Here is the caller graph for this function:

◆ get_utc_timestamp()

std::string EPS::get_utc_timestamp ( time_t  tt = 0)

Format the given time (or now) into a UTC timestamp.

Here is the caller graph for this function:

◆ hex_out()

std::string EPS::hex_out ( const uint8_t *  data,
const size_t  len,
const int  number_of_rows_to_display = 4 
)

Produce hex output for the given data.

If number_of_rows_to_display is set to 1 or less, then all rows will be shown without skipping. Otherwise, the middle section of large buffers will be skipped to reduce the number of lines logged, keeping both the start and end of the buffer intact.

Here is the caller graph for this function:

◆ initialize_file_logging()

void EPS::initialize_file_logging ( const std::string &  filename)

Add the specified filename to the logging output.

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

◆ initialize_logging()

void EPS::initialize_logging ( const EPS::EMode  mode)

Initialize boost::log for EPS client/server.

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

◆ ipset_to_string()

std::string EPS::ipset_to_string ( const IPv4Set s)

Convert a set of IPv4 addresses to a debug string.

Here is the caller graph for this function:

◆ length_including_pkcs_padding()

size_t EPS::length_including_pkcs_padding ( const size_t &  len)

This method returns the full length, meaning our own size plus the number of padding bytes required.

See also
PKCS #5 or PKCS #7
Here is the call graph for this function:
Here is the caller graph for this function:

◆ log_backtrace()

void EPS::log_backtrace ( void  )

Log a line for every function name in the call stack.

Todo:
why does this not compile in clang/pc-bsd?
Here is the call graph for this function:

◆ mode_to_string()

std::string EPS::mode_to_string ( const EPS::EMode  mode)

Convert the mode to a text string.

Here is the caller graph for this function:

◆ number_of_pkcs_padding_bytes()

size_t EPS::number_of_pkcs_padding_bytes ( const size_t &  len)

PKCS padding adds between 1 and 16 bytes to our own length.

AES requires exactly 16-bytes blocks. If a block is an exact multiple of 16 bytes, then another 16 bytes is added. Otherwise, between 1 and 15 bytes of padding are added to get an exact multiple of 16. This method returns the number of padding bytes needed to obtain a multiple of the AES block size.

See also
PKCS #5 or PKCS #7
Here is the caller graph for this function:

◆ parse_network_and_mask()

void EPS::parse_network_and_mask ( const std::string &  str,
IPv4 network,
IPv4 netmask 
)

Parse the network+mask string.

Todo:
only 24-bit "class C" networks are currently supported
Here is the caller graph for this function:

◆ proto_to_string() [1/2]

std::string EPS::proto_to_string ( const uint16_t  proto_in_host_order)

Convert the protocol field in the TAP packets to a readable string.

Here is the caller graph for this function:

◆ proto_to_string() [2/2]

std::string EPS::proto_to_string ( const EPS::CommData1 cd1)

Convert the protocol field in the TAP packets to a readable string.

Here is the call graph for this function:

◆ raise_tun_tap_interface()

void EPS::raise_tun_tap_interface ( const uint32_t  ip_address_in_network_order,
std::string &  device_name,
FILE_HANDLE_DESCRIPTOR device_fd 
)

Raise the expected TUN/TAP interface.

Here is the caller graph for this function:

◆ read_file()

std::string EPS::read_file ( const std::string &  filename)

Read the entire file and return it as a text string.

Here is the caller graph for this function:

◆ reset_logging()

void EPS::reset_logging ( void  )

Reset boost::log and disable logging.

◆ set_tun_tap_routes()

void EPS::set_tun_tap_routes ( const uint32_t &  network_in_network_order,
const uint32_t &  netmask_in_network_order,
const std::string &  device_name 
)

Setup a route for the TUN/TAP interface.

Todo:
routes not needed at this point in time
Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_hex_string()

std::string EPS::to_hex_string ( const uint8_t *  data,
const size_t  len 
)

Format the given bytes to a hex string.

See also
EPS::from_hex_string()
Here is the caller graph for this function:

◆ trim() [1/2]

std::string & EPS::trim ( std::string &  str)

Trim whitespace from string.

Here is the caller graph for this function:

◆ trim() [2/2]

std::string EPS::trim ( const std::string &  str)

Trim whitespace from string.

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

◆ validate_network_against_existing_routes()

bool EPS::validate_network_against_existing_routes ( const uint32_t &  eps_network_in_host_order,
const uint32_t &  eps_netmask_in_host_order 
)

Verify that the network doesn't conflict with any existing network setting.

Todo:
Need to find a way to get the existing routes in FreeBSD so we can validate the new EPS address.
Returns
TRUE if there doesn't seem to be a conflict
Here is the caller graph for this function:

◆ write_file()

void EPS::write_file ( const std::string &  filename,
const std::string &  text 
)

Overwrite the filename with this content.

Here is the caller graph for this function:

Variable Documentation

◆ bps_string_size

const size_t EPS::bps_string_size = 32
static

the size of the character-based BPS text fields

◆ cipher_block_size

const size_t EPS::cipher_block_size = 16
static

the size of blocks required for encryption/decryption

◆ network_buffer_size

const size_t EPS::network_buffer_size = 2048
static

the size of arrays to allocate for incoming, outgoing, encryption and decryption network buffers