mirror of
https://github.com/spacebarchat/server.git
synced 2024-11-10 20:52:42 +01:00
[edit] Hypothetical gRPC handshake
This commit is contained in:
parent
80282f6ba3
commit
f8eceb3124
4
.gitignore
vendored
4
.gitignore
vendored
@ -29,6 +29,10 @@
|
||||
# Executables
|
||||
*.o
|
||||
|
||||
# Protobuffer builds
|
||||
*.pb.cc
|
||||
*.pb.h
|
||||
|
||||
# Directories
|
||||
build/
|
||||
.vscode/
|
||||
|
45
src/main.cpp
45
src/main.cpp
@ -1,37 +1,36 @@
|
||||
// $$$$$$\ $$\
|
||||
// $$ __$$\ $$ |
|
||||
// $$ / \__|$$$$$$\ $$$$$$$\ $$$$$$$\ $$$$$$$\ $$$$$$\ $$$$$$\ $$$$$$$ |
|
||||
// $$$$\ $$ __$$\ $$ _____|$$ _____|$$ _____|$$ __$$\ $$ __$$\ $$ __$$ |
|
||||
// $$ _| $$ / $$ |\$$$$$$\ \$$$$$$\ $$ / $$ / $$ |$$ | \__|$$ / $$ |
|
||||
// $$ | $$ | $$ | \____$$\ \____$$\ $$ | $$ | $$ |$$ | $$ | $$ |
|
||||
// $$ | \$$$$$$ |$$$$$$$ |$$$$$$$ |\$$$$$$$\ \$$$$$$ |$$ | \$$$$$$$ |
|
||||
// \__| \______/ \_______/ \_______/ \_______| \______/ \__| \_______|
|
||||
//
|
||||
//
|
||||
//
|
||||
// $$ __$$\ $$ |
|
||||
// $$ / \__|$$$$$$\ $$$$$$$\ $$$$$$$\ $$$$$$$\ $$$$$$\ $$$$$$\ $$$$$$$ |
|
||||
// $$$$\ $$ __$$\ $$ _____|$$ _____|$$ _____|$$ __$$\ $$ __$$\ $$ __$$ |
|
||||
// $$ _| $$ / $$ |\$$$$$$\ \$$$$$$\ $$ / $$ / $$ |$$ | \__|$$ / $$ |
|
||||
// $$ | $$ | $$ | \____$$\ \____$$\ $$ | $$ | $$ |$$ | $$ | $$ |
|
||||
// $$ | \$$$$$$ |$$$$$$$ |$$$$$$$ |\$$$$$$$\ \$$$$$$ |$$ | \$$$$$$$ |
|
||||
// \__| \______/ \_______/ \_______/ \_______| \______/ \__| \_______|
|
||||
//
|
||||
//
|
||||
//
|
||||
// $$\ $$$$$$\
|
||||
// \__| $$ __$$\
|
||||
// $$\ $$\ $$$$$$\ $$\ $$$$$$$\ $$$$$$\ $$ / \__| $$$$$$\ $$$$$$\ $$\ $$\ $$$$$$\ $$$$$$\
|
||||
// \$$\ $$ |$$ __$$\ $$ |$$ _____|$$ __$$\ \$$$$$$\ $$ __$$\ $$ __$$\\$$\ $$ |$$ __$$\ $$ __$$\
|
||||
// \$$\$$ / $$ / $$ |$$ |$$ / $$$$$$$$ | \____$$\ $$$$$$$$ |$$ | \__|\$$\$$ / $$$$$$$$ |$$ | \__|
|
||||
// \$$$ / $$ | $$ |$$ |$$ | $$ ____|$$\ $$ |$$ ____|$$ | \$$$ / $$ ____|$$ |
|
||||
// \$ / \$$$$$$ |$$ |\$$$$$$$\ \$$$$$$$\ \$$$$$$ |\$$$$$$$\ $$ | \$ / \$$$$$$$\ $$ |
|
||||
// \_/ \______/ \__| \_______| \_______| \______/ \_______|\__| \_/ \_______|\__|
|
||||
//
|
||||
//
|
||||
//
|
||||
// \$$$ / $$ | $$ |$$ |$$ | $$ ____|$$\ $$ |$$ ____|$$ | \$$$ / $$ ____|$$ |
|
||||
// \$ / \$$$$$$ |$$ |\$$$$$$$\ \$$$$$$$\ \$$$$$$ |\$$$$$$$\ $$ | \$ / \$$$$$$$\ $$ |
|
||||
// \_/ \______/ \__| \_______| \_______| \______/ \_______|\__| \_/ \_______|\__|
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
#include "rtcPeerHandler.hpp" //Handle peer connection requests
|
||||
#include "rpcStub.hpp" //Handle gRPC communications between the different fosscord elements
|
||||
|
||||
#include "rtcPeerHandler.hpp" //HAndle peer connection requests
|
||||
#include "rpcStub.hpp" //Handle gRPC communications between the different fosscord elements
|
||||
|
||||
int main (int argc, char** argv){
|
||||
int main(int argc, char **argv){
|
||||
|
||||
auto commsHandler = std::make_shared<rtcPeerHandler>();
|
||||
auto rpcHandler = std::unique_ptr<rpcStub>();
|
||||
auto rpcHandler = std::unique_ptr<rpcStub>(new rpcStub(commsHandler, 8057));
|
||||
|
||||
std::cout << "Server created" <<std::endl;
|
||||
std::cout << "Server created" << std::endl;
|
||||
|
||||
//rpcHandler->server->Wait(); //blocking, this will need to be threaded
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
@ -3,13 +3,13 @@ syntax = "proto3";
|
||||
package fosscordMedia;
|
||||
|
||||
service fosscordInternals{
|
||||
rpc requestProtocol(voiceRequest) returns (voiceAnswer) {}
|
||||
rpc vRequest(voiceRequest) returns (voiceAnswer) {}
|
||||
}
|
||||
|
||||
message voiceRequest{ //OP1 from gw
|
||||
uint64 userid = 1;
|
||||
uint64 guildid = 2;
|
||||
string IP=3;
|
||||
string ip=3;
|
||||
uint32 port=4;
|
||||
string protocol=5;
|
||||
string rtcConnectionId=6;
|
||||
|
@ -1,24 +1,32 @@
|
||||
#include "rpcStub.hpp"
|
||||
|
||||
class fossCordInternalsImpl final : public fosscordMedia::fosscordInternals::Service{
|
||||
grpc::Status sendRequest(
|
||||
grpc::ServerContext* ctx,
|
||||
const fosscordMedia::rpcRequest* req,
|
||||
fosscordMedia::rpcResponse* resp
|
||||
) override{
|
||||
resp->set_b(333);
|
||||
return grpc::Status::OK;
|
||||
class fossCordInternalsImpl final : public fosscordMedia::fosscordInternals::Service {
|
||||
std::shared_ptr<rtcPeerHandler> ph;
|
||||
fossCordInternalsImpl(std::shared_ptr<rtcPeerHandler> handler){
|
||||
this->ph= handler;
|
||||
}
|
||||
grpc::Status vRequest(grpc::ServerContext* ctx,
|
||||
const fosscordMedia::voiceRequest* req,
|
||||
fosscordMedia::voiceAnswer* resp) override {
|
||||
|
||||
this->ph->initiateConnection(req->ip(), req->port());
|
||||
return grpc::Status::OK;
|
||||
}
|
||||
};
|
||||
|
||||
rpcStub::rpcStub(int port){
|
||||
grpc::ServerBuilder builder;
|
||||
rpcStub::rpcStub(std::shared_ptr<rtcPeerHandler> handler, int port) {
|
||||
if (not port) {
|
||||
port = 8057;
|
||||
}
|
||||
this->ph = handler;
|
||||
|
||||
fossCordInternalsImpl* service;
|
||||
builder.AddListeningPort("0.0.0.0:8057", grpc::InsecureServerCredentials() );
|
||||
builder.RegisterService(service);
|
||||
fossCordInternalsImpl* service;
|
||||
grpc::ServerBuilder builder;
|
||||
builder.AddListeningPort("0.0.0.0:" + std::to_string(port),
|
||||
grpc::InsecureServerCredentials());
|
||||
builder.RegisterService(service);
|
||||
|
||||
std::unique_ptr<grpc::Server> server(builder.BuildAndStart());
|
||||
std::cout << "Server listening on port 8057 " << std::endl;
|
||||
this->server = builder.BuildAndStart();
|
||||
|
||||
std::cout << "RPC stub listening on port " << port << std::endl;
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
#include <grpc++/grpc++.h>
|
||||
#include "protodefs/include/protos.grpc.pb.h"
|
||||
#include "rtcPeerHandler.hpp"
|
||||
|
||||
class rpcStub{
|
||||
public:
|
||||
rpcStub(int port);
|
||||
rpcStub(std::shared_ptr<rtcPeerHandler> peerHandler, int port);
|
||||
std::unique_ptr<grpc::Server> server;
|
||||
private:
|
||||
|
||||
|
||||
private:
|
||||
std::shared_ptr<rtcPeerHandler> ph;
|
||||
};
|
@ -1,45 +1,44 @@
|
||||
#include "rtcPeerHandler.hpp"
|
||||
rtcPeerHandler::rtcPeerHandler()
|
||||
{
|
||||
rtc::InitLogger(rtc::LogLevel::Verbose, NULL);
|
||||
|
||||
rtcPeerHandler::rtcPeerHandler() {
|
||||
rtc::InitLogger(rtc::LogLevel::Verbose, NULL);
|
||||
}
|
||||
|
||||
void rtcPeerHandler::initiateConnection(std::string peerIP, int peerPort)
|
||||
{
|
||||
//Socket connection between client and server
|
||||
SOCKET sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
sockaddr_in addr;
|
||||
addr.sin_addr.s_addr = inet_addr(peerIP.c_str());
|
||||
addr.sin_port = htons(peerPort);
|
||||
addr.sin_family = AF_INET;
|
||||
void rtcPeerHandler::initiateConnection(std::string peerIP, int peerPort) {
|
||||
// Socket connection between client and server
|
||||
SOCKET sock = socket(AF_INET, SOCK_DGRAM, 0);
|
||||
sockaddr_in addr;
|
||||
addr.sin_addr.s_addr = inet_addr(peerIP.c_str());
|
||||
addr.sin_port = htons(peerPort);
|
||||
addr.sin_family = AF_INET;
|
||||
|
||||
rtc::Configuration conf;
|
||||
conf.enableIceTcp = false;
|
||||
conf.disableAutoNegotiation = false;
|
||||
rtc::Configuration conf;
|
||||
conf.enableIceTcp = false;
|
||||
conf.disableAutoNegotiation = false;
|
||||
|
||||
auto pc = std::make_shared<rtc::PeerConnection>(conf);
|
||||
auto pc = std::make_shared<rtc::PeerConnection>(conf);
|
||||
|
||||
rtc::Description::Audio media("audio", rtc::Description::Direction::SendRecv);
|
||||
media.addOpusCodec(96);
|
||||
media.setBitrate(64);
|
||||
rtc::Description::Audio media("audio",
|
||||
rtc::Description::Direction::SendRecv);
|
||||
media.addOpusCodec(96);
|
||||
media.setBitrate(64);
|
||||
|
||||
auto track = pc->addTrack(media);
|
||||
|
||||
auto track = pc->addTrack(media);
|
||||
// auto session = std::make_shared<rtc::MediaHandler>();
|
||||
|
||||
//auto session = std::make_shared<rtc::MediaHandler>();
|
||||
// track->setMediaHandler(session);
|
||||
|
||||
//track->setMediaHandler(session);
|
||||
rtc::Reliability rtcRel;
|
||||
rtcRel.unordered = true;
|
||||
rtcRel.type = rtc::Reliability::Type::Timed;
|
||||
rtcRel.rexmit = 500;
|
||||
|
||||
rtc::Reliability rtcRel;
|
||||
rtcRel.unordered = true;
|
||||
rtcRel.type = rtc::Reliability::Type::Timed;
|
||||
rtcRel.rexmit = 500;
|
||||
rtc::DataChannelInit rtcConf;
|
||||
rtcConf.reliability = rtcRel;
|
||||
rtcConf.negotiated = false;
|
||||
|
||||
rtc::DataChannelInit rtcConf;
|
||||
rtcConf.reliability = rtcRel;
|
||||
rtcConf.negotiated = false;
|
||||
|
||||
pc->onStateChange([](rtc::PeerConnection::State state) {
|
||||
pc->onStateChange([](rtc::PeerConnection::State state) {
|
||||
std::cout << "State: " << state << std::endl;
|
||||
if (state == rtc::PeerConnection::State::Disconnected ||
|
||||
state == rtc::PeerConnection::State::Failed ||
|
||||
@ -48,10 +47,37 @@ void rtcPeerHandler::initiateConnection(std::string peerIP, int peerPort)
|
||||
}
|
||||
});
|
||||
|
||||
pc->onGatheringStateChange(
|
||||
[](rtc::PeerConnection::GatheringState state) { std::cout << "Gathering State: " << state << std::endl; });
|
||||
pc->onGatheringStateChange([](rtc::PeerConnection::GatheringState state) {
|
||||
std::cout << "Gathering State: " << state << std::endl;
|
||||
});
|
||||
|
||||
/*std::tuple<rtc::Track*, rtc::RtcpSrReporter*> addAudio(
|
||||
|
||||
const std::shared_ptr<rtc::PeerConnection> pc,
|
||||
const uint8_t payloadType, const uint32_t ssrc, const std::string cname,
|
||||
const std::string msid, const std::function<void(void)> onOpen) {
|
||||
auto audio = Description::Audio(cname);
|
||||
audio.addOpusCodec(payloadType);
|
||||
audio.addSSRC(ssrc, cname, msid, cname);
|
||||
auto track = pc->addTrack(audio);
|
||||
// create RTP configuration
|
||||
auto rtpConfig = make_shared<RtpPacketizationConfig>(
|
||||
ssrc, cname, payloadType, OpusRtpPacketizer::defaultClockRate);
|
||||
// create packetizer
|
||||
auto packetizer = make_shared<OpusRtpPacketizer>(rtpConfig);
|
||||
// create opus handler
|
||||
auto opusHandler = make_shared<OpusPacketizationHandler>(packetizer);
|
||||
|
||||
pc->createDataChannel("Fosscord voice connection", rtcConf);
|
||||
// add RTCP SR handler
|
||||
auto srReporter = make_shared<RtcpSrReporter>(rtpConfig);
|
||||
opusHandler->addToChain(srReporter);
|
||||
|
||||
// set handler
|
||||
track->setMediaHandler(opusHandler);
|
||||
track->onOpen(onOpen);
|
||||
auto trackData = make_shared<ClientTrackData>(track, srReporter);
|
||||
return trackData;
|
||||
}*/
|
||||
|
||||
pc->createDataChannel("Fosscord voice connection", rtcConf);
|
||||
}
|
||||
|
@ -13,6 +13,8 @@ typedef int SOCKET;
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
#ifndef RTCPEERHANDLER
|
||||
#define RTCPEERHANDLER
|
||||
class rtcPeerHandler{
|
||||
public:
|
||||
rtcPeerHandler();
|
||||
@ -26,4 +28,5 @@ public:
|
||||
|
||||
private:
|
||||
std::map<SOCKET, client> clients;
|
||||
};
|
||||
};
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user