diff --git a/controller/EmbeddedNetworkController.cpp b/controller/EmbeddedNetworkController.cpp index baed88e6c..b20c1365e 100644 --- a/controller/EmbeddedNetworkController.cpp +++ b/controller/EmbeddedNetworkController.cpp @@ -456,8 +456,9 @@ static bool _parseRule(json &r,ZT_VirtualNetworkRule &rule) } // anonymous namespace -EmbeddedNetworkController::EmbeddedNetworkController(Node *node,const char *dbPath) : +EmbeddedNetworkController::EmbeddedNetworkController(Node *node,const char *dbPath, int listenPort) : _startTime(OSUtils::now()), + _listenPort(listenPort), _node(node), _path(dbPath), _sender((NetworkController::Sender *)0) @@ -480,7 +481,7 @@ void EmbeddedNetworkController::init(const Identity &signingId,Sender *sender) _signingIdAddressString = signingId.address().toString(tmp); #ifdef ZT_CONTROLLER_USE_LIBPQ if ((_path.length() > 9)&&(_path.substr(0,9) == "postgres:")) - _db.reset(new PostgreSQL(this,_signingId,_path.substr(9).c_str())); + _db.reset(new PostgreSQL(this,_signingId,_path.substr(9).c_str(), _listenPort)); else // else use FileDB after endif #endif _db.reset(new FileDB(this,_signingId,_path.c_str())); diff --git a/controller/EmbeddedNetworkController.hpp b/controller/EmbeddedNetworkController.hpp index c3f121c54..14ee9d045 100644 --- a/controller/EmbeddedNetworkController.hpp +++ b/controller/EmbeddedNetworkController.hpp @@ -59,7 +59,7 @@ public: * @param node Parent node * @param dbPath Database path (file path or database credentials) */ - EmbeddedNetworkController(Node *node,const char *dbPath); + EmbeddedNetworkController(Node *node,const char *dbPath, int listenPort); virtual ~EmbeddedNetworkController(); virtual void init(const Identity &signingId,Sender *sender); @@ -141,6 +141,7 @@ private: }; const int64_t _startTime; + int _listenPort; Node *const _node; std::string _path; Identity _signingId; diff --git a/controller/PostgreSQL.cpp b/controller/PostgreSQL.cpp index db0537ec9..6d284d425 100644 --- a/controller/PostgreSQL.cpp +++ b/controller/PostgreSQL.cpp @@ -64,12 +64,13 @@ std::string join(const std::vector &elements, const char * const se using namespace ZeroTier; -PostgreSQL::PostgreSQL(EmbeddedNetworkController *const nc, const Identity &myId, const char *path) +PostgreSQL::PostgreSQL(EmbeddedNetworkController *const nc, const Identity &myId, const char *path, int listenPort) : DB(nc, myId, path) , _ready(0) , _connected(1) , _run(1) , _waitNoticePrinted(false) + , _listenPort(listenPort) { _connString = std::string(path) + " application_name=controller_" +_myAddressStr; diff --git a/controller/PostgreSQL.hpp b/controller/PostgreSQL.hpp index a20bfe992..6f1daa758 100644 --- a/controller/PostgreSQL.hpp +++ b/controller/PostgreSQL.hpp @@ -41,7 +41,7 @@ namespace ZeroTier class PostgreSQL : public DB { public: - PostgreSQL(EmbeddedNetworkController *const nc, const Identity &myId, const char *path); + PostgreSQL(EmbeddedNetworkController *const nc, const Identity &myId, const char *path, int listenPort); virtual ~PostgreSQL(); virtual bool waitForReady(); @@ -90,6 +90,8 @@ private: mutable std::mutex _readyLock; std::atomic _ready, _connected, _run; mutable volatile bool _waitNoticePrinted; + + int _listenPort; }; } diff --git a/service/OneService.cpp b/service/OneService.cpp index 69bbfeb09..718b54d41 100644 --- a/service/OneService.cpp +++ b/service/OneService.cpp @@ -805,7 +805,7 @@ public: OSUtils::rmDashRf((_homePath + ZT_PATH_SEPARATOR_S "iddb.d").c_str()); // Network controller is now enabled by default for desktop and server - _controller = new EmbeddedNetworkController(_node,_controllerDbPath.c_str()); + _controller = new EmbeddedNetworkController(_node,_controllerDbPath.c_str(),_ports[0]); _node->setNetconfMaster((void *)_controller); // Join existing networks in networks.d