summaryrefslogtreecommitdiff
path: root/src/network.h
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2020-02-16 20:18:32 +0100
committerRoman Smrž <roman.smrz@seznam.cz>2020-02-16 20:18:32 +0100
commit0e9e9c4d233a331e10dfb2db889fe437d0911ba2 (patch)
tree450b78801436d007efd5eaaf2b52f3e7dfe95a96 /src/network.h
parent69e4c826a34eb84c36bb07338a9a292a520f5970 (diff)
Peer list in public API
Diffstat (limited to 'src/network.h')
-rw-r--r--src/network.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/network.h b/src/network.h
index e07e020..07b5363 100644
--- a/src/network.h
+++ b/src/network.h
@@ -23,6 +23,8 @@ using std::variant;
using std::vector;
using std::weak_ptr;
+using std::enable_shared_from_this;
+
namespace chrono = std::chrono;
using chrono::steady_clock;
@@ -49,11 +51,31 @@ struct Server::Peer
Storage tempStorage;
PartialStorage partStorage;
+ shared_ptr<erebos::Peer::Priv> lpeer = nullptr;
+
void send(const struct TransportHeader &, const vector<Object> &) const;
void updateIdentity(struct ReplyBuilder &);
void updateChannel(struct ReplyBuilder &);
};
+struct Peer::Priv : enable_shared_from_this<Peer::Priv>
+{
+ weak_ptr<Server::Peer> speer;
+ weak_ptr<PeerList::Priv> list;
+ size_t listIndex;
+
+ void notifyWatchers();
+};
+
+struct PeerList::Priv : enable_shared_from_this<PeerList::Priv>
+{
+ mutex dataMutex;
+ vector<shared_ptr<Peer::Priv>> peers;
+ vector<function<void(size_t, const Peer *)>> watchers;
+
+ void push(const shared_ptr<Server::Peer> &);
+};
+
struct TransportHeader
{
enum class Type {
@@ -118,7 +140,9 @@ struct Server::Priv
thread threadListen;
thread threadAnnounce;
- vector<unique_ptr<Peer>> peers;
+ vector<shared_ptr<Peer>> peers;
+ PeerList plist;
+
vector<struct TransportHeader> outgoing;
vector<weak_ptr<WaitingRef>> waiting;