SOme updates

This commit is contained in:
WolverinDEV 2021-03-21 23:51:37 +01:00
parent fb517f0b72
commit ceb77a2c85
20 changed files with 80 additions and 33 deletions

View File

@ -486,7 +486,7 @@ int main(int argc, char** argv) {
logCriticalFmt(true, LOG_GENERAL, "Could not initialize SQL!");
if(errorMessage.find("database is locked") != string::npos) {
logCriticalFmt(true, LOG_GENERAL, "----------------------------[ ATTENTION ]----------------------------");
logCriticalFmt(true, LOG_GENERAL, "{:^69}", "You're database is already in use!");
logCriticalFmt(true, LOG_GENERAL, "{:^69}", "Your database is already in use!");
logCriticalFmt(true, LOG_GENERAL, "{:^69}", "Stop the other instance first!");
logCriticalFmt(true, LOG_GENERAL, "----------------------------[ ATTENTION ]----------------------------");
} else {

View File

@ -1534,45 +1534,45 @@ std::deque<std::shared_ptr<EntryBinding>> config::create_bindings() {
}
{
CREATE_BINDING("webrtc.port_min", 0);
CREATE_BINDING("webrtc.port_min", FLAG_RELOADABLE);
BIND_INTEGRAL(config::web::webrtc_port_min, 50000, 0, 65535);
ADD_DESCRIPTION("Define the port range within the web client and TeaClient operates in");
ADD_DESCRIPTION("A port of zero stands for no limit");
ADD_NOTE("These ports must opened to use the voice bridge (Protocol: UDP)");
}
{
CREATE_BINDING("webrtc.port_max", 0);
CREATE_BINDING("webrtc.port_max", FLAG_RELOADABLE);
BIND_INTEGRAL(config::web::webrtc_port_max, 56000, 0, 65535);
ADD_DESCRIPTION("Define the port range within the web client and TeaClient operates in");
ADD_DESCRIPTION("A port of zero stands for no limit");
ADD_NOTE("These ports must opened to use the voice bridge (Protocol: UDP)");
}
{
CREATE_BINDING("webrtc.stun.enabled", 0);
CREATE_BINDING("webrtc.stun.enabled", FLAG_RELOADABLE);
BIND_INTEGRAL(config::web::stun_enabled, true, false, true);
ADD_DESCRIPTION("Whatever to use a STUN server");
ADD_NOTE_RELOADABLE();
}
{
CREATE_BINDING("webrtc.stun.host", 0);
CREATE_BINDING("webrtc.stun.host", FLAG_RELOADABLE);
BIND_STRING(config::web::stun_host, "stun.l.google.com");
ADD_DESCRIPTION("The address of the stun server to use.");
ADD_NOTE_RELOADABLE();
}
{
CREATE_BINDING("webrtc.stun.port", 0);
CREATE_BINDING("webrtc.stun.port", FLAG_RELOADABLE);
BIND_INTEGRAL(config::web::stun_port, 19302, 1, 0xFFFF);
ADD_DESCRIPTION("Port of the stun server");
ADD_NOTE_RELOADABLE();
}
{
CREATE_BINDING("webrtc.udp", 0);
CREATE_BINDING("webrtc.udp", FLAG_RELOADABLE);
BIND_INTEGRAL(config::web::udp_enabled, true, false, true);
ADD_DESCRIPTION("Enable UDP for theweb client");
ADD_NOTE_RELOADABLE();
}
{
CREATE_BINDING("webrtc.tcp", 0);
CREATE_BINDING("webrtc.tcp", FLAG_RELOADABLE);
BIND_INTEGRAL(config::web::tcp_enabled, true, false, true);
ADD_DESCRIPTION("Enable TCP for theweb client");
ADD_NOTE_RELOADABLE();

View File

@ -484,9 +484,9 @@ bool ServerChannelTree::validateChannelNames() {
}
bool ServerChannelTree::validateChannelIcons() {
#if 0
for(const auto &channel : this->channels()) {
auto iconId = (IconId) channel->properties()[property::CHANNEL_ICON_ID];
#if 0
if(iconId != 0 && !serverInstance->getFileServer()->iconExists(this->server.lock(), iconId)) {
logMessage(this->getServerId(), "[FILE] Missing channel icon (" + to_string(iconId) + ").");
if(config::server::delete_missing_icon_permissions) {
@ -494,8 +494,8 @@ bool ServerChannelTree::validateChannelIcons() {
channel->permissions()->set_permission(permission::i_icon_id, {0, 0}, permission::v2::PermissionUpdateType::set_value, permission::v2::PermissionUpdateType::do_nothing);
}
}
#endif
}
#endif
return true;
}

View File

@ -384,7 +384,8 @@ std::deque<std::shared_ptr<BasicChannel>> ConnectedClient::unsubscribeChannel(co
}
bool ConnectedClient::isClientVisible(const std::shared_ptr<ts::server::ConnectedClient>& client, bool lock) {
for(const auto& entry : this->getVisibleClients(lock))
auto client_list = this->getVisibleClients(lock);
for(const auto& entry : client_list)
if(entry.lock() == client)
return true;
return false;

View File

@ -5,6 +5,7 @@
#include <cstdint>
#include <src/music/PlayablePlaylist.h>
#include <misc/task_executor.h>
#include <misc/sassert.h>
#include "music/Song.h"
#include "../channel/ClientChannelView.h"
#include "DataClient.h"
@ -125,6 +126,7 @@ namespace ts {
if(lock_channel) {
lock.lock();
}
assert(mutex_shared_locked(this->channel_lock));
return this->visibleClients;
}

View File

@ -442,6 +442,8 @@ bool ConnectedClient::notifyClientMoved(const shared_ptr<ConnectedClient> &clien
assert(client->getClientId() > 0);
assert(client->currentChannel);
assert(target_channel);
sassert(mutex_shared_locked(this->channel_lock));
sassert(mutex_shared_locked(client->channel_lock));
assert(this->isClientVisible(client, false) || &*client == this);
Command mv("notifyclientmoved");
@ -465,6 +467,7 @@ bool ConnectedClient::notifyClientUpdated(const std::shared_ptr<ConnectedClient>
channel_lock.lock();
}
sassert(mutex_shared_locked(this->channel_lock));
if(!this->isClientVisible(client, false) && client != this)
return false;
@ -627,6 +630,7 @@ bool ConnectedClient::notifyClientEnterView(const std::shared_ptr<ConnectedClien
sassert(client && client->getClientId() > 0);
sassert(to);
sassert(!lock_channel_tree); /* we don't support locking */
sassert(mutex_locked(this->channel_lock));
sassert(!this->isClientVisible(client, false) || &*client == this);
switch (reasonId) {

View File

@ -664,6 +664,7 @@ bool ConnectedClient::handle_text_command(
TLEN(4);
try {
/*
auto type = stol(arguments[1]);
auto generation = stol(arguments[2]);
auto pid = stol(arguments[3]);
@ -671,7 +672,6 @@ bool ConnectedClient::handle_text_command(
auto vc = dynamic_pointer_cast<VoiceClient>(this->ref());
if(!vc) return false;
/*
auto& genestis = vc->getConnection()->get_incoming_generation_estimators();
if(type >= genestis.size()) {
send_message(this->ref(), "Invalid type");

View File

@ -403,7 +403,9 @@ void SpeakingClient::processJoin() {
assert(ref_server);
this->resetIdleTime();
threads::MutexLock lock(this->command_lock); //Don't process any commands!
/* don't process any commands */
std::lock_guard command_lock_{this->command_lock};
if(this->state != ConnectionState::INIT_HIGH) {
logError(this->getServerId(), "{} Invalid processJoin() connection state!", CLIENT_STR_LOG_PREFIX);
@ -507,7 +509,10 @@ void SpeakingClient::processJoin() {
unique_lock server_channel_lock(this->server->channel_tree_lock);
this->server->client_move(this->ref(), channel, nullptr, "", ViewReasonId::VREASON_USER_ACTION, false, server_channel_lock);
if(this->getType() != ClientType::CLIENT_TEAMSPEAK) this->subscribeChannel({this->currentChannel}, false, true); /* su "improve" the TS3 clients join speed we send the channel clients a bit later, when the TS3 client gets his own client variables */
if(this->getType() != ClientType::CLIENT_TEAMSPEAK) {
std::lock_guard own_channel_lock{this->channel_lock};
this->subscribeChannel({this->currentChannel}, false, true); /* su "improve" the TS3 clients join speed we send the channel clients a bit later, when the TS3 client gets his own client variables */
}
}
TIMING_STEP(timings, "join move ");

View File

@ -79,7 +79,7 @@ namespace ts::server {
virtual command_result handleCommandBroadcastVideoConfigure(Command &);
void triggerVoiceEnd();
inline void updateSpeak(bool onlyUpdate, const std::chrono::system_clock::time_point &time);
void updateSpeak(bool onlyUpdate, const std::chrono::system_clock::time_point &time);
std::chrono::milliseconds speak_accuracy{1000};
std::mutex speak_mutex;

View File

@ -2,4 +2,5 @@
// Created by WolverinDEV on 07/05/2020.
//
#include <log/LogUtils.h>
#include "bulk_parsers.h"

View File

@ -3391,6 +3391,7 @@ command_result ConnectedClient::handleCommandListFeatureSupport(ts::Command &cmd
REGISTER_FEATURE("whisper-echo", FeatureSupportMode::FULL, 1);
REGISTER_FEATURE("video", FeatureSupportMode::EXPERIMENTAL, 1);
REGISTER_FEATURE("sidebar-mode", FeatureSupportMode::FULL, 1);
REGISTER_FEATURE("token", FeatureSupportMode::FULL, 1);
this->sendCommand(notify);
return command_result{error::ok};

View File

@ -494,7 +494,7 @@ command_result ConnectedClient::handleCommandServerGroupAddClient(Command &cmd)
);
}
return command_result{error::ok};
return ts::command_result{std::move(result)};
}
command_result ConnectedClient::handleCommandServerGroupDelClient(Command &cmd) {
@ -618,7 +618,7 @@ command_result ConnectedClient::handleCommandServerGroupDelClient(Command &cmd)
);
}
return command_result{error::ok};
return ts::command_result{std::move(result)};
}
command_result ConnectedClient::handleCommandServerGroupPermList(Command &cmd) {

View File

@ -155,6 +155,11 @@ bool QueryClient::notifyClientMoved(const std::shared_ptr<ConnectedClient> &clie
bool QueryClient::notifyClientLeftView(const std::shared_ptr<ConnectedClient> &client, const std::shared_ptr<BasicChannel> &target_channel, ViewReasonId reasonId, const std::string &reasonMessage, std::shared_ptr<ConnectedClient> invoker,
bool lock_channel_tree) {
if(!this->eventActive(QueryEventGroup::QEVENTGROUP_CLIENT_VIEW, QueryEventSpecifier::QEVENTSPECIFIER_CLIENT_VIEW_LEAVE)) {
std::unique_lock tree_lock{this->channel_lock, std::defer_lock};
if(lock_channel_tree) {
tree_lock.lock();
}
this->visibleClients.erase(std::remove_if(this->visibleClients.begin(), this->visibleClients.end(), [&, client](const weak_ptr<ConnectedClient>& weak) {
auto c = weak.lock();
if(!c) {
@ -168,8 +173,13 @@ bool QueryClient::notifyClientLeftView(const std::shared_ptr<ConnectedClient> &c
return ConnectedClient::notifyClientLeftView(client, target_channel, reasonId, reasonMessage, invoker, lock_channel_tree);
}
bool QueryClient::notifyClientLeftView(const std::deque<std::shared_ptr<ConnectedClient>> &clients, const std::string &string, bool b, const ViewReasonServerLeftT &t) {
bool QueryClient::notifyClientLeftView(const std::deque<std::shared_ptr<ConnectedClient>> &clients, const std::string &string, bool lock_channel_tree, const ViewReasonServerLeftT &t) {
if(!this->eventActive(QueryEventGroup::QEVENTGROUP_CLIENT_VIEW, QueryEventSpecifier::QEVENTSPECIFIER_CLIENT_VIEW_LEAVE)) {
std::unique_lock tree_lock{this->channel_lock, std::defer_lock};
if(lock_channel_tree) {
tree_lock.lock();
}
this->visibleClients.erase(std::remove_if(this->visibleClients.begin(), this->visibleClients.end(), [&](const weak_ptr<ConnectedClient>& weak) {
auto c = weak.lock();
if(!c) {
@ -180,11 +190,16 @@ bool QueryClient::notifyClientLeftView(const std::deque<std::shared_ptr<Connecte
}), this->visibleClients.end());
return true;
}
return ConnectedClient::notifyClientLeftView(clients, string, b, t);
return ConnectedClient::notifyClientLeftView(clients, string, lock_channel_tree, t);
}
bool QueryClient::notifyClientLeftViewKicked(const std::shared_ptr<ConnectedClient> &client, const std::shared_ptr<BasicChannel> &target_channel, const std::string &message, std::shared_ptr<ConnectedClient> invoker, bool lock_channel_tree) {
if(!this->eventActive(QueryEventGroup::QEVENTGROUP_CLIENT_VIEW, QueryEventSpecifier::QEVENTSPECIFIER_CLIENT_VIEW_LEAVE)) {
std::unique_lock tree_lock{this->channel_lock, std::defer_lock};
if(lock_channel_tree) {
tree_lock.lock();
}
this->visibleClients.erase(std::remove_if(this->visibleClients.begin(), this->visibleClients.end(), [&, client](const weak_ptr<ConnectedClient>& weak) {
auto c = weak.lock();
if(!c) {
@ -200,6 +215,11 @@ bool QueryClient::notifyClientLeftViewKicked(const std::shared_ptr<ConnectedClie
bool QueryClient::notifyClientLeftViewBanned(const std::shared_ptr<ConnectedClient> &client, const std::string &message, std::shared_ptr<ConnectedClient> invoker, size_t length, bool lock_channel_tree) {
if(!this->eventActive(QueryEventGroup::QEVENTGROUP_CLIENT_VIEW, QueryEventSpecifier::QEVENTSPECIFIER_CLIENT_VIEW_LEAVE)) {
std::unique_lock tree_lock{this->channel_lock, std::defer_lock};
if(lock_channel_tree) {
tree_lock.lock();
}
this->visibleClients.erase(std::remove_if(this->visibleClients.begin(), this->visibleClients.end(), [&, client](const weak_ptr<ConnectedClient>& weak) {
auto c = weak.lock();
if(!c) {

View File

@ -24,11 +24,11 @@ CryptSetupHandler::CryptSetupHandler(VoiceClientConnection *connection) : connec
CryptSetupHandler::CommandHandleResult CryptSetupHandler::handle_command(const std::string_view &payload) {
std::variant<ts::command_result, CommandHandleResult>(CryptSetupHandler::*command_handler)(const ts::command_parser&) = nullptr;
if(payload.starts_with("clientinitiv")) {
if(payload.starts_with("clientinitiv ")) {
command_handler = &CryptSetupHandler::handleCommandClientInitIv;
} else if(payload.starts_with("clientek")) {
} else if(payload.starts_with("clientek ")) {
command_handler = &CryptSetupHandler::handleCommandClientEk;
} else if(payload.starts_with("clientinit")) {
} else if(payload.starts_with("clientinit ")) {
command_handler = &CryptSetupHandler::handleCommandClientInit;
}
@ -262,7 +262,6 @@ CryptSetupHandler::CommandResult CryptSetupHandler::handleCommandClientEk(const
auto pflags = protocol::PacketFlag::NewProtocol;
this->connection->send_packet(protocol::PacketType::ACK, (protocol::PacketFlags) pflags, buffer, 2);
//Send the encrypted acknowledge (most the times the second packet; If not we're going into the resend loop)
//We cant use the send_packet_acknowledge function since it sends the acknowledge unencrypted
}

View File

@ -51,9 +51,12 @@ VoiceClient::~VoiceClient() {
delete this->connection;
this->connection = nullptr;
if(this->flushing_thread) {
logCritical(this->getServerId(), "Deleting a VoiceClient which should still be hold within the flush thread!");
this->flushing_thread->detach();
{
std::lock_guard fthread_lock{this->flush_thread_mutex};
if(this->flushing_thread) {
logCritical(this->getServerId(), "Deleting a VoiceClient which should still be hold within the flush thread!");
this->flushing_thread->detach();
}
}
memtrack::freed<VoiceClient>(this);
@ -194,13 +197,15 @@ bool VoiceClient::close_connection(const system_clock::time_point &timeout) {
}
debugMessage(this->getServerId(), "{} Closing voice client connection. (Flush: {})", CLIENT_STR_LOG_PREFIX, flush);
std::lock_guard fthread_lock{this->flush_thread_mutex};
//TODO: Move this out into a thread pool?
if(this->flushing_thread && this->flushing_thread->joinable()) {
logCritical(LOG_GENERAL, "VoiceClient::close_connection reached flushing thread with an active old handle. Ignoring request.");
return true;
}
this->flushing_thread = std::make_shared<std::thread>([this, self_lock, timeout, flush]{
auto flush_thread = std::make_shared<std::thread>([this, self_lock, timeout, flush]{
{
/* Await that all commands have been processed. It does not make sense to unregister the client while command handling. */
std::lock_guard cmd_lock{this->command_lock};
@ -235,7 +240,8 @@ bool VoiceClient::close_connection(const system_clock::time_point &timeout) {
this->finalDisconnect();
});
threads::name(*this->flushing_thread, "Flush thread VC");
this->flushing_thread = flush_thread;
threads::name(*flush_thread, "Flush thread VC");
return true;
}
@ -255,10 +261,11 @@ void VoiceClient::finalDisconnect() {
//Unload manager cache
this->processLeave();
{
std::lock_guard fthread_lock{this->flush_thread_mutex};
if(this->flushing_thread) {
this->flushing_thread->detach(); //The thread itself should be already done or executing this method
}
this->flushing_thread.reset();
this->flushing_thread = nullptr;
}
if(this->voice_server) {
this->voice_server->unregisterConnection(ownLock);

View File

@ -115,6 +115,7 @@ namespace ts {
command_result handleCommandClientDisconnect(Command&);
//Locked by finalDisconnect, disconnect and close connection
std::mutex flush_thread_mutex{};
std::shared_ptr<std::thread> flushing_thread;
std::unique_ptr<ServerCommandQueue> server_command_queue_{};

View File

@ -109,9 +109,13 @@ command_result VoiceClient::handleCommandClientInit(Command &cmd) {
command_result VoiceClient::handleCommandClientDisconnect(Command& cmd) {
auto reason = cmd["reasonmsg"].size() > 0 ? cmd["reasonmsg"].as<string>() : "";
this->notifyClientLeftView(this->ref(), nullptr, VREASON_SERVER_LEFT, reason, nullptr, false); //Before we're moving us out of the channel tree!
{
std::shared_lock own_lock{this->channel_lock};
this->notifyClientLeftView(this->ref(), nullptr, VREASON_SERVER_LEFT, reason, nullptr, false); //Before we're moving us out of the channel tree!
}
if(this->state == CONNECTED) {
unique_lock channel_lock(this->server->channel_tree_lock);
std::unique_lock channel_lock{this->server->channel_tree_lock};
this->server->client_move(this->ref(), nullptr, nullptr, reason, VREASON_SERVER_LEFT, true, channel_lock);
}
logMessage(this->getServerId(), "{} Got remote disconnect with the reason '{}'", CLIENT_STR_LOG_PREFIX, reason);

View File

@ -59,7 +59,7 @@ namespace ts::server::server::udp {
};
struct ServerEventLoops {
event_base* event_base{nullptr};
struct event_base* event_base{nullptr};
std::thread dispatch_thread{};
};

View File

@ -28,6 +28,7 @@ void testTomMath(){
#else
//assert(err != MP_OKAY); //if this method succeed than tommath failed. Unknown why but it is so
#endif
(void) err;
mp_clear_multi(&x, &n, &exp, &r, nullptr);
}
{
@ -53,6 +54,7 @@ void testTomMath(){
#else
//assert(err != MP_OKAY); //if this method succeed than tommath failed. Unknown why but it is so
#endif
(void) err;
mp_clear_multi(&x, &n, &exp, &r, nullptr);
}

2
shared

@ -1 +1 @@
Subproject commit eef0144e77ee87fc7fe275beb743bd85e6e37f19
Subproject commit 8dde5b1c23f0d84ca1b56a8c80389fb4e887b062