Skip to content

Commit

Permalink
BOB quiet command
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Dec 5, 2014
1 parent 07d5e8c commit 392075b
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 5 deletions.
51 changes: 48 additions & 3 deletions BOB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,46 @@ namespace client
connection->I2PConnect (m_ReceivedData, m_ReceivedDataLen);
}

BOBI2POutboundTunnel::BOBI2POutboundTunnel (boost::asio::io_service& service, const std::string& address, int port,
ClientDestination * localDestination, bool quiet): I2PTunnel (service, localDestination),
m_Endpoint (boost::asio::ip::address::from_string (address), port), m_IsQuiet (quiet)
{
}

void BOBI2POutboundTunnel::Start ()
{
Accept ();
}

void BOBI2POutboundTunnel::Stop ()
{
ClearConnections ();
}

void BOBI2POutboundTunnel::Accept ()
{
auto localDestination = GetLocalDestination ();
if (localDestination)
localDestination->AcceptStreams (std::bind (&BOBI2POutboundTunnel::HandleAccept, this, std::placeholders::_1));
else
LogPrint ("Local destination not set for server tunnel");
}

void BOBI2POutboundTunnel::HandleAccept (std::shared_ptr<i2p::stream::Stream> stream)
{
if (stream)
{
auto conn = std::make_shared<I2PTunnelConnection> (this, stream, new boost::asio::ip::tcp::socket (GetService ()), m_Endpoint);
AddConnection (conn);
conn->Connect ();
// TODO:
}
}


BOBCommandSession::BOBCommandSession (BOBCommandChannel& owner):
m_Owner (owner), m_Socket (m_Owner.GetService ()), m_ReceiveBufferOffset (0),
m_IsOpen (true), m_IsOutbound (false), m_Port (0)
m_IsOpen (true), m_IsOutbound (false), m_IsQuiet (false), m_Port (0)
{
}

Expand Down Expand Up @@ -264,7 +301,7 @@ namespace client
auto dest = context.CreateNewLocalDestination (m_Keys, true);
I2PTunnel * tunnel = nullptr;
if (m_IsOutbound)
tunnel = new I2PServerTunnel (m_Owner.GetService (), m_Address, m_Port, dest);
tunnel = new BOBI2POutboundTunnel (m_Owner.GetService (), m_Address, m_Port, dest, m_IsQuiet);
else
tunnel = new BOBI2PInboundTunnel (m_Owner.GetService (), m_Port, dest);
if (tunnel)
Expand Down Expand Up @@ -372,7 +409,14 @@ namespace client
m_Port = boost::lexical_cast<int>(operand);
SendReplyOK ("inbound port set");
}


void BOBCommandSession::QuietCommandHandler (const char * operand, size_t len)
{
LogPrint (eLogDebug, "BOB: quiet");
m_IsQuiet = true;
SendReplyOK ("quiet");
}

BOBCommandChannel::BOBCommandChannel (int port):
m_IsRunning (false), m_Thread (nullptr),
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port))
Expand All @@ -392,6 +436,7 @@ namespace client
m_CommandHandlers[BOB_COMMAND_OUTPORT] = &BOBCommandSession::OutportCommandHandler;
m_CommandHandlers[BOB_COMMAND_INHOST] = &BOBCommandSession::InhostCommandHandler;
m_CommandHandlers[BOB_COMMAND_INPORT] = &BOBCommandSession::InportCommandHandler;
m_CommandHandlers[BOB_COMMAND_QUIET] = &BOBCommandSession::QuietCommandHandler;
}

BOBCommandChannel::~BOBCommandChannel ()
Expand Down
29 changes: 27 additions & 2 deletions BOB.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ namespace client
const char BOB_COMMAND_OUTPORT[] = "outport";
const char BOB_COMMAND_INHOST[] = "inhost";
const char BOB_COMMAND_INPORT[] = "inport";

const char BOB_COMMAND_QUIET[] = "quiet";

const char BOB_REPLY_OK[] = "OK %s\n";
const char BOB_REPLY_ERROR[] = "ERROR %s\n";

Expand Down Expand Up @@ -66,6 +67,29 @@ namespace client
size_t m_ReceivedDataLen;
};

class BOBI2POutboundTunnel: public I2PTunnel
{
public:

BOBI2POutboundTunnel (boost::asio::io_service& service, const std::string& address, int port,
ClientDestination * localDestination, bool quiet);

void Start ();
void Stop ();

void SetQuiet () { m_IsQuiet = true; };

private:

void Accept ();
void HandleAccept (std::shared_ptr<i2p::stream::Stream> stream);

private:

boost::asio::ip::tcp::endpoint m_Endpoint;
bool m_IsQuiet;
};

class BOBCommandChannel;
class BOBCommandSession: public std::enable_shared_from_this<BOBCommandSession>
{
Expand Down Expand Up @@ -93,6 +117,7 @@ namespace client
void OutportCommandHandler (const char * operand, size_t len);
void InhostCommandHandler (const char * operand, size_t len);
void InportCommandHandler (const char * operand, size_t len);
void QuietCommandHandler (const char * operand, size_t len);

private:

Expand All @@ -109,7 +134,7 @@ namespace client
boost::asio::ip::tcp::socket m_Socket;
char m_ReceiveBuffer[BOB_COMMAND_BUFFER_SIZE + 1], m_SendBuffer[BOB_COMMAND_BUFFER_SIZE + 1];
size_t m_ReceiveBufferOffset;
bool m_IsOpen, m_IsOutbound;
bool m_IsOpen, m_IsOutbound, m_IsQuiet;
std::string m_Nickname, m_Address;
int m_Port;
i2p::data::PrivateKeys m_Keys;
Expand Down

0 comments on commit 392075b

Please sign in to comment.