diff options
author | Grant Limberg <glimberg@gmail.com> | 2015-05-21 19:14:49 -0700 |
---|---|---|
committer | Grant Limberg <glimberg@gmail.com> | 2015-05-21 19:14:49 -0700 |
commit | c430d88bd40d178685ac0a2e648d8c4ea675996c (patch) | |
tree | f69f497428fa34c6389173d39c889563dea9506c /controller/SqliteNetworkController.cpp | |
parent | 9a00366b18bc2bdb3ddf4345edcc7a459eb5ed60 (diff) | |
parent | d9006712f6ffc975d97097caf2d2b4264405b32c (diff) | |
download | infinitytier-c430d88bd40d178685ac0a2e648d8c4ea675996c.tar.gz infinitytier-c430d88bd40d178685ac0a2e648d8c4ea675996c.zip |
Merge branch 'adamierymenko-dev' into android-jni
Conflicts:
.gitignore
Diffstat (limited to 'controller/SqliteNetworkController.cpp')
-rw-r--r-- | controller/SqliteNetworkController.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/controller/SqliteNetworkController.cpp b/controller/SqliteNetworkController.cpp index 4ac40fc4..25a491dc 100644 --- a/controller/SqliteNetworkController.cpp +++ b/controller/SqliteNetworkController.cpp @@ -697,6 +697,37 @@ unsigned int SqliteNetworkController::handleControlPlaneHttpPOST( } else { if (!networkExists) { + if (path[1].substr(10) == "______") { + // A special POST /network/##########______ feature lets users create a network + // with an arbitrary unused network ID. + nwid = 0; + + uint64_t nwidPrefix = (Utils::hexStrToU64(path[1].substr(0,10).c_str()) << 24) & 0xffffffffff000000ULL; + uint64_t nwidPostfix = 0; + Utils::getSecureRandom(&nwidPostfix,sizeof(nwidPostfix)); + nwidPostfix &= 0xffffffULL; + uint64_t nwidOriginalPostfix = nwidPostfix; + do { + uint64_t tryNwid = nwidPrefix | nwidPostfix; + Utils::snprintf(nwids,sizeof(nwids),"%.16llx",(unsigned long long)tryNwid); + + sqlite3_reset(_sGetNetworkRevision); + sqlite3_bind_text(_sGetNetworkRevision,1,nwids,16,SQLITE_STATIC); + if (sqlite3_step(_sGetNetworkRevision) != SQLITE_ROW) { + nwid = tryNwid; + break; + } + + ++nwidPostfix; + nwidPostfix &= 0xffffffULL; + } while (nwidPostfix != nwidOriginalPostfix); + + // 503 means we have no more free IDs for this prefix. You shouldn't host anywhere + // near 16 million networks on the same controller, so shouldn't happen. + if (!nwid) + return 503; + } + sqlite3_reset(_sCreateNetwork); sqlite3_bind_text(_sCreateNetwork,1,nwids,16,SQLITE_STATIC); sqlite3_bind_text(_sCreateNetwork,2,nwids,16,SQLITE_STATIC); // default name, will be changed below if a name is specified in JSON |