From a7d8285c3a17e50a0118849017d1ae532d5776a2 Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Tue, 3 Sep 2019 14:57:54 -0700 Subject: [PATCH] Don't require siblings field --- root/root.cpp | 82 ++++++++++++++++++++++++++------------------------- 1 file changed, 42 insertions(+), 40 deletions(-) diff --git a/root/root.cpp b/root/root.cpp index 37c53b9f3..50496a702 100644 --- a/root/root.cpp +++ b/root/root.cpp @@ -782,51 +782,53 @@ int main(int argc,char **argv) } try { - auto sibs = s_config["s_siblings"]; - if (sibs.is_array()) { - for(long i=0;i<(long)sibs.size();++i) { - auto sib = sibs[i]; - if (sib.is_object()) { - std::string idStr = sib["id"]; - std::string ipStr = sib["ip"]; - Identity id; - if (!id.fromString(idStr.c_str())) { - printf("FATAL: invalid JSON while parsing s_siblings section in config file: invalid identity in sibling entry" ZT_EOL_S); - return 1; - } - InetAddress ip; - if (!ip.fromString(ipStr.c_str())) { - printf("FATAL: invalid JSON while parsing s_siblings section in config file: invalid IP address in sibling entry" ZT_EOL_S); - return 1; - } - ip.setPort((unsigned int)sib["port"]); - SharedPtr rp(new RootPeer); - rp->id = id; - if (!s_self.agree(id,rp->key)) { - printf("FATAL: invalid JSON while parsing s_siblings section in config file: invalid identity in sibling entry (unable to execute key agreement)" ZT_EOL_S); - return 1; - } - if (ip.isV4()) { - rp->ip4 = ip; - } else if (ip.isV6()) { - rp->ip6 = ip; + if (s_config.count("s_siblings") > 0) { + auto sibs = s_config["s_siblings"]; + if (sibs.is_array()) { + for(long i=0;i<(long)sibs.size();++i) { + auto sib = sibs[i]; + if (sib.is_object()) { + std::string idStr = sib["id"]; + std::string ipStr = sib["ip"]; + Identity id; + if (!id.fromString(idStr.c_str())) { + printf("FATAL: invalid JSON while parsing s_siblings section in config file: invalid identity in sibling entry" ZT_EOL_S); + return 1; + } + InetAddress ip; + if (!ip.fromString(ipStr.c_str())) { + printf("FATAL: invalid JSON while parsing s_siblings section in config file: invalid IP address in sibling entry" ZT_EOL_S); + return 1; + } + ip.setPort((unsigned int)sib["port"]); + SharedPtr rp(new RootPeer); + rp->id = id; + if (!s_self.agree(id,rp->key)) { + printf("FATAL: invalid JSON while parsing s_siblings section in config file: invalid identity in sibling entry (unable to execute key agreement)" ZT_EOL_S); + return 1; + } + if (ip.isV4()) { + rp->ip4 = ip; + } else if (ip.isV6()) { + rp->ip6 = ip; + } else { + printf("FATAL: invalid JSON while parsing s_siblings section in config file: invalid IP address in sibling entry" ZT_EOL_S); + return 1; + } + rp->sibling = true; + s_siblings.push_back(rp); + s_peersByIdentity[id] = rp; + s_peersByVirtAddr[id.address()].insert(rp); + s_peersByPhysAddr[ip].insert(rp); } else { - printf("FATAL: invalid JSON while parsing s_siblings section in config file: invalid IP address in sibling entry" ZT_EOL_S); + printf("FATAL: invalid JSON while parsing s_siblings section in config file: sibling entry is not a JSON object" ZT_EOL_S); return 1; } - rp->sibling = true; - s_siblings.push_back(rp); - s_peersByIdentity[id] = rp; - s_peersByVirtAddr[id.address()].insert(rp); - s_peersByPhysAddr[ip].insert(rp); - } else { - printf("FATAL: invalid JSON while parsing s_siblings section in config file: sibling entry is not a JSON object" ZT_EOL_S); - return 1; } + } else { + printf("FATAL: invalid JSON while parsing s_siblings section in config file: s_siblings is not a JSON array" ZT_EOL_S); + return 1; } - } else { - printf("FATAL: invalid JSON while parsing s_siblings section in config file: s_siblings is not a JSON array" ZT_EOL_S); - return 1; } } catch ( ... ) { printf("FATAL: invalid JSON while parsing s_siblings section in config file: parse error" ZT_EOL_S);