BOB quiet command

This commit is contained in:
orignal 2014-12-05 14:13:16 -05:00
parent 07d5e8c756
commit 392075bf60
2 changed files with 75 additions and 5 deletions

51
BOB.cpp
View File

@ -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)
{
}
@ -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)
@ -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))
@ -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 ()

29
BOB.h
View File

@ -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";
@ -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>
{
@ -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:
@ -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;