mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-19 05:26:54 +02:00
Reorg done and builds
This commit is contained in:
parent
af846f7e3f
commit
73795d05eb
16 changed files with 3301 additions and 244 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -2,8 +2,8 @@
|
|||
/cmake-build-debug
|
||||
/cmake-build-release
|
||||
/core/version.h
|
||||
|
||||
.idea
|
||||
/.idea
|
||||
/.ide-*
|
||||
.DS_Store
|
||||
.Trashes
|
||||
*.swp
|
||||
|
|
|
@ -113,7 +113,8 @@ set(
|
|||
|
||||
add_custom_target(zerotier ALL
|
||||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
||||
COMMAND rm -f ./build/zerotier && go build -trimpath -ldflags -s -w -buildmode=pie -o ./build/zerotier cmd/zerotier/zerotier.go
|
||||
ADDITIONAL_CLEAN_FILES ./build/zerotier
|
||||
COMMAND rm -f ./build/zerotier && go build -trimpath -ldflags -s -buildmode=pie -o ./build/zerotier cmd/zerotier/zerotier.go
|
||||
BYPRODUCTS zerotier
|
||||
)
|
||||
add_dependencies(zerotier zt_osdep zt_core zt_controller zt_service_io_core)
|
||||
set(ADDITIONAL_MAKE_CLEAN_FILES zerotier)
|
||||
|
|
|
@ -195,8 +195,8 @@ void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool no
|
|||
std::shared_ptr<_Network> nw;
|
||||
|
||||
if (old.is_object()) {
|
||||
memberId = OSUtils::jsonIntHex(old["id"],0ULL);
|
||||
networkId = OSUtils::jsonIntHex(old["nwid"],0ULL);
|
||||
memberId = DB::jsonIntHex(old["id"],0ULL);
|
||||
networkId = DB::jsonIntHex(old["nwid"],0ULL);
|
||||
if ((memberId)&&(networkId)) {
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_networks_l);
|
||||
|
@ -206,9 +206,9 @@ void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool no
|
|||
}
|
||||
if (nw) {
|
||||
std::lock_guard<std::mutex> l(nw->lock);
|
||||
if (OSUtils::jsonBool(old["activeBridge"],false))
|
||||
if (DB::jsonBool(old["activeBridge"],false))
|
||||
nw->activeBridgeMembers.erase(memberId);
|
||||
wasAuth = OSUtils::jsonBool(old["authorized"],false);
|
||||
wasAuth = DB::jsonBool(old["authorized"],false);
|
||||
if (wasAuth)
|
||||
nw->authorizedMembers.erase(memberId);
|
||||
json &ips = old["ipAssignments"];
|
||||
|
@ -229,8 +229,8 @@ void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool no
|
|||
|
||||
if (memberConfig.is_object()) {
|
||||
if (!nw) {
|
||||
memberId = OSUtils::jsonIntHex(memberConfig["id"],0ULL);
|
||||
networkId = OSUtils::jsonIntHex(memberConfig["nwid"],0ULL);
|
||||
memberId = DB::jsonIntHex(memberConfig["id"],0ULL);
|
||||
networkId = DB::jsonIntHex(memberConfig["nwid"],0ULL);
|
||||
if ((!memberId)||(!networkId))
|
||||
return;
|
||||
std::lock_guard<std::mutex> l(_networks_l);
|
||||
|
@ -245,9 +245,9 @@ void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool no
|
|||
|
||||
nw->members[memberId] = memberConfig;
|
||||
|
||||
if (OSUtils::jsonBool(memberConfig["activeBridge"],false))
|
||||
if (DB::jsonBool(memberConfig["activeBridge"],false))
|
||||
nw->activeBridgeMembers.insert(memberId);
|
||||
isAuth = OSUtils::jsonBool(memberConfig["authorized"],false);
|
||||
isAuth = DB::jsonBool(memberConfig["authorized"],false);
|
||||
if (isAuth)
|
||||
nw->authorizedMembers.insert(memberId);
|
||||
json &ips = memberConfig["ipAssignments"];
|
||||
|
@ -264,7 +264,7 @@ void DB::_memberChanged(nlohmann::json &old,nlohmann::json &memberConfig,bool no
|
|||
}
|
||||
|
||||
if (!isAuth) {
|
||||
const int64_t ldt = (int64_t)OSUtils::jsonInt(memberConfig["lastDeauthorizedTime"],0ULL);
|
||||
const int64_t ldt = (int64_t)DB::jsonInt(memberConfig["lastDeauthorizedTime"],0ULL);
|
||||
if (ldt > nw->mostRecentDeauthTime)
|
||||
nw->mostRecentDeauthTime = ldt;
|
||||
}
|
||||
|
@ -352,4 +352,77 @@ void DB::_fillSummaryInfo(const std::shared_ptr<_Network> &nw,NetworkSummaryInfo
|
|||
info.mostRecentDeauthTime = nw->mostRecentDeauthTime;
|
||||
}
|
||||
|
||||
|
||||
nlohmann::json DB::jsonParse(const std::string &buf) { return nlohmann::json::parse(buf.c_str()); }
|
||||
std::string DB::jsonDump(const nlohmann::json &j,int indentation) { return j.dump(indentation); }
|
||||
|
||||
uint64_t DB::jsonInt(const nlohmann::json &jv,const uint64_t dfl)
|
||||
{
|
||||
try {
|
||||
if (jv.is_number()) {
|
||||
return (uint64_t)jv;
|
||||
} else if (jv.is_string()) {
|
||||
std::string s = jv;
|
||||
return (uint64_t)strtoull(s.c_str(),nullptr,10);
|
||||
} else if (jv.is_boolean()) {
|
||||
return ((bool)jv ? 1ULL : 0ULL);
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
return dfl;
|
||||
}
|
||||
|
||||
uint64_t DB::jsonIntHex(const nlohmann::json &jv,const uint64_t dfl)
|
||||
{
|
||||
try {
|
||||
if (jv.is_number()) {
|
||||
return (uint64_t)jv;
|
||||
} else if (jv.is_string()) {
|
||||
std::string s = jv;
|
||||
return Utils::hexStrToU64(s.c_str());
|
||||
} else if (jv.is_boolean()) {
|
||||
return ((bool)jv ? 1ULL : 0ULL);
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
return dfl;
|
||||
}
|
||||
|
||||
bool DB::jsonBool(const nlohmann::json &jv,const bool dfl)
|
||||
{
|
||||
try {
|
||||
if (jv.is_boolean()) {
|
||||
return (bool)jv;
|
||||
} else if (jv.is_number()) {
|
||||
return ((uint64_t)jv > 0ULL);
|
||||
} else if (jv.is_string()) {
|
||||
std::string s = jv;
|
||||
if (s.length() > 0) {
|
||||
switch(s[0]) {
|
||||
case 't':
|
||||
case 'T':
|
||||
case '1':
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
return dfl;
|
||||
}
|
||||
|
||||
std::string DB::jsonString(const nlohmann::json &jv,const char *dfl)
|
||||
{
|
||||
try {
|
||||
if (jv.is_string()) {
|
||||
return jv;
|
||||
} else if (jv.is_number()) {
|
||||
char tmp[64];
|
||||
OSUtils::ztsnprintf(tmp,sizeof(tmp),"%llu",(uint64_t)jv);
|
||||
return tmp;
|
||||
} else if (jv.is_boolean()) {
|
||||
return ((bool)jv ? std::string("1") : std::string("0"));
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
return std::string((dfl) ? dfl : "");
|
||||
}
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
|
|
@ -113,6 +113,14 @@ public:
|
|||
_changeListeners.push_back(listener);
|
||||
}
|
||||
|
||||
// Helper methods
|
||||
static nlohmann::json jsonParse(const std::string &buf);
|
||||
static std::string jsonDump(const nlohmann::json &j,int indentation = 1);
|
||||
static uint64_t jsonInt(const nlohmann::json &jv,uint64_t dfl);
|
||||
static uint64_t jsonIntHex(const nlohmann::json &jv,uint64_t dfl);
|
||||
static bool jsonBool(const nlohmann::json &jv,bool dfl);
|
||||
static std::string jsonString(const nlohmann::json &jv,const char *dfl);
|
||||
|
||||
protected:
|
||||
static inline bool _compareRecords(const nlohmann::json &a,const nlohmann::json &b)
|
||||
{
|
||||
|
|
|
@ -43,7 +43,7 @@ DBMirrorSet::DBMirrorSet(DB::ChangeListener *listener) :
|
|||
for(auto db2=dbs.begin();db2!=dbs.end();++db2) {
|
||||
if (db->get() != db2->get()) {
|
||||
nlohmann::json nw2;
|
||||
if ((!(*db2)->get(networkId,nw2))||((nw2.is_object())&&(OSUtils::jsonInt(nw2["revision"],0) < OSUtils::jsonInt(network["revision"],0)))) {
|
||||
if ((!(*db2)->get(networkId,nw2))||((nw2.is_object())&&(DB::jsonInt(nw2["revision"],0) < DB::jsonInt(network["revision"],0)))) {
|
||||
nw2 = network;
|
||||
(*db2)->save(nw2,false);
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ DBMirrorSet::DBMirrorSet(DB::ChangeListener *listener) :
|
|||
for(auto db2=dbs.begin();db2!=dbs.end();++db2) {
|
||||
if (db->get() != db2->get()) {
|
||||
nlohmann::json nw2,m2;
|
||||
if ((!(*db2)->get(networkId,nw2,memberId,m2))||((m2.is_object())&&(OSUtils::jsonInt(m2["revision"],0) < OSUtils::jsonInt(member["revision"],0)))) {
|
||||
if ((!(*db2)->get(networkId,nw2,memberId,m2))||((m2.is_object())&&(DB::jsonInt(m2["revision"],0) < DB::jsonInt(member["revision"],0)))) {
|
||||
m2 = member;
|
||||
(*db2)->save(m2,false);
|
||||
}
|
||||
|
|
|
@ -243,13 +243,13 @@ static bool _parseRule(json &r,ZT_VirtualNetworkRule &rule)
|
|||
if (!r.is_object())
|
||||
return false;
|
||||
|
||||
const std::string t(OSUtils::jsonString(r["type"],""));
|
||||
const std::string t(DB::jsonString(r["type"],""));
|
||||
memset(&rule,0,sizeof(ZT_VirtualNetworkRule));
|
||||
|
||||
if (OSUtils::jsonBool(r["not"],false))
|
||||
if (DB::jsonBool(r["not"],false))
|
||||
rule.t = 0x80;
|
||||
else rule.t = 0x00;
|
||||
if (OSUtils::jsonBool(r["or"],false))
|
||||
if (DB::jsonBool(r["or"],false))
|
||||
rule.t |= 0x40;
|
||||
|
||||
bool tag = false;
|
||||
|
@ -261,117 +261,117 @@ static bool _parseRule(json &r,ZT_VirtualNetworkRule &rule)
|
|||
return true;
|
||||
} else if (t == "ACTION_TEE") {
|
||||
rule.t |= ZT_NETWORK_RULE_ACTION_TEE;
|
||||
rule.v.fwd.address = Utils::hexStrToU64(OSUtils::jsonString(r["address"],"0").c_str()) & 0xffffffffffULL;
|
||||
rule.v.fwd.flags = (uint32_t)(OSUtils::jsonInt(r["flags"],0ULL) & 0xffffffffULL);
|
||||
rule.v.fwd.length = (uint16_t)(OSUtils::jsonInt(r["length"],0ULL) & 0xffffULL);
|
||||
rule.v.fwd.address = Utils::hexStrToU64(DB::jsonString(r["address"],"0").c_str()) & 0xffffffffffULL;
|
||||
rule.v.fwd.flags = (uint32_t)(DB::jsonInt(r["flags"],0ULL) & 0xffffffffULL);
|
||||
rule.v.fwd.length = (uint16_t)(DB::jsonInt(r["length"],0ULL) & 0xffffULL);
|
||||
return true;
|
||||
} else if (t == "ACTION_WATCH") {
|
||||
rule.t |= ZT_NETWORK_RULE_ACTION_WATCH;
|
||||
rule.v.fwd.address = Utils::hexStrToU64(OSUtils::jsonString(r["address"],"0").c_str()) & 0xffffffffffULL;
|
||||
rule.v.fwd.flags = (uint32_t)(OSUtils::jsonInt(r["flags"],0ULL) & 0xffffffffULL);
|
||||
rule.v.fwd.length = (uint16_t)(OSUtils::jsonInt(r["length"],0ULL) & 0xffffULL);
|
||||
rule.v.fwd.address = Utils::hexStrToU64(DB::jsonString(r["address"],"0").c_str()) & 0xffffffffffULL;
|
||||
rule.v.fwd.flags = (uint32_t)(DB::jsonInt(r["flags"],0ULL) & 0xffffffffULL);
|
||||
rule.v.fwd.length = (uint16_t)(DB::jsonInt(r["length"],0ULL) & 0xffffULL);
|
||||
return true;
|
||||
} else if (t == "ACTION_REDIRECT") {
|
||||
rule.t |= ZT_NETWORK_RULE_ACTION_REDIRECT;
|
||||
rule.v.fwd.address = Utils::hexStrToU64(OSUtils::jsonString(r["address"],"0").c_str()) & 0xffffffffffULL;
|
||||
rule.v.fwd.flags = (uint32_t)(OSUtils::jsonInt(r["flags"],0ULL) & 0xffffffffULL);
|
||||
rule.v.fwd.address = Utils::hexStrToU64(DB::jsonString(r["address"],"0").c_str()) & 0xffffffffffULL;
|
||||
rule.v.fwd.flags = (uint32_t)(DB::jsonInt(r["flags"],0ULL) & 0xffffffffULL);
|
||||
return true;
|
||||
} else if (t == "ACTION_BREAK") {
|
||||
rule.t |= ZT_NETWORK_RULE_ACTION_BREAK;
|
||||
return true;
|
||||
} else if (t == "MATCH_SOURCE_ZEROTIER_ADDRESS") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_SOURCE_ZEROTIER_ADDRESS;
|
||||
rule.v.zt = Utils::hexStrToU64(OSUtils::jsonString(r["zt"],"0").c_str()) & 0xffffffffffULL;
|
||||
rule.v.zt = Utils::hexStrToU64(DB::jsonString(r["zt"],"0").c_str()) & 0xffffffffffULL;
|
||||
return true;
|
||||
} else if (t == "MATCH_DEST_ZEROTIER_ADDRESS") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_DEST_ZEROTIER_ADDRESS;
|
||||
rule.v.zt = Utils::hexStrToU64(OSUtils::jsonString(r["zt"],"0").c_str()) & 0xffffffffffULL;
|
||||
rule.v.zt = Utils::hexStrToU64(DB::jsonString(r["zt"],"0").c_str()) & 0xffffffffffULL;
|
||||
return true;
|
||||
} else if (t == "MATCH_VLAN_ID") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_VLAN_ID;
|
||||
rule.v.vlanId = (uint16_t)(OSUtils::jsonInt(r["vlanId"],0ULL) & 0xffffULL);
|
||||
rule.v.vlanId = (uint16_t)(DB::jsonInt(r["vlanId"],0ULL) & 0xffffULL);
|
||||
return true;
|
||||
} else if (t == "MATCH_VLAN_PCP") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_VLAN_PCP;
|
||||
rule.v.vlanPcp = (uint8_t)(OSUtils::jsonInt(r["vlanPcp"],0ULL) & 0xffULL);
|
||||
rule.v.vlanPcp = (uint8_t)(DB::jsonInt(r["vlanPcp"],0ULL) & 0xffULL);
|
||||
return true;
|
||||
} else if (t == "MATCH_VLAN_DEI") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_VLAN_DEI;
|
||||
rule.v.vlanDei = (uint8_t)(OSUtils::jsonInt(r["vlanDei"],0ULL) & 0xffULL);
|
||||
rule.v.vlanDei = (uint8_t)(DB::jsonInt(r["vlanDei"],0ULL) & 0xffULL);
|
||||
return true;
|
||||
} else if (t == "MATCH_MAC_SOURCE") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_MAC_SOURCE;
|
||||
const std::string mac(OSUtils::jsonString(r["mac"],"0"));
|
||||
const std::string mac(DB::jsonString(r["mac"],"0"));
|
||||
Utils::unhex(mac.c_str(),(unsigned int)mac.length(),rule.v.mac,6);
|
||||
return true;
|
||||
} else if (t == "MATCH_MAC_DEST") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_MAC_DEST;
|
||||
const std::string mac(OSUtils::jsonString(r["mac"],"0"));
|
||||
const std::string mac(DB::jsonString(r["mac"],"0"));
|
||||
Utils::unhex(mac.c_str(),(unsigned int)mac.length(),rule.v.mac,6);
|
||||
return true;
|
||||
} else if (t == "MATCH_IPV4_SOURCE") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_IPV4_SOURCE;
|
||||
InetAddress ip(OSUtils::jsonString(r["ip"],"0.0.0.0").c_str());
|
||||
InetAddress ip(DB::jsonString(r["ip"],"0.0.0.0").c_str());
|
||||
rule.v.ipv4.ip = reinterpret_cast<struct sockaddr_in *>(&ip)->sin_addr.s_addr;
|
||||
rule.v.ipv4.mask = Utils::ntoh(reinterpret_cast<struct sockaddr_in *>(&ip)->sin_port) & 0xff;
|
||||
if (rule.v.ipv4.mask > 32) rule.v.ipv4.mask = 32;
|
||||
return true;
|
||||
} else if (t == "MATCH_IPV4_DEST") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_IPV4_DEST;
|
||||
InetAddress ip(OSUtils::jsonString(r["ip"],"0.0.0.0").c_str());
|
||||
InetAddress ip(DB::jsonString(r["ip"],"0.0.0.0").c_str());
|
||||
rule.v.ipv4.ip = reinterpret_cast<struct sockaddr_in *>(&ip)->sin_addr.s_addr;
|
||||
rule.v.ipv4.mask = Utils::ntoh(reinterpret_cast<struct sockaddr_in *>(&ip)->sin_port) & 0xff;
|
||||
if (rule.v.ipv4.mask > 32) rule.v.ipv4.mask = 32;
|
||||
return true;
|
||||
} else if (t == "MATCH_IPV6_SOURCE") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_IPV6_SOURCE;
|
||||
InetAddress ip(OSUtils::jsonString(r["ip"],"::0").c_str());
|
||||
InetAddress ip(DB::jsonString(r["ip"],"::0").c_str());
|
||||
memcpy(rule.v.ipv6.ip,reinterpret_cast<struct sockaddr_in6 *>(&ip)->sin6_addr.s6_addr,16);
|
||||
rule.v.ipv6.mask = Utils::ntoh(reinterpret_cast<struct sockaddr_in6 *>(&ip)->sin6_port) & 0xff;
|
||||
if (rule.v.ipv6.mask > 128) rule.v.ipv6.mask = 128;
|
||||
return true;
|
||||
} else if (t == "MATCH_IPV6_DEST") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_IPV6_DEST;
|
||||
InetAddress ip(OSUtils::jsonString(r["ip"],"::0").c_str());
|
||||
InetAddress ip(DB::jsonString(r["ip"],"::0").c_str());
|
||||
memcpy(rule.v.ipv6.ip,reinterpret_cast<struct sockaddr_in6 *>(&ip)->sin6_addr.s6_addr,16);
|
||||
rule.v.ipv6.mask = Utils::ntoh(reinterpret_cast<struct sockaddr_in6 *>(&ip)->sin6_port) & 0xff;
|
||||
if (rule.v.ipv6.mask > 128) rule.v.ipv6.mask = 128;
|
||||
return true;
|
||||
} else if (t == "MATCH_IP_TOS") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_IP_TOS;
|
||||
rule.v.ipTos.mask = (uint8_t)(OSUtils::jsonInt(r["mask"],0ULL) & 0xffULL);
|
||||
rule.v.ipTos.value[0] = (uint8_t)(OSUtils::jsonInt(r["start"],0ULL) & 0xffULL);
|
||||
rule.v.ipTos.value[1] = (uint8_t)(OSUtils::jsonInt(r["end"],0ULL) & 0xffULL);
|
||||
rule.v.ipTos.mask = (uint8_t)(DB::jsonInt(r["mask"],0ULL) & 0xffULL);
|
||||
rule.v.ipTos.value[0] = (uint8_t)(DB::jsonInt(r["start"],0ULL) & 0xffULL);
|
||||
rule.v.ipTos.value[1] = (uint8_t)(DB::jsonInt(r["end"],0ULL) & 0xffULL);
|
||||
return true;
|
||||
} else if (t == "MATCH_IP_PROTOCOL") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_IP_PROTOCOL;
|
||||
rule.v.ipProtocol = (uint8_t)(OSUtils::jsonInt(r["ipProtocol"],0ULL) & 0xffULL);
|
||||
rule.v.ipProtocol = (uint8_t)(DB::jsonInt(r["ipProtocol"],0ULL) & 0xffULL);
|
||||
return true;
|
||||
} else if (t == "MATCH_ETHERTYPE") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_ETHERTYPE;
|
||||
rule.v.etherType = (uint16_t)(OSUtils::jsonInt(r["etherType"],0ULL) & 0xffffULL);
|
||||
rule.v.etherType = (uint16_t)(DB::jsonInt(r["etherType"],0ULL) & 0xffffULL);
|
||||
return true;
|
||||
} else if (t == "MATCH_ICMP") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_ICMP;
|
||||
rule.v.icmp.type = (uint8_t)(OSUtils::jsonInt(r["icmpType"],0ULL) & 0xffULL);
|
||||
rule.v.icmp.type = (uint8_t)(DB::jsonInt(r["icmpType"],0ULL) & 0xffULL);
|
||||
json &code = r["icmpCode"];
|
||||
if (code.is_null()) {
|
||||
rule.v.icmp.code = 0;
|
||||
rule.v.icmp.flags = 0x00;
|
||||
} else {
|
||||
rule.v.icmp.code = (uint8_t)(OSUtils::jsonInt(code,0ULL) & 0xffULL);
|
||||
rule.v.icmp.code = (uint8_t)(DB::jsonInt(code,0ULL) & 0xffULL);
|
||||
rule.v.icmp.flags = 0x01;
|
||||
}
|
||||
return true;
|
||||
} else if (t == "MATCH_IP_SOURCE_PORT_RANGE") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_IP_SOURCE_PORT_RANGE;
|
||||
rule.v.port[0] = (uint16_t)(OSUtils::jsonInt(r["start"],0ULL) & 0xffffULL);
|
||||
rule.v.port[1] = (uint16_t)(OSUtils::jsonInt(r["end"],(uint64_t)rule.v.port[0]) & 0xffffULL);
|
||||
rule.v.port[0] = (uint16_t)(DB::jsonInt(r["start"],0ULL) & 0xffffULL);
|
||||
rule.v.port[1] = (uint16_t)(DB::jsonInt(r["end"],(uint64_t)rule.v.port[0]) & 0xffffULL);
|
||||
return true;
|
||||
} else if (t == "MATCH_IP_DEST_PORT_RANGE") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_IP_DEST_PORT_RANGE;
|
||||
rule.v.port[0] = (uint16_t)(OSUtils::jsonInt(r["start"],0ULL) & 0xffffULL);
|
||||
rule.v.port[1] = (uint16_t)(OSUtils::jsonInt(r["end"],(uint64_t)rule.v.port[0]) & 0xffffULL);
|
||||
rule.v.port[0] = (uint16_t)(DB::jsonInt(r["start"],0ULL) & 0xffffULL);
|
||||
rule.v.port[1] = (uint16_t)(DB::jsonInt(r["end"],(uint64_t)rule.v.port[0]) & 0xffffULL);
|
||||
return true;
|
||||
} else if (t == "MATCH_CHARACTERISTICS") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_CHARACTERISTICS;
|
||||
|
@ -387,12 +387,12 @@ static bool _parseRule(json &r,ZT_VirtualNetworkRule &rule)
|
|||
return true;
|
||||
} else if (t == "MATCH_FRAME_SIZE_RANGE") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_FRAME_SIZE_RANGE;
|
||||
rule.v.frameSize[0] = (uint16_t)(OSUtils::jsonInt(r["start"],0ULL) & 0xffffULL);
|
||||
rule.v.frameSize[1] = (uint16_t)(OSUtils::jsonInt(r["end"],(uint64_t)rule.v.frameSize[0]) & 0xffffULL);
|
||||
rule.v.frameSize[0] = (uint16_t)(DB::jsonInt(r["start"],0ULL) & 0xffffULL);
|
||||
rule.v.frameSize[1] = (uint16_t)(DB::jsonInt(r["end"],(uint64_t)rule.v.frameSize[0]) & 0xffffULL);
|
||||
return true;
|
||||
} else if (t == "MATCH_RANDOM") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_RANDOM;
|
||||
rule.v.randomProbability = (uint32_t)(OSUtils::jsonInt(r["probability"],0ULL) & 0xffffffffULL);
|
||||
rule.v.randomProbability = (uint32_t)(DB::jsonInt(r["probability"],0ULL) & 0xffffffffULL);
|
||||
return true;
|
||||
} else if (t == "MATCH_TAGS_DIFFERENCE") {
|
||||
rule.t |= ZT_NETWORK_RULE_MATCH_TAGS_DIFFERENCE;
|
||||
|
@ -421,23 +421,23 @@ static bool _parseRule(json &r,ZT_VirtualNetworkRule &rule)
|
|||
std::string tmp = s;
|
||||
rule.v.intRange.start = Utils::hexStrToU64(tmp.c_str());
|
||||
} else {
|
||||
rule.v.intRange.start = OSUtils::jsonInt(s,0ULL);
|
||||
rule.v.intRange.start = DB::jsonInt(s,0ULL);
|
||||
}
|
||||
json &e = r["end"];
|
||||
if (e.is_string()) {
|
||||
std::string tmp = e;
|
||||
rule.v.intRange.end = (uint32_t)(Utils::hexStrToU64(tmp.c_str()) - rule.v.intRange.start);
|
||||
} else {
|
||||
rule.v.intRange.end = (uint32_t)(OSUtils::jsonInt(e,0ULL) - rule.v.intRange.start);
|
||||
rule.v.intRange.end = (uint32_t)(DB::jsonInt(e,0ULL) - rule.v.intRange.start);
|
||||
}
|
||||
rule.v.intRange.idx = (uint16_t)OSUtils::jsonInt(r["idx"],0ULL);
|
||||
rule.v.intRange.format = (OSUtils::jsonBool(r["little"],false)) ? 0x80 : 0x00;
|
||||
rule.v.intRange.format |= (uint8_t)((OSUtils::jsonInt(r["bits"],1ULL) - 1) & 63);
|
||||
rule.v.intRange.idx = (uint16_t)DB::jsonInt(r["idx"],0ULL);
|
||||
rule.v.intRange.format = (DB::jsonBool(r["little"],false)) ? 0x80 : 0x00;
|
||||
rule.v.intRange.format |= (uint8_t)((DB::jsonInt(r["bits"],1ULL) - 1) & 63);
|
||||
}
|
||||
|
||||
if (tag) {
|
||||
rule.v.tag.id = (uint32_t)(OSUtils::jsonInt(r["id"],0ULL) & 0xffffffffULL);
|
||||
rule.v.tag.value = (uint32_t)(OSUtils::jsonInt(r["value"],0ULL) & 0xffffffffULL);
|
||||
rule.v.tag.id = (uint32_t)(DB::jsonInt(r["id"],0ULL) & 0xffffffffULL);
|
||||
rule.v.tag.value = (uint32_t)(DB::jsonInt(r["value"],0ULL) & 0xffffffffULL);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -487,7 +487,7 @@ void EmbeddedNetworkController::init(const Identity &signingId,Sender *sender)
|
|||
String lfJSON;
|
||||
OSUtils::readFile((_ztPath + ZT_PATH_SEPARATOR_S "local.conf").c_str(),lfJSON);
|
||||
if (lfJSON.length() > 0) {
|
||||
nlohmann::json lfConfig(OSUtils::jsonParse(std::string(lfJSON.c_str())));
|
||||
nlohmann::json lfConfig(DB::jsonParse(std::string(lfJSON.c_str())));
|
||||
nlohmann::json &settings = lfConfig["settings"];
|
||||
if (settings.is_object()) {
|
||||
nlohmann::json &controllerDb = settings["controllerDb"];
|
||||
|
@ -562,7 +562,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
|
|||
json member;
|
||||
if (!_db.get(nwid,network,address,member))
|
||||
return 404;
|
||||
responseBody = OSUtils::jsonDump(member);
|
||||
responseBody = DB::jsonDump(member);
|
||||
responseContentType = "application/json";
|
||||
|
||||
} else {
|
||||
|
@ -576,7 +576,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
|
|||
for(auto member=members.begin();member!=members.end();++member) {
|
||||
mid = (*member)["id"];
|
||||
char tmp[128];
|
||||
OSUtils::ztsnprintf(tmp,sizeof(tmp),"%s\"%s\":%llu",(responseBody.length() > 1) ? "," : "",mid.c_str(),(unsigned long long)OSUtils::jsonInt((*member)["revision"],0));
|
||||
OSUtils::ztsnprintf(tmp,sizeof(tmp),"%s\"%s\":%llu",(responseBody.length() > 1) ? "," : "",mid.c_str(),(unsigned long long)DB::jsonInt((*member)["revision"],0));
|
||||
responseBody.append(tmp);
|
||||
}
|
||||
}
|
||||
|
@ -591,7 +591,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpGET(
|
|||
} else {
|
||||
// Get network
|
||||
|
||||
responseBody = OSUtils::jsonDump(network);
|
||||
responseBody = DB::jsonDump(network);
|
||||
responseContentType = "application/json";
|
||||
return 200;
|
||||
|
||||
|
@ -643,7 +643,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||
|
||||
json b;
|
||||
try {
|
||||
b = OSUtils::jsonParse(body);
|
||||
b = DB::jsonParse(body);
|
||||
if (!b.is_object()) {
|
||||
responseBody = "{ \"message\": \"body is not a JSON object\" }";
|
||||
responseContentType = "application/json";
|
||||
|
@ -675,22 +675,22 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||
DB::initMember(member);
|
||||
|
||||
try {
|
||||
if (b.count("activeBridge")) member["activeBridge"] = OSUtils::jsonBool(b["activeBridge"],false);
|
||||
if (b.count("noAutoAssignIps")) member["noAutoAssignIps"] = OSUtils::jsonBool(b["noAutoAssignIps"],false);
|
||||
if (b.count("activeBridge")) member["activeBridge"] = DB::jsonBool(b["activeBridge"],false);
|
||||
if (b.count("noAutoAssignIps")) member["noAutoAssignIps"] = DB::jsonBool(b["noAutoAssignIps"],false);
|
||||
|
||||
if (b.count("remoteTraceTarget")) {
|
||||
const std::string rtt(OSUtils::jsonString(b["remoteTraceTarget"],""));
|
||||
const std::string rtt(DB::jsonString(b["remoteTraceTarget"],""));
|
||||
if (rtt.length() == 10) {
|
||||
member["remoteTraceTarget"] = rtt;
|
||||
} else {
|
||||
member["remoteTraceTarget"] = json();
|
||||
}
|
||||
}
|
||||
if (b.count("remoteTraceLevel")) member["remoteTraceLevel"] = OSUtils::jsonInt(b["remoteTraceLevel"],0ULL);
|
||||
if (b.count("remoteTraceLevel")) member["remoteTraceLevel"] = DB::jsonInt(b["remoteTraceLevel"],0ULL);
|
||||
|
||||
if (b.count("authorized")) {
|
||||
const bool newAuth = OSUtils::jsonBool(b["authorized"],false);
|
||||
if (newAuth != OSUtils::jsonBool(member["authorized"],false)) {
|
||||
const bool newAuth = DB::jsonBool(b["authorized"],false);
|
||||
if (newAuth != DB::jsonBool(member["authorized"],false)) {
|
||||
member["authorized"] = newAuth;
|
||||
member[((newAuth) ? "lastAuthorizedTime" : "lastDeauthorizedTime")] = now;
|
||||
if (newAuth) {
|
||||
|
@ -725,7 +725,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||
for(unsigned long i=0;i<tags.size();++i) {
|
||||
json &tag = tags[i];
|
||||
if ((tag.is_array())&&(tag.size() == 2))
|
||||
mtags[OSUtils::jsonInt(tag[0],0ULL) & 0xffffffffULL] = OSUtils::jsonInt(tag[1],0ULL) & 0xffffffffULL;
|
||||
mtags[DB::jsonInt(tag[0],0ULL) & 0xffffffffULL] = DB::jsonInt(tag[1],0ULL) & 0xffffffffULL;
|
||||
}
|
||||
json mtagsa = json::array();
|
||||
for(std::map<uint64_t,uint64_t>::iterator t(mtags.begin());t!=mtags.end();++t) {
|
||||
|
@ -745,7 +745,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||
if (capabilities.is_array()) {
|
||||
json mcaps = json::array();
|
||||
for(unsigned long i=0;i<capabilities.size();++i) {
|
||||
mcaps.push_back(OSUtils::jsonInt(capabilities[i],0ULL));
|
||||
mcaps.push_back(DB::jsonInt(capabilities[i],0ULL));
|
||||
if (mcaps.size() >= ZT_CONTROLLER_MAX_ARRAY_SIZE)
|
||||
break;
|
||||
}
|
||||
|
@ -766,7 +766,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||
|
||||
DB::cleanMember(member);
|
||||
_db.save(member,true);
|
||||
responseBody = OSUtils::jsonDump(member);
|
||||
responseBody = DB::jsonDump(member);
|
||||
responseContentType = "application/json";
|
||||
|
||||
return 200;
|
||||
|
@ -799,29 +799,29 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||
DB::initNetwork(network);
|
||||
|
||||
try {
|
||||
if (b.count("name")) network["name"] = OSUtils::jsonString(b["name"],"");
|
||||
if (b.count("private")) network["private"] = OSUtils::jsonBool(b["private"],true);
|
||||
if (b.count("enableBroadcast")) network["enableBroadcast"] = OSUtils::jsonBool(b["enableBroadcast"],false);
|
||||
if (b.count("multicastLimit")) network["multicastLimit"] = OSUtils::jsonInt(b["multicastLimit"],32ULL);
|
||||
if (b.count("mtu")) network["mtu"] = std::max(std::min((unsigned int)OSUtils::jsonInt(b["mtu"],ZT_DEFAULT_MTU),(unsigned int)ZT_MAX_MTU),(unsigned int)ZT_MIN_MTU);
|
||||
if (b.count("name")) network["name"] = DB::jsonString(b["name"],"");
|
||||
if (b.count("private")) network["private"] = DB::jsonBool(b["private"],true);
|
||||
if (b.count("enableBroadcast")) network["enableBroadcast"] = DB::jsonBool(b["enableBroadcast"],false);
|
||||
if (b.count("multicastLimit")) network["multicastLimit"] = DB::jsonInt(b["multicastLimit"],32ULL);
|
||||
if (b.count("mtu")) network["mtu"] = std::max(std::min((unsigned int)DB::jsonInt(b["mtu"],ZT_DEFAULT_MTU),(unsigned int)ZT_MAX_MTU),(unsigned int)ZT_MIN_MTU);
|
||||
|
||||
if (b.count("remoteTraceTarget")) {
|
||||
const std::string rtt(OSUtils::jsonString(b["remoteTraceTarget"],""));
|
||||
const std::string rtt(DB::jsonString(b["remoteTraceTarget"],""));
|
||||
if (rtt.length() == 10) {
|
||||
network["remoteTraceTarget"] = rtt;
|
||||
} else {
|
||||
network["remoteTraceTarget"] = json();
|
||||
}
|
||||
}
|
||||
if (b.count("remoteTraceLevel")) network["remoteTraceLevel"] = OSUtils::jsonInt(b["remoteTraceLevel"],0ULL);
|
||||
if (b.count("remoteTraceLevel")) network["remoteTraceLevel"] = DB::jsonInt(b["remoteTraceLevel"],0ULL);
|
||||
|
||||
if (b.count("v4AssignMode")) {
|
||||
json nv4m;
|
||||
json &v4m = b["v4AssignMode"];
|
||||
if (v4m.is_string()) { // backward compatibility
|
||||
nv4m["zt"] = (OSUtils::jsonString(v4m,"") == "zt");
|
||||
nv4m["zt"] = (DB::jsonString(v4m,"") == "zt");
|
||||
} else if (v4m.is_object()) {
|
||||
nv4m["zt"] = OSUtils::jsonBool(v4m["zt"],false);
|
||||
nv4m["zt"] = DB::jsonBool(v4m["zt"],false);
|
||||
} else nv4m["zt"] = false;
|
||||
network["v4AssignMode"] = nv4m;
|
||||
}
|
||||
|
@ -831,7 +831,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||
json &v6m = b["v6AssignMode"];
|
||||
if (!nv6m.is_object()) nv6m = json::object();
|
||||
if (v6m.is_string()) { // backward compatibility
|
||||
Vector<String> v6ms(OSUtils::split(OSUtils::jsonString(v6m,"").c_str(),",","",""));
|
||||
Vector<String> v6ms(OSUtils::split(DB::jsonString(v6m,"").c_str(),",","",""));
|
||||
std::sort(v6ms.begin(),v6ms.end());
|
||||
v6ms.erase(std::unique(v6ms.begin(),v6ms.end()),v6ms.end());
|
||||
nv6m["rfc4193"] = false;
|
||||
|
@ -846,9 +846,9 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||
nv6m["6plane"] = true;
|
||||
}
|
||||
} else if (v6m.is_object()) {
|
||||
if (v6m.count("rfc4193")) nv6m["rfc4193"] = OSUtils::jsonBool(v6m["rfc4193"],false);
|
||||
if (v6m.count("zt")) nv6m["zt"] = OSUtils::jsonBool(v6m["zt"],false);
|
||||
if (v6m.count("6plane")) nv6m["6plane"] = OSUtils::jsonBool(v6m["6plane"],false);
|
||||
if (v6m.count("rfc4193")) nv6m["rfc4193"] = DB::jsonBool(v6m["rfc4193"],false);
|
||||
if (v6m.count("zt")) nv6m["zt"] = DB::jsonBool(v6m["zt"],false);
|
||||
if (v6m.count("6plane")) nv6m["6plane"] = DB::jsonBool(v6m["6plane"],false);
|
||||
} else {
|
||||
nv6m["rfc4193"] = false;
|
||||
nv6m["zt"] = false;
|
||||
|
@ -895,8 +895,8 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||
for(unsigned long i=0;i<ipp.size();++i) {
|
||||
json &ip = ipp[i];
|
||||
if ((ip.is_object())&&(ip.count("ipRangeStart"))&&(ip.count("ipRangeEnd"))) {
|
||||
InetAddress f(OSUtils::jsonString(ip["ipRangeStart"],"").c_str());
|
||||
InetAddress t(OSUtils::jsonString(ip["ipRangeEnd"],"").c_str());
|
||||
InetAddress f(DB::jsonString(ip["ipRangeStart"],"").c_str());
|
||||
InetAddress t(DB::jsonString(ip["ipRangeEnd"],"").c_str());
|
||||
if ( ((f.family() == AF_INET)||(f.family() == AF_INET6)) && (f.family() == t.family()) ) {
|
||||
json tmp = json::object();
|
||||
char tmp2[64];
|
||||
|
@ -953,9 +953,9 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||
json &cap = capabilities[i];
|
||||
if (cap.is_object()) {
|
||||
json ncap = json::object();
|
||||
const uint64_t capId = OSUtils::jsonInt(cap["id"],0ULL);
|
||||
const uint64_t capId = DB::jsonInt(cap["id"],0ULL);
|
||||
ncap["id"] = capId;
|
||||
ncap["default"] = OSUtils::jsonBool(cap["default"],false);
|
||||
ncap["default"] = DB::jsonBool(cap["default"],false);
|
||||
|
||||
json &rules = cap["rules"];
|
||||
json nrules = json::array();
|
||||
|
@ -996,12 +996,12 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||
json &tag = tags[i];
|
||||
if (tag.is_object()) {
|
||||
json ntag = json::object();
|
||||
const uint64_t tagId = OSUtils::jsonInt(tag["id"],0ULL);
|
||||
const uint64_t tagId = DB::jsonInt(tag["id"],0ULL);
|
||||
ntag["id"] = tagId;
|
||||
json &dfl = tag["default"];
|
||||
if (dfl.is_null())
|
||||
ntag["default"] = dfl;
|
||||
else ntag["default"] = OSUtils::jsonInt(dfl,0ULL);
|
||||
else ntag["default"] = DB::jsonInt(dfl,0ULL);
|
||||
ntags[tagId] = ntag;
|
||||
}
|
||||
}
|
||||
|
@ -1028,7 +1028,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpPOST(
|
|||
DB::cleanNetwork(network);
|
||||
_db.save(network,true);
|
||||
|
||||
responseBody = OSUtils::jsonDump(network);
|
||||
responseBody = DB::jsonDump(network);
|
||||
responseContentType = "application/json";
|
||||
return 200;
|
||||
} // else 404
|
||||
|
@ -1067,7 +1067,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE(
|
|||
|
||||
if (!member.size())
|
||||
return 404;
|
||||
responseBody = OSUtils::jsonDump(member);
|
||||
responseBody = DB::jsonDump(member);
|
||||
responseContentType = "application/json";
|
||||
return 200;
|
||||
}
|
||||
|
@ -1087,7 +1087,7 @@ unsigned int EmbeddedNetworkController::handleControlPlaneHttpDELETE(
|
|||
|
||||
if (!network.size())
|
||||
return 404;
|
||||
responseBody = OSUtils::jsonDump(network);
|
||||
responseBody = DB::jsonDump(network);
|
||||
responseContentType = "application/json";
|
||||
return 200;
|
||||
}
|
||||
|
@ -1170,7 +1170,7 @@ void EmbeddedNetworkController::_request(
|
|||
DB::initMember(member);
|
||||
|
||||
{
|
||||
const std::string haveIdStr(OSUtils::jsonString(member["identity"],""));
|
||||
const std::string haveIdStr(DB::jsonString(member["identity"],""));
|
||||
if (haveIdStr.length() > 0) {
|
||||
// If we already know this member's identity perform a full compare. This prevents
|
||||
// a "collision" from being able to auth onto our network in place of an already
|
||||
|
@ -1204,9 +1204,9 @@ void EmbeddedNetworkController::_request(
|
|||
bool authorized = false;
|
||||
bool autoAuthorized = false;
|
||||
json autoAuthCredentialType,autoAuthCredential;
|
||||
if (OSUtils::jsonBool(member["authorized"],false)) {
|
||||
if (DB::jsonBool(member["authorized"],false)) {
|
||||
authorized = true;
|
||||
} else if (!OSUtils::jsonBool(network["private"],true)) {
|
||||
} else if (!DB::jsonBool(network["private"],true)) {
|
||||
authorized = true;
|
||||
autoAuthorized = true;
|
||||
autoAuthCredentialType = "public";
|
||||
|
@ -1290,16 +1290,16 @@ void EmbeddedNetworkController::_request(
|
|||
std::unique_ptr<NetworkConfig> nc(new NetworkConfig());
|
||||
|
||||
nc->networkId = nwid;
|
||||
nc->type = OSUtils::jsonBool(network["private"],true) ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC;
|
||||
nc->type = DB::jsonBool(network["private"],true) ? ZT_NETWORK_TYPE_PRIVATE : ZT_NETWORK_TYPE_PUBLIC;
|
||||
nc->timestamp = now;
|
||||
nc->credentialTimeMaxDelta = credentialtmd;
|
||||
nc->revision = OSUtils::jsonInt(network["revision"],0ULL);
|
||||
nc->revision = DB::jsonInt(network["revision"],0ULL);
|
||||
nc->issuedTo = identity.address();
|
||||
memcpy(nc->issuedToFingerprintHash,identity.fingerprint().hash,sizeof(nc->issuedToFingerprintHash));
|
||||
if (OSUtils::jsonBool(network["enableBroadcast"],true)) nc->flags |= ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST;
|
||||
Utils::scopy(nc->name,sizeof(nc->name),OSUtils::jsonString(network["name"],"").c_str());
|
||||
nc->mtu = std::max(std::min((unsigned int)OSUtils::jsonInt(network["mtu"],ZT_DEFAULT_MTU),(unsigned int)ZT_MAX_MTU),(unsigned int)ZT_MIN_MTU);
|
||||
nc->multicastLimit = (unsigned int)OSUtils::jsonInt(network["multicastLimit"],32ULL);
|
||||
if (DB::jsonBool(network["enableBroadcast"],true)) nc->flags |= ZT_NETWORKCONFIG_FLAG_ENABLE_BROADCAST;
|
||||
Utils::scopy(nc->name,sizeof(nc->name),DB::jsonString(network["name"],"").c_str());
|
||||
nc->mtu = std::max(std::min((unsigned int)DB::jsonInt(network["mtu"],ZT_DEFAULT_MTU),(unsigned int)ZT_MAX_MTU),(unsigned int)ZT_MIN_MTU);
|
||||
nc->multicastLimit = (unsigned int)DB::jsonInt(network["multicastLimit"],32ULL);
|
||||
|
||||
for(std::vector<Address>::const_iterator ab(ns.activeBridges.begin());ab!=ns.activeBridges.end();++ab)
|
||||
nc->addSpecialist(*ab,ZT_NETWORKCONFIG_SPECIALIST_TYPE_ACTIVE_BRIDGE);
|
||||
|
@ -1337,12 +1337,12 @@ void EmbeddedNetworkController::_request(
|
|||
for(unsigned long i=0;i<capabilities.size();++i) {
|
||||
json &cap = capabilities[i];
|
||||
if (cap.is_object()) {
|
||||
const uint64_t id = OSUtils::jsonInt(cap["id"],0ULL) & 0xffffffffULL;
|
||||
const uint64_t id = DB::jsonInt(cap["id"],0ULL) & 0xffffffffULL;
|
||||
capsById[id] = ∩
|
||||
if ((newMember)&&(OSUtils::jsonBool(cap["default"],false))) {
|
||||
if ((newMember)&&(DB::jsonBool(cap["default"],false))) {
|
||||
bool have = false;
|
||||
for(unsigned long i=0;i<memberCapabilities.size();++i) {
|
||||
if (id == (OSUtils::jsonInt(memberCapabilities[i],0ULL) & 0xffffffffULL)) {
|
||||
if (id == (DB::jsonInt(memberCapabilities[i],0ULL) & 0xffffffffULL)) {
|
||||
have = true;
|
||||
break;
|
||||
}
|
||||
|
@ -1354,7 +1354,7 @@ void EmbeddedNetworkController::_request(
|
|||
}
|
||||
}
|
||||
for(unsigned long i=0;i<memberCapabilities.size();++i) {
|
||||
const uint64_t capId = OSUtils::jsonInt(memberCapabilities[i],0ULL) & 0xffffffffULL;
|
||||
const uint64_t capId = DB::jsonInt(memberCapabilities[i],0ULL) & 0xffffffffULL;
|
||||
std::map< uint64_t,json * >::const_iterator ctmp = capsById.find(capId);
|
||||
if (ctmp != capsById.end()) {
|
||||
json *cap = ctmp->second;
|
||||
|
@ -1384,17 +1384,17 @@ void EmbeddedNetworkController::_request(
|
|||
for(unsigned long i=0;i<memberTags.size();++i) {
|
||||
json &t = memberTags[i];
|
||||
if ((t.is_array())&&(t.size() == 2))
|
||||
memberTagsById[(uint32_t)(OSUtils::jsonInt(t[0],0ULL) & 0xffffffffULL)] = (uint32_t)(OSUtils::jsonInt(t[1],0ULL) & 0xffffffffULL);
|
||||
memberTagsById[(uint32_t)(DB::jsonInt(t[0],0ULL) & 0xffffffffULL)] = (uint32_t)(DB::jsonInt(t[1],0ULL) & 0xffffffffULL);
|
||||
}
|
||||
}
|
||||
if (tags.is_array()) { // check network tags array for defaults that are not present in member tags
|
||||
for(unsigned long i=0;i<tags.size();++i) {
|
||||
json &t = tags[i];
|
||||
if (t.is_object()) {
|
||||
const uint32_t id = (uint32_t)(OSUtils::jsonInt(t["id"],0) & 0xffffffffULL);
|
||||
const uint32_t id = (uint32_t)(DB::jsonInt(t["id"],0) & 0xffffffffULL);
|
||||
json &dfl = t["default"];
|
||||
if ((dfl.is_number())&&(memberTagsById.find(id) == memberTagsById.end())) {
|
||||
memberTagsById[id] = (uint32_t)(OSUtils::jsonInt(dfl,0) & 0xffffffffULL);
|
||||
memberTagsById[id] = (uint32_t)(DB::jsonInt(dfl,0) & 0xffffffffULL);
|
||||
json mt = json::array();
|
||||
mt.push_back(id);
|
||||
mt.push_back(dfl);
|
||||
|
@ -1434,15 +1434,15 @@ void EmbeddedNetworkController::_request(
|
|||
}
|
||||
}
|
||||
|
||||
const bool noAutoAssignIps = OSUtils::jsonBool(member["noAutoAssignIps"],false);
|
||||
const bool noAutoAssignIps = DB::jsonBool(member["noAutoAssignIps"],false);
|
||||
|
||||
// Set IPv6 static IPs based on NDP emulated schemes if enabled.
|
||||
if ((v6AssignMode.is_object())&&(!noAutoAssignIps)) {
|
||||
if ((OSUtils::jsonBool(v6AssignMode["rfc4193"],false))&&(nc->staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES)) {
|
||||
if ((DB::jsonBool(v6AssignMode["rfc4193"],false))&&(nc->staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES)) {
|
||||
nc->staticIps[nc->staticIpCount++] = InetAddress::makeIpv6rfc4193(nwid,identity.address().toInt());
|
||||
nc->flags |= ZT_NETWORKCONFIG_FLAG_ENABLE_IPV6_NDP_EMULATION;
|
||||
}
|
||||
if ((OSUtils::jsonBool(v6AssignMode["6plane"],false))&&(nc->staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES)) {
|
||||
if ((DB::jsonBool(v6AssignMode["6plane"],false))&&(nc->staticIpCount < ZT_MAX_ZT_ASSIGNED_ADDRESSES)) {
|
||||
nc->staticIps[nc->staticIpCount++] = InetAddress::makeIpv66plane(nwid,identity.address().toInt());
|
||||
nc->flags |= ZT_NETWORKCONFIG_FLAG_ENABLE_IPV6_NDP_EMULATION;
|
||||
}
|
||||
|
@ -1482,12 +1482,12 @@ void EmbeddedNetworkController::_request(
|
|||
ipAssignments = json::array();
|
||||
}
|
||||
|
||||
if ( (ipAssignmentPools.is_array()) && ((v6AssignMode.is_object())&&(OSUtils::jsonBool(v6AssignMode["zt"],false))) && (!haveManagedIpv6AutoAssignment) && (!noAutoAssignIps) ) {
|
||||
if ( (ipAssignmentPools.is_array()) && ((v6AssignMode.is_object())&&(DB::jsonBool(v6AssignMode["zt"],false))) && (!haveManagedIpv6AutoAssignment) && (!noAutoAssignIps) ) {
|
||||
for(unsigned long p=0;((p<ipAssignmentPools.size())&&(!haveManagedIpv6AutoAssignment));++p) {
|
||||
json &pool = ipAssignmentPools[p];
|
||||
if (pool.is_object()) {
|
||||
InetAddress ipRangeStart(OSUtils::jsonString(pool["ipRangeStart"],"").c_str());
|
||||
InetAddress ipRangeEnd(OSUtils::jsonString(pool["ipRangeEnd"],"").c_str());
|
||||
InetAddress ipRangeStart(DB::jsonString(pool["ipRangeStart"],"").c_str());
|
||||
InetAddress ipRangeEnd(DB::jsonString(pool["ipRangeEnd"],"").c_str());
|
||||
if ( (ipRangeStart.family() == AF_INET6) && (ipRangeEnd.family() == AF_INET6) ) {
|
||||
uint64_t s[2],e[2],x[2],xx[2];
|
||||
memcpy(s,ipRangeStart.rawIpData(),16);
|
||||
|
@ -1546,12 +1546,12 @@ void EmbeddedNetworkController::_request(
|
|||
}
|
||||
}
|
||||
|
||||
if ( (ipAssignmentPools.is_array()) && ((v4AssignMode.is_object())&&(OSUtils::jsonBool(v4AssignMode["zt"],false))) && (!haveManagedIpv4AutoAssignment) && (!noAutoAssignIps) ) {
|
||||
if ( (ipAssignmentPools.is_array()) && ((v4AssignMode.is_object())&&(DB::jsonBool(v4AssignMode["zt"],false))) && (!haveManagedIpv4AutoAssignment) && (!noAutoAssignIps) ) {
|
||||
for(unsigned long p=0;((p<ipAssignmentPools.size())&&(!haveManagedIpv4AutoAssignment));++p) {
|
||||
json &pool = ipAssignmentPools[p];
|
||||
if (pool.is_object()) {
|
||||
InetAddress ipRangeStartIA(OSUtils::jsonString(pool["ipRangeStart"],"").c_str());
|
||||
InetAddress ipRangeEndIA(OSUtils::jsonString(pool["ipRangeEnd"],"").c_str());
|
||||
InetAddress ipRangeStartIA(DB::jsonString(pool["ipRangeStart"],"").c_str());
|
||||
InetAddress ipRangeEndIA(DB::jsonString(pool["ipRangeEnd"],"").c_str());
|
||||
if ( (ipRangeStartIA.family() == AF_INET) && (ipRangeEndIA.family() == AF_INET) ) {
|
||||
uint32_t ipRangeStart = Utils::ntoh((uint32_t)(reinterpret_cast<struct sockaddr_in *>(&ipRangeStartIA)->sin_addr.s_addr));
|
||||
uint32_t ipRangeEnd = Utils::ntoh((uint32_t)(reinterpret_cast<struct sockaddr_in *>(&ipRangeEndIA)->sin_addr.s_addr));
|
||||
|
|
|
@ -32,7 +32,7 @@ FileDB::FileDB(const char *path) :
|
|||
buf.clear();
|
||||
if ((n->length() == 21)&&(OSUtils::readFile((_networksPath + ZT_PATH_SEPARATOR_S + *n).c_str(),buf))) {
|
||||
try {
|
||||
nlohmann::json network(OSUtils::jsonParse(std::string(buf.c_str())));
|
||||
nlohmann::json network(DB::jsonParse(std::string(buf.c_str())));
|
||||
const std::string nwids = network["id"];
|
||||
if (nwids.length() == 16) {
|
||||
nlohmann::json nullJson;
|
||||
|
@ -43,7 +43,7 @@ FileDB::FileDB(const char *path) :
|
|||
buf.clear();
|
||||
if ((m->length() == 15)&&(OSUtils::readFile((membersPath + ZT_PATH_SEPARATOR_S + *m).c_str(),buf))) {
|
||||
try {
|
||||
nlohmann::json member(OSUtils::jsonParse(std::string(buf.c_str())));
|
||||
nlohmann::json member(DB::jsonParse(std::string(buf.c_str())));
|
||||
const std::string addrs = member["id"];
|
||||
if (addrs.length() == 10) {
|
||||
nlohmann::json nullJson2;
|
||||
|
@ -79,14 +79,14 @@ bool FileDB::save(nlohmann::json &record,bool notifyListeners)
|
|||
const std::string objtype = record["objtype"];
|
||||
if (objtype == "network") {
|
||||
|
||||
const uint64_t nwid = OSUtils::jsonIntHex(record["id"],0ULL);
|
||||
const uint64_t nwid = DB::jsonIntHex(record["id"],0ULL);
|
||||
if (nwid) {
|
||||
nlohmann::json old;
|
||||
get(nwid,old);
|
||||
if ((!old.is_object())||(!_compareRecords(old,record))) {
|
||||
record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
record["revision"] = DB::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
OSUtils::ztsnprintf(p1,sizeof(p1),"%s" ZT_PATH_SEPARATOR_S "%.16llx.json",_networksPath.c_str(),nwid);
|
||||
if (!OSUtils::writeFile(p1,OSUtils::jsonDump(record,-1)))
|
||||
if (!OSUtils::writeFile(p1,DB::jsonDump(record,-1)))
|
||||
fprintf(stderr,"WARNING: controller unable to write to path: %s" ZT_EOL_S,p1);
|
||||
_networkChanged(old,record,notifyListeners);
|
||||
modified = true;
|
||||
|
@ -95,20 +95,20 @@ bool FileDB::save(nlohmann::json &record,bool notifyListeners)
|
|||
|
||||
} else if (objtype == "member") {
|
||||
|
||||
const uint64_t id = OSUtils::jsonIntHex(record["id"],0ULL);
|
||||
const uint64_t nwid = OSUtils::jsonIntHex(record["nwid"],0ULL);
|
||||
const uint64_t id = DB::jsonIntHex(record["id"],0ULL);
|
||||
const uint64_t nwid = DB::jsonIntHex(record["nwid"],0ULL);
|
||||
if ((id)&&(nwid)) {
|
||||
nlohmann::json network,old;
|
||||
get(nwid,network,id,old);
|
||||
if ((!old.is_object())||(!_compareRecords(old,record))) {
|
||||
record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
record["revision"] = DB::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
OSUtils::ztsnprintf(pb,sizeof(pb),"%s" ZT_PATH_SEPARATOR_S "%.16llx" ZT_PATH_SEPARATOR_S "member",_networksPath.c_str(),(unsigned long long)nwid);
|
||||
OSUtils::ztsnprintf(p1,sizeof(p1),"%s" ZT_PATH_SEPARATOR_S "%.10llx.json",pb,(unsigned long long)id);
|
||||
if (!OSUtils::writeFile(p1,OSUtils::jsonDump(record,-1))) {
|
||||
if (!OSUtils::writeFile(p1,DB::jsonDump(record,-1))) {
|
||||
OSUtils::ztsnprintf(p2,sizeof(p2),"%s" ZT_PATH_SEPARATOR_S "%.16llx",_networksPath.c_str(),(unsigned long long)nwid);
|
||||
OSUtils::mkdir(p2);
|
||||
OSUtils::mkdir(pb);
|
||||
if (!OSUtils::writeFile(p1,OSUtils::jsonDump(record,-1)))
|
||||
if (!OSUtils::writeFile(p1,DB::jsonDump(record,-1)))
|
||||
fprintf(stderr,"WARNING: controller unable to write to path: %s" ZT_EOL_S,p1);
|
||||
}
|
||||
_memberChanged(old,record,notifyListeners);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include <sstream>
|
||||
|
||||
#include "../osdep/OSUtils.hpp"
|
||||
#include "../ext/cpp-httplib/httplib.h"
|
||||
#include "./thirdparty/cpp-httplib/httplib.h"
|
||||
|
||||
namespace ZeroTier
|
||||
{
|
||||
|
@ -189,7 +189,7 @@ LFDB::LFDB(const Identity &myId,const char *path,const char *lfOwnerPrivate,cons
|
|||
auto resp = htcli.Post("/query",query.str(),"application/json");
|
||||
if (resp) {
|
||||
if (resp->status == 200) {
|
||||
nlohmann::json results(OSUtils::jsonParse(resp->body));
|
||||
nlohmann::json results(DB::jsonParse(resp->body));
|
||||
if ((results.is_array())&&(results.size() > 0)) {
|
||||
for(std::size_t ri=0;ri<results.size();++ri) {
|
||||
nlohmann::json &rset = results[ri];
|
||||
|
@ -201,7 +201,7 @@ LFDB::LFDB(const Identity &myId,const char *path,const char *lfOwnerPrivate,cons
|
|||
if (record.is_object()) {
|
||||
const std::string recordValue = result["Value"];
|
||||
//printf("GET network %s\n",recordValue.c_str());
|
||||
nlohmann::json network(OSUtils::jsonParse(recordValue));
|
||||
nlohmann::json network(DB::jsonParse(recordValue));
|
||||
if (network.is_object()) {
|
||||
const std::string idstr = network["id"];
|
||||
const uint64_t id = Utils::hexStrToU64(idstr.c_str());
|
||||
|
@ -257,7 +257,7 @@ LFDB::LFDB(const Identity &myId,const char *path,const char *lfOwnerPrivate,cons
|
|||
auto resp = htcli.Post("/query",query.str(),"application/json");
|
||||
if (resp) {
|
||||
if (resp->status == 200) {
|
||||
nlohmann::json results(OSUtils::jsonParse(resp->body));
|
||||
nlohmann::json results(DB::jsonParse(resp->body));
|
||||
if ((results.is_array())&&(results.size() > 0)) {
|
||||
for(std::size_t ri=0;ri<results.size();++ri) {
|
||||
nlohmann::json &rset = results[ri];
|
||||
|
@ -269,7 +269,7 @@ LFDB::LFDB(const Identity &myId,const char *path,const char *lfOwnerPrivate,cons
|
|||
if (record.is_object()) {
|
||||
const std::string recordValue = result["Value"];
|
||||
//printf("GET member %s\n",recordValue.c_str());
|
||||
nlohmann::json member(OSUtils::jsonParse(recordValue));
|
||||
nlohmann::json member(DB::jsonParse(recordValue));
|
||||
if (member.is_object()) {
|
||||
const std::string nwidstr = member["nwid"];
|
||||
const std::string idstr = member["id"];
|
||||
|
@ -344,12 +344,12 @@ bool LFDB::save(nlohmann::json &record,bool notifyListeners)
|
|||
bool modified = false;
|
||||
const std::string objtype = record["objtype"];
|
||||
if (objtype == "network") {
|
||||
const uint64_t nwid = OSUtils::jsonIntHex(record["id"],0ULL);
|
||||
const uint64_t nwid = DB::jsonIntHex(record["id"],0ULL);
|
||||
if (nwid) {
|
||||
nlohmann::json old;
|
||||
get(nwid,old);
|
||||
if ((!old.is_object())||(!_compareRecords(old,record))) {
|
||||
record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
record["revision"] = DB::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
_networkChanged(old,record,notifyListeners);
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_state_l);
|
||||
|
@ -359,13 +359,13 @@ bool LFDB::save(nlohmann::json &record,bool notifyListeners)
|
|||
}
|
||||
}
|
||||
} else if (objtype == "member") {
|
||||
const uint64_t nwid = OSUtils::jsonIntHex(record["nwid"],0ULL);
|
||||
const uint64_t id = OSUtils::jsonIntHex(record["id"],0ULL);
|
||||
const uint64_t nwid = DB::jsonIntHex(record["nwid"],0ULL);
|
||||
const uint64_t id = DB::jsonIntHex(record["id"],0ULL);
|
||||
if ((id)&&(nwid)) {
|
||||
nlohmann::json network,old;
|
||||
get(nwid,network,id,old);
|
||||
if ((!old.is_object())||(!_compareRecords(old,record))) {
|
||||
record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
record["revision"] = DB::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
_memberChanged(old,record,notifyListeners);
|
||||
{
|
||||
std::lock_guard<std::mutex> l(_state_l);
|
||||
|
|
|
@ -166,24 +166,24 @@ bool PostgreSQL::save(nlohmann::json &record,bool notifyListeners)
|
|||
return false;
|
||||
const std::string objtype = record["objtype"];
|
||||
if (objtype == "network") {
|
||||
const uint64_t nwid = OSUtils::jsonIntHex(record["id"],0ULL);
|
||||
const uint64_t nwid = DB::jsonIntHex(record["id"],0ULL);
|
||||
if (nwid) {
|
||||
nlohmann::json old;
|
||||
get(nwid,old);
|
||||
if ((!old.is_object())||(!_compareRecords(old,record))) {
|
||||
record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
record["revision"] = DB::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
_commitQueue.post(std::pair<nlohmann::json,bool>(record,notifyListeners));
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
} else if (objtype == "member") {
|
||||
const uint64_t nwid = OSUtils::jsonIntHex(record["nwid"],0ULL);
|
||||
const uint64_t id = OSUtils::jsonIntHex(record["id"],0ULL);
|
||||
const uint64_t nwid = DB::jsonIntHex(record["nwid"],0ULL);
|
||||
const uint64_t id = DB::jsonIntHex(record["id"],0ULL);
|
||||
if ((id)&&(nwid)) {
|
||||
nlohmann::json network,old;
|
||||
get(nwid,network,id,old);
|
||||
if ((!old.is_object())||(!_compareRecords(old,record))) {
|
||||
record["revision"] = OSUtils::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
record["revision"] = DB::jsonInt(record["revision"],0ULL) + 1ULL;
|
||||
_commitQueue.post(std::pair<nlohmann::json,bool>(record,notifyListeners));
|
||||
modified = true;
|
||||
}
|
||||
|
@ -872,12 +872,12 @@ void PostgreSQL::commitThread()
|
|||
target = (*config)["remoteTraceTarget"];
|
||||
}
|
||||
|
||||
std::string caps = OSUtils::jsonDump((*config)["capabilities"], -1);
|
||||
std::string caps = DB::jsonDump((*config)["capabilities"], -1);
|
||||
std::string lastAuthTime = std::to_string((long long)(*config)["lastAuthorizedTime"]);
|
||||
std::string lastDeauthTime = std::to_string((long long)(*config)["lastDeauthorizedTime"]);
|
||||
std::string rtraceLevel = std::to_string((int)(*config)["remoteTraceLevel"]);
|
||||
std::string rev = std::to_string((unsigned long long)(*config)["revision"]);
|
||||
std::string tags = OSUtils::jsonDump((*config)["tags"], -1);
|
||||
std::string tags = DB::jsonDump((*config)["tags"], -1);
|
||||
std::string vmajor = std::to_string((int)(*config)["vMajor"]);
|
||||
std::string vminor = std::to_string((int)(*config)["vMinor"]);
|
||||
std::string vrev = std::to_string((int)(*config)["vRev"]);
|
||||
|
@ -924,7 +924,7 @@ void PostgreSQL::commitThread()
|
|||
|
||||
if (PQresultStatus(res) != PGRES_COMMAND_OK) {
|
||||
fprintf(stderr, "ERROR: Error updating member: %s\n", PQresultErrorMessage(res));
|
||||
fprintf(stderr, "%s", OSUtils::jsonDump(*config, 2).c_str());
|
||||
fprintf(stderr, "%s", DB::jsonDump(*config, 2).c_str());
|
||||
PQclear(res);
|
||||
delete config;
|
||||
config = nullptr;
|
||||
|
@ -1007,8 +1007,8 @@ void PostgreSQL::commitThread()
|
|||
|
||||
PQclear(res);
|
||||
|
||||
const uint64_t nwidInt = OSUtils::jsonIntHex((*config)["nwid"], 0ULL);
|
||||
const uint64_t memberidInt = OSUtils::jsonIntHex((*config)["id"], 0ULL);
|
||||
const uint64_t nwidInt = DB::jsonIntHex((*config)["nwid"], 0ULL);
|
||||
const uint64_t memberidInt = DB::jsonIntHex((*config)["id"], 0ULL);
|
||||
if (nwidInt && memberidInt) {
|
||||
nlohmann::json nwOrig;
|
||||
nlohmann::json memOrig;
|
||||
|
@ -1038,15 +1038,15 @@ void PostgreSQL::commitThread()
|
|||
if ((*config)["rulesSource"].is_string()) {
|
||||
rulesSource = (*config)["rulesSource"];
|
||||
}
|
||||
std::string caps = OSUtils::jsonDump((*config)["capabilitles"], -1);
|
||||
std::string caps = DB::jsonDump((*config)["capabilitles"], -1);
|
||||
std::string now = std::to_string(OSUtils::now());
|
||||
std::string mtu = std::to_string((int)(*config)["mtu"]);
|
||||
std::string mcastLimit = std::to_string((int)(*config)["multicastLimit"]);
|
||||
std::string rtraceLevel = std::to_string((int)(*config)["remoteTraceLevel"]);
|
||||
std::string rules = OSUtils::jsonDump((*config)["rules"], -1);
|
||||
std::string tags = OSUtils::jsonDump((*config)["tags"], -1);
|
||||
std::string v4mode = OSUtils::jsonDump((*config)["v4AssignMode"],-1);
|
||||
std::string v6mode = OSUtils::jsonDump((*config)["v6AssignMode"], -1);
|
||||
std::string rules = DB::jsonDump((*config)["rules"], -1);
|
||||
std::string tags = DB::jsonDump((*config)["tags"], -1);
|
||||
std::string v4mode = DB::jsonDump((*config)["v4AssignMode"],-1);
|
||||
std::string v6mode = DB::jsonDump((*config)["v6AssignMode"], -1);
|
||||
bool enableBroadcast = (*config)["enableBroadcast"];
|
||||
bool isPrivate = (*config)["private"];
|
||||
|
||||
|
@ -1253,7 +1253,7 @@ void PostgreSQL::commitThread()
|
|||
}
|
||||
PQclear(res);
|
||||
|
||||
const uint64_t nwidInt = OSUtils::jsonIntHex((*config)["nwid"], 0ULL);
|
||||
const uint64_t nwidInt = DB::jsonIntHex((*config)["nwid"], 0ULL);
|
||||
if (nwidInt) {
|
||||
nlohmann::json nwOrig;
|
||||
nlohmann::json nwNew(*config);
|
||||
|
|
22
controller/thirdparty/cpp-httplib/LICENSE
vendored
Normal file
22
controller/thirdparty/cpp-httplib/LICENSE
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 yhirose
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
259
controller/thirdparty/cpp-httplib/README.md
vendored
Normal file
259
controller/thirdparty/cpp-httplib/README.md
vendored
Normal file
|
@ -0,0 +1,259 @@
|
|||
cpp-httplib
|
||||
===========
|
||||
|
||||
[](https://travis-ci.org/yhirose/cpp-httplib)
|
||||
[](https://ci.appveyor.com/project/yhirose/cpp-httplib)
|
||||
|
||||
A C++ header-only cross platform HTTP/HTTPS library.
|
||||
|
||||
It's extremely easy to setup. Just include **httplib.h** file in your code!
|
||||
|
||||
Inspired by [Sinatra](http://www.sinatrarb.com/) and [express](https://github.com/visionmedia/express).
|
||||
|
||||
Server Example
|
||||
--------------
|
||||
|
||||
```c++
|
||||
#include <httplib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
using namespace httplib;
|
||||
|
||||
Server svr;
|
||||
|
||||
svr.Get("/hi", [](const Request& req, Response& res) {
|
||||
res.set_content("Hello World!", "text/plain");
|
||||
});
|
||||
|
||||
svr.Get(R"(/numbers/(\d+))", [&](const Request& req, Response& res) {
|
||||
auto numbers = req.matches[1];
|
||||
res.set_content(numbers, "text/plain");
|
||||
});
|
||||
|
||||
svr.listen("localhost", 1234);
|
||||
}
|
||||
```
|
||||
|
||||
`Post`, `Put`, `Delete` and `Options` methods are also supported.
|
||||
|
||||
### Bind a socket to multiple interfaces and any available port
|
||||
|
||||
```cpp
|
||||
int port = svr.bind_to_any_port("0.0.0.0");
|
||||
svr.listen_after_bind();
|
||||
```
|
||||
|
||||
### Method Chain
|
||||
|
||||
```cpp
|
||||
svr.Get("/get", [](const auto& req, auto& res) {
|
||||
res.set_content("get", "text/plain");
|
||||
})
|
||||
.Post("/post", [](const auto& req, auto& res) {
|
||||
res.set_content(req.body(), "text/plain");
|
||||
})
|
||||
.listen("localhost", 1234);
|
||||
```
|
||||
|
||||
### Static File Server
|
||||
|
||||
```cpp
|
||||
svr.set_base_dir("./www");
|
||||
```
|
||||
|
||||
### Logging
|
||||
|
||||
```cpp
|
||||
svr.set_logger([](const auto& req, const auto& res) {
|
||||
your_logger(req, res);
|
||||
});
|
||||
```
|
||||
|
||||
### Error Handler
|
||||
|
||||
```cpp
|
||||
svr.set_error_handler([](const auto& req, auto& res) {
|
||||
const char* fmt = "<p>Error Status: <span style='color:red;'>%d</span></p>";
|
||||
char buf[BUFSIZ];
|
||||
snprintf(buf, sizeof(buf), fmt, res.status);
|
||||
res.set_content(buf, "text/html");
|
||||
});
|
||||
```
|
||||
|
||||
### 'multipart/form-data' POST data
|
||||
|
||||
```cpp
|
||||
svr.Post("/multipart", [&](const auto& req, auto& res) {
|
||||
auto size = req.files.size();
|
||||
auto ret = req.has_file("name1"));
|
||||
const auto& file = req.get_file_value("name1");
|
||||
// file.filename;
|
||||
// file.content_type;
|
||||
auto body = req.body.substr(file.offset, file.length));
|
||||
})
|
||||
```
|
||||
|
||||
Client Example
|
||||
--------------
|
||||
|
||||
### GET
|
||||
|
||||
```c++
|
||||
#include <httplib.h>
|
||||
#include <iostream>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
httplib::Client cli("localhost", 1234);
|
||||
|
||||
auto res = cli.Get("/hi");
|
||||
if (res && res->status == 200) {
|
||||
std::cout << res->body << std::endl;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### GET with Content Receiver
|
||||
|
||||
```c++
|
||||
std::string body;
|
||||
auto res = cli.Get("/large-data", [&](const char *data, size_t len) {
|
||||
body.append(data, len);
|
||||
});
|
||||
assert(res->body.empty());
|
||||
```
|
||||
|
||||
### POST
|
||||
|
||||
```c++
|
||||
res = cli.Post("/post", "text", "text/plain");
|
||||
res = cli.Post("/person", "name=john1¬e=coder", "application/x-www-form-urlencoded");
|
||||
```
|
||||
|
||||
### POST with parameters
|
||||
|
||||
```c++
|
||||
httplib::Params params;
|
||||
params.emplace("name", "john");
|
||||
params.emplace("note", "coder");
|
||||
|
||||
auto res = cli.Post("/post", params);
|
||||
```
|
||||
or
|
||||
|
||||
```c++
|
||||
httplib::Params params{
|
||||
{ "name", "john" },
|
||||
{ "note", "coder" }
|
||||
};
|
||||
|
||||
auto res = cli.Post("/post", params);
|
||||
```
|
||||
|
||||
### PUT
|
||||
|
||||
```c++
|
||||
res = cli.Put("/resource/foo", "text", "text/plain");
|
||||
```
|
||||
|
||||
### DELETE
|
||||
|
||||
```c++
|
||||
res = cli.Delete("/resource/foo");
|
||||
```
|
||||
|
||||
### OPTIONS
|
||||
|
||||
```c++
|
||||
res = cli.Options("*");
|
||||
res = cli.Options("/resource/foo");
|
||||
```
|
||||
|
||||
### Connection Timeout
|
||||
|
||||
```c++
|
||||
httplib::Client cli("localhost", 8080, 5); // timeouts in 5 seconds
|
||||
```
|
||||
### With Progress Callback
|
||||
|
||||
```cpp
|
||||
httplib::Client client(url, port);
|
||||
|
||||
// prints: 0 / 000 bytes => 50% complete
|
||||
std::shared_ptr<httplib::Response> res =
|
||||
cli.Get("/", [](uint64_t len, uint64_t total) {
|
||||
printf("%lld / %lld bytes => %d%% complete\n",
|
||||
len, total,
|
||||
(int)((len/total)*100));
|
||||
return true; // return 'false' if you want to cancel the request.
|
||||
}
|
||||
);
|
||||
```
|
||||
|
||||

|
||||
|
||||
This feature was contributed by [underscorediscovery](https://github.com/yhirose/cpp-httplib/pull/23).
|
||||
|
||||
### Basic Authentication
|
||||
|
||||
```cpp
|
||||
httplib::Client cli("httplib.org");
|
||||
|
||||
auto res = cli.Get("/basic-auth/hello/world", {
|
||||
httplib::make_basic_authentication_header("hello", "world")
|
||||
});
|
||||
// res->status should be 200
|
||||
// res->body should be "{\n \"authenticated\": true, \n \"user\": \"hello\"\n}\n".
|
||||
```
|
||||
|
||||
### Range
|
||||
|
||||
```cpp
|
||||
httplib::Client cli("httpbin.org");
|
||||
|
||||
auto res = cli.Get("/range/32", {
|
||||
httplib::make_range_header(1, 10) // 'Range: bytes=1-10'
|
||||
});
|
||||
// res->status should be 206.
|
||||
// res->body should be "bcdefghijk".
|
||||
```
|
||||
|
||||
OpenSSL Support
|
||||
---------------
|
||||
|
||||
SSL support is available with `CPPHTTPLIB_OPENSSL_SUPPORT`. `libssl` and `libcrypto` should be linked.
|
||||
|
||||
```c++
|
||||
#define CPPHTTPLIB_OPENSSL_SUPPORT
|
||||
|
||||
SSLServer svr("./cert.pem", "./key.pem");
|
||||
|
||||
SSLClient cli("localhost", 8080);
|
||||
cli.set_ca_cert_path("./ca-bundle.crt");
|
||||
cli.enable_server_certificate_verification(true);
|
||||
```
|
||||
|
||||
Zlib Support
|
||||
------------
|
||||
|
||||
'gzip' compression is available with `CPPHTTPLIB_ZLIB_SUPPORT`.
|
||||
|
||||
The server applies gzip compression to the following MIME type contents:
|
||||
|
||||
* all text types
|
||||
* image/svg+xml
|
||||
* application/javascript
|
||||
* application/json
|
||||
* application/xml
|
||||
* application/xhtml+xml
|
||||
|
||||
NOTE
|
||||
----
|
||||
|
||||
g++ 4.8 cannot build this library since `<regex>` in g++4.8 is [broken](https://stackoverflow.com/questions/12530406/is-gcc-4-8-or-earlier-buggy-about-regular-expressions).
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
MIT license (© 2019 Yuji Hirose)
|
2779
controller/thirdparty/cpp-httplib/httplib.h
vendored
Normal file
2779
controller/thirdparty/cpp-httplib/httplib.h
vendored
Normal file
File diff suppressed because it is too large
Load diff
|
@ -79,7 +79,7 @@
|
|||
#include <netinet6/nd6.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
#include "version.h"
|
||||
#include "../core/Constants.hpp"
|
||||
#include "MacEthernetTapAgent.h"
|
||||
|
||||
#ifndef SIOCAUTOCONF_START
|
||||
|
|
|
@ -351,81 +351,4 @@ ZeroTier::String OSUtils::platformDefaultHomePath()
|
|||
#endif // __UNIX_LIKE__ or not...
|
||||
}
|
||||
|
||||
#ifndef OMIT_JSON_SUPPORT
|
||||
|
||||
// Inline these massive JSON operations in one place only to reduce binary footprint and compile time
|
||||
nlohmann::json OSUtils::jsonParse(const std::string &buf) { return nlohmann::json::parse(buf.c_str()); }
|
||||
std::string OSUtils::jsonDump(const nlohmann::json &j,int indentation) { return j.dump(indentation); }
|
||||
|
||||
uint64_t OSUtils::jsonInt(const nlohmann::json &jv,const uint64_t dfl)
|
||||
{
|
||||
try {
|
||||
if (jv.is_number()) {
|
||||
return (uint64_t)jv;
|
||||
} else if (jv.is_string()) {
|
||||
std::string s = jv;
|
||||
return (uint64_t)strtoull(s.c_str(),nullptr,10);
|
||||
} else if (jv.is_boolean()) {
|
||||
return ((bool)jv ? 1ULL : 0ULL);
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
return dfl;
|
||||
}
|
||||
|
||||
uint64_t OSUtils::jsonIntHex(const nlohmann::json &jv,const uint64_t dfl)
|
||||
{
|
||||
try {
|
||||
if (jv.is_number()) {
|
||||
return (uint64_t)jv;
|
||||
} else if (jv.is_string()) {
|
||||
std::string s = jv;
|
||||
return Utils::hexStrToU64(s.c_str());
|
||||
} else if (jv.is_boolean()) {
|
||||
return ((bool)jv ? 1ULL : 0ULL);
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
return dfl;
|
||||
}
|
||||
|
||||
bool OSUtils::jsonBool(const nlohmann::json &jv,const bool dfl)
|
||||
{
|
||||
try {
|
||||
if (jv.is_boolean()) {
|
||||
return (bool)jv;
|
||||
} else if (jv.is_number()) {
|
||||
return ((uint64_t)jv > 0ULL);
|
||||
} else if (jv.is_string()) {
|
||||
std::string s = jv;
|
||||
if (s.length() > 0) {
|
||||
switch(s[0]) {
|
||||
case 't':
|
||||
case 'T':
|
||||
case '1':
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
return dfl;
|
||||
}
|
||||
|
||||
std::string OSUtils::jsonString(const nlohmann::json &jv,const char *dfl)
|
||||
{
|
||||
try {
|
||||
if (jv.is_string()) {
|
||||
return jv;
|
||||
} else if (jv.is_number()) {
|
||||
char tmp[64];
|
||||
ztsnprintf(tmp,sizeof(tmp),"%llu",(uint64_t)jv);
|
||||
return tmp;
|
||||
} else if (jv.is_boolean()) {
|
||||
return ((bool)jv ? std::string("1") : std::string("0"));
|
||||
}
|
||||
} catch ( ... ) {}
|
||||
return std::string((dfl) ? dfl : "");
|
||||
}
|
||||
|
||||
#endif // OMIT_JSON_SUPPORT
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include <sys/time.h> // NOLINT(modernize-deprecated-headers)
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
@ -229,15 +230,6 @@ public:
|
|||
* @return Platform default ZeroTier One home path
|
||||
*/
|
||||
static ZeroTier::String platformDefaultHomePath();
|
||||
|
||||
#ifndef OMIT_JSON_SUPPORT
|
||||
static nlohmann::json jsonParse(const std::string &buf);
|
||||
static std::string jsonDump(const nlohmann::json &j,int indentation = 1);
|
||||
static uint64_t jsonInt(const nlohmann::json &jv,uint64_t dfl);
|
||||
static uint64_t jsonIntHex(const nlohmann::json &jv,uint64_t dfl);
|
||||
static bool jsonBool(const nlohmann::json &jv,bool dfl);
|
||||
static std::string jsonString(const nlohmann::json &jv,const char *dfl);
|
||||
#endif // OMIT_JSON_SUPPORT
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
package zerotier
|
||||
|
||||
// #cgo CFLAGS: -O3
|
||||
// #cgo darwin LDFLAGS: ${SRCDIR}/../../../build/go/native/libzt_go_native.a ${SRCDIR}/../../../build/node/libzt_core.a ${SRCDIR}/../../../build/osdep/libzt_osdep.a -lc++ -lpthread
|
||||
// #cgo linux android LDFLAGS: ${SRCDIR}/../../../build/go/native/libzt_go_native.a ${SRCDIR}/../../../build/node/libzt_core.a ${SRCDIR}/../../../build/osdep/libzt_osdep.a -lstdc++ -lpthread -lm
|
||||
// #cgo darwin LDFLAGS: ${SRCDIR}/../../build/serviceiocore/libzt_service_io_core.a ${SRCDIR}/../../build/core/libzt_core.a ${SRCDIR}/../../build/osdep/libzt_osdep.a -lc++ -lpthread
|
||||
// #cgo linux android LDFLAGS: ${SRCDIR}/../../build/serviceiocore/libzt_service_io_core.a ${SRCDIR}/../../build/core/libzt_core.a ${SRCDIR}/../../build/osdep/libzt_osdep.a -lstdc++ -lpthread -lm
|
||||
// #include "../../serviceiocore/GoGlue.h"
|
||||
import "C"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue