From 7e7e28f5f7d53df8f4897b243088d2f664651ae6 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Thu, 17 Oct 2013 05:37:01 -0400 Subject: Add support for pushing network config refresh hints from a MEMORY queue table. That ways it will be possible for network changes to take effect almost immediately across all active peers. --- node/Node.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'node/Node.cpp') diff --git a/node/Node.cpp b/node/Node.cpp index fe95701a..71d8b097 100644 --- a/node/Node.cpp +++ b/node/Node.cpp @@ -269,6 +269,34 @@ static void _netconfServiceMessageHandler(void *renv,Service &svc,const Dictiona } } } + } else if (type == "netconf-push") { + if (msg.contains("to")) { + Dictionary to(msg.get("to")); // key: peer address, value: comma-delimited network list + for(Dictionary::iterator t(to.begin());t!=to.end();++t) { + Address ztaddr(t->first); + if (ztaddr) { + Packet outp(ztaddr,_r->identity.address(),Packet::VERB_NETWORK_CONFIG_REFRESH); + + char *saveptr = (char *)0; + // Note: this loop trashes t->second, which is quasi-legal C++ but + // shouldn't break anything as long as we don't try to use 'to' + // for anything interesting after doing this. + for(char *p=Utils::stok(const_cast(t->second.c_str()),",",&saveptr);(p);p=Utils::stok((char *)0,",",&saveptr)) { + uint64_t nwid = Utils::hexStrToU64(p); + if (nwid) { + if ((outp.size() + sizeof(uint64_t)) >= ZT_UDP_DEFAULT_PAYLOAD_MTU) { + _r->sw->send(outp,true); + outp.reset(ztaddr,_r->identity.address(),Packet::VERB_NETWORK_CONFIG_REFRESH); + } + outp.append(nwid); + } + } + + if (outp.payloadLength()) + _r->sw->send(outp,true); + } + } + } } } catch (std::exception &exc) { LOG("unexpected exception parsing response from netconf service: %s",exc.what()); -- cgit v1.2.3