Skip to content

Commit

Permalink
show next peer and connectivity on transit tunnels page
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Dec 17, 2024
1 parent 833e0a9 commit b4bcd99
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 14 deletions.
4 changes: 2 additions & 2 deletions daemon/HTTPServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -826,7 +826,7 @@ namespace http {
if (i2p::tunnel::tunnels.CountTransitTunnels())
{
s << "<b>" << tr("Transit Tunnels") << ":</b><br>\r\n";
s << "<table><thead><th>&#8658;</th><th>ID</th><th>&#8658;</th><th>" << tr("Amount") << "</th></thead><tbody class=\"tableitem\">";
s << "<table><thead><th>&#8658;</th><th>ID</th><th>&#8658;</th><th>" << tr("Amount") << "</th><th>" << tr("Next") << "</th></thead><tbody class=\"tableitem\">";
for (const auto& it: i2p::tunnel::tunnels.GetTransitTunnels ())
{
if (std::dynamic_pointer_cast<i2p::tunnel::TransitTunnelGateway>(it))
Expand All @@ -836,7 +836,7 @@ namespace http {
else
s << "<tr><td>&#8658;</td><td>" << it->GetTunnelID () << "</td><td>&#8658;</td><td>";
ShowTraffic(s, it->GetNumTransmittedBytes ());
s << "</td></tr>\r\n";
s << "</td><td>" << it->GetNextPeerName () << "</td></tr>\r\n";
}
s << "</tbody></table>\r\n";
}
Expand Down
6 changes: 6 additions & 0 deletions libi2pd/NTCP2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,12 @@ namespace transport
boost::asio::post (m_Server.GetService (), std::bind (&NTCP2Session::SendRouterInfo, shared_from_this ()));
}

i2p::data::RouterInfo::SupportedTransports NTCP2Session::GetTransportType () const
{
if (m_RemoteEndpoint.address ().is_v4 ()) return i2p::data::RouterInfo::eNTCP2V4;
return i2p::util::net::IsYggdrasilAddress (m_RemoteEndpoint.address ()) ? i2p::data::RouterInfo::eNTCP2V6Mesh : i2p::data::RouterInfo::eNTCP2V6;
}

NTCP2Server::NTCP2Server ():
RunnableServiceWithWork ("NTCP2"), m_TerminationTimer (GetService ()),
m_ProxyType(eNoProxy), m_Resolver(GetService ()),
Expand Down
1 change: 1 addition & 0 deletions libi2pd/NTCP2.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ namespace transport
void SetRemoteEndpoint (const boost::asio::ip::tcp::endpoint& ep) { m_RemoteEndpoint = ep; };

bool IsEstablished () const override { return m_IsEstablished; };
i2p::data::RouterInfo::SupportedTransports GetTransportType () const override;
bool IsTerminated () const { return m_IsTerminated; };

void ClientLogin (); // Alice
Expand Down
13 changes: 13 additions & 0 deletions libi2pd/RouterInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,19 @@ namespace data
return false;
}
}

std::string RouterInfo::GetTransportName (SupportedTransports tr)
{
switch (tr)
{
case eNTCP2V4: return "NTCP2V4";
case eNTCP2V6: return "NTCP2V6";
case eSSU2V4: return "SSU2V4";
case eSSU2V6: return "SSU2V6";
case eNTCP2V6Mesh: return "Mesh";
default: return "";
}
}

void LocalRouterInfo::CreateBuffer (const PrivateKeys& privateKeys)
{
Expand Down
4 changes: 4 additions & 0 deletions libi2pd/RouterInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ namespace data
int m_Version;
Congestion m_Congestion;
mutable std::shared_ptr<RouterProfile> m_Profile;

public:

static std::string GetTransportName (SupportedTransports tr);
};

class LocalRouterInfo: public RouterInfo
Expand Down
5 changes: 5 additions & 0 deletions libi2pd/SSU2Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3114,5 +3114,10 @@ namespace transport
else if (!sent && !m_SentPackets.empty ()) // if only acks received, nothing sent and we still have something to resend
Resend (i2p::util::GetMillisecondsSinceEpoch ()); // than right time to resend
}

i2p::data::RouterInfo::SupportedTransports SSU2Session::GetTransportType () const
{
return m_RemoteEndpoint.address ().is_v4 () ? i2p::data::RouterInfo::eSSU2V4 : i2p::data::RouterInfo::eSSU2V6;
}
}
}
1 change: 1 addition & 0 deletions libi2pd/SSU2Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ namespace transport
size_t Resend (uint64_t ts); // return number of resent packets
uint64_t GetLastResendTime () const { return m_LastResendTime; };
bool IsEstablished () const override { return m_State == eSSU2SessionStateEstablished; };
i2p::data::RouterInfo::SupportedTransports GetTransportType () const override;
uint64_t GetConnID () const { return m_SourceConnID; };
SSU2SessionState GetState () const { return m_State; };
void SetState (SSU2SessionState state) { m_State = state; };
Expand Down
50 changes: 41 additions & 9 deletions libi2pd/TransitTunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "I2PEndian.h"
#include "Crypto.h"
#include "Log.h"
#include "Identity.h"
#include "RouterInfo.h"
#include "RouterContext.h"
#include "I2NPProtocol.h"
#include "Garlic.h"
Expand Down Expand Up @@ -41,6 +43,21 @@ namespace tunnel
i2p::transport::transports.UpdateTotalTransitTransmittedBytes (TUNNEL_DATA_MSG_SIZE);
}

