The shared namespace.
More...
|
using | port_t = uint16_t |
|
using | address_t = uint32_t |
|
using | fd_t = int32_t |
|
using | con_t = uint64_t |
|
using | tag = uint8_t |
|
typedef struct shared::sys_packet | sys_packet |
| A system packet.
|
|
|
enum | status { DEAD
, INIT
, READY
, TERMINATE
} |
| Status used to communicate between Main and Network Threads.
|
|
enum | message_type {
STANDARD
, INFO
, WARN
, ERROR
,
SUCCESS
} |
|
|
std::string | connection_string (const connection &c) |
| Get a string representation of the connection.
|
|
crypto::string | Timestamp () |
| Get the current TAI64N timestamp.
|
|
bool | TimestampGreater (const crypto::string &a, const crypto::string &b) |
| Compares two timestamps.
|
|
size_t | TimestampDiff (const crypto::string &a, const crypto::string &b=Timestamp()) |
| Return the time between each timestamp in seconds.
|
|
uint64_t | TimeSeconds () |
| Get the current UNIX timestamp.
|
|
std::mt19937 | rng (dev()) |
|
void | sleep (const size_t &milliseconds=100) |
| Sleep.
|
|
void | output (const std::string &message, const std::string &thread="SYS", const message_type &t=STANDARD) |
| Output to STDOUT, thread safe.
|
|
void | clear () |
| Clear the screen.
|
|
template<typename T = bool> |
T | input (const std::string &title, const T &error_ret=T()) |
| std::cin can be a little difficult to use, particularly handling bad input. This sanitized it.
|
|
void | prompt (const std::string &message) |
| Prompt the user and wait until they have confirmed it.
|
|
void | pick_mode () |
|
void | pick_title () |
|
std::string | print_title (const uint64_t &cycle) |
|
|
tag | NONE = 0x0 |
|
tag | WG_HANDSHAKE = 0x1 |
|
tag | SYS = 0x2 |
|
tag | WG_COOKIE = 0x3 |
|
tag | WG_TRANSPORT = 0x4 |
|
connection | self = {.pair {.a = inet_addr("127.0.0.1"), .p = 5000}} |
|
std::atomic< status > | stat = DEAD |
|
std::atomic< bool > | verbose = false |
|
std::atomic< bool > | log = false |
|
std::string | logfile = "main.log" |
|
std::random_device | dev |
|
std::mutex | io_lock |
|
constexpr char | END [] = "\e[0m" |
|
constexpr char | RED [] = "\e[31m" |
|
constexpr char | YELLOW [] = "\e[1;33m" |
|
constexpr char | GREEN [] = "\e[32m" |
|
constexpr char | BLUE [] = "\e[34m" |
|
constexpr char | VIOLET [] = "\e[35m" |
|
std::vector< std::vector< std::string > > | titles |
|
size_t | title = 0 |
|
size_t | mode = 0 |
|
The shared namespace.
- Parameters
-
This | namespace contains a smattering of objects and functions that are used by the other files. |
◆ sys_packet
typedef struct shared::sys_packet shared::sys_packet |
◆ clear()
◆ connection_string()
std::string shared::connection_string |
( |
const connection & | c | ) |
|
Get a string representation of the connection.
- Returns
- the string.
◆ input()
template<typename T = bool>
T shared::input |
( |
const std::string & | title, |
|
|
const T & | error_ret = T() ) |
|
inline |
std::cin can be a little difficult to use, particularly handling bad input. This sanitized it.
- Template Parameters
-
T | The type of input to be returned. |
- Parameters
-
title | A title to be drawn for the input |
error_ret | If something causes an error, what we should return to let the caller know. |
- Returns
- The user input, or the error return.
- Warning
- This function is blocking.
◆ output()
void shared::output |
( |
const std::string & | message, |
|
|
const std::string & | thread = "SYS", |
|
|
const message_type & | t = STANDARD ) |
Output to STDOUT, thread safe.
- Parameters
-
message | The message to print. |
thread | For non-standard output types, the thread where the message is being sent from. |
t | The type of message. Standard gets output without formatting. Others print the thread and color code the output. |
◆ prompt()
void shared::prompt |
( |
const std::string & | message | ) |
|
|
inline |
Prompt the user and wait until they have confirmed it.
- Parameters
-
message | The message to display. |
- Warning
- This function is blocking.
◆ sleep()
void shared::sleep |
( |
const size_t & | milliseconds = 100 | ) |
|
Sleep.
- Parameters
-
milliseconds | The amount of milliseconds to sleep for. |
◆ TimeSeconds()
uint64_t shared::TimeSeconds |
( |
| ) |
|
Get the current UNIX timestamp.
- Returns
- The seconds since January 1st, 1970.
◆ Timestamp()
Get the current TAI64N timestamp.
- Returns
- The formatted timestamp.
◆ TimestampDiff()
Return the time between each timestamp in seconds.
- Parameters
-
a | The first timestamp. |
b | The second timestamp, defaulting to the current time. |
- Returns
- The time between the two in seconds.
◆ TimestampGreater()
Compares two timestamps.
- Parameters
-
- Returns
- If the timepoint at a is greater or equal to b.