summaryrefslogtreecommitdiff
path: root/src/network.h
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-01-27 21:25:39 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2020-02-05 21:02:08 +0100
commitab86a1f0c3b86050e65fc5b7ac1e88a00f0d228c (patch)
tree24f1b79bc9a90846bca31203b306eb4c60a055c1 /src/network.h
parentec402bfaa90cdb52276f5ccc2525e799cb4419d7 (diff)
Encrypted channels
Diffstat (limited to 'src/network.h')
-rw-r--r--src/network.h25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/network.h b/src/network.h
index bb32323..e07e020 100644
--- a/src/network.h
+++ b/src/network.h
@@ -2,6 +2,8 @@
#include <erebos/network.h>
+#include "channel.h"
+
#include <condition_variable>
#include <mutex>
#include <thread>
@@ -26,23 +28,30 @@ using chrono::steady_clock;
namespace erebos {
-struct Peer
+struct Server::Peer
{
Peer(const Peer &) = delete;
Peer & operator=(const Peer &) = delete;
- const int sock;
+ Priv & server;
const sockaddr_in addr;
variant<monostate,
shared_ptr<struct WaitingRef>,
Identity> identity;
+ variant<monostate,
+ Stored<ChannelRequest>,
+ shared_ptr<struct WaitingRef>,
+ Stored<ChannelAccept>,
+ Stored<Channel>> channel;
+
Storage tempStorage;
PartialStorage partStorage;
void send(const struct TransportHeader &, const vector<Object> &) const;
- void updateIdentity();
+ void updateIdentity(struct ReplyBuilder &);
+ void updateChannel(struct ReplyBuilder &);
};
struct TransportHeader
@@ -76,12 +85,18 @@ struct WaitingRef
{
const Storage storage;
const PartialRef ref;
- const Peer & peer;
+ const Server::Peer & peer;
vector<Digest> missing;
optional<Ref> check(vector<TransportHeader::Item> * request = nullptr);
};
+struct ReplyBuilder
+{
+ vector<TransportHeader::Item> header;
+ vector<Object> body;
+};
+
struct Server::Priv
{
Priv(const Identity & self);
@@ -90,7 +105,7 @@ struct Server::Priv
void doAnnounce();
Peer & getPeer(const sockaddr_in & paddr);
- void handlePacket(Peer &, const TransportHeader &);
+ void handlePacket(Peer &, const TransportHeader &, ReplyBuilder &);
constexpr static uint16_t discoveryPort { 29665 };
constexpr static chrono::seconds announceInterval { 60 };