ZyreEndpoint.h
Go to the documentation of this file.
1 #pragma once
2 
6 #include <g3log/g3log.hpp>
7 #include <readerwriterqueue.h>
8 #include <zyre.h>
9 #include <map>
10 #include <list>
11 #include <thread>
12 #include <shared_mutex>
13 #include <sodium.h>
14 #define CONTEXT "CPSwarm"
15 
17 {
29 class SWARMIO_API ZyreEndpoint : public BasicEndpoint
30 {
31 private:
36  zyre_t *_zyre;
37 
43 
48  std::map<std::string, ZyreNode> _nodes;
49 
54  std::shared_timed_mutex _mutex;
55 
60  std::thread *_worker = nullptr;
61 
66  std::string _uuid;
67 
72  bool security_enabled = false;
78  // Keys
79  unsigned char my_publickey[crypto_box_PUBLICKEYBYTES];
80  unsigned char my_secretkey[crypto_box_SECRETKEYBYTES];
81  unsigned char bcast_publickey[crypto_box_PUBLICKEYBYTES];
82  unsigned char bcast_secretkey[crypto_box_SECRETKEYBYTES];
83  unsigned char signature[crypto_sign_SECRETKEYBYTES];
84  unsigned char server_public[crypto_sign_PUBLICKEYBYTES];
85  unsigned char certificate[crypto_box_PUBLICKEYBYTES + crypto_sign_SECRETKEYBYTES];
86 
87  bool isJoining = false;
88  std::string configFilePath = "config.cfg";
93  void Process();
94 
99  void Deliver(moodycamel::BlockingReaderWriterQueue<zyre_event_t *> *queue);
100 
101 protected:
111  virtual void Send(const void *data, size_t size, const Node *node) override;
112 
113 public:
120  ZyreEndpoint(const char *name, const char *deviceClass);
121 
129  void SetPort(uint16_t port);
130 
138  void SetInterface(const char *ifname);
139 
145  void SetConfig(std::string cfg);
146 
152  virtual void Start() override;
153 
159  virtual void Stop() override;
160 
165  virtual ~ZyreEndpoint() override;
166 
172  virtual const std::string &GetUUID() override
173  {
174  return _uuid;
175  }
176 
182  std::list<const ZyreNode *> GetNodes();
183 
190  virtual const Node *NodeForUUID(const std::string &uuid) override;
191 };
192 } // namespace swarmio::transport::zyre
virtual const std::string & GetUUID() override
Get the UUID of the local node.
Definition: ZyreEndpoint.h:172
ZyreControlSocket _control
Control pipe to shut down event processing.
Definition: ZyreEndpoint.h:42
std::map< std::string, ZyreNode > _nodes
Node registry.
Definition: ZyreEndpoint.h:48
std::shared_timed_mutex _mutex
Mutex protecting the Nodes registry.
Definition: ZyreEndpoint.h:54
zyre_t * _zyre
Reference to the Zyre structure.
Definition: ZyreEndpoint.h:36
An Endpoint implementation using the Zyre protocol.
Definition: ZyreEndpoint.h:29
An inproc socket bound to a special name generated from an object pointer.
An helper class for Endpoint implementations which implements some common basic functionality.
Definition: BasicEndpoint.h:15
Represents a Node the Endpoint knows about and can send messages to.


swarmros
Author(s):
autogenerated on Fri Apr 3 2020 03:42:48