summaryrefslogtreecommitdiff
path: root/src/network.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/network.h')
-rw-r--r--src/network.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/network.h b/src/network.h
index bf01cfb..ad29496 100644
--- a/src/network.h
+++ b/src/network.h
@@ -14,6 +14,7 @@ using std::mutex;
using std::optional;
using std::string;
using std::thread;
+using std::unique_ptr;
using std::variant;
using std::vector;
@@ -22,6 +23,14 @@ using chrono::steady_clock;
namespace erebos {
+struct Peer
+{
+ const int sock;
+ const sockaddr_in addr;
+
+ void send(const struct TransportHeader &, const vector<Object> &);
+};
+
struct TransportHeader
{
enum class Type {
@@ -43,6 +52,8 @@ struct TransportHeader
TransportHeader(const vector<Item> & items): items(items) {}
static optional<TransportHeader> load(const Ref &);
+ static optional<TransportHeader> load(const Object &);
+ Object toObject() const;
Ref store(const Storage & st) const;
const vector<Item> items;
@@ -55,6 +66,9 @@ struct Server::Priv
void doListen();
void doAnnounce();
+ Peer & getPeer(const sockaddr_in & paddr);
+ void handlePacket(Peer &, const TransportHeader &);
+
constexpr static uint16_t discoveryPort { 29665 };
constexpr static chrono::seconds announceInterval { 60 };
@@ -66,6 +80,9 @@ struct Server::Priv
thread threadListen;
thread threadAnnounce;
+ vector<unique_ptr<Peer>> peers;
+ vector<struct TransportHeader> outgoing;
+
int sock;
vector<in_addr> bcastAddresses;
};