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 @@ -276,20 +276,27 @@ namespace client
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);
for(auto & c : m_ClientForwards)
for(const auto & c : m_ClientForwards)
{
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)
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,

2
ClientContext.h

@ -67,7 +67,7 @@ namespace client @@ -67,7 +67,7 @@ namespace client
AddressBook& GetAddressBook () { return m_AddressBook; };
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:

15
HTTPServer.cpp

@ -343,29 +343,26 @@ namespace http { @@ -343,29 +343,26 @@ namespace http {
s << "<th>IBGW</th>";
s << "<th>OBEP</th>";
s << "<th>UDP Converstation</th>";
s << "<th>Idle Time</th>";
s << "</th>";
auto forward = i2p::client::context.GetForwardInfosFor(dest->GetIdentHash());
for (auto info : forward)
{
s << "<tr>";
s << "<td>" << info.RemoteIdent.ToBase32() << "</td>";
s << "<td>" << info->RemoteIdent->ToBase32() << "</td>";
s << "<td>";
if(info.CurrentIBGW)
s << std::string(info.CurrentIBGW->ToBase64());
if(info->CurrentIBGW)
s << info->CurrentIBGW->ToBase64();
else
s << "(none)";
s << "</td>";
s << "<td>";
if(info.CurrentOBEP)
s << std::string(info.CurrentOBEP->ToBase64());
if(info->CurrentOBEP)
s << info->CurrentOBEP->ToBase64();
else
s << "(none)";
s << "</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 << "<td>" << info->LocalEndpoint << " &#8644; " << info->RemoteEndpoint << "</td>";
s << "</tr><br>\r\n";
}
s << "</table>\r\n";

45
I2PTunnel.cpp

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

47
I2PTunnel.h

@ -138,27 +138,6 @@ namespace client @@ -138,27 +138,6 @@ namespace client
/** max size for i2p udp */
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
{
i2p::datagram::DatagramDestination * m_Destination;
@ -182,6 +161,28 @@ namespace client @@ -182,6 +161,28 @@ namespace client
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 */
class I2PUDPServerTunnel
{
@ -195,7 +196,7 @@ namespace client @@ -195,7 +196,7 @@ namespace client
void ExpireStale(const uint64_t delta=I2P_UDP_SESSION_TIMEOUT);
void Start();
const char * GetName() const { return m_Name.c_str(); }
std::vector<DatagramSessionInfo> GetSessions();
std::vector<std::shared_ptr<DatagramSessionInfo> > GetSessions();
private:
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);
@ -218,7 +219,7 @@ namespace client @@ -218,7 +219,7 @@ namespace client
~I2PUDPClientTunnel();
void Start();
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(); }
private:
void HandleRecvFromI2P(const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);

Loading…
Cancel
Save