mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-04-28 11:47:48 +02:00
clean line trailing spaces and tabs
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
parent
94661f697b
commit
edc0162163
66 changed files with 998 additions and 999 deletions
|
@ -35,7 +35,7 @@ namespace client
|
|||
class AddressBookFilesystemStorage: public AddressBookStorage
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
AddressBookFilesystemStorage (): storage("addressbook", "b", "", "b32")
|
||||
{
|
||||
i2p::config::GetOption("persist.addressbook", m_IsPersist);
|
||||
|
@ -62,7 +62,7 @@ namespace client
|
|||
private:
|
||||
|
||||
i2p::fs::HashedStorage storage;
|
||||
std::string etagsPath, indexPath, localPath;
|
||||
std::string etagsPath, indexPath, localPath;
|
||||
bool m_IsPersist;
|
||||
std::string m_HostsFile; // file to dump hosts.txt, empty if not used
|
||||
};
|
||||
|
@ -185,7 +185,7 @@ namespace client
|
|||
|
||||
int AddressBookFilesystemStorage::Save (const std::map<std::string, std::shared_ptr<Address> >& addresses)
|
||||
{
|
||||
if (addresses.empty())
|
||||
if (addresses.empty())
|
||||
{
|
||||
LogPrint(eLogWarning, "Addressbook: Not saving empty addressbook");
|
||||
return 0;
|
||||
|
@ -200,7 +200,7 @@ namespace client
|
|||
for (const auto& it: addresses)
|
||||
{
|
||||
if (it.second->IsValid ())
|
||||
{
|
||||
{
|
||||
f << it.first << ",";
|
||||
if (it.second->IsIdentHash ())
|
||||
f << it.second->identHash.ToBase32 ();
|
||||
|
@ -208,15 +208,15 @@ namespace client
|
|||
f << it.second->blindedPublicKey->ToB33 ();
|
||||
f << std::endl;
|
||||
num++;
|
||||
}
|
||||
}
|
||||
else
|
||||
LogPrint (eLogWarning, "Addressbook: Invalid address ", it.first);
|
||||
}
|
||||
LogPrint (eLogInfo, "Addressbook: ", num, " addresses saved");
|
||||
}
|
||||
}
|
||||
else
|
||||
LogPrint (eLogWarning, "Addressbook: Can't open ", indexPath);
|
||||
}
|
||||
}
|
||||
if (!m_HostsFile.empty ())
|
||||
{
|
||||
// dump full hosts.txt
|
||||
|
@ -226,18 +226,18 @@ namespace client
|
|||
for (const auto& it: addresses)
|
||||
{
|
||||
std::shared_ptr<const i2p::data::IdentityEx> addr;
|
||||
if (it.second->IsIdentHash ())
|
||||
{
|
||||
if (it.second->IsIdentHash ())
|
||||
{
|
||||
addr = GetAddress (it.second->identHash);
|
||||
if (addr)
|
||||
f << it.first << "=" << addr->ToBase64 () << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
LogPrint (eLogWarning, "Addressbook: Can't open ", m_HostsFile);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return num;
|
||||
}
|
||||
|
||||
|
@ -495,7 +495,7 @@ namespace client
|
|||
if (it != m_Addresses.end ()) // already exists ?
|
||||
{
|
||||
if (it->second->IsIdentHash () && it->second->identHash != ident->GetIdentHash () && // address changed?
|
||||
ident->GetSigningKeyType () != i2p::data::SIGNING_KEY_TYPE_DSA_SHA1) // don't replace by DSA
|
||||
ident->GetSigningKeyType () != i2p::data::SIGNING_KEY_TYPE_DSA_SHA1) // don't replace by DSA
|
||||
{
|
||||
it->second->identHash = ident->GetIdentHash ();
|
||||
m_Storage->AddAddress (ident);
|
||||
|
|
|
@ -660,7 +660,7 @@ namespace client
|
|||
else
|
||||
SendReplyError ("Local LeaseSet Not found");
|
||||
}
|
||||
|
||||
|
||||
void BOBCommandSession::ClearCommandHandler (const char * operand, size_t len)
|
||||
{
|
||||
LogPrint (eLogDebug, "BOB: clear");
|
||||
|
@ -786,7 +786,7 @@ namespace client
|
|||
m_CommandHandlers[BOB_COMMAND_INPORT] = &BOBCommandSession::InportCommandHandler;
|
||||
m_CommandHandlers[BOB_COMMAND_QUIET] = &BOBCommandSession::QuietCommandHandler;
|
||||
m_CommandHandlers[BOB_COMMAND_LOOKUP] = &BOBCommandSession::LookupCommandHandler;
|
||||
m_CommandHandlers[BOB_COMMAND_LOOKUP_LOCAL] = &BOBCommandSession::LookupLocalCommandHandler;
|
||||
m_CommandHandlers[BOB_COMMAND_LOOKUP_LOCAL] = &BOBCommandSession::LookupLocalCommandHandler;
|
||||
m_CommandHandlers[BOB_COMMAND_CLEAR] = &BOBCommandSession::ClearCommandHandler;
|
||||
m_CommandHandlers[BOB_COMMAND_LIST] = &BOBCommandSession::ListCommandHandler;
|
||||
m_CommandHandlers[BOB_COMMAND_OPTION] = &BOBCommandSession::OptionCommandHandler;
|
||||
|
|
|
@ -406,7 +406,7 @@ namespace client
|
|||
|
||||
void ClientContext::CreateNewSharedLocalDestination ()
|
||||
{
|
||||
std::map<std::string, std::string> params
|
||||
std::map<std::string, std::string> params
|
||||
{
|
||||
{ I2CP_PARAM_INBOUND_TUNNELS_QUANTITY, "3" },
|
||||
{ I2CP_PARAM_OUTBOUND_TUNNELS_QUANTITY, "3" },
|
||||
|
@ -720,10 +720,10 @@ namespace client
|
|||
std::shared_ptr<ClientDestination> localDestination = nullptr;
|
||||
auto it = destinations.find (keys);
|
||||
if (it != destinations.end ())
|
||||
{
|
||||
{
|
||||
localDestination = it->second;
|
||||
localDestination->SetPublic (true);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
i2p::data::PrivateKeys k;
|
||||
|
@ -767,10 +767,10 @@ namespace client
|
|||
LogPrint(eLogInfo, "Clients: I2P Server Forward created for UDP Endpoint ", host, ":", port, " bound on ", address, " for ",localDestination->GetIdentHash().ToBase32());
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
ins.first->second->isUpdated = true;
|
||||
LogPrint(eLogError, "Clients: I2P Server Forward for destination/port ", m_AddressBook.ToAddress(localDestination->GetIdentHash()), "/", port, " already exists");
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace client
|
|||
// i18n
|
||||
std::shared_ptr<const i2p::i18n::Locale> GetLanguage () { return m_Language; };
|
||||
void SetLanguage (const std::shared_ptr<const i2p::i18n::Locale> language) { m_Language = language; };
|
||||
|
||||
|
||||
private:
|
||||
|
||||
void ReadTunnels ();
|
||||
|
@ -157,7 +157,7 @@ namespace client
|
|||
|
||||
// i18n
|
||||
std::shared_ptr<const i2p::i18n::Locale> m_Language;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
// for HTTP
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace i2p
|
|||
namespace client
|
||||
{
|
||||
|
||||
I2CPDestination::I2CPDestination (boost::asio::io_service& service, std::shared_ptr<I2CPSession> owner,
|
||||
I2CPDestination::I2CPDestination (boost::asio::io_service& service, std::shared_ptr<I2CPSession> owner,
|
||||
std::shared_ptr<const i2p::data::IdentityEx> identity, bool isPublic, const std::map<std::string, std::string>& params):
|
||||
LeaseSetDestination (service, isPublic, ¶ms),
|
||||
m_Owner (owner), m_Identity (identity), m_EncryptionKeyType (m_Identity->GetCryptoKeyType ()),
|
||||
|
@ -36,8 +36,8 @@ namespace client
|
|||
LeaseSetDestination::Stop ();
|
||||
m_Owner = nullptr;
|
||||
m_LeaseSetCreationTimer.cancel ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void I2CPDestination::SetEncryptionPrivateKey (const uint8_t * key)
|
||||
{
|
||||
m_Decryptor = i2p::data::PrivateKeys::CreateDecryptor (m_Identity->GetCryptoKeyType (), key);
|
||||
|
@ -46,12 +46,12 @@ namespace client
|
|||
void I2CPDestination::SetECIESx25519EncryptionPrivateKey (const uint8_t * key)
|
||||
{
|
||||
if (!m_ECIESx25519Decryptor || memcmp (m_ECIESx25519PrivateKey, key, 32)) // new key?
|
||||
{
|
||||
{
|
||||
m_ECIESx25519Decryptor = std::make_shared<i2p::crypto::ECIESX25519AEADRatchetDecryptor>(key, true); // calculate public
|
||||
memcpy (m_ECIESx25519PrivateKey, key, 32);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool I2CPDestination::Decrypt (const uint8_t * encrypted, uint8_t * data, i2p::data::CryptoKeyType preferredCrypto) const
|
||||
{
|
||||
if (preferredCrypto == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD && m_ECIESx25519Decryptor)
|
||||
|
@ -68,14 +68,14 @@ namespace client
|
|||
if (keyType == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD && m_ECIESx25519Decryptor)
|
||||
return m_ECIESx25519Decryptor->GetPubicKey ();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool I2CPDestination::SupportsEncryptionType (i2p::data::CryptoKeyType keyType) const
|
||||
{
|
||||
return keyType == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD ? (bool)m_ECIESx25519Decryptor : m_EncryptionKeyType == keyType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool I2CPDestination::SupportsEncryptionType (i2p::data::CryptoKeyType keyType) const
|
||||
{
|
||||
return keyType == i2p::data::CRYPTO_KEY_TYPE_ECIES_X25519_AEAD ? (bool)m_ECIESx25519Decryptor : m_EncryptionKeyType == keyType;
|
||||
}
|
||||
|
||||
|
||||
void I2CPDestination::HandleDataMessage (const uint8_t * buf, size_t len)
|
||||
{
|
||||
uint32_t length = bufbe32toh (buf);
|
||||
|
@ -88,25 +88,25 @@ namespace client
|
|||
{
|
||||
GetService ().post (std::bind (&I2CPDestination::PostCreateNewLeaseSet, this, tunnels));
|
||||
}
|
||||
|
||||
|
||||
void I2CPDestination::PostCreateNewLeaseSet (std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels)
|
||||
{
|
||||
if (m_IsCreatingLeaseSet)
|
||||
{
|
||||
LogPrint (eLogInfo, "I2CP: LeaseSet is being created");
|
||||
return;
|
||||
}
|
||||
}
|
||||
uint8_t priv[256] = {0};
|
||||
i2p::data::LocalLeaseSet ls (m_Identity, priv, tunnels); // we don't care about encryption key, we need leases only
|
||||
m_LeaseSetExpirationTime = ls.GetExpirationTime ();
|
||||
uint8_t * leases = ls.GetLeases ();
|
||||
leases[-1] = tunnels.size ();
|
||||
if (m_Owner)
|
||||
{
|
||||
{
|
||||
uint16_t sessionID = m_Owner->GetSessionID ();
|
||||
if (sessionID != 0xFFFF)
|
||||
{
|
||||
m_IsCreatingLeaseSet = true;
|
||||
{
|
||||
m_IsCreatingLeaseSet = true;
|
||||
htobe16buf (leases - 3, sessionID);
|
||||
size_t l = 2/*sessionID*/ + 1/*num leases*/ + i2p::data::LEASE_SIZE*tunnels.size ();
|
||||
m_Owner->SendI2CPMessage (I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE, leases - 3, l);
|
||||
|
@ -120,8 +120,8 @@ namespace client
|
|||
if (s->m_Owner) s->m_Owner->Stop ();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void I2CPDestination::LeaseSetCreated (const uint8_t * buf, size_t len)
|
||||
|
@ -237,18 +237,18 @@ namespace client
|
|||
}
|
||||
}
|
||||
|
||||
RunnableI2CPDestination::RunnableI2CPDestination (std::shared_ptr<I2CPSession> owner,
|
||||
RunnableI2CPDestination::RunnableI2CPDestination (std::shared_ptr<I2CPSession> owner,
|
||||
std::shared_ptr<const i2p::data::IdentityEx> identity, bool isPublic, const std::map<std::string, std::string>& params):
|
||||
RunnableService ("I2CP"),
|
||||
I2CPDestination (GetIOService (), owner, identity, isPublic, params)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
RunnableI2CPDestination::~RunnableI2CPDestination ()
|
||||
{
|
||||
if (IsRunning ())
|
||||
Stop ();
|
||||
}
|
||||
}
|
||||
|
||||
void RunnableI2CPDestination::Start ()
|
||||
{
|
||||
|
@ -267,9 +267,9 @@ namespace client
|
|||
StopIOService ();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
I2CPSession::I2CPSession (I2CPServer& owner, std::shared_ptr<proto::socket> socket):
|
||||
m_Owner (owner), m_Socket (socket), m_SessionID (0xFFFF),
|
||||
m_Owner (owner), m_Socket (socket), m_SessionID (0xFFFF),
|
||||
m_MessageID (0), m_IsSendAccepted (true), m_IsSending (false)
|
||||
{
|
||||
}
|
||||
|
@ -307,11 +307,11 @@ namespace client
|
|||
|
||||
void I2CPSession::ReceiveHeader ()
|
||||
{
|
||||
if (!m_Socket)
|
||||
if (!m_Socket)
|
||||
{
|
||||
LogPrint (eLogError, "I2CP: Can't receive header");
|
||||
return;
|
||||
}
|
||||
}
|
||||
boost::asio::async_read (*m_Socket, boost::asio::buffer (m_Header, I2CP_HEADER_SIZE),
|
||||
boost::asio::transfer_all (),
|
||||
std::bind (&I2CPSession::HandleReceivedHeader, shared_from_this (), std::placeholders::_1, std::placeholders::_2));
|
||||
|
@ -344,11 +344,11 @@ namespace client
|
|||
|
||||
void I2CPSession::ReceivePayload ()
|
||||
{
|
||||
if (!m_Socket)
|
||||
{
|
||||
if (!m_Socket)
|
||||
{
|
||||
LogPrint (eLogError, "I2CP: Can't receive payload");
|
||||
return;
|
||||
}
|
||||
}
|
||||
boost::asio::async_read (*m_Socket, boost::asio::buffer (m_Payload, m_PayloadLen),
|
||||
boost::asio::transfer_all (),
|
||||
std::bind (&I2CPSession::HandleReceivedPayload, shared_from_this (), std::placeholders::_1, std::placeholders::_2));
|
||||
|
@ -390,11 +390,11 @@ namespace client
|
|||
if (!m_SendQueue.IsEmpty ())
|
||||
m_SendQueue.CleanUp ();
|
||||
if (m_SessionID != 0xFFFF)
|
||||
{
|
||||
{
|
||||
m_Owner.RemoveSession (GetSessionID ());
|
||||
LogPrint (eLogDebug, "I2CP: Session ", m_SessionID, " terminated");
|
||||
m_SessionID = 0xFFFF;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void I2CPSession::SendI2CPMessage (uint8_t type, const uint8_t * payload, size_t len)
|
||||
|
@ -404,39 +404,39 @@ namespace client
|
|||
{
|
||||
LogPrint (eLogError, "I2CP: Message to send is too long ", l);
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto sendBuf = m_IsSending ? std::make_shared<i2p::stream::SendBuffer> (l) : nullptr;
|
||||
uint8_t * buf = sendBuf ? sendBuf->buf : m_SendBuffer;
|
||||
htobe32buf (buf + I2CP_HEADER_LENGTH_OFFSET, len);
|
||||
buf[I2CP_HEADER_TYPE_OFFSET] = type;
|
||||
memcpy (buf + I2CP_HEADER_SIZE, payload, len);
|
||||
if (sendBuf)
|
||||
{
|
||||
{
|
||||
if (m_SendQueue.GetSize () < I2CP_MAX_SEND_QUEUE_SIZE)
|
||||
m_SendQueue.Add (sendBuf);
|
||||
else
|
||||
{
|
||||
LogPrint (eLogWarning, "I2CP: Send queue size exceeds ", I2CP_MAX_SEND_QUEUE_SIZE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrint (eLogWarning, "I2CP: Send queue size exceeds ", I2CP_MAX_SEND_QUEUE_SIZE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto socket = m_Socket;
|
||||
if (socket)
|
||||
{
|
||||
{
|
||||
m_IsSending = true;
|
||||
boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, l),
|
||||
boost::asio::transfer_all (), std::bind(&I2CPSession::HandleI2CPMessageSent,
|
||||
boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, l),
|
||||
boost::asio::transfer_all (), std::bind(&I2CPSession::HandleI2CPMessageSent,
|
||||
shared_from_this (), std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void I2CPSession::HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred)
|
||||
{
|
||||
if (ecode)
|
||||
{
|
||||
{
|
||||
if (ecode != boost::asio::error::operation_aborted)
|
||||
Terminate ();
|
||||
}
|
||||
|
@ -444,19 +444,19 @@ namespace client
|
|||
{
|
||||
auto socket = m_Socket;
|
||||
if (socket)
|
||||
{
|
||||
{
|
||||
auto len = m_SendQueue.Get (m_SendBuffer, I2CP_MAX_MESSAGE_LENGTH);
|
||||
boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, len),
|
||||
boost::asio::transfer_all (),std::bind(&I2CPSession::HandleI2CPMessageSent,
|
||||
boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, len),
|
||||
boost::asio::transfer_all (),std::bind(&I2CPSession::HandleI2CPMessageSent,
|
||||
shared_from_this (), std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
}
|
||||
else
|
||||
m_IsSending = false;
|
||||
}
|
||||
else
|
||||
m_IsSending = false;
|
||||
}
|
||||
|
||||
|
||||
std::string I2CPSession::ExtractString (const uint8_t * buf, size_t len)
|
||||
{
|
||||
uint8_t l = buf[0];
|
||||
|
@ -699,12 +699,12 @@ namespace client
|
|||
m_Destination->SetECIESx25519EncryptionPrivateKey (buf + offset);
|
||||
else
|
||||
{
|
||||
m_Destination->SetEncryptionType (keyType);
|
||||
m_Destination->SetEncryptionType (keyType);
|
||||
m_Destination->SetEncryptionPrivateKey (buf + offset);
|
||||
}
|
||||
offset += keyLen;
|
||||
}
|
||||
|
||||
|
||||
m_Destination->LeaseSet2Created (storeType, ls.GetBuffer (), ls.GetBufferLen ());
|
||||
}
|
||||
}
|
||||
|
@ -885,7 +885,7 @@ namespace client
|
|||
{
|
||||
LogPrint (eLogError, "I2CP: Message to send is too long ", l);
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto sendBuf = m_IsSending ? std::make_shared<i2p::stream::SendBuffer> (l) : nullptr;
|
||||
uint8_t * buf = sendBuf ? sendBuf->buf : m_SendBuffer;
|
||||
htobe32buf (buf + I2CP_HEADER_LENGTH_OFFSET, len + 10);
|
||||
|
@ -895,26 +895,26 @@ namespace client
|
|||
htobe32buf (buf + I2CP_HEADER_SIZE + 6, len);
|
||||
memcpy (buf + I2CP_HEADER_SIZE + 10, payload, len);
|
||||
if (sendBuf)
|
||||
{
|
||||
{
|
||||
if (m_SendQueue.GetSize () < I2CP_MAX_SEND_QUEUE_SIZE)
|
||||
m_SendQueue.Add (sendBuf);
|
||||
else
|
||||
{
|
||||
LogPrint (eLogWarning, "I2CP: Send queue size exceeds ", I2CP_MAX_SEND_QUEUE_SIZE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
LogPrint (eLogWarning, "I2CP: Send queue size exceeds ", I2CP_MAX_SEND_QUEUE_SIZE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
auto socket = m_Socket;
|
||||
if (socket)
|
||||
{
|
||||
{
|
||||
m_IsSending = true;
|
||||
boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, l),
|
||||
boost::asio::transfer_all (), std::bind(&I2CPSession::HandleI2CPMessageSent,
|
||||
boost::asio::async_write (*socket, boost::asio::buffer (m_SendBuffer, l),
|
||||
boost::asio::transfer_all (), std::bind(&I2CPSession::HandleI2CPMessageSent,
|
||||
shared_from_this (), std::placeholders::_1, std::placeholders::_2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
I2CPServer::I2CPServer (const std::string& interface, int port, bool isSingleThread):
|
||||
|
|
|
@ -27,8 +27,8 @@ namespace client
|
|||
const size_t I2CP_SESSION_BUFFER_SIZE = 4096;
|
||||
const size_t I2CP_MAX_MESSAGE_LENGTH = 65535;
|
||||
const size_t I2CP_MAX_SEND_QUEUE_SIZE = 1024*1024; // in bytes, 1M
|
||||
const int I2CP_LEASESET_CREATION_TIMEOUT = 10; // in seconds
|
||||
|
||||
const int I2CP_LEASESET_CREATION_TIMEOUT = 10; // in seconds
|
||||
|
||||
const size_t I2CP_HEADER_LENGTH_OFFSET = 0;
|
||||
const size_t I2CP_HEADER_TYPE_OFFSET = I2CP_HEADER_LENGTH_OFFSET + 4;
|
||||
const size_t I2CP_HEADER_SIZE = I2CP_HEADER_TYPE_OFFSET + 1;
|
||||
|
@ -69,12 +69,12 @@ namespace client
|
|||
{
|
||||
public:
|
||||
|
||||
I2CPDestination (boost::asio::io_service& service, std::shared_ptr<I2CPSession> owner,
|
||||
I2CPDestination (boost::asio::io_service& service, std::shared_ptr<I2CPSession> owner,
|
||||
std::shared_ptr<const i2p::data::IdentityEx> identity, bool isPublic, const std::map<std::string, std::string>& params);
|
||||
~I2CPDestination () {};
|
||||
|
||||
void Stop ();
|
||||
|
||||
|
||||
void SetEncryptionPrivateKey (const uint8_t * key);
|
||||
void SetEncryptionType (i2p::data::CryptoKeyType keyType) { m_EncryptionKeyType = keyType; };
|
||||
void SetECIESx25519EncryptionPrivateKey (const uint8_t * key);
|
||||
|
@ -84,7 +84,7 @@ namespace client
|
|||
|
||||
// implements LocalDestination
|
||||
bool Decrypt (const uint8_t * encrypted, uint8_t * data, i2p::data::CryptoKeyType preferredCrypto) const;
|
||||
bool SupportsEncryptionType (i2p::data::CryptoKeyType keyType) const;
|
||||
bool SupportsEncryptionType (i2p::data::CryptoKeyType keyType) const;
|
||||
const uint8_t * GetEncryptionPublicKey (i2p::data::CryptoKeyType keyType) const; // for 4 only
|
||||
std::shared_ptr<const i2p::data::IdentityEx> GetIdentity () const { return m_Identity; };
|
||||
|
||||
|
@ -101,7 +101,7 @@ namespace client
|
|||
bool SendMsg (std::shared_ptr<I2NPMessage> msg, std::shared_ptr<const i2p::data::LeaseSet> remote);
|
||||
|
||||
void PostCreateNewLeaseSet (std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<I2CPSession> m_Owner;
|
||||
|
@ -115,18 +115,18 @@ namespace client
|
|||
boost::asio::deadline_timer m_LeaseSetCreationTimer;
|
||||
};
|
||||
|
||||
class RunnableI2CPDestination: private i2p::util::RunnableService, public I2CPDestination
|
||||
class RunnableI2CPDestination: private i2p::util::RunnableService, public I2CPDestination
|
||||
{
|
||||
public:
|
||||
|
||||
RunnableI2CPDestination (std::shared_ptr<I2CPSession> owner, std::shared_ptr<const i2p::data::IdentityEx> identity,
|
||||
bool isPublic, const std::map<std::string, std::string>& params);
|
||||
RunnableI2CPDestination (std::shared_ptr<I2CPSession> owner, std::shared_ptr<const i2p::data::IdentityEx> identity,
|
||||
bool isPublic, const std::map<std::string, std::string>& params);
|
||||
~RunnableI2CPDestination ();
|
||||
|
||||
void Start ();
|
||||
void Stop ();
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
class I2CPServer;
|
||||
class I2CPSession: public std::enable_shared_from_this<I2CPSession>
|
||||
{
|
||||
|
@ -174,9 +174,9 @@ namespace client
|
|||
void HandleReceivedPayload (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||
void HandleMessage ();
|
||||
void Terminate ();
|
||||
|
||||
|
||||
void HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||
|
||||
|
||||
std::string ExtractString (const uint8_t * buf, size_t len);
|
||||
size_t PutString (uint8_t * buf, size_t len, const std::string& str);
|
||||
void ExtractMapping (const uint8_t * buf, size_t len, std::map<std::string, std::string>& mapping);
|
||||
|
@ -198,7 +198,7 @@ namespace client
|
|||
// to client
|
||||
bool m_IsSending;
|
||||
uint8_t m_SendBuffer[I2CP_MAX_MESSAGE_LENGTH];
|
||||
i2p::stream::SendBufferQueue m_SendQueue;
|
||||
i2p::stream::SendBufferQueue m_SendQueue;
|
||||
};
|
||||
typedef void (I2CPSession::*I2CPMessageHandler)(const uint8_t * buf, size_t len);
|
||||
|
||||
|
@ -213,7 +213,7 @@ namespace client
|
|||
void Stop ();
|
||||
boost::asio::io_service& GetService () { return GetIOService (); };
|
||||
bool IsSingleThread () const { return m_IsSingleThread; };
|
||||
|
||||
|
||||
bool InsertSession (std::shared_ptr<I2CPSession> session);
|
||||
void RemoveSession (uint16_t sessionID);
|
||||
|
||||
|
|
|
@ -87,7 +87,7 @@ namespace client
|
|||
boost::system::error_code ec;
|
||||
sock->bind (boost::asio::ip::tcp::endpoint (ourIP, 0), ec);
|
||||
if (ec)
|
||||
LogPrint (eLogError, "I2PTunnel: Can't bind ourIP to ", ourIP.to_string (), ": ", ec.message ());
|
||||
LogPrint (eLogError, "I2PTunnel: Can't bind ourIP to ", ourIP.to_string (), ": ", ec.message ());
|
||||
|
||||
}
|
||||
#endif
|
||||
|
@ -122,11 +122,11 @@ namespace client
|
|||
boost::system::error_code ec;
|
||||
m_Socket->bind (boost::asio::ip::tcp::endpoint (localAddress, 0), ec);
|
||||
if (ec)
|
||||
LogPrint (eLogError, "I2PTunnel: Can't bind to ", localAddress.to_string (), ": ", ec.message ());
|
||||
}
|
||||
LogPrint (eLogError, "I2PTunnel: Can't bind to ", localAddress.to_string (), ": ", ec.message ());
|
||||
}
|
||||
Connect (false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void I2PTunnelConnection::Terminate ()
|
||||
{
|
||||
if (Kill()) return;
|
||||
|
@ -177,8 +177,8 @@ namespace client
|
|||
s->Terminate ();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void I2PTunnelConnection::HandleWrite (const boost::system::error_code& ecode)
|
||||
{
|
||||
if (ecode)
|
||||
|
@ -326,7 +326,7 @@ namespace client
|
|||
I2PServerTunnelConnectionHTTP::I2PServerTunnelConnectionHTTP (I2PService * owner, std::shared_ptr<i2p::stream::Stream> stream,
|
||||
std::shared_ptr<boost::asio::ip::tcp::socket> socket,
|
||||
const boost::asio::ip::tcp::endpoint& target, const std::string& host):
|
||||
I2PTunnelConnection (owner, stream, socket, target), m_Host (host),
|
||||
I2PTunnelConnection (owner, stream, socket, target), m_Host (host),
|
||||
m_HeaderSent (false), m_ResponseHeaderSent (false), m_From (stream->GetRemoteIdentity ())
|
||||
{
|
||||
}
|
||||
|
@ -368,7 +368,7 @@ namespace client
|
|||
m_OutHeader << X_I2P_DEST_HASH << ": " << m_From->GetIdentHash ().ToBase64 () << "\r\n";
|
||||
m_OutHeader << X_I2P_DEST_B64 << ": " << m_From->ToBase64 () << "\r\n";
|
||||
}
|
||||
|
||||
|
||||
m_OutHeader << "\r\n"; // end of header
|
||||
m_OutHeader << m_InHeader.str ().substr (m_InHeader.tellg ()); // data right after header
|
||||
m_InHeader.str ("");
|
||||
|
@ -404,11 +404,11 @@ namespace client
|
|||
};
|
||||
bool matched = false;
|
||||
for (const auto& it: excluded)
|
||||
if (!line.compare(0, it.length (), it))
|
||||
if (!line.compare(0, it.length (), it))
|
||||
{
|
||||
matched = true;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!matched)
|
||||
m_OutHeader << line << "\n";
|
||||
}
|
||||
|
@ -425,12 +425,12 @@ namespace client
|
|||
m_ResponseHeaderSent = true;
|
||||
I2PTunnelConnection::WriteToStream ((uint8_t *)m_OutHeader.str ().c_str (), m_OutHeader.str ().length ());
|
||||
m_OutHeader.str ("");
|
||||
}
|
||||
}
|
||||
else
|
||||
Receive ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
I2PTunnelConnectionIRC::I2PTunnelConnectionIRC (I2PService * owner, std::shared_ptr<i2p::stream::Stream> stream,
|
||||
std::shared_ptr<boost::asio::ip::tcp::socket> socket,
|
||||
const boost::asio::ip::tcp::endpoint& target, const std::string& webircpass):
|
||||
|
@ -556,8 +556,8 @@ namespace client
|
|||
m_KeepAliveInterval = keepAliveInterval;
|
||||
if (m_KeepAliveInterval)
|
||||
m_KeepAliveTimer.reset (new boost::asio::deadline_timer (GetLocalDestination ()->GetService ()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* HACK: maybe we should create a caching IdentHash provider in AddressBook */
|
||||
std::shared_ptr<const Address> I2PClientTunnel::GetAddress ()
|
||||
{
|
||||
|
@ -586,24 +586,24 @@ namespace client
|
|||
m_KeepAliveTimer->expires_from_now (boost::posix_time::seconds(m_KeepAliveInterval));
|
||||
m_KeepAliveTimer->async_wait (std::bind (&I2PClientTunnel::HandleKeepAliveTimer,
|
||||
this, std::placeholders::_1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void I2PClientTunnel::HandleKeepAliveTimer (const boost::system::error_code& ecode)
|
||||
{
|
||||
if (ecode != boost::asio::error::operation_aborted)
|
||||
{
|
||||
if (m_Address && m_Address->IsValid ())
|
||||
{
|
||||
{
|
||||
if (m_Address->IsIdentHash ())
|
||||
GetLocalDestination ()->SendPing (m_Address->identHash);
|
||||
else
|
||||
GetLocalDestination ()->SendPing (m_Address->blindedPublicKey);
|
||||
}
|
||||
}
|
||||
ScheduleKeepAliveTimer ();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
I2PServerTunnel::I2PServerTunnel (const std::string& name, const std::string& address,
|
||||
int port, std::shared_ptr<ClientDestination> localDestination, int inport, bool gzip):
|
||||
I2PService (localDestination), m_IsUniqueLocal(true), m_Name (name), m_Address (address), m_Port (port), m_IsAccessList (false)
|
||||
|
@ -643,16 +643,16 @@ namespace client
|
|||
bool found = false;
|
||||
boost::asio::ip::tcp::endpoint ep;
|
||||
if (m_LocalAddress)
|
||||
{
|
||||
{
|
||||
boost::asio::ip::tcp::resolver::iterator end;
|
||||
while (it != end)
|
||||
{
|
||||
{
|
||||
ep = *it;
|
||||
if (!ep.address ().is_unspecified ())
|
||||
{
|
||||
if (ep.address ().is_v4 ())
|
||||
{
|
||||
if (m_LocalAddress->is_v4 ()) found = true;
|
||||
{
|
||||
if (m_LocalAddress->is_v4 ()) found = true;
|
||||
}
|
||||
else if (ep.address ().is_v6 ())
|
||||
{
|
||||
|
@ -660,26 +660,26 @@ namespace client
|
|||
{
|
||||
if (i2p::util::net::IsYggdrasilAddress (*m_LocalAddress))
|
||||
found = true;
|
||||
}
|
||||
else if (m_LocalAddress->is_v6 ())
|
||||
}
|
||||
else if (m_LocalAddress->is_v6 ())
|
||||
found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (found) break;
|
||||
it++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
found = true;
|
||||
ep = *it; // first available
|
||||
}
|
||||
}
|
||||
if (!found)
|
||||
{
|
||||
LogPrint (eLogError, "I2PTunnel: Unable to resolve to compatible address");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
auto addr = ep.address ();
|
||||
LogPrint (eLogInfo, "I2PTunnel: Server tunnel ", (*it).host_name (), " has been resolved to ", addr);
|
||||
m_Endpoint.address (addr);
|
||||
|
@ -703,8 +703,8 @@ namespace client
|
|||
m_LocalAddress.reset (new boost::asio::ip::address (addr));
|
||||
else
|
||||
LogPrint (eLogError, "I2PTunnel: Can't set local address ", localAddress);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void I2PServerTunnel::Accept ()
|
||||
{
|
||||
if (m_PortDestination)
|
||||
|
@ -738,7 +738,7 @@ namespace client
|
|||
AddHandler (conn);
|
||||
if (m_LocalAddress)
|
||||
conn->Connect (*m_LocalAddress);
|
||||
else
|
||||
else
|
||||
conn->Connect (m_IsUniqueLocal);
|
||||
}
|
||||
}
|
||||
|
@ -793,9 +793,9 @@ namespace client
|
|||
{
|
||||
m_LastSession->IPSocket.send_to(boost::asio::buffer(buf, len), m_RemoteEndpoint);
|
||||
m_LastSession->LastActivity = i2p::util::GetMillisecondsSinceEpoch();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void I2PUDPServerTunnel::ExpireStale(const uint64_t delta) {
|
||||
std::lock_guard<std::mutex> lock(m_SessionsMutex);
|
||||
uint64_t now = i2p::util::GetMillisecondsSinceEpoch();
|
||||
|
@ -883,20 +883,20 @@ namespace client
|
|||
m_Destination->SendRawDatagram(session, m_Buffer, len, LocalPort, RemotePort);
|
||||
size_t numPackets = 0;
|
||||
while (numPackets < i2p::datagram::DATAGRAM_SEND_QUEUE_MAX_SIZE)
|
||||
{
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
size_t moreBytes = IPSocket.available(ec);
|
||||
if (ec || !moreBytes) break;
|
||||
len = IPSocket.receive_from (boost::asio::buffer (m_Buffer, I2P_UDP_MAX_MTU), FromEndpoint, 0, ec);
|
||||
m_Destination->SendRawDatagram (session, m_Buffer, len, LocalPort, RemotePort);
|
||||
m_Destination->SendRawDatagram (session, m_Buffer, len, LocalPort, RemotePort);
|
||||
numPackets++;
|
||||
}
|
||||
}
|
||||
if (numPackets > 0)
|
||||
LogPrint(eLogDebug, "UDPSession: Forward more ", numPackets, "packets B from ", FromEndpoint);
|
||||
m_Destination->FlushSendQueue (session);
|
||||
LastActivity = ts;
|
||||
Receive();
|
||||
}
|
||||
}
|
||||
else
|
||||
LogPrint(eLogError, "UDPSession: ", ecode.message());
|
||||
}
|
||||
|
@ -912,7 +912,7 @@ namespace client
|
|||
m_LocalDest->Start();
|
||||
auto dgram = m_LocalDest->CreateDatagramDestination(gzip);
|
||||
dgram->SetReceiver(std::bind(&I2PUDPServerTunnel::HandleRecvFromI2P, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5));
|
||||
dgram->SetRawReceiver(std::bind(&I2PUDPServerTunnel::HandleRecvFromI2PRaw, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
|
||||
dgram->SetRawReceiver(std::bind(&I2PUDPServerTunnel::HandleRecvFromI2PRaw, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4));
|
||||
}
|
||||
|
||||
I2PUDPServerTunnel::~I2PUDPServerTunnel()
|
||||
|
@ -1011,9 +1011,9 @@ namespace client
|
|||
{
|
||||
m_LastSession = std::make_shared<UDPConvo>(boost::asio::ip::udp::endpoint(m_RecvEndpoint), 0);
|
||||
m_Sessions.emplace (remotePort, m_LastSession);
|
||||
}
|
||||
}
|
||||
m_LastPort = remotePort;
|
||||
}
|
||||
}
|
||||
// send off to remote i2p destination
|
||||
auto ts = i2p::util::GetMillisecondsSinceEpoch();
|
||||
LogPrint(eLogDebug, "UDP Client: Send ", transferred, " to ", m_RemoteIdent->ToBase32(), ":", RemotePort);
|
||||
|
@ -1024,20 +1024,20 @@ namespace client
|
|||
m_LocalDest->GetDatagramDestination()->SendRawDatagram (session, m_RecvBuff, transferred, remotePort, RemotePort);
|
||||
size_t numPackets = 0;
|
||||
while (numPackets < i2p::datagram::DATAGRAM_SEND_QUEUE_MAX_SIZE)
|
||||
{
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
size_t moreBytes = m_LocalSocket.available(ec);
|
||||
if (ec || !moreBytes) break;
|
||||
transferred = m_LocalSocket.receive_from (boost::asio::buffer (m_RecvBuff, I2P_UDP_MAX_MTU), m_RecvEndpoint, 0, ec);
|
||||
remotePort = m_RecvEndpoint.port();
|
||||
// TODO: check remotePort
|
||||
m_LocalDest->GetDatagramDestination()->SendRawDatagram (session, m_RecvBuff, transferred, remotePort, RemotePort);
|
||||
m_LocalDest->GetDatagramDestination()->SendRawDatagram (session, m_RecvBuff, transferred, remotePort, RemotePort);
|
||||
numPackets++;
|
||||
}
|
||||
}
|
||||
if (numPackets)
|
||||
LogPrint(eLogDebug, "UDP Client: Sent ", numPackets, " more packets to ", m_RemoteIdent->ToBase32());
|
||||
m_LocalDest->GetDatagramDestination()->FlushSendQueue (session);
|
||||
|
||||
|
||||
// mark convo as active
|
||||
if (m_LastSession)
|
||||
m_LastSession->second = ts;
|
||||
|
@ -1091,7 +1091,7 @@ namespace client
|
|||
if(itr != m_Sessions.end())
|
||||
{
|
||||
// found convo
|
||||
if (len > 0)
|
||||
if (len > 0)
|
||||
{
|
||||
LogPrint(eLogDebug, "UDP Client: Got ", len, "B from ", m_RemoteIdent ? m_RemoteIdent->ToBase32() : "");
|
||||
m_LocalSocket.send_to(boost::asio::buffer(buf, len), itr->second->first);
|
||||
|
|
|
@ -49,7 +49,7 @@ namespace client
|
|||
void I2PConnect (const uint8_t * msg = nullptr, size_t len = 0);
|
||||
void Connect (bool isUniqueLocal = true);
|
||||
void Connect (const boost::asio::ip::address& localAddress);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
void Terminate ();
|
||||
|
@ -59,7 +59,7 @@ namespace client
|
|||
virtual void Write (const uint8_t * buf, size_t len); // can be overloaded
|
||||
void HandleWrite (const boost::system::error_code& ecode);
|
||||
virtual void WriteToStream (const uint8_t * buf, size_t len); // can be overloaded
|
||||
|
||||
|
||||
void StreamReceive ();
|
||||
void HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred);
|
||||
void HandleConnect (const boost::system::error_code& ecode);
|
||||
|
@ -105,7 +105,7 @@ namespace client
|
|||
protected:
|
||||
|
||||
void Write (const uint8_t * buf, size_t len);
|
||||
void WriteToStream (const uint8_t * buf, size_t len);
|
||||
void WriteToStream (const uint8_t * buf, size_t len);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -154,11 +154,11 @@ namespace client
|
|||
|
||||
const char* GetName() { return m_Name.c_str (); }
|
||||
void SetKeepAliveInterval (uint32_t keepAliveInterval);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
std::shared_ptr<const Address> GetAddress ();
|
||||
|
||||
|
||||
void ScheduleKeepAliveTimer ();
|
||||
void HandleKeepAliveTimer (const boost::system::error_code& ecode);
|
||||
|
||||
|
@ -174,8 +174,8 @@ namespace client
|
|||
|
||||
/** 2 minute timeout for udp sessions */
|
||||
const uint64_t I2P_UDP_SESSION_TIMEOUT = 1000 * 60 * 2;
|
||||
const uint64_t I2P_UDP_REPLIABLE_DATAGRAM_INTERVAL = 100; // in milliseconds
|
||||
|
||||
const uint64_t I2P_UDP_REPLIABLE_DATAGRAM_INTERVAL = 100; // in milliseconds
|
||||
|
||||
/** max size for i2p udp */
|
||||
const size_t I2P_UDP_MAX_MTU = 64*1024;
|
||||
|
||||
|
@ -330,7 +330,7 @@ namespace client
|
|||
bool IsUniqueLocal () const { return m_IsUniqueLocal; }
|
||||
|
||||
void SetLocalAddress (const std::string& localAddress);
|
||||
|
||||
|
||||
const std::string& GetAddress() const { return m_Address; }
|
||||
int GetPort () const { return m_Port; };
|
||||
uint16_t GetLocalPort () const { return m_PortDestination->GetLocalPort (); };
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace client
|
|||
bool MatchedTunnelDestination::SelectPeers(i2p::tunnel::Path & path, int hops, bool inbound)
|
||||
{
|
||||
auto pool = GetTunnelPool();
|
||||
if(!i2p::tunnel::StandardSelectPeers(path, hops, inbound,
|
||||
if(!i2p::tunnel::StandardSelectPeers(path, hops, inbound,
|
||||
std::bind(&i2p::tunnel::TunnelPool::SelectNextHop, pool, std::placeholders::_1, std::placeholders::_2)))
|
||||
return false;
|
||||
// more here for outbound tunnels
|
||||
|
@ -86,14 +86,14 @@ namespace client
|
|||
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases();
|
||||
// pick lease
|
||||
std::shared_ptr<i2p::data::RouterInfo> obep;
|
||||
while(!obep && leases.size() > 0)
|
||||
while(!obep && leases.size() > 0)
|
||||
{
|
||||
auto idx = rand() % leases.size();
|
||||
auto lease = leases[idx];
|
||||
obep = i2p::data::netdb.FindRouter(lease->tunnelGateway);
|
||||
leases.erase(leases.begin()+idx);
|
||||
}
|
||||
if(obep)
|
||||
if(obep)
|
||||
{
|
||||
path.Add (obep);
|
||||
LogPrint(eLogDebug, "Destination: Found OBEP matching IBGW");
|
||||
|
|
|
@ -54,7 +54,7 @@ namespace client
|
|||
break;
|
||||
}
|
||||
case eSAMSocketTypeAcceptor:
|
||||
case eSAMSocketTypeForward:
|
||||
case eSAMSocketTypeForward:
|
||||
{
|
||||
if (Session)
|
||||
{
|
||||
|
@ -481,7 +481,7 @@ namespace client
|
|||
{
|
||||
SendI2PError ("Socket already in use");
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::map<std::string, std::string> params;
|
||||
ExtractParams (buf, params);
|
||||
std::string& id = params[SAM_PARAM_ID];
|
||||
|
@ -502,7 +502,7 @@ namespace client
|
|||
|
||||
std::shared_ptr<const Address> addr;
|
||||
if (destination.find(".i2p") != std::string::npos)
|
||||
addr = context.GetAddressBook().GetAddress (destination);
|
||||
addr = context.GetAddressBook().GetAddress (destination);
|
||||
else
|
||||
{
|
||||
auto dest = std::make_shared<i2p::data::IdentityEx> ();
|
||||
|
@ -511,13 +511,13 @@ namespace client
|
|||
{
|
||||
context.GetAddressBook().InsertFullAddress(dest);
|
||||
addr = std::make_shared<Address>(dest->GetIdentHash ());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (addr && addr->IsValid ())
|
||||
{
|
||||
if (addr->IsIdentHash ())
|
||||
{
|
||||
{
|
||||
auto leaseSet = session->GetLocalDestination ()->FindLeaseSet(addr->identHash);
|
||||
if (leaseSet)
|
||||
Connect(leaseSet, session);
|
||||
|
@ -527,7 +527,7 @@ namespace client
|
|||
std::bind(&SAMSocket::HandleConnectLeaseSetRequestComplete,
|
||||
shared_from_this(), std::placeholders::_1));
|
||||
}
|
||||
}
|
||||
}
|
||||
else // B33
|
||||
session->GetLocalDestination ()->RequestDestinationWithEncryptedLeaseSet (addr->blindedPublicKey,
|
||||
std::bind(&SAMSocket::HandleConnectLeaseSetRequestComplete,
|
||||
|
@ -548,12 +548,12 @@ namespace client
|
|||
m_SocketType = eSAMSocketTypeStream;
|
||||
m_Stream = session->GetLocalDestination ()->CreateStream (remote);
|
||||
if (m_Stream)
|
||||
{
|
||||
{
|
||||
m_Stream->Send ((uint8_t *)m_Buffer, m_BufferOffset); // connect and send
|
||||
m_BufferOffset = 0;
|
||||
I2PReceive ();
|
||||
SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false);
|
||||
}
|
||||
}
|
||||
else
|
||||
SendMessageReply (SAM_STREAM_STATUS_INVALID_ID, strlen(SAM_STREAM_STATUS_INVALID_ID), true);
|
||||
}
|
||||
|
@ -579,7 +579,7 @@ namespace client
|
|||
{
|
||||
SendI2PError ("Socket already in use");
|
||||
return;
|
||||
}
|
||||
}
|
||||
std::map<std::string, std::string> params;
|
||||
ExtractParams (buf, params);
|
||||
std::string& id = params[SAM_PARAM_ID];
|
||||
|
@ -612,42 +612,42 @@ namespace client
|
|||
{
|
||||
SendMessageReply (SAM_STREAM_STATUS_INVALID_ID, strlen(SAM_STREAM_STATUS_INVALID_ID), true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (session->GetLocalDestination ()->IsAcceptingStreams ())
|
||||
{
|
||||
{
|
||||
SendI2PError ("Already accepting");
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto it = params.find (SAM_PARAM_PORT);
|
||||
if (it == params.end ())
|
||||
{
|
||||
SendI2PError ("PORT is missing");
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto port = std::stoi (it->second);
|
||||
if (port <= 0 || port >= 0xFFFF)
|
||||
{
|
||||
SendI2PError ("Invalid PORT");
|
||||
return;
|
||||
}
|
||||
}
|
||||
boost::system::error_code ec;
|
||||
auto ep = m_Socket.remote_endpoint (ec);
|
||||
if (ec)
|
||||
{
|
||||
SendI2PError ("Socket error");
|
||||
return;
|
||||
}
|
||||
}
|
||||
ep.port (port);
|
||||
m_SocketType = eSAMSocketTypeForward;
|
||||
m_ID = id;
|
||||
m_IsAccepting = true;
|
||||
std::string& silent = params[SAM_PARAM_SILENT];
|
||||
if (silent == SAM_VALUE_TRUE) m_IsSilent = true;
|
||||
session->GetLocalDestination ()->AcceptStreams (std::bind (&SAMSocket::HandleI2PForward,
|
||||
session->GetLocalDestination ()->AcceptStreams (std::bind (&SAMSocket::HandleI2PForward,
|
||||
shared_from_this (), std::placeholders::_1, ep));
|
||||
SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false);
|
||||
}
|
||||
|
||||
SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false);
|
||||
}
|
||||
|
||||
size_t SAMSocket::ProcessDatagramSend (char * buf, size_t len, const char * data)
|
||||
{
|
||||
LogPrint (eLogDebug, "SAM: Datagram send: ", buf, " ", len);
|
||||
|
@ -778,8 +778,8 @@ namespace client
|
|||
// session exists
|
||||
SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, strlen(SAM_SESSION_CREATE_DUPLICATED_ID), false);
|
||||
return;
|
||||
}
|
||||
std::string& style = params[SAM_PARAM_STYLE];
|
||||
}
|
||||
std::string& style = params[SAM_PARAM_STYLE];
|
||||
SAMSessionType type = eSAMSessionTypeUnknown;
|
||||
if (style == SAM_VALUE_STREAM) type = eSAMSessionTypeStream;
|
||||
// TODO: implement other styles
|
||||
|
@ -800,14 +800,14 @@ namespace client
|
|||
{
|
||||
masterSession->subsessions.insert (id);
|
||||
SendSessionCreateReplyOk ();
|
||||
}
|
||||
}
|
||||
else
|
||||
SendMessageReply (SAM_SESSION_CREATE_DUPLICATED_ID, strlen(SAM_SESSION_CREATE_DUPLICATED_ID), false);
|
||||
}
|
||||
}
|
||||
else
|
||||
SendI2PError ("Wrong session type");
|
||||
}
|
||||
|
||||
|
||||
void SAMSocket::ProcessSessionRemove (char * buf, size_t len)
|
||||
{
|
||||
auto session = m_Owner.FindSession(m_ID);
|
||||
|
@ -819,17 +819,17 @@ namespace client
|
|||
ExtractParams (buf, params);
|
||||
std::string& id = params[SAM_PARAM_ID];
|
||||
if (!masterSession->subsessions.erase (id))
|
||||
{
|
||||
{
|
||||
SendMessageReply (SAM_SESSION_STATUS_INVALID_KEY, strlen(SAM_SESSION_STATUS_INVALID_KEY), false);
|
||||
return;
|
||||
}
|
||||
m_Owner.CloseSession (id);
|
||||
SendSessionCreateReplyOk ();
|
||||
}
|
||||
}
|
||||
else
|
||||
SendI2PError ("Wrong session type");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SAMSocket::SendI2PError(const std::string & msg)
|
||||
{
|
||||
LogPrint (eLogError, "SAM: I2P error: ", msg);
|
||||
|
@ -1067,7 +1067,7 @@ namespace client
|
|||
LogPrint (eLogWarning, "SAM: I2P acceptor has been reset");
|
||||
}
|
||||
|
||||
void SAMSocket::HandleI2PForward (std::shared_ptr<i2p::stream::Stream> stream,
|
||||
void SAMSocket::HandleI2PForward (std::shared_ptr<i2p::stream::Stream> stream,
|
||||
boost::asio::ip::tcp::endpoint ep)
|
||||
{
|
||||
if (stream)
|
||||
|
@ -1076,7 +1076,7 @@ namespace client
|
|||
auto newSocket = std::make_shared<SAMSocket>(m_Owner);
|
||||
newSocket->SetSocketType (eSAMSocketTypeStream);
|
||||
auto s = shared_from_this ();
|
||||
newSocket->GetSocket ().async_connect (ep,
|
||||
newSocket->GetSocket ().async_connect (ep,
|
||||
[s, newSocket, stream](const boost::system::error_code& ecode)
|
||||
{
|
||||
if (!ecode)
|
||||
|
@ -1098,12 +1098,12 @@ namespace client
|
|||
}
|
||||
else
|
||||
stream->AsyncClose ();
|
||||
});
|
||||
});
|
||||
}
|
||||
else
|
||||
LogPrint (eLogWarning, "SAM: I2P forward acceptor has been reset");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SAMSocket::HandleI2PDatagramReceive (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len)
|
||||
{
|
||||
LogPrint (eLogDebug, "SAM: Datagram received ", len);
|
||||
|
@ -1198,11 +1198,11 @@ namespace client
|
|||
localDestination (dest)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SAMSingleSession::~SAMSingleSession ()
|
||||
{
|
||||
i2p::client::context.DeleteLocalDestination (localDestination);
|
||||
}
|
||||
}
|
||||
|
||||
void SAMSingleSession::StopLocalDestination ()
|
||||
{
|
||||
|
@ -1220,24 +1220,24 @@ namespace client
|
|||
for (const auto& it: subsessions)
|
||||
m_Bridge.CloseSession (it);
|
||||
subsessions.clear ();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SAMSubSession::SAMSubSession (std::shared_ptr<SAMMasterSession> master, const std::string& name, SAMSessionType type, int port):
|
||||
SAMSession (master->m_Bridge, name, type), masterSession (master), inPort (port)
|
||||
{
|
||||
if (Type == eSAMSessionTypeStream)
|
||||
{
|
||||
{
|
||||
auto d = masterSession->GetLocalDestination ()->CreateStreamingDestination (inPort);
|
||||
if (d) d->Start ();
|
||||
}
|
||||
// TODO: implement datagrams
|
||||
}
|
||||
|
||||
}
|
||||
// TODO: implement datagrams
|
||||
}
|
||||
|
||||
std::shared_ptr<ClientDestination> SAMSubSession::GetLocalDestination ()
|
||||
{
|
||||
return masterSession ? masterSession->GetLocalDestination () : nullptr;
|
||||
}
|
||||
|
||||
|
||||
void SAMSubSession::StopLocalDestination ()
|
||||
{
|
||||
auto dest = GetLocalDestination ();
|
||||
|
@ -1245,10 +1245,10 @@ namespace client
|
|||
{
|
||||
auto d = dest->RemoveStreamingDestination (inPort);
|
||||
if (d) d->Stop ();
|
||||
}
|
||||
}
|
||||
// TODO: implement datagrams
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
SAMBridge::SAMBridge (const std::string& address, int port, bool singleThread):
|
||||
RunnableService ("SAM"), m_IsSingleThread (singleThread),
|
||||
m_Acceptor (GetIOService (), boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(address), port)),
|
||||
|
@ -1311,8 +1311,8 @@ namespace client
|
|||
{
|
||||
std::unique_lock<std::mutex> lock(m_OpenSocketsMutex);
|
||||
m_OpenSockets.push_back(socket);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void SAMBridge::RemoveSocket(const std::shared_ptr<SAMSocket> & socket)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(m_OpenSocketsMutex);
|
||||
|
@ -1403,7 +1403,7 @@ namespace client
|
|||
auto ret = m_Sessions.emplace (session->Name, session);
|
||||
return ret.second;
|
||||
}
|
||||
|
||||
|
||||
void SAMBridge::CloseSession (const std::string& id)
|
||||
{
|
||||
std::shared_ptr<SAMSession> session;
|
||||
|
|
|
@ -80,7 +80,7 @@ namespace client
|
|||
const char SAM_VALUE_STREAM[] = "STREAM";
|
||||
const char SAM_VALUE_DATAGRAM[] = "DATAGRAM";
|
||||
const char SAM_VALUE_RAW[] = "RAW";
|
||||
const char SAM_VALUE_MASTER[] = "MASTER";
|
||||
const char SAM_VALUE_MASTER[] = "MASTER";
|
||||
const char SAM_VALUE_TRUE[] = "true";
|
||||
const char SAM_VALUE_FALSE[] = "false";
|
||||
|
||||
|
@ -188,14 +188,14 @@ namespace client
|
|||
std::string Name;
|
||||
SAMSessionType Type;
|
||||
std::shared_ptr<boost::asio::ip::udp::endpoint> UDPEndpoint; // TODO: move
|
||||
|
||||
|
||||
SAMSession (SAMBridge & parent, const std::string & name, SAMSessionType type);
|
||||
virtual ~SAMSession () {};
|
||||
|
||||
|
||||
virtual std::shared_ptr<ClientDestination> GetLocalDestination () = 0;
|
||||
virtual void StopLocalDestination () = 0;
|
||||
virtual void Close () { CloseStreams (); };
|
||||
|
||||
|
||||
void CloseStreams ();
|
||||
};
|
||||
|
||||
|
@ -208,15 +208,15 @@ namespace client
|
|||
|
||||
std::shared_ptr<ClientDestination> GetLocalDestination () { return localDestination; };
|
||||
void StopLocalDestination ();
|
||||
};
|
||||
};
|
||||
|
||||
struct SAMMasterSession: public SAMSingleSession
|
||||
{
|
||||
std::set<std::string> subsessions;
|
||||
SAMMasterSession (SAMBridge & parent, const std::string & name, std::shared_ptr<ClientDestination> dest):
|
||||
SAMSingleSession (parent, name, eSAMSessionTypeMaster, dest) {};
|
||||
void Close ();
|
||||
};
|
||||
void Close ();
|
||||
};
|
||||
|
||||
struct SAMSubSession: public SAMSession
|
||||
{
|
||||
|
@ -227,8 +227,8 @@ namespace client
|
|||
// implements SAMSession
|
||||
std::shared_ptr<ClientDestination> GetLocalDestination ();
|
||||
void StopLocalDestination ();
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
class SAMBridge: private i2p::util::RunnableService
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue