mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-09-09 08:12:52 +02:00
append 8 random hex chars to the subscription id
This commit is contained in:
parent
f51bfdb666
commit
88f08fa58c
3 changed files with 19 additions and 1 deletions
|
@ -80,6 +80,21 @@ std::string url_encode(const std::string& value)
|
|||
return escaped.str();
|
||||
}
|
||||
|
||||
std::string random_hex_string(std::size_t length)
|
||||
{
|
||||
static const char hex_chars[] = "0123456789abcdef";
|
||||
std::random_device rd;
|
||||
std::mt19937 gen(rd());
|
||||
std::uniform_int_distribution<> dis(0, 15);
|
||||
|
||||
std::string result;
|
||||
result.reserve(length);
|
||||
for (std::size_t i = 0; i < length; ++i) {
|
||||
result += hex_chars[dis(gen)];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef ZT1_CENTRAL_CONTROLLER
|
||||
void create_gcp_pubsub_topic_if_needed(std::string project_id, std::string topic_id)
|
||||
{
|
||||
|
|
|
@ -16,8 +16,10 @@ std::vector<std::string> split(std::string str, char delim);
|
|||
|
||||
std::string url_encode(const std::string& value);
|
||||
|
||||
std::string random_hex_string(std::size_t length)
|
||||
|
||||
#ifdef ZT1_CENTRAL_CONTROLLER
|
||||
void create_gcp_pubsub_topic_if_needed(std::string project_id, std::string topic_id);
|
||||
void create_gcp_pubsub_topic_if_needed(std::string project_id, std::string topic_id);
|
||||
#endif
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
|
|
@ -35,6 +35,7 @@ PubSubListener::PubSubListener(std::string controller_id, std::string project, s
|
|||
, _adminClient(pubsub_admin::MakeSubscriptionAdminConnection())
|
||||
, _subscription(pubsub::Subscription(_project, _subscription_id))
|
||||
{
|
||||
_subscription_id = _subscription_id + "-" + random_hex_string(8);
|
||||
fprintf(
|
||||
stderr, "PubSubListener for controller %s project %s topic %s subscription %s\n", controller_id.c_str(),
|
||||
project.c_str(), topic.c_str(), _subscription_id.c_str());
|
||||
|
|
Loading…
Add table
Reference in a new issue