Updated to 1.4.13 ;)
This commit is contained in:
@@ -201,9 +201,11 @@ shared_ptr<VirtualServer> VirtualServerManager::findServerByPort(uint16_t port)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint16_t VirtualServerManager::next_available_port() {
|
||||
uint16_t VirtualServerManager::next_available_port(const std::string& host_string) {
|
||||
auto instances = this->serverInstances();
|
||||
deque<uint16_t> unallowed_ports;
|
||||
std::vector<uint16_t> unallowed_ports{};
|
||||
unallowed_ports.reserve(instances.size());
|
||||
|
||||
for(const auto& instance : instances) {
|
||||
unallowed_ports.push_back(instance->properties()[property::VIRTUALSERVER_PORT].as<uint16_t>());
|
||||
|
||||
@@ -214,18 +216,39 @@ uint16_t VirtualServerManager::next_available_port() {
|
||||
}
|
||||
}
|
||||
}
|
||||
auto bindings = net::resolve_bindings(host_string, 0);
|
||||
|
||||
uint16_t port = config::voice::default_voice_port;
|
||||
while(true) {
|
||||
if(port < 1024) goto c;
|
||||
if(port < 1024) goto next_port;
|
||||
|
||||
for(auto& p : unallowed_ports) {
|
||||
if(p == port)
|
||||
goto c;
|
||||
goto next_port;
|
||||
}
|
||||
|
||||
for(auto& binding : bindings) {
|
||||
if(!std::get<2>(binding).empty()) continue; /* error on that */
|
||||
auto& baddress = std::get<1>(binding);
|
||||
auto& raw_port = baddress.ss_family == AF_INET ? ((sockaddr_in*) &baddress)->sin_port : ((sockaddr_in6*) &baddress)->sin6_port;
|
||||
raw_port = htons(port);
|
||||
|
||||
switch (net::address_available(baddress, net::binding_type::TCP)) {
|
||||
case net::binding_result::ADDRESS_USED:
|
||||
goto next_port;
|
||||
default:
|
||||
break; /* if we've an internal error we ignore it */
|
||||
}
|
||||
switch (net::address_available(baddress, net::binding_type::UDP)) {
|
||||
case net::binding_result::ADDRESS_USED:
|
||||
goto next_port;
|
||||
default:
|
||||
break; /* if we've an internal error we ignore it */
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
c:
|
||||
next_port:
|
||||
port++;
|
||||
}
|
||||
return port;
|
||||
@@ -317,6 +340,7 @@ shared_ptr<VirtualServer> VirtualServerManager::create_server(std::string hosts,
|
||||
if(!sid_success)
|
||||
return nullptr;
|
||||
|
||||
this->delete_server_in_db(serverId); /* just to ensure */
|
||||
sql::command(this->handle->getSql(), "INSERT INTO `servers` (`serverId`, `host`, `port`) VALUES (:sid, :host, :port)", variable{":sid", serverId}, variable{":host", hosts}, variable{":port", port}).executeLater().waitAndGetLater(LOG_SQL_CMD, {1, "future failed"});
|
||||
|
||||
auto prop_copy = sql::command(this->handle->getSql(), "INSERT INTO `properties` (`serverId`, `type`, `id`, `key`, `value`) SELECT :target_sid AS `serverId`, `type`, `id`, `key`, `value` FROM `properties` WHERE `type` = :type AND `id` = 0 AND `serverId` = 0;",
|
||||
|
||||
Reference in New Issue
Block a user