mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-09 04:04:13 +00:00
Network preferred relay stuff in netconf controller.
This commit is contained in:
parent
8a13cfdace
commit
ed107c4daf
@ -105,12 +105,13 @@ SqliteNetworkController::SqliteNetworkController(const char *dbPath) :
|
||||
||(sqlite3_prepare_v2(_db,"UPDATE Member SET clientReportedRevision = ? WHERE rowid = ?",-1,&_sUpdateMemberClientReportedRevision,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT etherType FROM Rule WHERE networkId = ? AND \"action\" = 'accept'",-1,&_sGetEtherTypesFromRuleTable,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT mgMac,mgAdi,preload,maxBalance,accrual FROM MulticastRate WHERE networkId = ?",-1,&_sGetMulticastRates,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT nodeId FROM Member WHERE networkId = ? AND authorized > 0 AND activeBridge > 0",-1,&_sGetActiveBridges,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT nodeId FROM Member WHERE networkId = ? AND activeBridge > 0 AND authorized > 0",-1,&_sGetActiveBridges,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT DISTINCT ip,ipNetmaskBits FROM IpAssignment WHERE networkId = ? AND nodeId = ? AND ipVersion = ?",-1,&_sGetIpAssignmentsForNode,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT DISTINCT ipNetwork,ipNetmaskBits FROM IpAssignmentPool WHERE networkId = ? AND ipVersion = ? AND active > 0",-1,&_sGetIpAssignmentPools,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT 1 FROM IpAssignment WHERE networkId = ? AND ip = ? AND ipVersion = ?",-1,&_sCheckIfIpIsAllocated,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"INSERT INTO IpAssignment (networkId,nodeId,ip,ipNetmaskBits,ipVersion) VALUES (?,?,?,?,?)",-1,&_sAllocateIp,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"UPDATE Member SET cachedNetconf = ?,cachedNetconfRevision = ? WHERE rowid = ?",-1,&_sCacheNetconf,(const char **)0) != SQLITE_OK)
|
||||
||(sqlite3_prepare_v2(_db,"SELECT DISTINCT nodeId,address FROM Relay WHERE networkId = ?",-1,&_sGetRelays,(const char **)0) != SQLITE_OK)
|
||||
) {
|
||||
sqlite3_close(_db);
|
||||
throw std::runtime_error("SqliteNetworkController unable to initialize one or more prepared statements");
|
||||
@ -137,6 +138,7 @@ SqliteNetworkController::~SqliteNetworkController()
|
||||
sqlite3_finalize(_sCheckIfIpIsAllocated);
|
||||
sqlite3_finalize(_sAllocateIp);
|
||||
sqlite3_finalize(_sCacheNetconf);
|
||||
sqlite3_finalize(_sGetRelays);
|
||||
sqlite3_close(_db);
|
||||
}
|
||||
}
|
||||
@ -389,6 +391,29 @@ NetworkController::ResultCode SqliteNetworkController::doNetworkConfigRequest(co
|
||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_ACTIVE_BRIDGES] = activeBridges;
|
||||
}
|
||||
|
||||
{
|
||||
std::string relays;
|
||||
sqlite3_reset(_sGetRelays);
|
||||
sqlite3_bind_text(_sGetRelays,1,network.id,16,SQLITE_STATIC);
|
||||
while (sqlite3_step(_sGetRelays) == SQLITE_ROW) {
|
||||
const char *n = (const char *)sqlite3_column_text(_sGetRelays,0);
|
||||
const char *a = (const char *)sqlite3_column_text(_sGetRelays,1);
|
||||
if ((n)&&(a)) {
|
||||
Address node(n);
|
||||
InetAddress addr(a);
|
||||
if ((node)&&(addr)) {
|
||||
if (relays.length())
|
||||
relays.push_back(',');
|
||||
relays.append(node.toString());
|
||||
relays.push_back(';');
|
||||
relays.append(addr.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (relays.length())
|
||||
netconf[ZT_NETWORKCONFIG_DICT_KEY_RELAYS] = relays;
|
||||
}
|
||||
|
||||
if ((network.v4AssignMode)&&(!strcmp(network.v4AssignMode,"zt"))) {
|
||||
std::string v4s;
|
||||
|
||||
|
@ -81,6 +81,7 @@ private:
|
||||
sqlite3_stmt *_sCheckIfIpIsAllocated;
|
||||
sqlite3_stmt *_sAllocateIp;
|
||||
sqlite3_stmt *_sCacheNetconf;
|
||||
sqlite3_stmt *_sGetRelays;
|
||||
|
||||
Mutex _lock;
|
||||
|
||||
|
@ -40,6 +40,8 @@ CREATE TABLE Member (
|
||||
|
||||
CREATE INDEX Member_networkId ON Member (networkId);
|
||||
|
||||
CREATE INDEX Member_networkId_activeBridge ON Member(networkId, activeBridge);
|
||||
|
||||
CREATE UNIQUE INDEX Member_networkId_nodeId ON Member (networkId, nodeId);
|
||||
|
||||
CREATE TABLE MulticastRate (
|
||||
@ -68,7 +70,8 @@ CREATE TABLE Network (
|
||||
|
||||
CREATE TABLE Relay (
|
||||
networkId char(16) NOT NULL,
|
||||
nodeId char(10) NOT NULL
|
||||
nodeId char(10) NOT NULL,
|
||||
address varchar(64) NOT NULL
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX Relay_networkId_nodeId ON Relay (networkId, nodeId);
|
||||
|
@ -41,6 +41,8 @@
|
||||
"\n"\
|
||||
"CREATE INDEX Member_networkId ON Member (networkId);\n"\
|
||||
"\n"\
|
||||
"CREATE INDEX Member_networkId_activeBridge ON Member(networkId, activeBridge);\n"\
|
||||
"\n"\
|
||||
"CREATE UNIQUE INDEX Member_networkId_nodeId ON Member (networkId, nodeId);\n"\
|
||||
"\n"\
|
||||
"CREATE TABLE MulticastRate (\n"\
|
||||
@ -69,7 +71,8 @@
|
||||
"\n"\
|
||||
"CREATE TABLE Relay (\n"\
|
||||
" networkId char(16) NOT NULL,\n"\
|
||||
" nodeId char(10) NOT NULL\n"\
|
||||
" nodeId char(10) NOT NULL,\n"\
|
||||
" address varchar(64) NOT NULL\n"\
|
||||
");\n"\
|
||||
"\n"\
|
||||
"CREATE UNIQUE INDEX Relay_networkId_nodeId ON Relay (networkId, nodeId);\n"\
|
||||
|
Loading…
x
Reference in New Issue
Block a user