std::string TransitTunnel::GetNextPeerName () const
{
return i2p::data::GetIdentHashAbbreviation (GetNextIdentHash ());
}

void TransitTunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg)
{
LogPrint (eLogError, "TransitTunnel: We are not a gateway for ", GetTunnelID ());
}

void TransitTunnel::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg)
{
LogPrint (eLogError, "TransitTunnel: Incoming tunnel message is not supported ", GetTunnelID ());
}

TransitTunnelParticipant::~TransitTunnelParticipant ()
{
}
Expand All @@ -67,16 +84,18 @@ namespace tunnel
}
}

void TransitTunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg)
std::string TransitTunnelParticipant::GetNextPeerName () const
{
LogPrint (eLogError, "TransitTunnel: We are not a gateway for ", GetTunnelID ());
}

void TransitTunnel::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg)
{
LogPrint (eLogError, "TransitTunnel: Incoming tunnel message is not supported ", GetTunnelID ());
}

if (m_Sender)
{
auto transport = m_Sender->GetCurrentTransport ();
if (transport)
return TransitTunnel::GetNextPeerName () + "-" +
i2p::data::RouterInfo::GetTransportName (transport->GetTransportType ());
}
return TransitTunnel::GetNextPeerName ();
}

void TransitTunnelGateway::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg)
{
TunnelMessageBlock block;
Expand All @@ -92,6 +111,19 @@ namespace tunnel
m_Gateway.SendBuffer ();
}

std::string TransitTunnelGateway::GetNextPeerName () const
{
const auto& sender = m_Gateway.GetSender ();
if (sender)
{
auto transport = sender->GetCurrentTransport ();
if (transport)
return TransitTunnel::GetNextPeerName () + "-" +
i2p::data::RouterInfo::GetTransportName (transport->GetTransportType ());
}
return TransitTunnel::GetNextPeerName ();
}

void TransitTunnelEndpoint::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg)
{
auto newMsg = CreateEmptyTunnelDataMsg (true);
Expand Down
11 changes: 8 additions & 3 deletions libi2pd/TransitTunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ namespace tunnel
const i2p::crypto::AESKey& layerKey, const i2p::crypto::AESKey& ivKey);

virtual size_t GetNumTransmittedBytes () const { return 0; };
virtual std::string GetNextPeerName () const;

// implements TunnelBase
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg) override;
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg) override;
void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out) override;

private:

i2p::crypto::AESKey m_LayerKey, m_IVKey;
Expand All @@ -56,6 +58,7 @@ namespace tunnel
~TransitTunnelParticipant ();

size_t GetNumTransmittedBytes () const override { return m_NumTransmittedBytes; };
std::string GetNextPeerName () const override;
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg) override;
void FlushTunnelDataMsgs () override;

Expand All @@ -79,7 +82,8 @@ namespace tunnel
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg) override;
void FlushTunnelDataMsgs () override;
size_t GetNumTransmittedBytes () const override { return m_Gateway.GetNumSentBytes (); };

std::string GetNextPeerName () const override;

private:

std::mutex m_SendMutex;
Expand All @@ -97,10 +101,11 @@ namespace tunnel
m_Endpoint (false) {}; // transit endpoint is always outbound

void Cleanup () override { m_Endpoint.Cleanup (); }

void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg) override;
size_t GetNumTransmittedBytes () const override { return m_Endpoint.GetNumReceivedBytes (); }

std::string GetNextPeerName () const override { return ""; }

private:

TunnelEndpoint m_Endpoint;
Expand Down
1 change: 1 addition & 0 deletions libi2pd/TransportSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ namespace transport
};
virtual void SendI2NPMessages (std::list<std::shared_ptr<I2NPMessage> >& msgs) = 0;
virtual bool IsEstablished () const = 0;
virtual i2p::data::RouterInfo::SupportedTransports GetTransportType () const = 0;

private:

Expand Down
6 changes: 6 additions & 0 deletions libi2pd/TunnelBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,11 @@ namespace tunnel
msgs.swap (msgs1);
SendMessagesTo (to, std::move (msgs1));
}

void TunnelTransportSender::Reset ()
{
m_CurrentTransport.reset ();
m_PendingTransport = std::future<std::shared_ptr<i2p::transport::TransportSession> >();
}
}
}
3 changes: 3 additions & 0 deletions libi2pd/TunnelBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ namespace tunnel

void SendMessagesTo (const i2p::data::IdentHash& to, std::list<std::shared_ptr<I2NPMessage> >&& msgs);
void SendMessagesTo (const i2p::data::IdentHash& to, std::list<std::shared_ptr<I2NPMessage> >& msgs); // send and clear

std::shared_ptr<const i2p::transport::TransportSession> GetCurrentTransport () const { return m_CurrentTransport.lock (); }
void Reset ();

private:

Expand Down
1 change: 1 addition & 0 deletions libi2pd/TunnelGateway.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ namespace tunnel
void PutTunnelDataMsg (const TunnelMessageBlock& block);
void SendBuffer ();
size_t GetNumSentBytes () const { return m_NumSentBytes; };
const std::unique_ptr<TunnelTransportSender>& GetSender () const { return m_Sender; };

private:

Expand Down

0 comments on commit b4bcd99

Please sign in to comment.