Browse Source

tabify and use shared pointers

pull/628/head
Jeff Becker 8 years ago
parent
commit
8a29dfc3fa
No known key found for this signature in database
GPG Key ID: AB950234D6EA286B
  1. 19
      ClientContext.cpp
  2. 2
      ClientContext.h
  3. 15
      HTTPServer.cpp
  4. 45
      I2PTunnel.cpp
  5. 47
      I2PTunnel.h

19
ClientContext.cpp

@ -276,20 +276,27 @@ namespace client
return success; return success;
} }
std::vector<DatagramSessionInfo> ClientContext::GetForwardInfosFor(const i2p::data::IdentHash & destination) std::vector<std::shared_ptr<DatagramSessionInfo> > ClientContext::GetForwardInfosFor(const i2p::data::IdentHash & destination)
{ {
std::vector<std::shared_ptr<DatagramSessionInfo> > infos;
std::lock_guard<std::mutex> lock(m_ForwardsMutex); std::lock_guard<std::mutex> lock(m_ForwardsMutex);
for(auto & c : m_ClientForwards) for(const auto & c : m_ClientForwards)
{ {
if (c.second->IsLocalDestination(destination)) if (c.second->IsLocalDestination(destination))
return c.second->GetSessions(); {
for (auto & i : c.second->GetSessions()) infos.push_back(i);
break;
}
} }
for(auto & s : m_ServerForwards) for(const auto & s : m_ServerForwards)
{ {
if(std::get<0>(s.first) == destination) if(std::get<0>(s.first) == destination)
return s.second->GetSessions(); {
for( auto & i : s.second->GetSessions()) infos.push_back(i);
break;
}
} }
return {}; return infos;
} }
std::shared_ptr<ClientDestination> ClientContext::CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType, std::shared_ptr<ClientDestination> ClientContext::CreateNewLocalDestination (bool isPublic, i2p::data::SigningKeyType sigType,

2
ClientContext.h

@ -67,7 +67,7 @@ namespace client
AddressBook& GetAddressBook () { return m_AddressBook; }; AddressBook& GetAddressBook () { return m_AddressBook; };
const SAMBridge * GetSAMBridge () const { return m_SamBridge; }; const SAMBridge * GetSAMBridge () const { return m_SamBridge; };
std::vector<DatagramSessionInfo> GetForwardInfosFor(const i2p::data::IdentHash & destination); std::vector<std::shared_ptr<DatagramSessionInfo> > GetForwardInfosFor(const i2p::data::IdentHash & destination);
private: private:

15
HTTPServer.cpp

@ -343,29 +343,26 @@ namespace http {
s << "<th>IBGW</th>"; s << "<th>IBGW</th>";
s << "<th>OBEP</th>"; s << "<th>OBEP</th>";
s << "<th>UDP Converstation</th>"; s << "<th>UDP Converstation</th>";
s << "<th>Idle Time</th>";
s << "</th>"; s << "</th>";
auto forward = i2p::client::context.GetForwardInfosFor(dest->GetIdentHash()); auto forward = i2p::client::context.GetForwardInfosFor(dest->GetIdentHash());
for (auto info : forward) for (auto info : forward)
{ {
s << "<tr>"; s << "<tr>";
s << "<td>" << info.RemoteIdent.ToBase32() << "</td>"; s << "<td>" << info->RemoteIdent->ToBase32() << "</td>";
s << "<td>"; s << "<td>";
if(info.CurrentIBGW) if(info->CurrentIBGW)
s << std::string(info.CurrentIBGW->ToBase64()); s << info->CurrentIBGW->ToBase64();
else else
s << "(none)"; s << "(none)";
s << "</td>"; s << "</td>";
s << "<td>"; s << "<td>";
if(info.CurrentOBEP) if(info->CurrentOBEP)
s << std::string(info.CurrentOBEP->ToBase64()); s << info->CurrentOBEP->ToBase64();
else else
s << "(none)"; s << "(none)";
s << "</td>"; s << "</td>";
s << "<td>" << info.LocalEndpoint << " &#8644; " << info.RemoteEndpoint << "</td>"; s << "<td>" << info->LocalEndpoint << " &#8644; " << info->RemoteEndpoint << "</td>";
auto sec = std::chrono::duration<float, std::ratio<1000, 1 > >( std::chrono::milliseconds(info.idle) );
s << "<td>" << sec.count() << " seconds </td>";
s << "</tr><br>\r\n"; s << "</tr><br>\r\n";
} }
s << "</table>\r\n"; s << "</table>\r\n";

45
I2PTunnel.cpp

@ -632,26 +632,23 @@ namespace client
m_LocalDest->Start(); m_LocalDest->Start();
} }
std::vector<DatagramSessionInfo> I2PUDPServerTunnel::GetSessions() std::vector<std::shared_ptr<DatagramSessionInfo> > I2PUDPServerTunnel::GetSessions()
{ {
std::vector<DatagramSessionInfo> sessions; std::vector<std::shared_ptr<DatagramSessionInfo> > sessions;
auto localident = m_LocalDest->GetIdentHash();
std::lock_guard<std::mutex> lock(m_SessionsMutex); std::lock_guard<std::mutex> lock(m_SessionsMutex);
for ( UDPSession * s : m_Sessions ) for ( UDPSession * s : m_Sessions )
{ {
if (!s->m_Destination) continue; if (!s->m_Destination) continue;
auto info = s->m_Destination->GetInfoForRemote(s->Identity); auto info = s->m_Destination->GetInfoForRemote(s->Identity);
if(!info) continue; if(!info) continue;
sessions.push_back(DatagramSessionInfo{
m_Name, auto sinfo = std::make_shared<DatagramSessionInfo>();
localident, sinfo->Name = m_Name;
s->Identity, sinfo->LocalIdent = std::make_shared<i2p::data::IdentHash>(m_LocalDest->GetIdentHash().data());
info->IBGW, sinfo->RemoteIdent = std::make_shared<i2p::data::IdentHash>(s->Identity.data());
info->OBEP, sinfo->CurrentIBGW = info->IBGW;
s->IPSocket.local_endpoint(), sinfo->CurrentOBEP = info->OBEP;
s->SendEndpoint, sessions.push_back(sinfo);
info->success
});
} }
return sessions; return sessions;
} }
@ -686,28 +683,24 @@ namespace client
m_ResolveThread = new std::thread(std::bind(&I2PUDPClientTunnel::TryResolving, this)); m_ResolveThread = new std::thread(std::bind(&I2PUDPClientTunnel::TryResolving, this));
} }
std::vector<DatagramSessionInfo> I2PUDPClientTunnel::GetSessions() std::vector<std::shared_ptr<DatagramSessionInfo> > I2PUDPClientTunnel::GetSessions()
{ {
std::vector<DatagramSessionInfo> infos; std::vector<std::shared_ptr<DatagramSessionInfo> > infos;
if(m_Session && m_LocalDest) if(m_Session && m_LocalDest)
{ {
auto localident = m_LocalDest->GetIdentHash();
auto s = m_Session; auto s = m_Session;
if (s->m_Destination) if (s->m_Destination)
{ {
auto info = m_Session->m_Destination->GetInfoForRemote(s->Identity); auto info = m_Session->m_Destination->GetInfoForRemote(s->Identity);
if(info) if(info)
{ {
infos.push_back(DatagramSessionInfo{ auto sinfo = std::make_shared<DatagramSessionInfo>();
m_Name, sinfo->Name = m_Name;
localident, sinfo->LocalIdent = std::make_shared<i2p::data::IdentHash>(m_LocalDest->GetIdentHash().data());
s->Identity, sinfo->RemoteIdent = std::make_shared<i2p::data::IdentHash>(s->Identity.data());
info->IBGW, sinfo->CurrentIBGW = info->IBGW;
info->OBEP, sinfo->CurrentOBEP = info->OBEP;
s->IPSocket.local_endpoint(), infos.push_back(sinfo);
s->SendEndpoint,
info->success
});
} }
} }
} }

47
I2PTunnel.h

@ -138,27 +138,6 @@ namespace client
/** max size for i2p udp */ /** max size for i2p udp */
const size_t I2P_UDP_MAX_MTU = i2p::datagram::MAX_DATAGRAM_SIZE; const size_t I2P_UDP_MAX_MTU = i2p::datagram::MAX_DATAGRAM_SIZE;
/** read only info about a datagram session */
struct DatagramSessionInfo
{
/** the name of this forward */
const std::string Name;
/** ident hash of local destination */
const i2p::data::IdentHash LocalIdent;
/** ident hash of remote destination */
const i2p::data::IdentHash RemoteIdent;
/** ident hash of IBGW in use currently in this session or nullptr if none is set */
std::shared_ptr<const i2p::data::IdentHash> CurrentIBGW;
/** ident hash of OBEP in use for this session or nullptr if none is set */
std::shared_ptr<const i2p::data::IdentHash> CurrentOBEP;
/** i2p router's udp endpoint */
const boost::asio::ip::udp::endpoint LocalEndpoint;
/** client's udp endpoint */
const boost::asio::ip::udp::endpoint RemoteEndpoint;
/** how long has this converstation been idle in ms */
const uint64_t idle;
};
struct UDPSession struct UDPSession
{ {
i2p::datagram::DatagramDestination * m_Destination; i2p::datagram::DatagramDestination * m_Destination;
@ -182,6 +161,28 @@ namespace client
void Receive(); void Receive();
}; };
/** read only info about a datagram session */
struct DatagramSessionInfo
{
/** the name of this forward */
std::string Name;
/** ident hash of local destination */
std::shared_ptr<const i2p::data::IdentHash> LocalIdent;
/** ident hash of remote destination */
std::shared_ptr<const i2p::data::IdentHash> RemoteIdent;
/** ident hash of IBGW in use currently in this session or nullptr if none is set */
std::shared_ptr<const i2p::data::IdentHash> CurrentIBGW;
/** ident hash of OBEP in use for this session or nullptr if none is set */
std::shared_ptr<const i2p::data::IdentHash> CurrentOBEP;
/** i2p router's udp endpoint */
boost::asio::ip::udp::endpoint LocalEndpoint;
/** client's udp endpoint */
boost::asio::ip::udp::endpoint RemoteEndpoint;
/** how long has this converstation been idle in ms */
uint64_t idle;
};
/** server side udp tunnel, many i2p inbound to 1 ip outbound */ /** server side udp tunnel, many i2p inbound to 1 ip outbound */
class I2PUDPServerTunnel class I2PUDPServerTunnel
{ {
@ -195,7 +196,7 @@ namespace client
void ExpireStale(const uint64_t delta=I2P_UDP_SESSION_TIMEOUT); void ExpireStale(const uint64_t delta=I2P_UDP_SESSION_TIMEOUT);
void Start(); void Start();
const char * GetName() const { return m_Name.c_str(); } const char * GetName() const { return m_Name.c_str(); }
std::vector<DatagramSessionInfo> GetSessions(); std::vector<std::shared_ptr<DatagramSessionInfo> > GetSessions();
private: private:
void HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len); void HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);
UDPSession * ObtainUDPSession(const i2p::data::IdentityEx& from, uint16_t localPort, uint16_t remotePort); UDPSession * ObtainUDPSession(const i2p::data::IdentityEx& from, uint16_t localPort, uint16_t remotePort);
@ -218,7 +219,7 @@ namespace client
~I2PUDPClientTunnel(); ~I2PUDPClientTunnel();
void Start(); void Start();
const char * GetName() const { return m_Name.c_str(); } const char * GetName() const { return m_Name.c_str(); }
std::vector<DatagramSessionInfo> GetSessions(); std::vector<std::shared_ptr<DatagramSessionInfo> > GetSessions();
bool IsLocalDestination(const i2p::data::IdentHash & destination) const { return destination == m_LocalDest->GetIdentHash(); } bool IsLocalDestination(const i2p::data::IdentHash & destination) const { return destination == m_LocalDest->GetIdentHash(); }
private: private:
void HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len); void HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);

Loading…
Cancel
Save