mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-05 03:53:44 +02:00
look up hook URLs dynamically
This commit is contained in:
parent
0dc92c2d7b
commit
88b96265d7
2 changed files with 46 additions and 8 deletions
|
@ -1425,14 +1425,7 @@ void PostgreSQL::commitThread()
|
||||||
w.commit();
|
w.commit();
|
||||||
|
|
||||||
if (_smee != NULL && isNewMember) {
|
if (_smee != NULL && isNewMember) {
|
||||||
// TODO: Look up hook URL for network owner organization
|
notifyNewMember(networkId, memberId);
|
||||||
smeeclient::smee_client_notify_network_joined(
|
|
||||||
_smee,
|
|
||||||
networkId.c_str(),
|
|
||||||
memberId.c_str(),
|
|
||||||
"http://hookcatcher:9999/hook",
|
|
||||||
NULL
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint64_t nwidInt = OSUtils::jsonIntHex(config["nwid"], 0ULL);
|
const uint64_t nwidInt = OSUtils::jsonIntHex(config["nwid"], 0ULL);
|
||||||
|
@ -1678,6 +1671,50 @@ void PostgreSQL::commitThread()
|
||||||
fprintf(stderr, "%s commitThread finished\n", _myAddressStr.c_str());
|
fprintf(stderr, "%s commitThread finished\n", _myAddressStr.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PostgreSQL::notifyNewMember(const std::string &networkID, const std::string &memberID) {
|
||||||
|
// TODO: Look up hook URL for network owner organization
|
||||||
|
|
||||||
|
std::shared_ptr<PostgresConnection> c;
|
||||||
|
try {
|
||||||
|
c = _pool->borrow();
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
pqxx::work w(*c->c);
|
||||||
|
|
||||||
|
// TODO: Add check for active subscription
|
||||||
|
|
||||||
|
auto res = w.exec_params("SELECT h.hook_url "
|
||||||
|
"FROM ztc_hook h "
|
||||||
|
"INNER JOIN ztc_org o "
|
||||||
|
"ON o.org_id = h.org_id "
|
||||||
|
"INNER JOIN ztc_user u "
|
||||||
|
"ON u.id = o.owner_id "
|
||||||
|
"INNER JOIN ztc_network n "
|
||||||
|
"ON n.owner_id = u.id "
|
||||||
|
"WHERE n.id = $1", networkID);
|
||||||
|
|
||||||
|
for (auto const &row: res) {
|
||||||
|
std::string hookURL = row[0].as<std::string>();
|
||||||
|
smeeclient::smee_client_notify_network_joined(
|
||||||
|
_smee,
|
||||||
|
networkID.c_str(),
|
||||||
|
memberID.c_str(),
|
||||||
|
hookURL.c_str(),
|
||||||
|
NULL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
_pool->unborrow(c);
|
||||||
|
} catch (std::exception &e) {
|
||||||
|
fprintf(stderr, "ERROR: %s\n", e.what());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PostgreSQL::onlineNotificationThread()
|
void PostgreSQL::onlineNotificationThread()
|
||||||
{
|
{
|
||||||
waitForReady();
|
waitForReady();
|
||||||
|
|
|
@ -149,6 +149,7 @@ private:
|
||||||
std::unordered_map< std::pair<uint64_t,uint64_t>,std::pair<int64_t,InetAddress>,_PairHasher > &lastOnline);
|
std::unordered_map< std::pair<uint64_t,uint64_t>,std::pair<int64_t,InetAddress>,_PairHasher > &lastOnline);
|
||||||
|
|
||||||
void configureSmee();
|
void configureSmee();
|
||||||
|
void notifyNewMember(const std::string &networkID, const std::string &memberID);
|
||||||
|
|
||||||
enum OverrideMode {
|
enum OverrideMode {
|
||||||
ALLOW_PGBOUNCER_OVERRIDE = 0,
|
ALLOW_PGBOUNCER_OVERRIDE = 0,
|
||||||
|
|
Loading…
Add table
Reference in a new issue