ZIO
Python and C++ interface to ZeroMQ and Zyre
peer.hpp
Go to the documentation of this file.
1 #ifndef ZIO_PEER_HPP_SEEN
2 #define ZIO_PEER_HPP_SEEN
3 
4 #include <zyre.h>
5 #include <map>
6 #include <string>
7 #include <vector>
8 
9 namespace zio {
10 
12  typedef std::string nickname_t;
14  typedef std::string uuid_t;
15 
17  typedef std::string header_key_t;
18  typedef std::string header_value_t;
19 
20  // header key must be unique in a header set
21  typedef std::pair<header_key_t, header_value_t> header_t;
22  typedef std::map<header_key_t, header_value_t> headerset_t;
23 
24  struct peer_info_t {
25  nickname_t nick{""};
26  headerset_t headers;
27 
28  // return a new mapping with entries of matching prefix.
29  // Eg, {"a":"blech", "a.b":"foo", "a.b.c":"bar"}.
30  // Branched on "a.b." returns: {c:"bar"}.
31  // Branched on "a.b" returns: {"":"foo", ".c":"bar"}
32  headerset_t branch(const std::string& prefix);
33 
34  };
35 
36  typedef std::map<uuid_t, peer_info_t> peerset_t;
37 
44  class Peer {
45  public:
47  typedef int timeout_t;
48 
49  ~Peer();
50 
52  Peer(const nickname_t& nickname,
53  const headerset_t& headers={}, bool verbose=false);
54 
55 
57  void set_verbose(bool verbose=true);
58 
60  const nickname_t nickname() { return m_nick; }
61 
66  bool poll(timeout_t timeout = 0);
67 
69  void drain();
70 
75  std::vector<uuid_t> waitfor(const nickname_t& nickname,
76  timeout_t timeout = -1);
77 
82  void waituntil(const uuid_t& uuid, timeout_t timeout = -1);
83 
88  const peerset_t& peers();
89 
91  peer_info_t peer_info(const uuid_t& uuid);
92 
94  bool isknown(const uuid_t& uuid);
95 
97  std::vector<uuid_t> nickmatch(const nickname_t& nick);
98 
99  private:
100  std::string m_nick;
101  bool m_verbose;
102  zyre_t* m_zyre;
103 
104  peerset_t m_known_peers;
105  };
106 }
107 
108 #endif
std::pair< header_key_t, header_value_t > header_t
Definition: peer.hpp:21
const nickname_t nickname()
Get our nickname.
Definition: peer.hpp:60
std::string uuid_t
Uniquely identify a peer.
Definition: peer.hpp:14
std::string header_key_t
A "header" is on in a set of key/value pairs asserted by a peer.
Definition: peer.hpp:17
std::map< header_key_t, header_value_t > headerset_t
Definition: peer.hpp:22
int poll(zmq_pollitem_t *items_, size_t nitems_, long timeout_=-1)
Definition: zmq.hpp:259
nickname_t nick
Definition: peer.hpp:25
headerset_t headers
Definition: peer.hpp:26
std::map< uuid_t, peer_info_t > peerset_t
Definition: peer.hpp:36
int timeout_t
A timeout in milliseconds.
Definition: peer.hpp:47
def peers(timeout, wait_for, pre_sleep, post_sleep, name, headers)
Definition: peers.py:27
std::string nickname_t
A peer asserts a nickname.
Definition: peer.hpp:12
headerset_t branch(const std::string &prefix)
Definition: peer.cpp:4
implementation of ZIO data flow protocol endpoints
Definition: actor.hpp:14
std::string header_value_t
Definition: peer.hpp:18
Peer at the network to discover peers and advertise self.
Definition: peer.hpp:44