mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-06 12:33:44 +02:00
Bit more netconf cleanup...
This commit is contained in:
parent
37931d8589
commit
56d8bbf780
3 changed files with 21 additions and 58 deletions
|
@ -231,11 +231,23 @@ int main(int argc,char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string etherTypeWhitelist;
|
std::string etherTypeWhitelistOld;
|
||||||
{
|
{
|
||||||
Query q = dbCon->query();
|
Query q = dbCon->query();
|
||||||
q << "SELECT DISTINCT etherType FROM NetworkEthertypes WHERE Network_id = " << nwid;
|
q << "SELECT DISTINCT etherType FROM NetworkEthertypes WHERE Network_id = " << nwid;
|
||||||
StoreQueryResult rs = q.store();
|
StoreQueryResult rs = q.store();
|
||||||
|
for(unsigned long i=0;i<rs.num_rows();++i) {
|
||||||
|
if (etherTypeWhitelistOld.length() > 0)
|
||||||
|
etherTypeWhitelistOld.push_back(',');
|
||||||
|
etherTypeWhitelistOld.append(rs[i]["etherType"].c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string etherTypeWhitelist;
|
||||||
|
{
|
||||||
|
Query q = dbCon->query();
|
||||||
|
q << "SELECT DISTINCT LOWER(HEX(etherType)) AS etherType FROM NetworkEthertypes WHERE Network_id = " << nwid;
|
||||||
|
StoreQueryResult rs = q.store();
|
||||||
for(unsigned long i=0;i<rs.num_rows();++i) {
|
for(unsigned long i=0;i<rs.num_rows();++i) {
|
||||||
if (etherTypeWhitelist.length() > 0)
|
if (etherTypeWhitelist.length() > 0)
|
||||||
etherTypeWhitelist.push_back(',');
|
etherTypeWhitelist.push_back(',');
|
||||||
|
@ -251,7 +263,7 @@ int main(int argc,char **argv)
|
||||||
netconf["o"] = (isOpen ? "1" : "0");
|
netconf["o"] = (isOpen ? "1" : "0");
|
||||||
netconf["name"] = name;
|
netconf["name"] = name;
|
||||||
netconf["desc"] = desc;
|
netconf["desc"] = desc;
|
||||||
netconf["etherTypes"] = etherTypeWhitelist; // TODO: remove, old name
|
netconf["etherTypes"] = etherTypeWhitelistOld; // TODO: remove, old name
|
||||||
netconf["et"] = etherTypeWhitelist;
|
netconf["et"] = etherTypeWhitelist;
|
||||||
sprintf(buf,"%llx",(unsigned long long)Utils::now());
|
sprintf(buf,"%llx",(unsigned long long)Utils::now());
|
||||||
netconf["ts"] = buf;
|
netconf["ts"] = buf;
|
||||||
|
|
|
@ -80,21 +80,15 @@ bool Network::Certificate::qualifyMembership(const Network::Certificate &mc) con
|
||||||
// indicates a floating point comparison. Otherwise an integer
|
// indicates a floating point comparison. Otherwise an integer
|
||||||
// comparison occurs.
|
// comparison occurs.
|
||||||
if (deltaField->second.find('.') != std::string::npos) {
|
if (deltaField->second.find('.') != std::string::npos) {
|
||||||
double my = strtod(myField->second.c_str(),(char **)0);
|
double my = Utils::strToDouble(myField->second.c_str());
|
||||||
double their = strtod(theirField->second.c_str(),(char **)0);
|
double their = Utils::strToDouble(theirField->second.c_str());
|
||||||
double delta = strtod(deltaField->second.c_str(),(char **)0);
|
double delta = Utils::strToDouble(deltaField->second.c_str());
|
||||||
if (fabs(my - their) > delta)
|
if (fabs(my - their) > delta)
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
#ifdef __WINDOWS__
|
uint64_t my = Utils::hexStrToU64(myField->second.c_str());
|
||||||
int64_t my = _strtoi64(myField->second.c_str(),(char **)0,10);
|
uint64_t their = Utils::hexStrToU64(theirField->second.c_str());
|
||||||
int64_t their = _strtoi64(theirField->second.c_str(),(char **)0,10);
|
uint64_t delta = Utils::hexStrToU64(deltaField->second.c_str());
|
||||||
int64_t delta = _strtoi64(deltaField->second.c_str(),(char **)0,10);
|
|
||||||
#else
|
|
||||||
int64_t my = strtoll(myField->second.c_str(),(char **)0,10);
|
|
||||||
int64_t their = strtoll(theirField->second.c_str(),(char **)0,10);
|
|
||||||
int64_t delta = strtoll(deltaField->second.c_str(),(char **)0,10);
|
|
||||||
#endif
|
|
||||||
if (my > their) {
|
if (my > their) {
|
||||||
if ((my - their) > delta)
|
if ((my - their) > delta)
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -91,49 +91,6 @@ public:
|
||||||
Certificate(const std::string &s) : Dictionary(s) {}
|
Certificate(const std::string &s) : Dictionary(s) {}
|
||||||
inline std::string toString() const { return Dictionary::toString(); }
|
inline std::string toString() const { return Dictionary::toString(); }
|
||||||
|
|
||||||
inline void setNetworkId(uint64_t id)
|
|
||||||
{
|
|
||||||
char buf[32];
|
|
||||||
Utils::snprintf(buf,sizeof(buf),"%.16llx",(unsigned long long)id);
|
|
||||||
(*this)["nwid"] = buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline uint64_t networkId() const
|
|
||||||
throw(std::invalid_argument)
|
|
||||||
{
|
|
||||||
#ifdef __WINDOWS__
|
|
||||||
return _strtoui64(get("nwid").c_str(),(char **)0,16);
|
|
||||||
#else
|
|
||||||
return strtoull(get("nwid").c_str(),(char **)0,16);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
inline void setPeerAddress(Address &a)
|
|
||||||
{
|
|
||||||
(*this)["peer"] = a.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Address peerAddress() const
|
|
||||||
throw(std::invalid_argument)
|
|
||||||
{
|
|
||||||
return Address(get("peer"));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set the timestamp and timestamp max-delta
|
|
||||||
*
|
|
||||||
* @param ts Timestamp in ms since epoch
|
|
||||||
* @param maxDelta Maximum difference between two peers on the same network
|
|
||||||
*/
|
|
||||||
inline void setTimestamp(uint64_t ts,uint64_t maxDelta)
|
|
||||||
{
|
|
||||||
char foo[32];
|
|
||||||
Utils::snprintf(foo,sizeof(foo),"%llu",(unsigned long long)ts);
|
|
||||||
(*this)["ts"] = foo;
|
|
||||||
Utils::snprintf(foo,sizeof(foo),"%llu",(unsigned long long)maxDelta);
|
|
||||||
(*this)["~ts"] = foo;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sign this certificate
|
* Sign this certificate
|
||||||
*
|
*
|
||||||
|
@ -381,7 +338,7 @@ public:
|
||||||
if (!Utils::scopy(tmp,sizeof(tmp),get("et","").c_str()))
|
if (!Utils::scopy(tmp,sizeof(tmp),get("et","").c_str()))
|
||||||
return et; // sanity check, packet can't really be that big
|
return et; // sanity check, packet can't really be that big
|
||||||
for(char *f=Utils::stok(tmp,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
|
for(char *f=Utils::stok(tmp,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
|
||||||
unsigned int t = Utils::strToUInt(f);
|
unsigned int t = Utils::hexStrToUInt(f);
|
||||||
if (t)
|
if (t)
|
||||||
et.insert(t);
|
et.insert(t);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue