* tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
* mode and allows tunneling of every ETHER TYPE protocol (e.g.
* ethernet, ip, arp ...). satp directly includes cryptography and
- * message authentication based on the methodes used by SRTP. It is
+ * message authentication based on the methods used by SRTP. It is
* intended to deliver a generic, scaleable and secure solution for
* tunneling and relaying of packets of any protocol.
*
*
- * Copyright (C) 2007-2009 Othmar Gsenger, Erwin Nindl,
+ * Copyright (C) 2007-2014 Markus Grüneis, Othmar Gsenger, Erwin Nindl,
* Christian Pointner <satp@wirdorange.org>
*
* This file is part of Anytun.
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with anytun. If not, see <http://www.gnu.org/licenses/>.
+ * along with Anytun. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL. If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so. If you
+ * do not wish to do so, delete this exception statement from your
+ * version. If you delete this exception statement from all source
+ * files in the program, then also delete it here.
*/
#include <sstream>
#define MAX_COMMAND_LENGTH 1000
-CommandHandler::CommandHandler(SyncQueue& q, std::string lp,PortWindow & pw) : thread_(boost::bind(run,this)),
- queue_(q), running_(true), control_sock_(io_service_),
- local_address_(""), local_port_(lp),port_window_(pw)
+CommandHandler::CommandHandler(SyncQueue& q, std::string lp,PortWindow& pw) : thread_(boost::bind(run,this)),
+ queue_(q), running_(true), control_sock_(io_service_),
+ local_address_(""), local_port_(lp),port_window_(pw)
{
proto::resolver resolver(io_service_);
- proto::resolver::query query(local_port_);
+ proto::resolver::query query(local_port_);
proto::endpoint e = *resolver.resolve(query);
control_sock_.open(e.protocol());
control_sock_.bind(e);
}
-CommandHandler::CommandHandler(SyncQueue& q, string la, std::string lp, PortWindow & pw) : thread_(boost::bind(run,this)),
- queue_(q), running_(true), control_sock_(io_service_),
- local_address_(la), local_port_(lp),port_window_(pw)
+CommandHandler::CommandHandler(SyncQueue& q, string la, std::string lp, PortWindow& pw) : thread_(boost::bind(run,this)),
+ queue_(q), running_(true), control_sock_(io_service_),
+ local_address_(la), local_port_(lp),port_window_(pw)
{
proto::resolver resolver(io_service_);
- proto::resolver::query query(local_address_, local_port_);
+ proto::resolver::query query(local_address_, local_port_);
proto::endpoint e = *resolver.resolve(query);
control_sock_.open(e.protocol());
control_sock_.bind(e);
{
CommandHandler* self = reinterpret_cast<CommandHandler*>(s);
- Buffer buf(u_int32_t(MAX_COMMAND_LENGTH));
- try
- {
+ Buffer buf(uint32_t(MAX_COMMAND_LENGTH));
+ try {
proto::endpoint remote_end;
int len;
- while(1)
- {
+ for(;;) {
buf.setLength(MAX_COMMAND_LENGTH);
len = self->control_sock_.receive_from(boost::asio::buffer(buf.getBuf(), buf.getLength()), remote_end);
self->control_sock_.send_to(boost::asio::buffer(ret.c_str(), ret.length()), remote_end);
}
- }
- catch(std::exception& e)
- {
+ } catch(std::exception& e) {
self->running_ = false;
}
self->running_ = false;
params.push_back(tmp);
}
- switch(std::toupper(cmd[0]))
- {
+ switch(std::toupper(cmd[0])) {
case CMD_REQUEST:
if(params.size() < 4) { oss << RET_ERR_SYNTAX; break; }
oss << handleRequest(cmd.erase(0,1), params[0], params[1], params[2], params[3], (params.size() < 5) ? "" : params[4]);
string CommandHandler::handleRequest(string modifiers, string call_id, string addr, string port, string from_tag, string to_tag)
{
- std::cout << "received request[" << modifiers << "] command ('" << call_id << "','" << addr << "','" << port
+ std::cout << "received request[" << modifiers << "] command ('" << call_id << "','" << addr << "','" << port
<< "','" << from_tag << "','" << to_tag << "')" << std::endl;
- try
- {
+ try {
RtpSession::proto::resolver resolver(io_service_);
bool is_new;
RtpSession& session = gRtpSessionTable.getOrNewSession(call_id, is_new);
- if(is_new)
- {
- u_int16_t port1 = port_window_.newPort(); // TODO: get next available port
- u_int16_t port2 = port_window_.newPort(); // TODO: get next available port
- if( !port1 || !port2)
- {
- if( port1) port_window_.freePort(port1);
- if( port2) port_window_.freePort(port2);
- throw std::runtime_error("no free port found");
- }
+ if(is_new) {
+ uint16_t port1 = port_window_.newPort(); // TODO: get next available port
+ uint16_t port2 = port_window_.newPort(); // TODO: get next available port
+ if(!port1 || !port2) {
+ if(port1) { port_window_.freePort(port1); }
+ if(port2) { port_window_.freePort(port2); }
+ throw std::runtime_error("no free port found");
+ }
std::stringstream ps1, ps2;
ps1 << port1;
ps2 << port2;
e1 = *resolver.resolve(query1);
RtpSession::proto::resolver::query query2(ps2.str());
e2 = *resolver.resolve(query2);
- }
- else {
+ } else {
RtpSession::proto::resolver::query query1(gOpt.getLocalAddr(),ps1.str());
e1 = *resolver.resolve(query1);
RtpSession::proto::resolver::query query2(gOpt.getLocalAddr(),ps2.str());
ostringstream oss;
oss << session.getLocalEnd2().port();
return oss.str();
- }
- catch(std::exception& e)
- {
+ } catch(std::exception& e) {
return RET_ERR_UNKNOWN; // TODO: change to corret error value
}
}
string CommandHandler::handleResponse(string modifiers, string call_id, string addr, string port, string from_tag, string to_tag)
{
- std::cout << "received response[" << modifiers << "] command ('" << call_id << "','" << addr << "','" << port
+ std::cout << "received response[" << modifiers << "] command ('" << call_id << "','" << addr << "','" << port
<< "','" << from_tag << "','" << to_tag << "')" << std::endl;
- try
- {
+ try {
RtpSession& session = gRtpSessionTable.getSession(call_id);
RtpSession::proto::resolver resolver(io_service_);
RtpSession::proto::resolver::query query(addr,port);
ostringstream oss;
oss << session.getLocalEnd1().port();
return oss.str();
- }
- catch(std::exception& e)
- {
+ } catch(std::exception& e) {
return RET_ERR_UNKNOWN; // TODO: change to corret error value
}
}
{
std::cout << "received delete command ('" << call_id << "','" << from_tag << "','" << to_tag << "')" << std::endl;
- try
- {
+ try {
RtpSession& session = gRtpSessionTable.getSession(call_id);
session.isDead(true);
SyncRtpCommand sc(call_id);
queue_.push(sc);
return RET_OK;
- }
- catch(std::exception& e)
- {
+ } catch(std::exception& e) {
return RET_ERR_UNKNOWN; // TODO: change to corret error value
}
}
string CommandHandler::handleVersion()
{
- std::cout << "received version command" << std::endl;
+ std::cout << "received version command" << std::endl;
return BASE_VERSION;
}
string CommandHandler::handleVersionF(string date_code)
{
- std::cout << "received version[F] command ('" << date_code << "')" << std::endl;
- if(!date_code.compare(SUP_VERSION))
+ std::cout << "received version[F] command ('" << date_code << "')" << std::endl;
+ if(!date_code.compare(SUP_VERSION)) {
return "1";
-
+ }
+
return "0";
}
string CommandHandler::handleInfo()
{
- std::cout << "received info command, ignoring" << std::endl;
+ std::cout << "received info command, ignoring" << std::endl;
return RET_OK;
}