Loading src/authdb.cpp +56 −52 Changes for src/authdb.cpp: 56 added lines, 52 removed lines. Original line number Diff line number Diff line Loading @@ -489,14 +489,66 @@ int main(int argc,char *argv[]){ confplus::Config config(cmd.getCmdbyKey("config")->getValue()); authdb::AuthBackend backend(authdb::AuthBackendType::File, config.getValue(config.getKey("/AUTHDB/ADMINDB/PATH"),0), "admin.local" ); /* Determine backend type: cluster or file */ bool clusterEnabled = false; { auto *clusterEnable = config.getKey("/AUTHDB/CLUSTER/ENABLE"); if (clusterEnable && config.getValue(clusterEnable, 0) == "true") clusterEnabled = true; } try { std::string cert=config.getValue(config.getKey("/AUTHDB/SSL/CERT"),0); std::string key=config.getValue(config.getKey("/AUTHDB/SSL/KEY"),0); /* Cluster setup — must happen before backend is used */ authdb::Cluster cluster; if (clusterEnabled) { authdb::ClusterConfig ccfg; ccfg.bind_address = config.getValue(config.getKey("/AUTHDB/CLUSTER/BIND"), 0); ccfg.port = config.getIntValue(config.getKey("/AUTHDB/CLUSTER/PORT"), 0); ccfg.cert_file = cert; ccfg.key_file = key; auto *authName = config.getKey("/AUTHDB/CLUSTER/AUTH_NAME"); auto *authKey = config.getKey("/AUTHDB/CLUSTER/AUTH_KEY"); if (authName) ccfg.client_name = config.getValue(authName, 0); if (authKey) ccfg.client_key = config.getValue(authKey, 0); auto *dataBlocks = config.getKey("/AUTHDB/CLUSTER/DATA_BLOCKS"); auto *parityBlocks = config.getKey("/AUTHDB/CLUSTER/PARITY_BLOCKS"); if (dataBlocks) ccfg.data_blocks = config.getIntValue(dataBlocks, 0); if (parityBlocks) ccfg.parity_blocks = config.getIntValue(parityBlocks, 0); auto *peersKey = config.getKey("/AUTHDB/CLUSTER/PEERS"); if (peersKey) { for (int pi = 0; ; pi++) { try { std::string peerStr = config.getValue(peersKey, pi); if (peerStr.empty()) break; auto colon = peerStr.rfind(':'); if (colon != std::string::npos) { authdb::ClusterNode node; node.address = peerStr.substr(0, colon); node.port = std::stoi(peerStr.substr(colon + 1)); ccfg.peers.push_back(node); } } catch (...) { break; } } } cluster.init(ccfg); cluster.start(); authdb::g_Cluster = &cluster; std::cerr << "Cluster started on " << ccfg.bind_address << ":" << ccfg.port << " with " << ccfg.peers.size() << " peer(s)" << std::endl; } authdb::AuthBackend backend( clusterEnabled ? authdb::AuthBackendType::ClusterStore : authdb::AuthBackendType::File, clusterEnabled ? "" : config.getValue(config.getKey("/AUTHDB/ADMINDB/PATH"),0), "admin.local" ); libhttppp::HttpD httpd( config.getValue(config.getKey("/AUTHDB/BIND"),0), config.getIntValue(config.getKey("/AUTHDB/PORT"),0), Loading Loading @@ -596,54 +648,6 @@ int main(int argc,char *argv[]){ } #endif /* Cluster setup (optional) */ authdb::Cluster cluster; { auto *clusterEnable = config.getKey("/AUTHDB/CLUSTER/ENABLE"); if (clusterEnable && config.getValue(clusterEnable, 0) == "true") { authdb::ClusterConfig ccfg; ccfg.bind_address = config.getValue(config.getKey("/AUTHDB/CLUSTER/BIND"), 0); ccfg.port = config.getIntValue(config.getKey("/AUTHDB/CLUSTER/PORT"), 0); ccfg.cert_file = cert; ccfg.key_file = key; auto *authName = config.getKey("/AUTHDB/CLUSTER/AUTH_NAME"); auto *authKey = config.getKey("/AUTHDB/CLUSTER/AUTH_KEY"); if (authName) ccfg.client_name = config.getValue(authName, 0); if (authKey) ccfg.client_key = config.getValue(authKey, 0); auto *dataBlocks = config.getKey("/AUTHDB/CLUSTER/DATA_BLOCKS"); auto *parityBlocks = config.getKey("/AUTHDB/CLUSTER/PARITY_BLOCKS"); if (dataBlocks) ccfg.data_blocks = config.getIntValue(dataBlocks, 0); if (parityBlocks) ccfg.parity_blocks = config.getIntValue(parityBlocks, 0); /* Read peer list: /AUTHDB/CLUSTER/PEERS/0..N */ auto *peersKey = config.getKey("/AUTHDB/CLUSTER/PEERS"); if (peersKey) { for (int pi = 0; ; pi++) { try { std::string peerStr = config.getValue(peersKey, pi); if (peerStr.empty()) break; /* Format: address:port */ auto colon = peerStr.rfind(':'); if (colon != std::string::npos) { authdb::ClusterNode node; node.address = peerStr.substr(0, colon); node.port = std::stoi(peerStr.substr(colon + 1)); ccfg.peers.push_back(node); } } catch (...) { break; } } } cluster.init(ccfg); cluster.start(); authdb::g_Cluster = &cluster; std::cerr << "Cluster started on " << ccfg.bind_address << ":" << ccfg.port << " with " << ccfg.peers.size() << " peer(s)" << std::endl; } } authdb.runEventloop(); /* Shutdown cluster */ Loading src/backend.cpp +3 −3 Changes for src/backend.cpp: 3 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ authdb::AuthBackend::AuthBackend(int type, const std::string &options,const std: _Type=type; if(_Type==AuthBackendType::File){ _Api = new class File(_Options.c_str(),VERSION,_Domain.c_str()); }else if(_Type==AuthBackendType::Cluster){ }else if(_Type==AuthBackendType::ClusterStore){ _Api = new class ClusterBackend(_Domain.c_str(),VERSION); }else{ throw AuthBackendError("unkown file backend"); Loading @@ -45,7 +45,7 @@ authdb::AuthBackend::AuthBackend(const AuthBackend &backend){ _Type=backend._Type; if(_Type==AuthBackendType::File){ _Api = new class File(backend._Options.c_str(),VERSION,backend._Domain.c_str()); }else if(_Type==AuthBackendType::Cluster){ }else if(_Type==AuthBackendType::ClusterStore){ _Api = new class ClusterBackend(backend._Domain.c_str(),VERSION); } } Loading @@ -53,7 +53,7 @@ authdb::AuthBackend::AuthBackend(const AuthBackend &backend){ authdb::AuthBackend::~AuthBackend(){ if(_Type==AuthBackendType::File){ delete (class File*) _Api; }else if(_Type==AuthBackendType::Cluster){ }else if(_Type==AuthBackendType::ClusterStore){ delete (class ClusterBackend*) _Api; } } Loading src/backend.h +1 −1 Changes for src/backend.h: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ namespace authdb{ enum AuthBackendType{ File=0, Ceph=1, Cluster=2 ClusterStore=2 }; class VISIBILITY AuthBackendApi { Loading Loading
src/authdb.cpp +56 −52 Changes for src/authdb.cpp: 56 added lines, 52 removed lines. Original line number Diff line number Diff line Loading @@ -489,14 +489,66 @@ int main(int argc,char *argv[]){ confplus::Config config(cmd.getCmdbyKey("config")->getValue()); authdb::AuthBackend backend(authdb::AuthBackendType::File, config.getValue(config.getKey("/AUTHDB/ADMINDB/PATH"),0), "admin.local" ); /* Determine backend type: cluster or file */ bool clusterEnabled = false; { auto *clusterEnable = config.getKey("/AUTHDB/CLUSTER/ENABLE"); if (clusterEnable && config.getValue(clusterEnable, 0) == "true") clusterEnabled = true; } try { std::string cert=config.getValue(config.getKey("/AUTHDB/SSL/CERT"),0); std::string key=config.getValue(config.getKey("/AUTHDB/SSL/KEY"),0); /* Cluster setup — must happen before backend is used */ authdb::Cluster cluster; if (clusterEnabled) { authdb::ClusterConfig ccfg; ccfg.bind_address = config.getValue(config.getKey("/AUTHDB/CLUSTER/BIND"), 0); ccfg.port = config.getIntValue(config.getKey("/AUTHDB/CLUSTER/PORT"), 0); ccfg.cert_file = cert; ccfg.key_file = key; auto *authName = config.getKey("/AUTHDB/CLUSTER/AUTH_NAME"); auto *authKey = config.getKey("/AUTHDB/CLUSTER/AUTH_KEY"); if (authName) ccfg.client_name = config.getValue(authName, 0); if (authKey) ccfg.client_key = config.getValue(authKey, 0); auto *dataBlocks = config.getKey("/AUTHDB/CLUSTER/DATA_BLOCKS"); auto *parityBlocks = config.getKey("/AUTHDB/CLUSTER/PARITY_BLOCKS"); if (dataBlocks) ccfg.data_blocks = config.getIntValue(dataBlocks, 0); if (parityBlocks) ccfg.parity_blocks = config.getIntValue(parityBlocks, 0); auto *peersKey = config.getKey("/AUTHDB/CLUSTER/PEERS"); if (peersKey) { for (int pi = 0; ; pi++) { try { std::string peerStr = config.getValue(peersKey, pi); if (peerStr.empty()) break; auto colon = peerStr.rfind(':'); if (colon != std::string::npos) { authdb::ClusterNode node; node.address = peerStr.substr(0, colon); node.port = std::stoi(peerStr.substr(colon + 1)); ccfg.peers.push_back(node); } } catch (...) { break; } } } cluster.init(ccfg); cluster.start(); authdb::g_Cluster = &cluster; std::cerr << "Cluster started on " << ccfg.bind_address << ":" << ccfg.port << " with " << ccfg.peers.size() << " peer(s)" << std::endl; } authdb::AuthBackend backend( clusterEnabled ? authdb::AuthBackendType::ClusterStore : authdb::AuthBackendType::File, clusterEnabled ? "" : config.getValue(config.getKey("/AUTHDB/ADMINDB/PATH"),0), "admin.local" ); libhttppp::HttpD httpd( config.getValue(config.getKey("/AUTHDB/BIND"),0), config.getIntValue(config.getKey("/AUTHDB/PORT"),0), Loading Loading @@ -596,54 +648,6 @@ int main(int argc,char *argv[]){ } #endif /* Cluster setup (optional) */ authdb::Cluster cluster; { auto *clusterEnable = config.getKey("/AUTHDB/CLUSTER/ENABLE"); if (clusterEnable && config.getValue(clusterEnable, 0) == "true") { authdb::ClusterConfig ccfg; ccfg.bind_address = config.getValue(config.getKey("/AUTHDB/CLUSTER/BIND"), 0); ccfg.port = config.getIntValue(config.getKey("/AUTHDB/CLUSTER/PORT"), 0); ccfg.cert_file = cert; ccfg.key_file = key; auto *authName = config.getKey("/AUTHDB/CLUSTER/AUTH_NAME"); auto *authKey = config.getKey("/AUTHDB/CLUSTER/AUTH_KEY"); if (authName) ccfg.client_name = config.getValue(authName, 0); if (authKey) ccfg.client_key = config.getValue(authKey, 0); auto *dataBlocks = config.getKey("/AUTHDB/CLUSTER/DATA_BLOCKS"); auto *parityBlocks = config.getKey("/AUTHDB/CLUSTER/PARITY_BLOCKS"); if (dataBlocks) ccfg.data_blocks = config.getIntValue(dataBlocks, 0); if (parityBlocks) ccfg.parity_blocks = config.getIntValue(parityBlocks, 0); /* Read peer list: /AUTHDB/CLUSTER/PEERS/0..N */ auto *peersKey = config.getKey("/AUTHDB/CLUSTER/PEERS"); if (peersKey) { for (int pi = 0; ; pi++) { try { std::string peerStr = config.getValue(peersKey, pi); if (peerStr.empty()) break; /* Format: address:port */ auto colon = peerStr.rfind(':'); if (colon != std::string::npos) { authdb::ClusterNode node; node.address = peerStr.substr(0, colon); node.port = std::stoi(peerStr.substr(colon + 1)); ccfg.peers.push_back(node); } } catch (...) { break; } } } cluster.init(ccfg); cluster.start(); authdb::g_Cluster = &cluster; std::cerr << "Cluster started on " << ccfg.bind_address << ":" << ccfg.port << " with " << ccfg.peers.size() << " peer(s)" << std::endl; } } authdb.runEventloop(); /* Shutdown cluster */ Loading
src/backend.cpp +3 −3 Changes for src/backend.cpp: 3 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ authdb::AuthBackend::AuthBackend(int type, const std::string &options,const std: _Type=type; if(_Type==AuthBackendType::File){ _Api = new class File(_Options.c_str(),VERSION,_Domain.c_str()); }else if(_Type==AuthBackendType::Cluster){ }else if(_Type==AuthBackendType::ClusterStore){ _Api = new class ClusterBackend(_Domain.c_str(),VERSION); }else{ throw AuthBackendError("unkown file backend"); Loading @@ -45,7 +45,7 @@ authdb::AuthBackend::AuthBackend(const AuthBackend &backend){ _Type=backend._Type; if(_Type==AuthBackendType::File){ _Api = new class File(backend._Options.c_str(),VERSION,backend._Domain.c_str()); }else if(_Type==AuthBackendType::Cluster){ }else if(_Type==AuthBackendType::ClusterStore){ _Api = new class ClusterBackend(backend._Domain.c_str(),VERSION); } } Loading @@ -53,7 +53,7 @@ authdb::AuthBackend::AuthBackend(const AuthBackend &backend){ authdb::AuthBackend::~AuthBackend(){ if(_Type==AuthBackendType::File){ delete (class File*) _Api; }else if(_Type==AuthBackendType::Cluster){ }else if(_Type==AuthBackendType::ClusterStore){ delete (class ClusterBackend*) _Api; } } Loading
src/backend.h +1 −1 Changes for src/backend.h: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ namespace authdb{ enum AuthBackendType{ File=0, Ceph=1, Cluster=2 ClusterStore=2 }; class VISIBILITY AuthBackendApi { Loading