|
|
@ -58,8 +58,8 @@ namespace client |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (Session) |
|
|
|
if (Session) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (m_IsAccepting && Session->localDestination) |
|
|
|
if (m_IsAccepting && Session->GetLocalDestination ()) |
|
|
|
Session->localDestination->StopAcceptingStreams (); |
|
|
|
Session->GetLocalDestination ()->StopAcceptingStreams (); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -410,7 +410,7 @@ namespace client |
|
|
|
if (type == eSAMSessionTypeDatagram || type == eSAMSessionTypeRaw) |
|
|
|
if (type == eSAMSessionTypeDatagram || type == eSAMSessionTypeRaw) |
|
|
|
{ |
|
|
|
{ |
|
|
|
session->UDPEndpoint = forward; |
|
|
|
session->UDPEndpoint = forward; |
|
|
|
auto dest = session->localDestination->CreateDatagramDestination (); |
|
|
|
auto dest = session->GetLocalDestination ()->CreateDatagramDestination (); |
|
|
|
if (type == eSAMSessionTypeDatagram) |
|
|
|
if (type == eSAMSessionTypeDatagram) |
|
|
|
dest->SetReceiver (std::bind (&SAMSocket::HandleI2PDatagramReceive, shared_from_this (), |
|
|
|
dest->SetReceiver (std::bind (&SAMSocket::HandleI2PDatagramReceive, shared_from_this (), |
|
|
|
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5)); |
|
|
|
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5)); |
|
|
@ -419,7 +419,7 @@ namespace client |
|
|
|
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); |
|
|
|
std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (session->localDestination->IsReady ()) |
|
|
|
if (session->GetLocalDestination ()->IsReady ()) |
|
|
|
SendSessionCreateReplyOk (); |
|
|
|
SendSessionCreateReplyOk (); |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
@ -439,7 +439,7 @@ namespace client |
|
|
|
auto session = m_Owner.FindSession(m_ID); |
|
|
|
auto session = m_Owner.FindSession(m_ID); |
|
|
|
if(session) |
|
|
|
if(session) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (session->localDestination->IsReady ()) |
|
|
|
if (session->GetLocalDestination ()->IsReady ()) |
|
|
|
SendSessionCreateReplyOk (); |
|
|
|
SendSessionCreateReplyOk (); |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
@ -458,7 +458,7 @@ namespace client |
|
|
|
{ |
|
|
|
{ |
|
|
|
uint8_t buf[1024]; |
|
|
|
uint8_t buf[1024]; |
|
|
|
char priv[1024]; |
|
|
|
char priv[1024]; |
|
|
|
size_t l = session->localDestination->GetPrivateKeys ().ToBuffer (buf, 1024); |
|
|
|
size_t l = session->GetLocalDestination ()->GetPrivateKeys ().ToBuffer (buf, 1024); |
|
|
|
size_t l1 = i2p::data::ByteStreamToBase64 (buf, l, priv, 1024); |
|
|
|
size_t l1 = i2p::data::ByteStreamToBase64 (buf, l, priv, 1024); |
|
|
|
priv[l1] = 0; |
|
|
|
priv[l1] = 0; |
|
|
|
#ifdef _MSC_VER |
|
|
|
#ifdef _MSC_VER |
|
|
@ -514,18 +514,18 @@ namespace client |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (addr->IsIdentHash ()) |
|
|
|
if (addr->IsIdentHash ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto leaseSet = session->localDestination->FindLeaseSet(addr->identHash); |
|
|
|
auto leaseSet = session->GetLocalDestination ()->FindLeaseSet(addr->identHash); |
|
|
|
if (leaseSet) |
|
|
|
if (leaseSet) |
|
|
|
Connect(leaseSet, session); |
|
|
|
Connect(leaseSet, session); |
|
|
|
else |
|
|
|
else |
|
|
|
{ |
|
|
|
{ |
|
|
|
session->localDestination->RequestDestination(addr->identHash, |
|
|
|
session->GetLocalDestination ()->RequestDestination(addr->identHash, |
|
|
|
std::bind(&SAMSocket::HandleConnectLeaseSetRequestComplete, |
|
|
|
std::bind(&SAMSocket::HandleConnectLeaseSetRequestComplete, |
|
|
|
shared_from_this(), std::placeholders::_1)); |
|
|
|
shared_from_this(), std::placeholders::_1)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
else // B33
|
|
|
|
else // B33
|
|
|
|
session->localDestination->RequestDestinationWithEncryptedLeaseSet (addr->blindedPublicKey, |
|
|
|
session->GetLocalDestination ()->RequestDestinationWithEncryptedLeaseSet (addr->blindedPublicKey, |
|
|
|
std::bind(&SAMSocket::HandleConnectLeaseSetRequestComplete, |
|
|
|
std::bind(&SAMSocket::HandleConnectLeaseSetRequestComplete, |
|
|
|
shared_from_this(), std::placeholders::_1)); |
|
|
|
shared_from_this(), std::placeholders::_1)); |
|
|
|
} |
|
|
|
} |
|
|
@ -542,7 +542,7 @@ namespace client |
|
|
|
if (session) |
|
|
|
if (session) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_SocketType = eSAMSocketTypeStream; |
|
|
|
m_SocketType = eSAMSocketTypeStream; |
|
|
|
m_Stream = session->localDestination->CreateStream (remote); |
|
|
|
m_Stream = session->GetLocalDestination ()->CreateStream (remote); |
|
|
|
if (m_Stream) |
|
|
|
if (m_Stream) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_Stream->Send ((uint8_t *)m_Buffer, m_BufferOffset); // connect and send
|
|
|
|
m_Stream->Send ((uint8_t *)m_Buffer, m_BufferOffset); // connect and send
|
|
|
@ -586,10 +586,10 @@ namespace client |
|
|
|
if (session) |
|
|
|
if (session) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_SocketType = eSAMSocketTypeAcceptor; |
|
|
|
m_SocketType = eSAMSocketTypeAcceptor; |
|
|
|
if (!session->localDestination->IsAcceptingStreams ()) |
|
|
|
if (!session->GetLocalDestination ()->IsAcceptingStreams ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
m_IsAccepting = true; |
|
|
|
m_IsAccepting = true; |
|
|
|
session->localDestination->AcceptOnce (std::bind (&SAMSocket::HandleI2PAccept, shared_from_this (), std::placeholders::_1)); |
|
|
|
session->GetLocalDestination ()->AcceptOnce (std::bind (&SAMSocket::HandleI2PAccept, shared_from_this (), std::placeholders::_1)); |
|
|
|
} |
|
|
|
} |
|
|
|
SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false); |
|
|
|
SendMessageReply (SAM_STREAM_STATUS_OK, strlen(SAM_STREAM_STATUS_OK), false); |
|
|
|
} |
|
|
|
} |
|
|
@ -609,7 +609,7 @@ namespace client |
|
|
|
SendMessageReply (SAM_STREAM_STATUS_INVALID_ID, strlen(SAM_STREAM_STATUS_INVALID_ID), true); |
|
|
|
SendMessageReply (SAM_STREAM_STATUS_INVALID_ID, strlen(SAM_STREAM_STATUS_INVALID_ID), true); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (session->localDestination->IsAcceptingStreams ()) |
|
|
|
if (session->GetLocalDestination ()->IsAcceptingStreams ()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
SendI2PError ("Already accepting"); |
|
|
|
SendI2PError ("Already accepting"); |
|
|
|
return; |
|
|
|
return; |
|
|
@ -639,7 +639,7 @@ namespace client |
|
|
|
m_IsAccepting = true; |
|
|
|
m_IsAccepting = true; |
|
|
|
std::string& silent = params[SAM_PARAM_SILENT]; |
|
|
|
std::string& silent = params[SAM_PARAM_SILENT]; |
|
|
|
if (silent == SAM_VALUE_TRUE) m_IsSilent = true; |
|
|
|
if (silent == SAM_VALUE_TRUE) m_IsSilent = true; |
|
|
|
session->localDestination->AcceptStreams (std::bind (&SAMSocket::HandleI2PForward, |
|
|
|
session->GetLocalDestination ()->AcceptStreams (std::bind (&SAMSocket::HandleI2PForward, |
|
|
|
shared_from_this (), std::placeholders::_1, ep)); |
|
|
|
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); |
|
|
|
} |
|
|
|
} |
|
|
@ -655,7 +655,7 @@ namespace client |
|
|
|
auto session = m_Owner.FindSession(m_ID); |
|
|
|
auto session = m_Owner.FindSession(m_ID); |
|
|
|
if (session) |
|
|
|
if (session) |
|
|
|
{ |
|
|
|
{ |
|
|
|
auto d = session->localDestination->GetDatagramDestination (); |
|
|
|
auto d = session->GetLocalDestination ()->GetDatagramDestination (); |
|
|
|
if (d) |
|
|
|
if (d) |
|
|
|
{ |
|
|
|
{ |
|
|
|
i2p::data::IdentityEx dest; |
|
|
|
i2p::data::IdentityEx dest; |
|
|
@ -725,7 +725,7 @@ namespace client |
|
|
|
std::shared_ptr<const i2p::data::IdentityEx> identity; |
|
|
|
std::shared_ptr<const i2p::data::IdentityEx> identity; |
|
|
|
std::shared_ptr<const Address> addr; |
|
|
|
std::shared_ptr<const Address> addr; |
|
|
|
auto session = m_Owner.FindSession(m_ID); |
|
|
|
auto session = m_Owner.FindSession(m_ID); |
|
|
|
auto dest = session == nullptr ? context.GetSharedLocalDestination() : session->localDestination; |
|
|
|
auto dest = session == nullptr ? context.GetSharedLocalDestination() : session->GetLocalDestination (); |
|
|
|
if (name == "ME") |
|
|
|
if (name == "ME") |
|
|
|
SendNamingLookupReply (name, dest->GetIdentity ()); |
|
|
|
SendNamingLookupReply (name, dest->GetIdentity ()); |
|
|
|
else if ((identity = context.GetAddressBook ().GetFullAddress (name)) != nullptr) |
|
|
|
else if ((identity = context.GetAddressBook ().GetFullAddress (name)) != nullptr) |
|
|
@ -971,7 +971,7 @@ namespace client |
|
|
|
if (it->m_SocketType == eSAMSocketTypeAcceptor) |
|
|
|
if (it->m_SocketType == eSAMSocketTypeAcceptor) |
|
|
|
{ |
|
|
|
{ |
|
|
|
it->m_IsAccepting = true; |
|
|
|
it->m_IsAccepting = true; |
|
|
|
session->localDestination->AcceptOnce (std::bind (&SAMSocket::HandleI2PAccept, it, std::placeholders::_1)); |
|
|
|
session->GetLocalDestination ()->AcceptOnce (std::bind (&SAMSocket::HandleI2PAccept, it, std::placeholders::_1)); |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -1109,19 +1109,11 @@ namespace client |
|
|
|
m_Owner.GetService ().post (std::bind( !ec ? &SAMSocket::Receive : &SAMSocket::TerminateClose, shared_from_this())); |
|
|
|
m_Owner.GetService ().post (std::bind( !ec ? &SAMSocket::Receive : &SAMSocket::TerminateClose, shared_from_this())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SAMSession::SAMSession (SAMBridge & parent, const std::string & id, SAMSessionType type, std::shared_ptr<ClientDestination> dest): |
|
|
|
SAMSession::SAMSession (SAMBridge & parent, const std::string & id, SAMSessionType type): |
|
|
|
m_Bridge(parent), |
|
|
|
m_Bridge(parent), Name(id), Type (type), UDPEndpoint(nullptr) |
|
|
|
localDestination (dest), |
|
|
|
|
|
|
|
UDPEndpoint(nullptr), |
|
|
|
|
|
|
|
Name(id), Type (type) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SAMSession::~SAMSession () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
i2p::client::context.DeleteLocalDestination (localDestination); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void SAMSession::CloseStreams () |
|
|
|
void SAMSession::CloseStreams () |
|
|
|
{ |
|
|
|
{ |
|
|
|
for(const auto & itr : m_Bridge.ListSockets(Name)) |
|
|
|
for(const auto & itr : m_Bridge.ListSockets(Name)) |
|
|
@ -1130,6 +1122,17 @@ namespace client |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SAMSingleSession::SAMSingleSession (SAMBridge & parent, const std::string & name, SAMSessionType type, std::shared_ptr<ClientDestination> dest): |
|
|
|
|
|
|
|
SAMSession (parent, name, type), |
|
|
|
|
|
|
|
localDestination (dest) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SAMSingleSession::~SAMSingleSession () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
i2p::client::context.DeleteLocalDestination (localDestination); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
SAMBridge::SAMBridge (const std::string& address, int port, bool singleThread): |
|
|
|
SAMBridge::SAMBridge (const std::string& address, int port, bool singleThread): |
|
|
|
RunnableService ("SAM"), m_IsSingleThread (singleThread), |
|
|
|
RunnableService ("SAM"), m_IsSingleThread (singleThread), |
|
|
|
m_Acceptor (GetIOService (), boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(address), port)), |
|
|
|
m_Acceptor (GetIOService (), boost::asio::ip::tcp::endpoint(boost::asio::ip::address::from_string(address), port)), |
|
|
@ -1267,7 +1270,8 @@ namespace client |
|
|
|
if (localDestination) |
|
|
|
if (localDestination) |
|
|
|
{ |
|
|
|
{ |
|
|
|
localDestination->Acquire (); |
|
|
|
localDestination->Acquire (); |
|
|
|
auto session = std::make_shared<SAMSession>(*this, id, type, localDestination); |
|
|
|
auto session = (type == eSAMSessionTypeMaster) ? std::make_shared<SAMMasterSession>(*this, id, localDestination) : |
|
|
|
|
|
|
|
std::make_shared<SAMSingleSession>(*this, id, type, localDestination); |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
std::unique_lock<std::mutex> l(m_SessionsMutex); |
|
|
|
auto ret = m_Sessions.insert (std::make_pair(id, session)); |
|
|
|
auto ret = m_Sessions.insert (std::make_pair(id, session)); |
|
|
|
if (!ret.second) |
|
|
|
if (!ret.second) |
|
|
@ -1291,8 +1295,8 @@ namespace client |
|
|
|
} |
|
|
|
} |
|
|
|
if (session) |
|
|
|
if (session) |
|
|
|
{ |
|
|
|
{ |
|
|
|
session->localDestination->Release (); |
|
|
|
session->GetLocalDestination ()->Release (); |
|
|
|
session->localDestination->StopAcceptingStreams (); |
|
|
|
session->GetLocalDestination ()->StopAcceptingStreams (); |
|
|
|
session->CloseStreams (); |
|
|
|
session->CloseStreams (); |
|
|
|
if (m_IsSingleThread) |
|
|
|
if (m_IsSingleThread) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -1368,10 +1372,10 @@ namespace client |
|
|
|
i2p::data::IdentityEx dest; |
|
|
|
i2p::data::IdentityEx dest; |
|
|
|
dest.FromBase64 (destination); |
|
|
|
dest.FromBase64 (destination); |
|
|
|
if (session->Type == eSAMSessionTypeDatagram) |
|
|
|
if (session->Type == eSAMSessionTypeDatagram) |
|
|
|
session->localDestination->GetDatagramDestination ()-> |
|
|
|
session->GetLocalDestination ()->GetDatagramDestination ()-> |
|
|
|
SendDatagramTo ((uint8_t *)eol, payloadLen, dest.GetIdentHash ()); |
|
|
|
SendDatagramTo ((uint8_t *)eol, payloadLen, dest.GetIdentHash ()); |
|
|
|
else // raw
|
|
|
|
else // raw
|
|
|
|
session->localDestination->GetDatagramDestination ()-> |
|
|
|
session->GetLocalDestination ()->GetDatagramDestination ()-> |
|
|
|
SendRawDatagramTo ((uint8_t *)eol, payloadLen, dest.GetIdentHash ()); |
|
|
|
SendRawDatagramTo ((uint8_t *)eol, payloadLen, dest.GetIdentHash ()); |
|
|
|
} |
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|