Fle server & Query server improvements

This commit is contained in:
WolverinDEV
2019-07-21 10:43:26 +02:00
parent e507d1f75d
commit d4d6978d5f
18 changed files with 1138 additions and 313 deletions
+42
View File
@@ -262,6 +262,18 @@ void WebClient::tick(const std::chrono::system_clock::time_point& point) {
this->ws_handler.send({pipes::PING, {buffer, 2}});
}
}
if(this->js_ping.last_request + seconds(1) < point) {
if(this->js_ping.last_response > this->js_ping.last_request || this->js_ping.last_request + this->js_ping.timeout < point) {
this->js_ping.current_id++;
this->js_ping.last_request = point;
Json::Value jsonCandidate;
jsonCandidate["type"] = "ping";
jsonCandidate["payload"] = to_string(this->js_ping.current_id);
this->sendJson(jsonCandidate);
}
}
}
void WebClient::onWSConnected() {
@@ -554,6 +566,36 @@ void WebClient::handleMessage(const std::string &message) {
}
this->voice_bridge->remote_ice_finished();
}
} else if(val["type"].asString() == "ping") {
Json::Value response;
response["type"] = "pong";
response["payload"] = val["payload"];
response["ping_native"] = to_string(duration_cast<microseconds>(this->ping.value).count());
this->sendJson(response);
return;
} else if(val["type"].asString() == "pong") {
auto payload = val["payload"].isString() ? val["payload"].asString() : "";
uint8_t response_id = 0;
try {
response_id = (uint8_t) stoul(payload);
} catch(std::exception& ex) {
debugMessage(this->getServerId(), "[{}] Failed to parse pong payload.");
return;
}
if(response_id != this->js_ping.current_id) {
debugMessage(
this->getServerId(),
"{} Received pong on web socket from javascript which is older than the last request. Delay may over {}ms? (Index: {}, Current index: {})",
CLIENT_STR_LOG_PREFIX,
duration_cast<milliseconds>(this->js_ping.timeout).count(),
response_id,
this->js_ping.current_id
);
return;
}
this->js_ping.last_response = system_clock::now();
this->js_ping.value = duration_cast<nanoseconds>(this->js_ping.last_response - this->js_ping.last_request);
}
} catch (const std::exception& ex) {
logError(this->server->getServerId(), "Could not handle json packet! Message {}", ex.what());
+12 -1
View File
@@ -32,6 +32,9 @@ namespace ts {
bool shouldReceiveVoice(const std::shared_ptr<ConnectedClient> &sender) override;
inline std::chrono::nanoseconds client_ping() { return this->client_ping_layer_7(); }
inline std::chrono::nanoseconds client_ping_layer_5() { return this->ping.value; }
inline std::chrono::nanoseconds client_ping_layer_7() { return this->js_ping.value; }
protected:
void handlePacketVoiceWhisper(const pipes::buffer_view &string, bool) override;
@@ -60,6 +63,15 @@ namespace ts {
std::chrono::nanoseconds timeout{2000};
} ping;
struct {
uint8_t current_id = 0;
std::chrono::system_clock::time_point last_request;
std::chrono::system_clock::time_point last_response;
std::chrono::nanoseconds value;
std::chrono::nanoseconds timeout{2000};
} js_ping;
std::mutex queue_lock;
std::deque<pipes::buffer> queue_read;
std::deque<pipes::buffer> queue_write;
@@ -93,7 +105,6 @@ namespace ts {
public:
void send_voice_packet(const pipes::buffer_view &view, const VoicePacketFlags &flags) override;
void send_voice_whisper_packet(const pipes::buffer_view &view, const VoicePacketFlags &flags) override;
protected: