Browse Source

pass BOB options to destination

pull/113/head
orignal 10 years ago
parent
commit
797c8750d8
  1. 26
      BOB.cpp
  2. 3
      BOB.h

26
BOB.cpp

@ -12,7 +12,7 @@ namespace client
BOBI2PInboundTunnel::BOBI2PInboundTunnel (boost::asio::io_service& service, int port, ClientDestination * localDestination): BOBI2PInboundTunnel::BOBI2PInboundTunnel (boost::asio::io_service& service, int port, ClientDestination * localDestination):
BOBI2PTunnel (service, localDestination), BOBI2PTunnel (service, localDestination),
m_Acceptor (service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)), m_Acceptor (service, boost::asio::ip::tcp::endpoint (boost::asio::ip::tcp::v4(), port)),
m_Timer (service), m_ReceivedData (nullptr), m_ReceivedDataLen (0) m_Timer (service), m_ReceivedData (nullptr), m_ReceivedDataLen (0), m_ReceiveBufferOffset (0)
{ {
} }
@ -53,7 +53,8 @@ namespace client
void BOBI2PInboundTunnel::ReceiveAddress (boost::asio::ip::tcp::socket * socket) void BOBI2PInboundTunnel::ReceiveAddress (boost::asio::ip::tcp::socket * socket)
{ {
socket->async_read_some (boost::asio::buffer(m_ReceiveBuffer, BOB_COMMAND_BUFFER_SIZE), socket->async_read_some (boost::asio::buffer(m_ReceiveBuffer + m_ReceiveBufferOffset,
BOB_COMMAND_BUFFER_SIZE - m_ReceiveBufferOffset),
std::bind(&BOBI2PInboundTunnel::HandleReceivedAddress, this, std::bind(&BOBI2PInboundTunnel::HandleReceivedAddress, this,
std::placeholders::_1, std::placeholders::_2, socket)); std::placeholders::_1, std::placeholders::_2, socket));
} }
@ -68,14 +69,15 @@ namespace client
} }
else else
{ {
m_ReceiveBuffer[bytes_transferred] = 0; m_ReceiveBufferOffset += bytes_transferred;
m_ReceiveBuffer[m_ReceiveBufferOffset] = 0;
char * eol = strchr (m_ReceiveBuffer, '\n'); char * eol = strchr (m_ReceiveBuffer, '\n');
if (eol) if (eol)
{ {
*eol = 0; *eol = 0;
m_ReceivedData = (uint8_t *)eol + 1; m_ReceivedData = (uint8_t *)eol + 1;
m_ReceivedDataLen = bytes_transferred - (eol - m_ReceiveBuffer + 1); m_ReceivedDataLen = m_ReceiveBufferOffset - (eol - m_ReceiveBuffer + 1);
i2p::data::IdentHash ident; i2p::data::IdentHash ident;
if (!context.GetAddressBook ().GetIdentHash (m_ReceiveBuffer, ident)) if (!context.GetAddressBook ().GetIdentHash (m_ReceiveBuffer, ident))
{ {
@ -95,12 +97,17 @@ namespace client
} }
} }
else else
{
if (m_ReceiveBufferOffset < BOB_COMMAND_BUFFER_SIZE)
ReceiveAddress (socket);
else
{ {
LogPrint ("BOB missing inbound address ", bytes_transferred); LogPrint ("BOB missing inbound address ", bytes_transferred);
delete socket; delete socket;
} }
} }
} }
}
void BOBI2PInboundTunnel::HandleDestinationRequestTimer (const boost::system::error_code& ecode, boost::asio::ip::tcp::socket * socket, i2p::data::IdentHash ident) void BOBI2PInboundTunnel::HandleDestinationRequestTimer (const boost::system::error_code& ecode, boost::asio::ip::tcp::socket * socket, i2p::data::IdentHash ident)
{ {
@ -314,7 +321,7 @@ namespace client
void BOBCommandSession::StartCommandHandler (const char * operand, size_t len) void BOBCommandSession::StartCommandHandler (const char * operand, size_t len)
{ {
LogPrint (eLogDebug, "BOB: start ", m_Nickname); LogPrint (eLogDebug, "BOB: start ", m_Nickname);
auto dest = context.CreateNewLocalDestination (m_Keys, true); auto dest = context.CreateNewLocalDestination (m_Keys, true, &m_Options);
BOBI2PTunnel * tunnel = nullptr; BOBI2PTunnel * tunnel = nullptr;
if (m_IsOutbound) if (m_IsOutbound)
tunnel = new BOBI2POutboundTunnel (m_Owner.GetService (), m_Address, m_Port, dest, m_IsQuiet); tunnel = new BOBI2POutboundTunnel (m_Owner.GetService (), m_Address, m_Port, dest, m_IsQuiet);
@ -464,8 +471,17 @@ namespace client
void BOBCommandSession::OptionCommandHandler (const char * operand, size_t len) void BOBCommandSession::OptionCommandHandler (const char * operand, size_t len)
{ {
LogPrint (eLogDebug, "BOB: option ", operand); LogPrint (eLogDebug, "BOB: option ", operand);
const char * value = strchr (operand, '=');
if (value)
{
*(const_cast<char *>(value)) = 0;
m_Options[operand] = value + 1;
*(const_cast<char *>(value)) = '=';
SendReplyOK ("option"); SendReplyOK ("option");
} }
else
SendReplyError ("malformed");
}
BOBCommandChannel::BOBCommandChannel (int port): BOBCommandChannel::BOBCommandChannel (int port):
m_IsRunning (false), m_Thread (nullptr), m_IsRunning (false), m_Thread (nullptr),

3
BOB.h

@ -81,7 +81,7 @@ namespace client
boost::asio::deadline_timer m_Timer; boost::asio::deadline_timer m_Timer;
char m_ReceiveBuffer[BOB_COMMAND_BUFFER_SIZE + 1]; // for destination base64 address char m_ReceiveBuffer[BOB_COMMAND_BUFFER_SIZE + 1]; // for destination base64 address
uint8_t * m_ReceivedData; uint8_t * m_ReceivedData;
size_t m_ReceivedDataLen; size_t m_ReceivedDataLen, m_ReceiveBufferOffset;
}; };
class BOBI2POutboundTunnel: public BOBI2PTunnel class BOBI2POutboundTunnel: public BOBI2PTunnel
@ -161,6 +161,7 @@ namespace client
std::string m_Nickname, m_Address; std::string m_Nickname, m_Address;
int m_Port; int m_Port;
i2p::data::PrivateKeys m_Keys; i2p::data::PrivateKeys m_Keys;
std::map<std::string, std::string> m_Options;
}; };
typedef void (BOBCommandSession::*BOBCommandHandler)(const char * operand, size_t len); typedef void (BOBCommandSession::*BOBCommandHandler)(const char * operand, size_t len);

Loading…
Cancel
Save