Skip to content

Commit

Permalink
Merge pull request #25 from Bobscorn/feat/send-strings
Browse files Browse the repository at this point in the history
Feat/send strings
  • Loading branch information
DoubleCouponDay committed Feb 6, 2022
2 parents 36e4f31 + 30153ab commit 221768f
Show file tree
Hide file tree
Showing 22 changed files with 1,110 additions and 560 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "(Linux) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/ptop_rendezvous",
"program": "${workspaceFolder}/build/ptop",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
Expand Down
2 changes: 1 addition & 1 deletion doc/happy path.drawio
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<mxfile host="Electron" modified="2022-01-15T09:35:20.230Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/16.1.2 Chrome/96.0.4664.55 Electron/16.0.5 Safari/537.36" etag="xlhTFhz2_wHvZWcBhbvX" version="16.1.2" type="device"><diagram id="J3UECziaqcWZgJUt_NWS" name="Page-1">1ZdNc5swEIZ/Dcd2+IiJc0wcNzm0J3fS5pRRYANKBcsIYaC/vgIWYxV/tdPU5IT0akHadx/tDJa3SKo7ybL4C4YgLNcOK8u7tVzXcWxXPxql7pS5P+uESPKQggZhxX8CiTapBQ8hNwIVolA8M8UA0xQCZWhMSizNsBcU5q4Zi2AkrAImxuo3HqqYsnAvB/0eeBT3Ozv+VbeSsD6YMsljFmK5JXlLy1tIRNWNkmoBojGv96V779Oe1c3BJKTqlBfkGuJHl72G4dd7Uav84YGrD45Hh1N1nzGE2gCaolQxRpgysRzUG4lFGkLzWVvPhpjPiJkWHS2+glI1VZMVCrUUq0TQqj6xrL8373+c9dNH+lw7ua2MWU2zccrkQo6FDOBQnoQOkxGoQ3FUrMaErR3I0TvABPSBdIAEwRRfm5Qwgi3axA310AMqyZ+Up/vumomCdgoE18knjKejwpllKWOuYJWx1pZSX06zBHutXINUUB3MnVYverPoajsezcvhojg9/fHWJfHtN7LrcmTXOej+e0rdEyn1JwWpO3K9bbLXLQmp7nn5U47BD52R6wud1s2z1KOoGaWgG+J1H5Xp076gTEZFO8KyWbF/QbZtku05O8i++J9kO/47R9s/Ee35pNAeu74T7X1g77gB5yb7t569If1sPXu+32LIeHCkdTR+KMwma+/Vue11Zu+8cfSOHu0c7qQ6R3/sXVwfRboLeGqAzUBOjurNL80bUK2nwy9Ru7b1Y+ktfwE=</diagram></mxfile>
<mxfile host="Electron" modified="2022-01-24T23:46:43.313Z" agent="5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/16.1.2 Chrome/96.0.4664.55 Electron/16.0.5 Safari/537.36" etag="BuQF6eK3Cef1sS4_Jwsq" version="16.1.2" type="device"><diagram id="rkX0dKiBWzb8pAJWs5m8" name="Page-1">5Zpbd5s4EIB/jU+fdg93u49ex213t028cU7b7EuOAhOjLUYcIXzJr18JhLloN6a1HcTpQ2I0DCAN34xmJEb2bL17T1ESfiIBRCPLCHYj+2pkWaZpWPxHSPaFZOK5hWBFcSCVKsESP4MUGlKa4QDShiIjJGI4aQp9Esfgs4YMUUq2TbUnEjWfmqAVKIKljyJV+gUHLJSjcI1K/gHwKmSHAcsza1QqS0EaooBsayJ7PrJnlBBWHK13M4iE8Uq7FNe9+5+zh45RiFmXC57/9ndGSn0wP/+VhH/8/ufSe/rFKe6yQVEmByw7y/alBSDgBpFNQllIViRG0byS/kZJFgcgHmPwVqXzkZCEC00u/AcY28u3izJGuChk60ieVYciR5eSjHf4hf6XSCC6AvaCnl3oibHUHiAN9R7IGhjdcwUKEWJ403z5SDK0OuhVZuYH0tLfYXVTsfqSj4Appm8adhtiBssE5QbZcnfraMQNUAa7F4ddnnUkq9JZrRLzbYW+WfIc1rD3jAtZ6u3A+bQ78jnRik9bsfpMhlcRffm/W+AGfd6QLOWNJVCOWO/w2trBa6p+Pix6Jx3pLSdrTfCdqOGV8yqwnU+v7h/e3dw+LKwFb0+v+Unj0/3D1fRuKuZsSFM+oafKWzpCb/MVnYFlt82y3ZHlQ/pxfpjVoDAsmEtIj9NsaUVz2e+a4b8gzPJklooH8r/ZzfX1fHb3sJjPbyuOhQolazHmUDTS/w7Urw33WEO43aHDbXWF29EL7vFPY3hPL8PrkVnDDrOv4vJfXdm6r5252sk75439sRB0xpd19nw8v3RKKdrXFBKCY5bW7rwQgipSToxmpHTaJX5L3xufpu96RgusoscVZoehn0CepZA3ZQzWyaG6+EAiMV0tstgPtZut7Ld9lxXW4DMxp6MblgPTJWaqq2X5uo0ogj/ilEGM49UhL7vhSZf4XQDQN0JF1tCYxL1D7UxaUDsdoZ5cDGpv6FB7XaF29YJaNXwrHLfWfg48L7LHCPv8YB4HSTGxaIa107WyuBzWeqRZJ2DddQ3I0msJ01QXgbpiTfEGMdCZa9fqm2t76DmI1XU1yD57DvJDpYDptULb+BVSdUtdemo50TTjWU7MsF94zJL436B/fzHb80DX9OZyObvTh3twC9J9rbwWzXt5u7xRFdh56/QKuwwDx6eLs28Z/JBbWe3q7lXcSq2AGyu6onCA0sMexRGq+ZaBNghH6FHUyD37mW23rNf7lpvt9epnZsPLKqc7v5+5vfnZaXFQXWhvoI8PM0ua+T7wl6Ib4/3PJWWH9JhLzMsx3rn00IxxtfQYGONu17r5cowPfUOuLBuO1xd6bciV/a7DC282IgmRn1gKXgt8i13lBDTYUzZbOyVe/wSrUWBgBHddpbfHehGsrtLfURSn6zzuikz6CUegIcPtKKwBw+ru/C34gPNwIK3oh1n8TaybyU9NtDBle8Hskqbkzeoj7qJErD6Ft+f/Ag==</diagram></mxfile>
533 changes: 279 additions & 254 deletions src/client.cpp

