From 7ddc2aaf39f2e34f4a6c1540a36b347ba1a1e102 Mon Sep 17 00:00:00 2001 From: Newe Date: Mon, 24 May 2021 17:52:06 +0200 Subject: [PATCH 1/6] [edit] Edited README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a1ff3c08..f965b84a 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ A Fosscord media (voice and video) server ## Installation ### Prerequisites - Install the [libdatachannel](https://github.com/paullouisageneau/libdatachannel) library -- Install the [limbongocxx]() driver +- Install the [libmongocxx](http://mongocxx.org/mongocxx-v3/installation/) driver and its requirements ### Building From 63407d96e37df8457e8350e9184b9e3de376fd1f Mon Sep 17 00:00:00 2001 From: Newe Date: Tue, 25 May 2021 12:41:28 +0200 Subject: [PATCH 2/6] [edit] Retrieve the event name from mongoDB event payload --- src/main.cpp | 8 +++++--- src/mongoStub.cpp | 26 ++++++++++++++++++++++---- src/mongoStub.hpp | 17 +++++++++++++---- 3 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index bd4ebbec..372eaa00 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -30,16 +30,18 @@ int main(int argc, char **argv){ auto mongoHandler = std::make_unique(); mongocxx::options::change_stream options; + //voiceEvents collection watcher mongocxx::change_stream colCs = mongoHandler->getCol().watch(options); + std::cout << "Server created and listening for events" << std::endl; + //Check for new messages in the collection for (;;){ - std::vector t = mongoHandler->getNewMessages(&colCs); + std::vector t = mongoHandler->getNewMessages(&colCs); for(auto &i : t){ - std::cout << i << std::endl; + std::cout << "[" << i.eventName << "] " << std::endl; } } - std::cout << "Server created" << std::endl; return 0; } \ No newline at end of file diff --git a/src/mongoStub.cpp b/src/mongoStub.cpp index 50312fc6..3e7ae3df 100644 --- a/src/mongoStub.cpp +++ b/src/mongoStub.cpp @@ -17,10 +17,28 @@ mongoStub::mongoStub() { } } -std::vectormongoStub::getNewMessages(mongocxx::change_stream* colCs) { - std::vector retVec; - for (const auto& event : *colCs) { - retVec.push_back(bsoncxx::to_json(event)); +//Too slow for my liking +std::vector mongoStub::getNewMessages(mongocxx::change_stream* colCs) { + std::vector retVec; + + for (auto&& event : *colCs) { + mongoStub::mongoMessage returnValue; + + /*if(event["fullDocument"]["data"]){ + returnValue.data.push_back(event["fullDocument"]["data"].get_utf8().value.to_string()); + }*/ + + + + std::cout << bsoncxx::to_json(event) << std::endl; + + //Oly listen to insert events (to avoid "precondition failed: data" exception) + if(event["operationType"].get_utf8().value.to_string()!="insert"){ + continue; + } + returnValue.eventName = event["fullDocument"]["event"].get_utf8().value.to_string(); + retVec.push_back(returnValue); } + return retVec; } diff --git a/src/mongoStub.hpp b/src/mongoStub.hpp index 3cee472c..71bac792 100644 --- a/src/mongoStub.hpp +++ b/src/mongoStub.hpp @@ -7,23 +7,32 @@ #include #include #include -#include +#include #include +#include -class mongoStub : boost::noncopyable { +class mongoStub{ public: mongoStub(); - std::vector getNewMessages(mongocxx::change_stream* colCs); + + struct mongoMessage{ + std::string eventName; + std::vector data; + }; + + std::vector getNewMessages(mongocxx::change_stream* colCs); mongocxx::collection getCol() const { return col; } + + private: mongocxx::instance instance; mongocxx::client client{mongocxx::uri{}}; mongocxx::database db; mongocxx::collection col; - mongocxx::change_stream* colCs = nullptr; + mongocxx::change_stream* colCs = nullptr; }; #endif From d6c30fc027d3ea71615c994ba1d6a1fc13636a76 Mon Sep 17 00:00:00 2001 From: Newe Date: Tue, 25 May 2021 23:00:54 +0200 Subject: [PATCH 3/6] [add] Mongo collection insert :) --- src/mongoStub.cpp | 65 +++++++++++++++++++++++++++++++++-------------- src/mongoStub.hpp | 4 +++ 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/src/mongoStub.cpp b/src/mongoStub.cpp index 3e7ae3df..7e5c4a6c 100644 --- a/src/mongoStub.cpp +++ b/src/mongoStub.cpp @@ -6,7 +6,7 @@ mongoStub::mongoStub() { if (this->db) { this->col = db["events"]; - + } else { std::cout << "db not found"; exit(-1); @@ -17,28 +17,55 @@ mongoStub::mongoStub() { } } -//Too slow for my liking -std::vector mongoStub::getNewMessages(mongocxx::change_stream* colCs) { - std::vector retVec; - +// Too slow for my liking +std::vector mongoStub::getNewMessages( + mongocxx::change_stream* colCs) { + std::vector retVec; + for (auto&& event : *colCs) { - mongoStub::mongoMessage returnValue; + mongoStub::mongoMessage returnValue; - /*if(event["fullDocument"]["data"]){ - returnValue.data.push_back(event["fullDocument"]["data"].get_utf8().value.to_string()); - }*/ + std::cout << bsoncxx::to_json(event) << std::endl; + // Only listen to insert events (to avoid "precondition failed: data" + // exception) + if (event["operationType"].get_utf8().value.to_string() != "insert") { + continue; + } + std::string evNameTmp = + event["fullDocument"]["event"].get_utf8().value.to_string(); + if (evNameTmp == "UDP_CONNECTION") { + handleUdpRequest(); + } else if (evNameTmp == "VOICE_REQUEST") { + continue; + } - - std::cout << bsoncxx::to_json(event) << std::endl; - - //Oly listen to insert events (to avoid "precondition failed: data" exception) - if(event["operationType"].get_utf8().value.to_string()!="insert"){ - continue; - } - returnValue.eventName = event["fullDocument"]["event"].get_utf8().value.to_string(); - retVec.push_back(returnValue); + returnValue.eventName = evNameTmp; + retVec.push_back(returnValue); } - return retVec; + return retVec; } + +void mongoStub::handleUdpRequest() { + using bsoncxx::builder::basic::kvp; + using bsoncxx::builder::basic::sub_array; + using bsoncxx::builder::basic::sub_document; + + auto builder = bsoncxx::builder::basic::document{}; + + builder.append(kvp("event", "VSERVER_UDP_RESPONSE")); + builder.append(kvp("op", "4")); + builder.append(kvp("d", [](sub_document subdoc) { + subdoc.append(kvp("mode", "CRYPT_MODE")), + subdoc.append(kvp("secret_key", [](sub_array subarr) { + subarr.append(1, 2, 3, 5); // HOW DO I GEN A SKEY? + })); + })); + + + bsoncxx::stdx::optional r= col.insert_one(builder.view()); + std::cout << "Insert"<< std::endl; +} + +void handleVoiceRequest() {} \ No newline at end of file diff --git a/src/mongoStub.hpp b/src/mongoStub.hpp index 71bac792..18b899ae 100644 --- a/src/mongoStub.hpp +++ b/src/mongoStub.hpp @@ -23,6 +23,10 @@ class mongoStub{ std::vector getNewMessages(mongocxx::change_stream* colCs); + void handleUdpRequest(); + + void handleVoiceRequest(); + mongocxx::collection getCol() const { return col; } From e98e307aedc195ba2adafa3129aa60c84fc8efa5 Mon Sep 17 00:00:00 2001 From: Newe Date: Tue, 25 May 2021 23:07:44 +0200 Subject: [PATCH 4/6] [edit] Ignore event if emited by a vServer --- src/mongoStub.cpp | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/mongoStub.cpp b/src/mongoStub.cpp index 7e5c4a6c..03744bd4 100644 --- a/src/mongoStub.cpp +++ b/src/mongoStub.cpp @@ -34,9 +34,14 @@ std::vector mongoStub::getNewMessages( } std::string evNameTmp = event["fullDocument"]["event"].get_utf8().value.to_string(); + + if(evNameTmp.substr(0, 7)=="VSERVER"){ continue; } //Ignore the event if it's been emited by a voice server + if (evNameTmp == "UDP_CONNECTION") { handleUdpRequest(); + } else if (evNameTmp == "VOICE_REQUEST") { + //TODO continue; } @@ -47,6 +52,7 @@ std::vector mongoStub::getNewMessages( return retVec; } +//------- ABOVE THIS LINE IS COPY & PASTE HAVEN ------- void mongoStub::handleUdpRequest() { using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::sub_array; @@ -68,4 +74,23 @@ void mongoStub::handleUdpRequest() { std::cout << "Insert"<< std::endl; } -void handleVoiceRequest() {} \ No newline at end of file +void mongoStub::handleVoiceRequest() { + using bsoncxx::builder::basic::kvp; + using bsoncxx::builder::basic::sub_array; + using bsoncxx::builder::basic::sub_document; + + auto builder = bsoncxx::builder::basic::document{}; + + builder.append(kvp("event", "VSERVER_UDP_RESPONSE")); + builder.append(kvp("op", "4")); + builder.append(kvp("d", [](sub_document subdoc) { + subdoc.append(kvp("mode", "CRYPT_MODE")), + subdoc.append(kvp("secret_key", [](sub_array subarr) { + subarr.append(1, 2, 3, 5); // HOW DO I GEN A SKEY? + })); + })); + + + bsoncxx::stdx::optional r= col.insert_one(builder.view()); + std::cout << "Insert"<< std::endl; +} \ No newline at end of file From e04c5bf1380760a3a48bd65e8e8ffe4dd651a2d4 Mon Sep 17 00:00:00 2001 From: Newe Date: Tue, 25 May 2021 23:35:24 +0200 Subject: [PATCH 5/6] [add] Udp request handler mockup --- src/mongoStub.cpp | 54 ++++++++++++++++++----------------------------- src/mongoStub.hpp | 9 ++++---- 2 files changed, 25 insertions(+), 38 deletions(-) diff --git a/src/mongoStub.cpp b/src/mongoStub.cpp index 03744bd4..ccd2abda 100644 --- a/src/mongoStub.cpp +++ b/src/mongoStub.cpp @@ -32,65 +32,53 @@ std::vector mongoStub::getNewMessages( if (event["operationType"].get_utf8().value.to_string() != "insert") { continue; } - std::string evNameTmp = - event["fullDocument"]["event"].get_utf8().value.to_string(); - if(evNameTmp.substr(0, 7)=="VSERVER"){ continue; } //Ignore the event if it's been emited by a voice server + std::string evName = event["fullDocument"]["event"].get_utf8().value.to_string(); - if (evNameTmp == "UDP_CONNECTION") { - handleUdpRequest(); + if(evName.substr(0, 7)=="VSERVER"){ continue; } //Ignore the event if it's been emited by a voice server - } else if (evNameTmp == "VOICE_REQUEST") { + if (evName == "UDP_CONNECTION") { + handleUdpRequest( + event["fullDocument"]["data"]["d"]["address"].get_utf8().value.to_string(), + event["fullDocument"]["data"]["d"]["port"].get_int32().value, + event["fullDocument"]["data"]["d"]["mode"].get_utf8().value.to_string() + ); + + } else if (evName == "VOICE_REQUEST") { //TODO continue; } - returnValue.eventName = evNameTmp; + returnValue.eventName = evName; retVec.push_back(returnValue); } return retVec; } -//------- ABOVE THIS LINE IS COPY & PASTE HAVEN ------- -void mongoStub::handleUdpRequest() { + +void mongoStub::handleUdpRequest(std::string address, int port, std::string mode) { using bsoncxx::builder::basic::kvp; using bsoncxx::builder::basic::sub_array; using bsoncxx::builder::basic::sub_document; auto builder = bsoncxx::builder::basic::document{}; + //Handle UDP socket stuff (later tho) + builder.append(kvp("event", "VSERVER_UDP_RESPONSE")); builder.append(kvp("op", "4")); builder.append(kvp("d", [](sub_document subdoc) { - subdoc.append(kvp("mode", "CRYPT_MODE")), - subdoc.append(kvp("secret_key", [](sub_array subarr) { - subarr.append(1, 2, 3, 5); // HOW DO I GEN A SKEY? - })); - })); + subdoc.append(kvp("mode", "CRYPT_MODE")), + subdoc.append(kvp("secret_key", [](sub_array subarr) { + subarr.append(1, 2, 3, 5); // HOW DO I GEN A SKEY? + })); + })); bsoncxx::stdx::optional r= col.insert_one(builder.view()); - std::cout << "Insert"<< std::endl; } void mongoStub::handleVoiceRequest() { - using bsoncxx::builder::basic::kvp; - using bsoncxx::builder::basic::sub_array; - using bsoncxx::builder::basic::sub_document; - - auto builder = bsoncxx::builder::basic::document{}; - - builder.append(kvp("event", "VSERVER_UDP_RESPONSE")); - builder.append(kvp("op", "4")); - builder.append(kvp("d", [](sub_document subdoc) { - subdoc.append(kvp("mode", "CRYPT_MODE")), - subdoc.append(kvp("secret_key", [](sub_array subarr) { - subarr.append(1, 2, 3, 5); // HOW DO I GEN A SKEY? - })); - })); - - - bsoncxx::stdx::optional r= col.insert_one(builder.view()); - std::cout << "Insert"<< std::endl; + //Is this really needed? idk } \ No newline at end of file diff --git a/src/mongoStub.hpp b/src/mongoStub.hpp index 18b899ae..2809142f 100644 --- a/src/mongoStub.hpp +++ b/src/mongoStub.hpp @@ -23,10 +23,6 @@ class mongoStub{ std::vector getNewMessages(mongocxx::change_stream* colCs); - void handleUdpRequest(); - - void handleVoiceRequest(); - mongocxx::collection getCol() const { return col; } @@ -36,7 +32,10 @@ class mongoStub{ mongocxx::client client{mongocxx::uri{}}; mongocxx::database db; mongocxx::collection col; - mongocxx::change_stream* colCs = nullptr; + mongocxx::change_stream* colCs = nullptr; + + void handleUdpRequest(std::string address, int port, std::string mode); + void handleVoiceRequest(); }; #endif From 7f1719994de7eed6bff120225ba0eff9c7ccb298 Mon Sep 17 00:00:00 2001 From: Newe Date: Tue, 25 May 2021 23:35:33 +0200 Subject: [PATCH 6/6] [del] Deleted .proto --- src/protodefs/protos.proto | 24 ------------------------ 1 file changed, 24 deletions(-) delete mode 100644 src/protodefs/protos.proto diff --git a/src/protodefs/protos.proto b/src/protodefs/protos.proto deleted file mode 100644 index 11face5f..00000000 --- a/src/protodefs/protos.proto +++ /dev/null @@ -1,24 +0,0 @@ -syntax = "proto3"; - -package fosscordMedia; - -service fosscordInternals{ - rpc vRequest(voiceRequest) returns (voiceAnswer) {} -} - -message voiceRequest{ //OP1 from gw - uint64 userid = 1; - uint64 guildid = 2; - string ip=3; - uint32 port=4; - string protocol=5; - string rtcConnectionId=6; -} - -message voiceAnswer{//OP2 and OP4 to gw - string ip=1; - uint32 port=3; - repeated string modes=2; - int32 ssrc=4; - string audioCodec=5; -} \ No newline at end of file