ZyreNode.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include <string>
5 #include <sstream>
6 #include <atomic>
7 
9 {
14  class ZyreEndpoint;
15 
20  class SWARMIO_API ZyreNode final : public BasicNode
21  {
22  private:
23 
28  friend ZyreEndpoint;
29 
34  unsigned char _message_counter[24];
35 
40  unsigned char _key[32];
41 
46  unsigned char _pubkey[32];
47 
52  std::string _address;
53 
58  std::atomic<bool> _online;
59 
64  std::atomic<bool> _verified;
65 
71  void SetOnline(bool online)
72  {
73  _online = online;
74  }
75 
76  public:
77 
86  ZyreNode(const std::string& uuid, const std::string& name, const std::string& deviceClass, const std::string& address)
87  : BasicNode(uuid, name, deviceClass), _address(address), _online(false) { }
88 
94  bool IsOnline() const override
95  {
96  return _online;
97  }
98 
104  const std::string& GetAddress() const
105  {
106  return _address;
107  }
108 
114  const unsigned char* GetKey() const
115  {
116  return _key;
117  }
118 
124  const unsigned char* GetPubKey() const
125  {
126  return _pubkey;
127  }
128 
133  void SetKeys(unsigned char* k, unsigned char* pk)
134  {
135  memcpy(_key, k, 32);
136  memcpy(_pubkey, pk, 32);
137  }
138 
144  const unsigned char* GetCtr() const
145  {
146  return _message_counter;
147  }
148 
154  const bool GetVerified() const
155  {
156  return _verified;
157  }
158 
163  void SetVerified()
164  {
165  _verified = true;
166  }
167 
172  void IncrementCtr() const
173  {
174  for (int i = 23; i >= 0; i--) if (++const_cast <ZyreNode*>(this)->_message_counter[i]) break;
175  }
176 
181  void SetCtr(unsigned char* c) const
182  {
183  memcpy(const_cast <ZyreNode*>(this)->_message_counter, c, 24);
184  }
185 
191  virtual std::string GetDescription() const override
192  {
193  std::ostringstream stream;
194  stream << "online=" << (_online ? "true" : "false") << ", "
195  << "address=" << _address;
196  return stream.str();
197  }
198  };
199 }
ZyreNode(const std::string &uuid, const std::string &name, const std::string &deviceClass, const std::string &address)
Construct a new ZyreNode object.
Definition: ZyreNode.h:86
void SetVerified()
Set the verified status of the node.
Definition: ZyreNode.h:163
A Node as discovered by the Zyre protocol.
Definition: ZyreNode.h:20
bool IsOnline() const override
Is the Node currently online?
Definition: ZyreNode.h:94
void IncrementCtr() const
Increment the nonce counter the node.
Definition: ZyreNode.h:172
std::atomic< bool > _online
Is the Node currently online?
Definition: ZyreNode.h:58
void SetKeys(unsigned char *k, unsigned char *pk)
Set the shared cryptographic key and the public key of the node.
Definition: ZyreNode.h:133
const std::string & GetAddress() const
Get the IP address of the node.
Definition: ZyreNode.h:104
void SetCtr(unsigned char *c) const
Set the nonce (counter)
Definition: ZyreNode.h:181
void SetOnline(bool online)
Mark the Node as online or offline.
Definition: ZyreNode.h:71
std::string _address
IP address of the node.
Definition: ZyreNode.h:52
const bool GetVerified() const
Is the node verified?
Definition: ZyreNode.h:154
const unsigned char * GetKey() const
Get the shared cryptographic key of the node.
Definition: ZyreNode.h:114
virtual std::string GetDescription() const override
Get a user-readable description of the node.
Definition: ZyreNode.h:191
std::atomic< bool > _verified
Is the Node verified?
Definition: ZyreNode.h:64
friend ZyreEndpoint
Only ZyreEdpoint can manage these objects.
Definition: ZyreNode.h:28
const unsigned char * GetPubKey() const
Get the public key of the node.
Definition: ZyreNode.h:124
const unsigned char * GetCtr() const
Get the nonce counter of the node.
Definition: ZyreNode.h:144
A simple Node with a UUID.
Definition: BasicNode.h:11


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