Large diffs are not rendered by default.

39 changes: 20 additions & 19 deletions src/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,35 @@
#include "interfaces.h"
#include "platform.h"


void client_loop(std::string server_address_pair, protocol input_protocol);
void client_loop(std::string server_address_pair, Protocol input_protocol);

class client_init_kit {
public:
client_init_kit(std::string server_address_pair, ::protocol input_protocol);
std::chrono::system_clock::time_point last_send;
int auth_key;
client_init_kit(std::string server_address_pair, ::Protocol input_protocol);
std::chrono::system_clock::time_point server_last_send;
EXECUTION_STATUS status;
::protocol protocol;
bool is_leader;
::Protocol protocol;
bool do_delay = false;

std::unique_ptr<IDataSocketWrapper>& get_conn_socket();
void set_conn_socket(std::unique_ptr<IDataSocketWrapper>&& input);
std::unique_ptr<IDataSocketWrapper>& get_server_socket();
void set_server_socket(std::unique_ptr<IDataSocketWrapper>&& input);

protected:
std::unique_ptr<IDataSocketWrapper> _conn_socket;
std::unique_ptr<IDataSocketWrapper> _server_socket;
};

class client_auth_kit {
class client_peer_kit {
public:
client_auth_kit(client_init_kit& init_kit, const char* data, int i, MESSAGE_LENGTH_T data_len);
std::vector<std::unique_ptr<IDataSocketWrapper>> unauthed_sockets;
std::unique_ptr<ReusableListener> listen_sock;
int auth_key_out;
std::unique_ptr<ReusableConnector> public_connector;
std::unique_ptr<ReusableConnector> private_connector;
readable_ip_info peer_public;
readable_ip_info peer_private;
client_peer_kit();
void set_peer_data(client_init_kit& init_kit, const char* data, int message_data_index, MESSAGE_LENGTH_T data_len);

std::unique_ptr<NonBlockingConnector> public_connector;
std::unique_ptr<NonBlockingConnector> private_connector;
std::unique_ptr<NonBlockingListener> listen_sock;
readable_ip_info public_info;
readable_ip_info private_info;
raw_name_data old_privatename;

std::chrono::system_clock::time_point peer_connect_start_time;
std::unique_ptr<IDataSocketWrapper> peer_socket;
};
2 changes: 1 addition & 1 deletion src/clientmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ int main(int argc, char** argv) {
std::string possible_protocol{};

std::cin >> possible_protocol;
protocol validated{ possible_protocol };
Protocol validated{ possible_protocol };

client_loop(raw_ip, validated);
}
Expand Down
2 changes: 1 addition & 1 deletion src/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#define LINE_CONTEXT (std::string("(") + __func__ + ", " + std::to_string(__LINE__) + ")")
#endif

void throw_new_exception(std::string input, std::string line_context);
[[noreturn]] void throw_new_exception(std::string input, std::string line_context);
void throw_with_context(const std::exception& e, std::string context);

void print_exception(const std::exception& e, int level = 0);
15 changes: 14 additions & 1 deletion src/interfaces.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
#include "name_data.h"
#include "message.h"

// BEGIN UDP CRAP

struct udp_Message
{
Message message;
raw_name_data from;
};

// END UDP CRAP

class ISocketWrapper
{
public:
Expand All @@ -20,7 +30,10 @@ class ISocketWrapper
virtual std::string get_my_port() const = 0;
virtual std::string get_endpoint_ip() const = 0;
virtual std::string get_endpoint_port() const = 0;
virtual std::string get_identifier_str() const = 0;
virtual std::string get_identifier_str() = 0;

virtual const std::string& get_name() const = 0;
virtual void set_name(std::string name) = 0;
};

class IDataSocketWrapper : virtual public ISocketWrapper
Expand Down
1 change: 1 addition & 0 deletions src/ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct readable_ip_info
std::string port;

std::vector<char> to_bytes() const;
inline std::string to_string() const { return "(" + ip_address + ":" + port + ")"; }
};

inline std::ostream& operator<<(std::ostream& os, const readable_ip_info& ip_info)
Expand Down
Loading

0 comments on commit 221768f

Please sign in to comment.