Don't require siblings field

This commit is contained in:
Adam Ierymenko 2019-09-03 14:57:54 -07:00
parent 5f1dc4b851
commit a7d8285c3a
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3

View file

@ -782,51 +782,53 @@ int main(int argc,char **argv)
} }
try { try {
auto sibs = s_config["s_siblings"]; if (s_config.count("s_siblings") > 0) {
if (sibs.is_array()) { auto sibs = s_config["s_siblings"];
for(long i=0;i<(long)sibs.size();++i) { if (sibs.is_array()) {
auto sib = sibs[i]; for(long i=0;i<(long)sibs.size();++i) {
if (sib.is_object()) { auto sib = sibs[i];
std::string idStr = sib["id"]; if (sib.is_object()) {
std::string ipStr = sib["ip"]; std::string idStr = sib["id"];
Identity id; std::string ipStr = sib["ip"];
if (!id.fromString(idStr.c_str())) { Identity id;
printf("FATAL: invalid JSON while parsing s_siblings section in config file: invalid identity in sibling entry" ZT_EOL_S); if (!id.fromString(idStr.c_str())) {
return 1; 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())) { InetAddress ip;
printf("FATAL: invalid JSON while parsing s_siblings section in config file: invalid IP address in sibling entry" ZT_EOL_S); if (!ip.fromString(ipStr.c_str())) {
return 1; 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<RootPeer> rp(new RootPeer); ip.setPort((unsigned int)sib["port"]);
rp->id = id; SharedPtr<RootPeer> rp(new RootPeer);
if (!s_self.agree(id,rp->key)) { rp->id = id;
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); if (!s_self.agree(id,rp->key)) {
return 1; 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; if (ip.isV4()) {
} else if (ip.isV6()) { rp->ip4 = ip;
rp->ip6 = 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 { } 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; 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 ( ... ) { } catch ( ... ) {
printf("FATAL: invalid JSON while parsing s_siblings section in config file: parse error" ZT_EOL_S); printf("FATAL: invalid JSON while parsing s_siblings section in config file: parse error" ZT_EOL_S);