mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-27 11:17:49 +02:00
remove trailing whitespaces
This commit is contained in:
parent
b91efaa973
commit
46f62e1af9
117 changed files with 3039 additions and 3040 deletions
|
@ -8,7 +8,7 @@ namespace i2p
|
|||
{
|
||||
namespace client
|
||||
{
|
||||
BOBI2PInboundTunnel::BOBI2PInboundTunnel (const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr<ClientDestination> localDestination):
|
||||
BOBI2PInboundTunnel::BOBI2PInboundTunnel (const boost::asio::ip::tcp::endpoint& ep, std::shared_ptr<ClientDestination> localDestination):
|
||||
BOBI2PTunnel (localDestination), m_Acceptor (localDestination->GetService (), ep)
|
||||
{
|
||||
}
|
||||
|
@ -36,13 +36,13 @@ namespace client
|
|||
receiver->socket = std::make_shared<boost::asio::ip::tcp::socket> (GetService ());
|
||||
m_Acceptor.async_accept (*receiver->socket, std::bind (&BOBI2PInboundTunnel::HandleAccept, this,
|
||||
std::placeholders::_1, receiver));
|
||||
}
|
||||
}
|
||||
|
||||
void BOBI2PInboundTunnel::HandleAccept (const boost::system::error_code& ecode, std::shared_ptr<AddressReceiver> receiver)
|
||||
{
|
||||
if (!ecode)
|
||||
{
|
||||
Accept ();
|
||||
Accept ();
|
||||
ReceiveAddress (receiver);
|
||||
}
|
||||
}
|
||||
|
@ -50,12 +50,12 @@ namespace client
|
|||
void BOBI2PInboundTunnel::ReceiveAddress (std::shared_ptr<AddressReceiver> receiver)
|
||||
{
|
||||
receiver->socket->async_read_some (boost::asio::buffer(
|
||||
receiver->buffer + receiver->bufferOffset,
|
||||
BOB_COMMAND_BUFFER_SIZE - receiver->bufferOffset),
|
||||
std::bind(&BOBI2PInboundTunnel::HandleReceivedAddress, this,
|
||||
receiver->buffer + receiver->bufferOffset,
|
||||
BOB_COMMAND_BUFFER_SIZE - receiver->bufferOffset),
|
||||
std::bind(&BOBI2PInboundTunnel::HandleReceivedAddress, this,
|
||||
std::placeholders::_1, std::placeholders::_2, receiver));
|
||||
}
|
||||
|
||||
|
||||
void BOBI2PInboundTunnel::HandleReceivedAddress (const boost::system::error_code& ecode, std::size_t bytes_transferred,
|
||||
std::shared_ptr<AddressReceiver> receiver)
|
||||
{
|
||||
|
@ -69,11 +69,11 @@ namespace client
|
|||
if (eol)
|
||||
{
|
||||
*eol = 0;
|
||||
if (eol != receiver->buffer && eol[-1] == '\r') eol[-1] = 0; // workaround for Transmission, it sends '\r\n' terminated address
|
||||
if (eol != receiver->buffer && eol[-1] == '\r') eol[-1] = 0; // workaround for Transmission, it sends '\r\n' terminated address
|
||||
receiver->data = (uint8_t *)eol + 1;
|
||||
receiver->dataLen = receiver->bufferOffset - (eol - receiver->buffer + 1);
|
||||
i2p::data::IdentHash ident;
|
||||
if (!context.GetAddressBook ().GetIdentHash (receiver->buffer, ident))
|
||||
if (!context.GetAddressBook ().GetIdentHash (receiver->buffer, ident))
|
||||
{
|
||||
LogPrint (eLogError, "BOB: address ", receiver->buffer, " not found");
|
||||
return;
|
||||
|
@ -82,7 +82,7 @@ namespace client
|
|||
if (leaseSet)
|
||||
CreateConnection (receiver, leaseSet);
|
||||
else
|
||||
GetLocalDestination ()->RequestDestination (ident,
|
||||
GetLocalDestination ()->RequestDestination (ident,
|
||||
std::bind (&BOBI2PInboundTunnel::HandleDestinationRequestComplete,
|
||||
this, std::placeholders::_1, receiver));
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ namespace client
|
|||
ReceiveAddress (receiver);
|
||||
else
|
||||
LogPrint (eLogError, "BOB: missing inbound address");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -102,7 +102,7 @@ namespace client
|
|||
CreateConnection (receiver, leaseSet);
|
||||
else
|
||||
LogPrint (eLogError, "BOB: LeaseSet for inbound destination not found");
|
||||
}
|
||||
}
|
||||
|
||||
void BOBI2PInboundTunnel::CreateConnection (std::shared_ptr<AddressReceiver> receiver, std::shared_ptr<const i2p::data::LeaseSet> leaseSet)
|
||||
{
|
||||
|
@ -112,12 +112,12 @@ namespace client
|
|||
connection->I2PConnect (receiver->data, receiver->dataLen);
|
||||
}
|
||||
|
||||
BOBI2POutboundTunnel::BOBI2POutboundTunnel (const std::string& address, int port,
|
||||
BOBI2POutboundTunnel::BOBI2POutboundTunnel (const std::string& address, int port,
|
||||
std::shared_ptr<ClientDestination> localDestination, bool quiet): BOBI2PTunnel (localDestination),
|
||||
m_Endpoint (boost::asio::ip::address::from_string (address), port), m_IsQuiet (quiet)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void BOBI2POutboundTunnel::Start ()
|
||||
{
|
||||
Accept ();
|
||||
|
@ -126,11 +126,11 @@ namespace client
|
|||
void BOBI2POutboundTunnel::Stop ()
|
||||
{
|
||||
ClearHandlers ();
|
||||
}
|
||||
}
|
||||
|
||||
void BOBI2POutboundTunnel::Accept ()
|
||||
{
|
||||
auto localDestination = GetLocalDestination ();
|
||||
auto localDestination = GetLocalDestination ();
|
||||
if (localDestination)
|
||||
localDestination->AcceptStreams (std::bind (&BOBI2POutboundTunnel::HandleAccept, this, std::placeholders::_1));
|
||||
else
|
||||
|
@ -140,54 +140,54 @@ namespace client
|
|||
void BOBI2POutboundTunnel::HandleAccept (std::shared_ptr<i2p::stream::Stream> stream)
|
||||
{
|
||||
if (stream)
|
||||
{
|
||||
{
|
||||
auto conn = std::make_shared<I2PTunnelConnection> (this, stream, std::make_shared<boost::asio::ip::tcp::socket> (GetService ()), m_Endpoint, m_IsQuiet);
|
||||
AddHandler (conn);
|
||||
conn->Connect ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BOBDestination::BOBDestination (std::shared_ptr<ClientDestination> localDestination):
|
||||
m_LocalDestination (localDestination),
|
||||
m_LocalDestination (localDestination),
|
||||
m_OutboundTunnel (nullptr), m_InboundTunnel (nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
BOBDestination::~BOBDestination ()
|
||||
{
|
||||
delete m_OutboundTunnel;
|
||||
delete m_InboundTunnel;
|
||||
i2p::client::context.DeleteLocalDestination (m_LocalDestination);
|
||||
}
|
||||
}
|
||||
|
||||
void BOBDestination::Start ()
|
||||
{
|
||||
if (m_OutboundTunnel) m_OutboundTunnel->Start ();
|
||||
if (m_InboundTunnel) m_InboundTunnel->Start ();
|
||||
}
|
||||
|
||||
|
||||
void BOBDestination::Stop ()
|
||||
{
|
||||
{
|
||||
StopTunnels ();
|
||||
m_LocalDestination->Stop ();
|
||||
}
|
||||
}
|
||||
|
||||
void BOBDestination::StopTunnels ()
|
||||
{
|
||||
if (m_OutboundTunnel)
|
||||
{
|
||||
{
|
||||
m_OutboundTunnel->Stop ();
|
||||
delete m_OutboundTunnel;
|
||||
m_OutboundTunnel = nullptr;
|
||||
}
|
||||
}
|
||||
if (m_InboundTunnel)
|
||||
{
|
||||
{
|
||||
m_InboundTunnel->Stop ();
|
||||
delete m_InboundTunnel;
|
||||
m_InboundTunnel = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void BOBDestination::CreateInboundTunnel (int port, const std::string& address)
|
||||
{
|
||||
if (!m_InboundTunnel)
|
||||
|
@ -200,21 +200,21 @@ namespace client
|
|||
if (!ec)
|
||||
ep.address (addr);
|
||||
else
|
||||
LogPrint (eLogError, "BOB: ", ec.message ());
|
||||
}
|
||||
LogPrint (eLogError, "BOB: ", ec.message ());
|
||||
}
|
||||
m_InboundTunnel = new BOBI2PInboundTunnel (ep, m_LocalDestination);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BOBDestination::CreateOutboundTunnel (const std::string& address, int port, bool quiet)
|
||||
{
|
||||
if (!m_OutboundTunnel)
|
||||
m_OutboundTunnel = new BOBI2POutboundTunnel (address, port, m_LocalDestination, quiet);
|
||||
}
|
||||
|
||||
BOBCommandSession::BOBCommandSession (BOBCommandChannel& owner):
|
||||
}
|
||||
|
||||
BOBCommandSession::BOBCommandSession (BOBCommandChannel& owner):
|
||||
m_Owner (owner), m_Socket (m_Owner.GetService ()),
|
||||
m_ReceiveBufferOffset (0), m_IsOpen (true), m_IsQuiet (false), m_IsActive (false),
|
||||
m_ReceiveBufferOffset (0), m_IsOpen (true), m_IsQuiet (false), m_IsActive (false),
|
||||
m_InPort (0), m_OutPort (0), m_CurrentDestination (nullptr)
|
||||
{
|
||||
}
|
||||
|
@ -226,13 +226,13 @@ namespace client
|
|||
void BOBCommandSession::Terminate ()
|
||||
{
|
||||
m_Socket.close ();
|
||||
m_IsOpen = false;
|
||||
m_IsOpen = false;
|
||||
}
|
||||
|
||||
void BOBCommandSession::Receive ()
|
||||
{
|
||||
m_Socket.async_read_some (boost::asio::buffer(m_ReceiveBuffer + m_ReceiveBufferOffset, BOB_COMMAND_BUFFER_SIZE - m_ReceiveBufferOffset),
|
||||
std::bind(&BOBCommandSession::HandleReceived, shared_from_this (),
|
||||
m_Socket.async_read_some (boost::asio::buffer(m_ReceiveBuffer + m_ReceiveBufferOffset, BOB_COMMAND_BUFFER_SIZE - m_ReceiveBufferOffset),
|
||||
std::bind(&BOBCommandSession::HandleReceived, shared_from_this (),
|
||||
std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
|
@ -243,29 +243,29 @@ namespace client
|
|||
LogPrint (eLogError, "BOB: command channel read error: ", ecode.message ());
|
||||
if (ecode != boost::asio::error::operation_aborted)
|
||||
Terminate ();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
size_t size = m_ReceiveBufferOffset + bytes_transferred;
|
||||
{
|
||||
size_t size = m_ReceiveBufferOffset + bytes_transferred;
|
||||
m_ReceiveBuffer[size] = 0;
|
||||
char * eol = strchr (m_ReceiveBuffer, '\n');
|
||||
if (eol)
|
||||
{
|
||||
*eol = 0;
|
||||
char * operand = strchr (m_ReceiveBuffer, ' ');
|
||||
if (operand)
|
||||
{
|
||||
if (operand)
|
||||
{
|
||||
*operand = 0;
|
||||
operand++;
|
||||
}
|
||||
else
|
||||
}
|
||||
else
|
||||
operand = eol;
|
||||
// process command
|
||||
auto& handlers = m_Owner.GetCommandHandlers ();
|
||||
auto it = handlers.find (m_ReceiveBuffer);
|
||||
if (it != handlers.end ())
|
||||
(this->*(it->second))(operand, eol - operand);
|
||||
else
|
||||
else
|
||||
{
|
||||
LogPrint (eLogError, "BOB: unknown command ", m_ReceiveBuffer);
|
||||
SendReplyError ("unknown command");
|
||||
|
@ -283,15 +283,15 @@ namespace client
|
|||
LogPrint (eLogError, "BOB: Malformed input of the command channel");
|
||||
Terminate ();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BOBCommandSession::Send (size_t len)
|
||||
{
|
||||
boost::asio::async_write (m_Socket, boost::asio::buffer (m_SendBuffer, len),
|
||||
boost::asio::async_write (m_Socket, boost::asio::buffer (m_SendBuffer, len),
|
||||
boost::asio::transfer_all (),
|
||||
std::bind(&BOBCommandSession::HandleSent, shared_from_this (),
|
||||
std::bind(&BOBCommandSession::HandleSent, shared_from_this (),
|
||||
std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,7 @@ namespace client
|
|||
if (m_IsOpen)
|
||||
Receive ();
|
||||
else
|
||||
Terminate ();
|
||||
Terminate ();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -316,7 +316,7 @@ namespace client
|
|||
{
|
||||
#ifdef _MSC_VER
|
||||
size_t len = sprintf_s (m_SendBuffer, BOB_COMMAND_BUFFER_SIZE, BOB_REPLY_OK, msg);
|
||||
#else
|
||||
#else
|
||||
size_t len = snprintf (m_SendBuffer, BOB_COMMAND_BUFFER_SIZE, BOB_REPLY_OK, msg);
|
||||
#endif
|
||||
Send (len);
|
||||
|
@ -326,12 +326,12 @@ namespace client
|
|||
{
|
||||
#ifdef _MSC_VER
|
||||
size_t len = sprintf_s (m_SendBuffer, BOB_COMMAND_BUFFER_SIZE, BOB_REPLY_ERROR, msg);
|
||||
#else
|
||||
#else
|
||||
size_t len = snprintf (m_SendBuffer, BOB_COMMAND_BUFFER_SIZE, BOB_REPLY_ERROR, msg);
|
||||
#endif
|
||||
Send (len);
|
||||
Send (len);
|
||||
}
|
||||
|
||||
|
||||
void BOBCommandSession::SendVersion ()
|
||||
{
|
||||
size_t len = strlen (BOB_VERSION);
|
||||
|
@ -343,12 +343,12 @@ namespace client
|
|||
{
|
||||
#ifdef _MSC_VER
|
||||
size_t len = sprintf_s (m_SendBuffer, BOB_COMMAND_BUFFER_SIZE, BOB_DATA, nickname);
|
||||
#else
|
||||
#else
|
||||
size_t len = snprintf (m_SendBuffer, BOB_COMMAND_BUFFER_SIZE, BOB_DATA, nickname);
|
||||
#endif
|
||||
Send (len);
|
||||
Send (len);
|
||||
}
|
||||
|
||||
|
||||
void BOBCommandSession::ZapCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
LogPrint (eLogDebug, "BOB: zap");
|
||||
|
@ -368,21 +368,21 @@ namespace client
|
|||
if (m_IsActive)
|
||||
{
|
||||
SendReplyError ("tunnel is active");
|
||||
return;
|
||||
return;
|
||||
}
|
||||
if (!m_CurrentDestination)
|
||||
{
|
||||
{
|
||||
m_CurrentDestination = new BOBDestination (i2p::client::context.CreateNewLocalDestination (m_Keys, true, &m_Options));
|
||||
m_Owner.AddDestination (m_Nickname, m_CurrentDestination);
|
||||
}
|
||||
}
|
||||
if (m_InPort)
|
||||
m_CurrentDestination->CreateInboundTunnel (m_InPort, m_Address);
|
||||
if (m_OutPort && !m_Address.empty ())
|
||||
m_CurrentDestination->CreateOutboundTunnel (m_Address, m_OutPort, m_IsQuiet);
|
||||
m_CurrentDestination->Start ();
|
||||
m_CurrentDestination->Start ();
|
||||
SendReplyOK ("Tunnel starting");
|
||||
m_IsActive = true;
|
||||
}
|
||||
}
|
||||
|
||||
void BOBCommandSession::StopCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
|
@ -401,8 +401,8 @@ namespace client
|
|||
else
|
||||
SendReplyError ("tunnel not found");
|
||||
m_IsActive = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BOBCommandSession::SetNickCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
LogPrint (eLogDebug, "BOB: setnick ", operand);
|
||||
|
@ -410,30 +410,30 @@ namespace client
|
|||
std::string msg ("Nickname set to ");
|
||||
msg += m_Nickname;
|
||||
SendReplyOK (msg.c_str ());
|
||||
}
|
||||
}
|
||||
|
||||
void BOBCommandSession::GetNickCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
LogPrint (eLogDebug, "BOB: getnick ", operand);
|
||||
m_CurrentDestination = m_Owner.FindDestination (operand);
|
||||
m_CurrentDestination = m_Owner.FindDestination (operand);
|
||||
if (m_CurrentDestination)
|
||||
{
|
||||
m_Keys = m_CurrentDestination->GetKeys ();
|
||||
m_Nickname = operand;
|
||||
}
|
||||
if (m_Nickname == operand)
|
||||
{
|
||||
{
|
||||
std::string msg ("Nickname set to ");
|
||||
msg += m_Nickname;
|
||||
SendReplyOK (msg.c_str ());
|
||||
}
|
||||
}
|
||||
else
|
||||
SendReplyError ("no nickname has been set");
|
||||
}
|
||||
SendReplyError ("no nickname has been set");
|
||||
}
|
||||
|
||||
void BOBCommandSession::NewkeysCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
LogPrint (eLogDebug, "BOB: newkeys");
|
||||
LogPrint (eLogDebug, "BOB: newkeys");
|
||||
i2p::data::SigningKeyType signatureType = i2p::data::SIGNING_KEY_TYPE_DSA_SHA1;
|
||||
i2p::data::CryptoKeyType cryptoType = i2p::data::CRYPTO_KEY_TYPE_ELGAMAL;
|
||||
if (*operand)
|
||||
|
@ -441,23 +441,23 @@ namespace client
|
|||
try
|
||||
{
|
||||
char * operand1 = (char *)strchr (operand, ' ');
|
||||
if (operand1)
|
||||
if (operand1)
|
||||
{
|
||||
*operand1 = 0; operand1++;
|
||||
cryptoType = std::stoi(operand1);
|
||||
}
|
||||
signatureType = std::stoi(operand);
|
||||
signatureType = std::stoi(operand);
|
||||
}
|
||||
catch (std::invalid_argument& ex)
|
||||
{
|
||||
LogPrint (eLogWarning, "BOB: newkeys ", ex.what ());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
m_Keys = i2p::data::PrivateKeys::CreateRandomKeys (signatureType, cryptoType);
|
||||
SendReplyOK (m_Keys.GetPublic ()->ToBase64 ().c_str ());
|
||||
}
|
||||
}
|
||||
|
||||
void BOBCommandSession::SetkeysCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
|
@ -467,9 +467,9 @@ namespace client
|
|||
else
|
||||
SendReplyError ("invalid keys");
|
||||
}
|
||||
|
||||
|
||||
void BOBCommandSession::GetkeysCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
{
|
||||
LogPrint (eLogDebug, "BOB: getkeys");
|
||||
if (m_Keys.GetPublic ()) // keys are set ?
|
||||
SendReplyOK (m_Keys.ToBase64 ().c_str ());
|
||||
|
@ -484,15 +484,15 @@ namespace client
|
|||
SendReplyOK (m_Keys.GetPublic ()->ToBase64 ().c_str ());
|
||||
else
|
||||
SendReplyError ("keys are not set");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BOBCommandSession::OuthostCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
LogPrint (eLogDebug, "BOB: outhost ", operand);
|
||||
m_Address = operand;
|
||||
SendReplyOK ("outhost set");
|
||||
}
|
||||
|
||||
|
||||
void BOBCommandSession::OutportCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
LogPrint (eLogDebug, "BOB: outport ", operand);
|
||||
|
@ -501,7 +501,7 @@ namespace client
|
|||
SendReplyOK ("outbound port set");
|
||||
else
|
||||
SendReplyError ("port out of range");
|
||||
}
|
||||
}
|
||||
|
||||
void BOBCommandSession::InhostCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
|
@ -509,7 +509,7 @@ namespace client
|
|||
m_Address = operand;
|
||||
SendReplyOK ("inhost set");
|
||||
}
|
||||
|
||||
|
||||
void BOBCommandSession::InportCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
LogPrint (eLogDebug, "BOB: inport ", operand);
|
||||
|
@ -518,7 +518,7 @@ namespace client
|
|||
SendReplyOK ("inbound port set");
|
||||
else
|
||||
SendReplyError ("port out of range");
|
||||
}
|
||||
}
|
||||
|
||||
void BOBCommandSession::QuietCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
|
@ -535,17 +535,17 @@ namespace client
|
|||
}
|
||||
else
|
||||
SendReplyError ("no nickname has been set");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void BOBCommandSession::LookupCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
LogPrint (eLogDebug, "BOB: lookup ", operand);
|
||||
i2p::data::IdentHash ident;
|
||||
if (!context.GetAddressBook ().GetIdentHash (operand, ident))
|
||||
if (!context.GetAddressBook ().GetIdentHash (operand, ident))
|
||||
{
|
||||
SendReplyError ("Address Not found");
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto localDestination = m_CurrentDestination ? m_CurrentDestination->GetLocalDestination () : i2p::client::context.GetSharedLocalDestination ();
|
||||
auto leaseSet = localDestination->FindLeaseSet (ident);
|
||||
if (leaseSet)
|
||||
|
@ -553,14 +553,14 @@ namespace client
|
|||
else
|
||||
{
|
||||
auto s = shared_from_this ();
|
||||
localDestination->RequestDestination (ident,
|
||||
localDestination->RequestDestination (ident,
|
||||
[s](std::shared_ptr<i2p::data::LeaseSet> ls)
|
||||
{
|
||||
if (ls)
|
||||
s->SendReplyOK (ls->GetIdentity ()->ToBase64 ().c_str ());
|
||||
else
|
||||
else
|
||||
s->SendReplyError ("LeaseSet Not found");
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -571,7 +571,7 @@ namespace client
|
|||
m_Owner.DeleteDestination (m_Nickname);
|
||||
m_Nickname = "";
|
||||
SendReplyOK ("cleared");
|
||||
}
|
||||
}
|
||||
|
||||
void BOBCommandSession::ListCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
|
@ -580,26 +580,26 @@ namespace client
|
|||
for (const auto& it: destinations)
|
||||
SendData (it.first.c_str ());
|
||||
SendReplyOK ("Listing done");
|
||||
}
|
||||
}
|
||||
|
||||
void BOBCommandSession::OptionCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
LogPrint (eLogDebug, "BOB: option ", operand);
|
||||
const char * value = strchr (operand, '=');
|
||||
if (value)
|
||||
{
|
||||
{
|
||||
std::string msg ("option ");
|
||||
*(const_cast<char *>(value)) = 0;
|
||||
m_Options[operand] = value + 1;
|
||||
m_Options[operand] = value + 1;
|
||||
msg += operand;
|
||||
*(const_cast<char *>(value)) = '=';
|
||||
msg += " set to ";
|
||||
msg += value;
|
||||
msg += value;
|
||||
SendReplyOK (msg.c_str ());
|
||||
}
|
||||
}
|
||||
else
|
||||
SendReplyError ("malformed");
|
||||
}
|
||||
}
|
||||
|
||||
void BOBCommandSession::StatusCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
|
@ -609,37 +609,37 @@ namespace client
|
|||
std::stringstream s;
|
||||
s << "DATA"; s << " NICKNAME: "; s << m_Nickname;
|
||||
if (m_CurrentDestination)
|
||||
{
|
||||
{
|
||||
if (m_CurrentDestination->GetLocalDestination ()->IsReady ())
|
||||
s << " STARTING: false RUNNING: true STOPPING: false";
|
||||
else
|
||||
s << " STARTING: true RUNNING: false STOPPING: false";
|
||||
}
|
||||
}
|
||||
else
|
||||
s << " STARTING: false RUNNING: false STOPPING: false";
|
||||
s << " KEYS: true"; s << " QUIET: "; s << (m_IsQuiet ? "true":"false");
|
||||
if (m_InPort)
|
||||
{
|
||||
{
|
||||
s << " INPORT: " << m_InPort;
|
||||
s << " INHOST: " << (m_Address.length () > 0 ? m_Address : "127.0.0.1");
|
||||
}
|
||||
}
|
||||
if (m_OutPort)
|
||||
{
|
||||
{
|
||||
s << " OUTPORT: " << m_OutPort;
|
||||
s << " OUTHOST: " << (m_Address.length () > 0 ? m_Address : "127.0.0.1");
|
||||
}
|
||||
}
|
||||
SendReplyOK (s.str().c_str());
|
||||
}
|
||||
else
|
||||
SendReplyError ("no nickname has been set");
|
||||
}
|
||||
|
||||
SendReplyError ("no nickname has been set");
|
||||
}
|
||||
|
||||
BOBCommandChannel::BOBCommandChannel (const std::string& address, int port):
|
||||
m_IsRunning (false), m_Thread (nullptr),
|
||||
m_Acceptor (m_Service, boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(address), port))
|
||||
{
|
||||
// command -> handler
|
||||
m_CommandHandlers[BOB_COMMAND_ZAP] = &BOBCommandSession::ZapCommandHandler;
|
||||
m_CommandHandlers[BOB_COMMAND_ZAP] = &BOBCommandSession::ZapCommandHandler;
|
||||
m_CommandHandlers[BOB_COMMAND_QUIT] = &BOBCommandSession::QuitCommandHandler;
|
||||
m_CommandHandlers[BOB_COMMAND_START] = &BOBCommandSession::StartCommandHandler;
|
||||
m_CommandHandlers[BOB_COMMAND_STOP] = &BOBCommandSession::StopCommandHandler;
|
||||
|
@ -680,35 +680,35 @@ namespace client
|
|||
m_IsRunning = false;
|
||||
for (auto& it: m_Destinations)
|
||||
it.second->Stop ();
|
||||
m_Acceptor.cancel ();
|
||||
m_Acceptor.cancel ();
|
||||
m_Service.stop ();
|
||||
if (m_Thread)
|
||||
{
|
||||
m_Thread->join ();
|
||||
{
|
||||
m_Thread->join ();
|
||||
delete m_Thread;
|
||||
m_Thread = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BOBCommandChannel::Run ()
|
||||
{
|
||||
|
||||
void BOBCommandChannel::Run ()
|
||||
{
|
||||
while (m_IsRunning)
|
||||
{
|
||||
try
|
||||
{
|
||||
{
|
||||
m_Service.run ();
|
||||
}
|
||||
catch (std::exception& ex)
|
||||
{
|
||||
LogPrint (eLogError, "BOB: runtime exception: ", ex.what ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BOBCommandChannel::AddDestination (const std::string& name, BOBDestination * dest)
|
||||
{
|
||||
m_Destinations[name] = dest;
|
||||
}
|
||||
}
|
||||
|
||||
void BOBCommandChannel::DeleteDestination (const std::string& name)
|
||||
{
|
||||
|
@ -718,17 +718,17 @@ namespace client
|
|||
it->second->Stop ();
|
||||
delete it->second;
|
||||
m_Destinations.erase (it);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
BOBDestination * BOBCommandChannel::FindDestination (const std::string& name)
|
||||
{
|
||||
auto it = m_Destinations.find (name);
|
||||
if (it != m_Destinations.end ())
|
||||
return it->second;
|
||||
return nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
|
||||
void BOBCommandChannel::Accept ()
|
||||
{
|
||||
auto newSession = std::make_shared<BOBCommandSession> (*this);
|
||||
|
@ -744,7 +744,7 @@ namespace client
|
|||
if (!ecode)
|
||||
{
|
||||
LogPrint (eLogInfo, "BOB: New command connection from ", session->GetSocket ().remote_endpoint ());
|
||||
session->SendVersion ();
|
||||
session->SendVersion ();
|
||||
}
|
||||
else
|
||||
LogPrint (eLogError, "BOB: accept error: ", ecode.message ());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue