Skip to content

Commit b4bcd99

Browse files
committed
show next peer and connectivity on transit tunnels page
1 parent 833e0a9 commit b4bcd99

13 files changed

+92
-14
lines changed

daemon/HTTPServer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ namespace http {
826826
if (i2p::tunnel::tunnels.CountTransitTunnels())
827827
{
828828
s << "<b>" << tr("Transit Tunnels") << ":</b><br>\r\n";
829-
s << "<table><thead><th>&#8658;</th><th>ID</th><th>&#8658;</th><th>" << tr("Amount") << "</th></thead><tbody class=\"tableitem\">";
829+
s << "<table><thead><th>&#8658;</th><th>ID</th><th>&#8658;</th><th>" << tr("Amount") << "</th><th>" << tr("Next") << "</th></thead><tbody class=\"tableitem\">";
830830
for (const auto& it: i2p::tunnel::tunnels.GetTransitTunnels ())
831831
{
832832
if (std::dynamic_pointer_cast<i2p::tunnel::TransitTunnelGateway>(it))
@@ -836,7 +836,7 @@ namespace http {
836836
else
837837
s << "<tr><td>&#8658;</td><td>" << it->GetTunnelID () << "</td><td>&#8658;</td><td>";
838838
ShowTraffic(s, it->GetNumTransmittedBytes ());
839-
s << "</td></tr>\r\n";
839+
s << "</td><td>" << it->GetNextPeerName () << "</td></tr>\r\n";
840840
}
841841
s << "</tbody></table>\r\n";
842842
}

libi2pd/NTCP2.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,6 +1435,12 @@ namespace transport
14351435
boost::asio::post (m_Server.GetService (), std::bind (&NTCP2Session::SendRouterInfo, shared_from_this ()));
14361436
}
14371437

1438+
i2p::data::RouterInfo::SupportedTransports NTCP2Session::GetTransportType () const
1439+
{
1440+
if (m_RemoteEndpoint.address ().is_v4 ()) return i2p::data::RouterInfo::eNTCP2V4;
1441+
return i2p::util::net::IsYggdrasilAddress (m_RemoteEndpoint.address ()) ? i2p::data::RouterInfo::eNTCP2V6Mesh : i2p::data::RouterInfo::eNTCP2V6;
1442+
}
1443+
14381444
NTCP2Server::NTCP2Server ():
14391445
RunnableServiceWithWork ("NTCP2"), m_TerminationTimer (GetService ()),
14401446
m_ProxyType(eNoProxy), m_Resolver(GetService ()),

libi2pd/NTCP2.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ namespace transport
147147
void SetRemoteEndpoint (const boost::asio::ip::tcp::endpoint& ep) { m_RemoteEndpoint = ep; };
148148

149149
bool IsEstablished () const override { return m_IsEstablished; };
150+
i2p::data::RouterInfo::SupportedTransports GetTransportType () const override;
150151
bool IsTerminated () const { return m_IsTerminated; };
151152

152153
void ClientLogin (); // Alice

libi2pd/RouterInfo.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,6 +1195,19 @@ namespace data
11951195
return false;
11961196
}
11971197
}
1198+
1199+
std::string RouterInfo::GetTransportName (SupportedTransports tr)
1200+
{
1201+
switch (tr)
1202+
{
1203+
case eNTCP2V4: return "NTCP2V4";
1204+
case eNTCP2V6: return "NTCP2V6";
1205+
case eSSU2V4: return "SSU2V4";
1206+
case eSSU2V6: return "SSU2V6";
1207+
case eNTCP2V6Mesh: return "Mesh";
1208+
default: return "";
1209+
}
1210+
}
11981211

11991212
void LocalRouterInfo::CreateBuffer (const PrivateKeys& privateKeys)
12001213
{

libi2pd/RouterInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,10 @@ namespace data
363363
int m_Version;
364364
Congestion m_Congestion;
365365
mutable std::shared_ptr<RouterProfile> m_Profile;
366+
367+
public:
368+
369+
static std::string GetTransportName (SupportedTransports tr);
366370
};
367371

368372
class LocalRouterInfo: public RouterInfo

libi2pd/SSU2Session.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,5 +3114,10 @@ namespace transport
31143114
else if (!sent && !m_SentPackets.empty ()) // if only acks received, nothing sent and we still have something to resend
31153115
Resend (i2p::util::GetMillisecondsSinceEpoch ()); // than right time to resend
31163116
}
3117+
3118+
i2p::data::RouterInfo::SupportedTransports SSU2Session::GetTransportType () const
3119+
{
3120+
return m_RemoteEndpoint.address ().is_v4 () ? i2p::data::RouterInfo::eSSU2V4 : i2p::data::RouterInfo::eSSU2V6;
3121+
}
31173122
}
31183123
}

libi2pd/SSU2Session.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ namespace transport
267267
size_t Resend (uint64_t ts); // return number of resent packets
268268
uint64_t GetLastResendTime () const { return m_LastResendTime; };
269269
bool IsEstablished () const override { return m_State == eSSU2SessionStateEstablished; };
270+
i2p::data::RouterInfo::SupportedTransports GetTransportType () const override;
270271
uint64_t GetConnID () const { return m_SourceConnID; };
271272
SSU2SessionState GetState () const { return m_State; };
272273
void SetState (SSU2SessionState state) { m_State = state; };

libi2pd/TransitTunnel.cpp

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "I2PEndian.h"
1111
#include "Crypto.h"
1212
#include "Log.h"
13+
#include "Identity.h"
14+
#include "RouterInfo.h"
1315
#include "RouterContext.h"
1416
#include "I2NPProtocol.h"
1517
#include "Garlic.h"
@@ -41,6 +43,21 @@ namespace tunnel
4143
i2p::transport::transports.UpdateTotalTransitTransmittedBytes (TUNNEL_DATA_MSG_SIZE);
4244
}
4345

46+
std::string TransitTunnel::GetNextPeerName () const
47+
{
48+
return i2p::data::GetIdentHashAbbreviation (GetNextIdentHash ());
49+
}
50+
51+
void TransitTunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg)
52+
{
53+
LogPrint (eLogError, "TransitTunnel: We are not a gateway for ", GetTunnelID ());
54+
}
55+
56+
void TransitTunnel::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg)
57+
{
58+
LogPrint (eLogError, "TransitTunnel: Incoming tunnel message is not supported ", GetTunnelID ());
59+
}
60+
4461
TransitTunnelParticipant::~TransitTunnelParticipant ()
4562
{
4663
}
@@ -67,16 +84,18 @@ namespace tunnel
6784
}
6885
}
6986

70-
void TransitTunnel::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg)
87+
std::string TransitTunnelParticipant::GetNextPeerName () const
7188
{
72-
LogPrint (eLogError, "TransitTunnel: We are not a gateway for ", GetTunnelID ());
73-
}
74-
75-
void TransitTunnel::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg)
76-
{
77-
LogPrint (eLogError, "TransitTunnel: Incoming tunnel message is not supported ", GetTunnelID ());
78-
}
79-
89+
if (m_Sender)
90+
{
91+
auto transport = m_Sender->GetCurrentTransport ();
92+
if (transport)
93+
return TransitTunnel::GetNextPeerName () + "-" +
94+
i2p::data::RouterInfo::GetTransportName (transport->GetTransportType ());
95+
}
96+
return TransitTunnel::GetNextPeerName ();
97+
}
98+
8099
void TransitTunnelGateway::SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg)
81100
{
82101
TunnelMessageBlock block;
@@ -92,6 +111,19 @@ namespace tunnel
92111
m_Gateway.SendBuffer ();
93112
}
94113

114+
std::string TransitTunnelGateway::GetNextPeerName () const
115+
{
116+
const auto& sender = m_Gateway.GetSender ();
117+
if (sender)
118+
{
119+
auto transport = sender->GetCurrentTransport ();
120+
if (transport)
121+
return TransitTunnel::GetNextPeerName () + "-" +
122+
i2p::data::RouterInfo::GetTransportName (transport->GetTransportType ());
123+
}
124+
return TransitTunnel::GetNextPeerName ();
125+
}
126+
95127
void TransitTunnelEndpoint::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg)
96128
{
97129
auto newMsg = CreateEmptyTunnelDataMsg (true);

libi2pd/TransitTunnel.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ namespace tunnel
3333
const i2p::crypto::AESKey& layerKey, const i2p::crypto::AESKey& ivKey);
3434

3535
virtual size_t GetNumTransmittedBytes () const { return 0; };
36+
virtual std::string GetNextPeerName () const;
3637

3738
// implements TunnelBase
3839
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg) override;
3940
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg) override;
4041
void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out) override;
42+
4143
private:
4244

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

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

@@ -79,7 +82,8 @@ namespace tunnel
7982
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg) override;
8083
void FlushTunnelDataMsgs () override;
8184
size_t GetNumTransmittedBytes () const override { return m_Gateway.GetNumSentBytes (); };
82-
85+
std::string GetNextPeerName () const override;
86+
8387
private:
8488

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

99103
void Cleanup () override { m_Endpoint.Cleanup (); }
100-
104+
101105
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage>&& tunnelMsg) override;
102106
size_t GetNumTransmittedBytes () const override { return m_Endpoint.GetNumReceivedBytes (); }
103-
107+
std::string GetNextPeerName () const override { return ""; }
108+
104109
private:
105110

106111
TunnelEndpoint m_Endpoint;

libi2pd/TransportSession.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ namespace transport
151151
};
152152
virtual void SendI2NPMessages (std::list<std::shared_ptr<I2NPMessage> >& msgs) = 0;
153153
virtual bool IsEstablished () const = 0;
154+
virtual i2p::data::RouterInfo::SupportedTransports GetTransportType () const = 0;
154155

155156
private:
156157

0 commit comments

Comments
 (0)