summaryrefslogtreecommitdiff
path: root/anyrtpproxy
diff options
context:
space:
mode:
Diffstat (limited to 'anyrtpproxy')
-rw-r--r--anyrtpproxy/anyrtpproxy.cpp140
1 files changed, 58 insertions, 82 deletions
diff --git a/anyrtpproxy/anyrtpproxy.cpp b/anyrtpproxy/anyrtpproxy.cpp
index 41cb643..9079994 100644
--- a/anyrtpproxy/anyrtpproxy.cpp
+++ b/anyrtpproxy/anyrtpproxy.cpp
@@ -12,61 +12,54 @@
#include "../buffer.h"
#include "options.h"
-#include <list>
+#include <map>
+
#define MAX_PACKET_SIZE 1500
-class ControlHost
+class ControlHost : public Host
{
public:
- ControlHost() : host_("",0) {};
-
- Host getHost() {
- Lock lock(mutex);
- return host_;
- }
-
- void setHost(std::string addr, u_int16_t port)
+ ControlHost() : Host("",0) {};
+ bool operator<(const ControlHost& cmp_to)
{
- Lock lock(mutex);
- if(host_.addr_ != addr || host_.port_ != port)
- cLog.msg(Log::PRIO_NOTICE) << "control Host detected at " << addr << ":" << port;
-
- host_.addr_ = addr;
- host_.port_ = port;
+ return port_ < cmp_to.port_;
}
-
-private:
- Mutex mutex;
-
- Host host_;
};
-struct ThreadParam
+class ControlHostMap
{
- ControlHost& control_;
- UDPSocket& control_sock_;
- UDPSocket& sock_;
- Host first_receiver_;
-};
+public:
+
-void* sender(void* p)
-{
- ThreadParam* param = reinterpret_cast<ThreadParam*>(p);
+private:
+ Mutex mutex;
+
+ std::map<ControlHost, std::pair<UDPSocket*, pthread_t>> control_hosts_;
+}
+void* sender(void* dont_use_me)
+{
try
{
HostList remote_host_list(gOpt.getRemoteHosts());
+ UDPSocket control_sock(gOpt.getControlInterface().addr_, gOpt.getControlInterface().port_);
Buffer buf(u_int32_t(MAX_PACKET_SIZE));
string remote_host;
u_int16_t remote_port;
while(1) {
buf.setLength(MAX_PACKET_SIZE);
- u_int32_t len = param->control_sock_.recvFrom(buf.getBuf(), buf.getLength(), remote_host, remote_port);
+ u_int32_t len = control_sock_.recvFrom(buf.getBuf(), buf.getLength(), remote_host, remote_port);
buf.setLength(len);
param->control_.setHost(remote_host, remote_port);
+
+// SenderThreadParam receiverParam = {control_host, control_sock, sock, gOpt.getRemoteHosts().front()};
+// pthread_t receiverThread;
+// pthread_create(&receiverThread, NULL, receiver, &receiverParam);
+// pthread_detach(receiverThread);
+
HostList::const_iterator it = remote_host_list.begin();
for(;it != remote_host_list.end(); it++)
@@ -84,37 +77,37 @@ void* sender(void* p)
void* receiver(void* p)
{
- ThreadParam* param = reinterpret_cast<ThreadParam*>(p);
+// SenderThreadParam* param = reinterpret_cast<SenderThreadParam*>(p);
- try
- {
- Buffer buf(u_int32_t(MAX_PACKET_SIZE));
- string remote_host;
- u_int16_t remote_port;
-
- while(1) {
- buf.setLength(MAX_PACKET_SIZE);
- u_int32_t len = param->sock_.recvFrom(buf.getBuf(), buf.getLength(), remote_host, remote_port);
- buf.setLength(len);
-
- if(remote_host != param->first_receiver_.addr_ || remote_port != param->first_receiver_.port_)
- continue;
+// try
+// {
+// Buffer buf(u_int32_t(MAX_PACKET_SIZE));
+// string remote_host;
+// u_int16_t remote_port;
+
+// while(1) {
+// buf.setLength(MAX_PACKET_SIZE);
+// u_int32_t len = param->sock_.recvFrom(buf.getBuf(), buf.getLength(), remote_host, remote_port);
+// buf.setLength(len);
+
+// if(remote_host != param->first_receiver_.addr_ || remote_port != param->first_receiver_.port_)
+// continue;
- Host control_host = param->control_.getHost();
- if(control_host.addr_ == "" || !control_host.port_)
- {
- cLog.msg(Log::PRIO_NOTICE) << "no control host detected till now, ignoring packet";
- continue;
- }
-
- param->control_sock_.sendTo(buf.getBuf(), buf.getLength(), control_host.addr_, control_host.port_);
- }
- }
- catch(std::exception &e)
- {
- cLog.msg(Log::PRIO_ERR) << "receiver exiting because: " << e.what() << std::endl;
- }
- pthread_exit(NULL);
+// Host control_host = param->control_.getHost();
+// if(control_host.addr_ == "" || !control_host.port_)
+// {
+// cLog.msg(Log::PRIO_NOTICE) << "no control host detected till now, ignoring packet";
+// continue;
+// }
+
+// param->control_sock_.sendTo(buf.getBuf(), buf.getLength(), control_host.addr_, control_host.port_);
+// }
+// }
+// catch(std::exception &e)
+// {
+// cLog.msg(Log::PRIO_ERR) << "receiver exiting because: " << e.what() << std::endl;
+// }
+// pthread_exit(NULL);
}
void chrootAndDrop(string const& chrootdir, string const& username)
@@ -190,28 +183,11 @@ int main(int argc, char* argv[])
SignalController sig;
sig.init();
- try {
- ControlHost control_host;
- UDPSocket control_sock(gOpt.getControlInterface().addr_, gOpt.getControlInterface().port_);
- UDPSocket sock(gOpt.getSendPort());
-
- ThreadParam senderParam = {control_host, control_sock, sock, gOpt.getRemoteHosts().front()};
- pthread_t senderThread;
- pthread_create(&senderThread, NULL, sender, &senderParam);
- pthread_detach(senderThread);
-
- ThreadParam receiverParam = {control_host, control_sock, sock, gOpt.getRemoteHosts().front()};
- pthread_t receiverThread;
- pthread_create(&receiverThread, NULL, receiver, &receiverParam);
- pthread_detach(receiverThread);
+ pthread_t senderThread;
+ pthread_create(&senderThread, NULL, sender, NULL);
+ pthread_detach(senderThread);
- int ret = sig.run();
- return ret;
- }
- catch(std::exception& e)
- {
- cLog.msg(Log::PRIO_ERR) << "an error occurred: " << e.what();
- return -1;
- }
+ int ret = sig.run();
+ return ret;
}