Fle server & Query server improvements

This commit is contained in:
WolverinDEV 2019-07-21 10:43:26 +02:00
parent d9ddc2c06d
commit a0cca36eca
5 changed files with 77 additions and 5 deletions

View File

@ -7,7 +7,7 @@
using namespace ts;
const std::vector<ErrorType> ts::avariableErrors = {
{0x0000, "ok" , "ok" },
{0x0000, "ok" , "ok" },
{0x0001, "undefined" , "undefined error" },
{0x0002, "not_implemented" , "not implemented" },
{0x0005, "lib_time_limit_reached" , "library time limit reached" },
@ -149,7 +149,10 @@ const std::vector<ErrorType> ts::avariableErrors = {
{0x1200, "query_not_exists" , "query account does not exists" },
{0x1201, "query_already_exists" , "query account already exists" },
{0x1202, "query_too_many_simultaneously_sessions", "too many simultaneously connected sessions" },
{0x1203, "query_maxclients_reached" , "query server reached its limit" },
{0xE000, "resource_limit_reached" , "resource limit reached" },
{0xFFFF, "custom_error" , "costume" },
};

View File

@ -427,15 +427,18 @@ namespace ts {
make_shared<PropertyDescription>(V(CONNECTION_FILETRANSFER_BYTES_SENT_TOTAL, FLAG_CLIENT_INFO)) //how many bytes we sent in total through file transfers
};
array<shared_ptr<PropertyDescription>, InstanceProperties::SERVERINSTANCE_ENDMARKER> instance_info = {
make_shared<PropertyDescription>(SERVERINSTANCE_UNDEFINED, "SERVERINSTANCE_UNDEFINED", "undefined", TYPE_UNKNOWN, 0),
make_shared<PropertyDescription>(SERVERINSTANCE_DATABASE_VERSION, "SERVERINSTANCE_DATABASE_VERSION", "0", TYPE_UNSIGNED_NUMBER, FLAG_INSTANCE_VARIABLE),
make_shared<PropertyDescription>(SERVERINSTANCE_PERMISSIONS_VERSION, "SERVERINSTANCE_PERMISSIONS_VERSION", "0", TYPE_UNSIGNED_NUMBER, FLAG_INSTANCE_VARIABLE),
make_shared<PropertyDescription>(SERVERINSTANCE_FILETRANSFER_HOST, "SERVERINSTANCE_FILETRANSFER_HOST", "0.0.0.0", TYPE_STRING, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),
make_shared<PropertyDescription>(SERVERINSTANCE_FILETRANSFER_HOST, "SERVERINSTANCE_FILETRANSFER_HOST", "0.0.0.0,[::]", TYPE_STRING, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),
make_shared<PropertyDescription>(SERVERINSTANCE_FILETRANSFER_PORT, "SERVERINSTANCE_FILETRANSFER_PORT", "30303", TYPE_UNSIGNED_NUMBER, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),
make_shared<PropertyDescription>(SERVERINSTANCE_QUERY_HOST, "SERVERINSTANCE_QUERY_HOST", "0.0.0.0", TYPE_STRING, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),
make_shared<PropertyDescription>(SERVERINSTANCE_FILETRANSFER_MAX_CONNECTIONS, "SERVERINSTANCE_FILETRANSFER_MAX_CONNECTIONS", "100", TYPE_UNSIGNED_NUMBER, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),
make_shared<PropertyDescription>(SERVERINSTANCE_FILETRANSFER_MAX_CONNECTIONS_PER_IP, "SERVERINSTANCE_FILETRANSFER_MAX_CONNECTIONS_PER_IP", "20", TYPE_UNSIGNED_NUMBER, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),
make_shared<PropertyDescription>(SERVERINSTANCE_QUERY_HOST, "SERVERINSTANCE_QUERY_HOST", "0.0.0.0,[::]", TYPE_STRING, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),
make_shared<PropertyDescription>(SERVERINSTANCE_QUERY_PORT, "SERVERINSTANCE_QUERY_PORT", "10101", TYPE_UNSIGNED_NUMBER, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),
make_shared<PropertyDescription>(SERVERINSTANCE_QUERY_MAX_CONNECTIONS, "SERVERINSTANCE_QUERY_MAX_CONNECTIONS", "100", TYPE_UNSIGNED_NUMBER, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),
make_shared<PropertyDescription>(SERVERINSTANCE_QUERY_MAX_CONNECTIONS_PER_IP, "SERVERINSTANCE_QUERY_MAX_CONNECTIONS_PER_IP", "1", TYPE_UNSIGNED_NUMBER, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),
make_shared<PropertyDescription>(SERVERINSTANCE_MONTHLY_TIMESTAMP, "SERVERINSTANCE_MONTHLY_TIMESTAMP", "0", TYPE_UNSIGNED_NUMBER, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),
make_shared<PropertyDescription>(SERVERINSTANCE_MAX_DOWNLOAD_TOTAL_BANDWIDTH, "SERVERINSTANCE_MAX_DOWNLOAD_TOTAL_BANDWIDTH", "-1", TYPE_SIGNED_NUMBER, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),
make_shared<PropertyDescription>(SERVERINSTANCE_MAX_UPLOAD_TOTAL_BANDWIDTH, "SERVERINSTANCE_MAX_UPLOAD_TOTAL_BANDWIDTH", "-1", TYPE_SIGNED_NUMBER, FLAG_INSTANCE_VARIABLE | FLAG_SAVE),

View File

@ -88,8 +88,14 @@ namespace ts {
SERVERINSTANCE_DATABASE_VERSION = SERVERINSTANCE_BEGINMARKER,
SERVERINSTANCE_FILETRANSFER_HOST,
SERVERINSTANCE_FILETRANSFER_PORT,
SERVERINSTANCE_FILETRANSFER_MAX_CONNECTIONS,
SERVERINSTANCE_FILETRANSFER_MAX_CONNECTIONS_PER_IP,
SERVERINSTANCE_QUERY_HOST,
SERVERINSTANCE_QUERY_PORT,
SERVERINSTANCE_QUERY_MAX_CONNECTIONS,
SERVERINSTANCE_QUERY_MAX_CONNECTIONS_PER_IP,
SERVERINSTANCE_MONTHLY_TIMESTAMP,
SERVERINSTANCE_MAX_DOWNLOAD_TOTAL_BANDWIDTH,
SERVERINSTANCE_MAX_UPLOAD_TOTAL_BANDWIDTH,

View File

@ -2,6 +2,8 @@
#include <string>
#include <cstring>
#include <deque>
#include <vector>
#ifdef WIN32
#include <WS2tcpip.h>
@ -191,10 +193,68 @@ namespace net {
if(!record) return false;
s.sin6_addr = *(in6_addr*) record->h_addr;
memcpy(&result, &s, sizeof(s));
return true;
} else if(address == "[::]" || address == "::") {
sockaddr_in6 s{};
s.sin6_family = AF_INET6;
s.sin6_port = 0;
s.sin6_flowinfo = 0;
s.sin6_scope_id = 0;
memcpy(&s.sin6_addr, &in6addr_any, sizeof(in6_addr));
memcpy(&result, &s, sizeof(s));
return true;
}
return false;
}
namespace helpers {
inline void strip(std::string& message) {
while(!message.empty()) {
if(message[0] == ' ')
message = message.substr(1);
else if(message[message.length() - 1] == ' ')
message = message.substr(0, message.length() - 1);
else break;
}
}
inline std::deque<std::string> split(const std::string& message, char delimiter) {
std::deque<std::string> result{};
size_t found, index = 0;
do {
found = message.find(delimiter, index);
result.push_back(message.substr(index, found - index));
index = found + 1;
} while(index != 0);
return result;
}
}
inline std::vector<std::tuple<std::string, sockaddr_storage, std::string>> resolve_bindings(const std::string& bindings, uint16_t port) {
auto binding_list = helpers::split(bindings, ',');
std::vector<std::tuple<std::string, sockaddr_storage, std::string>> result;
result.reserve(binding_list.size());
for(auto& address : binding_list) {
helpers::strip(address);
sockaddr_storage element{};
memset(&element, 0, sizeof(element));
if(!resolve_address(address, element)) {
result.emplace_back(address, element, "address resolve failed");
continue;
}
if(element.ss_family == AF_INET) {
((sockaddr_in*) &element)->sin_port = htons(port);
} else if(element.ss_family == AF_INET6) {
((sockaddr_in6*) &element)->sin6_port = htons(port);
}
result.emplace_back(address, element, "");
}
return result;
}
}

View File

@ -94,7 +94,7 @@ bool AcknowledgeManager::process_acknowledge(const ts::protocol::BasicPacket &pa
auto time = system_clock::now() - entry->next_resend + entry->resend_period;
auto ms_time = duration_cast<milliseconds>(time).count();
if(ms_time > 5) {
this->average_response = this->average_response / 2 + ms_time / 2;
this->average_response = this->average_response * .80 + ms_time * .2;
}
entry->acknowledged = true;