5 std::string get_hostname()
7 zactor_t *beacon = zactor_new (zbeacon, NULL);
9 zsock_send (beacon,
"si",
"CONFIGURE", 31415);
10 char *tmp = zstr_recv (beacon);
11 std::string ret = tmp;
13 zactor_destroy (&beacon);
20 const std::string& hostname)
23 , m_hostname(hostname)
26 if (m_hostname.empty()) {
27 m_hostname = get_hostname();
40 if (ret) {
return ret; }
41 ret = std::make_shared<Port>(
name, stype, m_hostname);
42 ret->set_origin(m_origin);
43 ret->set_verbose(m_verbose);
45 m_portnames.push_back(name);
51 auto it = m_ports.find(name);
52 if (it == m_ports.end()) {
61 if (m_peer) {
return; }
64 for (
auto& np : m_ports) {
66 headers.insert(hs.begin(), hs.end());
68 zio::debug(
"[node {}] going online with:", m_nick.c_str());
69 for (
const auto& hh : headers) {
70 zio::debug(
"\t{} = {}", hh.first.c_str(), hh.second.c_str());
72 m_peer =
new Peer(m_nick, headers, m_verbose);
73 for (
auto& np : m_ports) {
74 np.second->online(*m_peer);
80 if (!m_peer) { return ; }
81 for (
auto& np : m_ports) {
92 for (
auto& np : m_ports) {
93 np.second->set_origin(origin);
void online(const headerset_t &extra_headers={})
Bring the node online.
void set_verbose(bool verbose=true)
Set verbose for underlying Zyre and internal debug messages.
portptr_t port(const std::string &name, int stype)
Create a named port with the given socket type.
Node(nickname_t nick="", origin_t origin=0, const std::string &hostname="")
Create a node.
std::map< header_key_t, header_value_t > headerset_t
origin_t origin() const
Return a previously set node origin.
void set_origin(origin_t origin)
Set the node origin.
std::shared_ptr< Port > portptr_t
The context can't be copied and ports like to be shared.
void set_verbose(bool verbose=true)
Turn on verbose debugging of the underlying Zyre actor.
std::string nickname_t
A peer asserts a nickname.
void offline()
Bring the node offline.
Peer at the network to discover peers and advertise self.