Skip to content

Commit

Permalink
drop messages to other router coming down an inbound tunnel
Browse files Browse the repository at this point in the history
  • Loading branch information
orignal committed Jul 10, 2014
1 parent b02c777 commit 4de9ed8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
3 changes: 2 additions & 1 deletion TransitTunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ namespace tunnel
TransitTunnelEndpoint (uint32_t receiveTunnelID,
const uint8_t * nextIdent, uint32_t nextTunnelID,
const uint8_t * layerKey,const uint8_t * ivKey):
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID, layerKey, ivKey) {};
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID, layerKey, ivKey),
m_Endpoint (false) {}; // transit endpoint is always outbound

void HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg);
size_t GetNumTransmittedBytes () const { return m_Endpoint.GetNumReceivedBytes (); }
Expand Down
2 changes: 1 addition & 1 deletion Tunnel.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace tunnel
{
public:

InboundTunnel (TunnelConfig * config): Tunnel (config) {};
InboundTunnel (TunnelConfig * config): Tunnel (config), m_Endpoint (true) {};
void HandleTunnelDataMsg (I2NPMessage * msg);
size_t GetNumReceivedBytes () const { return m_Endpoint.GetNumReceivedBytes (); };

Expand Down
25 changes: 24 additions & 1 deletion TunnelEndpoint.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#include "I2PEndian.h"
#include <string.h>
#include "Log.h"
#include "NetDb.h"
#include "I2NPProtocol.h"
#include "Transports.h"
#include "RouterContext.h"
#include "TunnelEndpoint.h"

namespace i2p
Expand Down Expand Up @@ -194,7 +196,28 @@ namespace tunnel
i2p::transports.SendMessage (msg.hash, i2p::CreateTunnelGatewayMsg (msg.tunnelID, msg.data));
break;
case eDeliveryTypeRouter:
i2p::transports.SendMessage (msg.hash, msg.data);
if (msg.hash == i2p::context.GetRouterInfo ().GetIdentHash ()) // check if message is sent to us
i2p::HandleI2NPMessage (msg.data);
else
{
// to somebody else
if (!m_IsInbound) // outbound transit tunnel
{
if (msg.data->GetHeader()->typeID == eI2NPDatabaseStore)
{
// catch RI
auto ds = NewI2NPMessage ();
*ds = *(msg.data);
i2p::data::netdb.PostI2NPMsg (ds);
}
i2p::transports.SendMessage (msg.hash, msg.data);
}
else // we shouldn't send this message. possible leakage
{
LogPrint ("Message to another router arrived from an inbound tunnel. Dropped");
i2p::DeleteI2NPMessage (msg.data);
}
}
break;
default:
LogPrint ("TunnelMessage: Unknown delivery type ", (int)msg.deliveryType);
Expand Down
3 changes: 2 additions & 1 deletion TunnelEndpoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace tunnel

public:

TunnelEndpoint (): m_NumReceivedBytes (0) {};
TunnelEndpoint (bool isInbound): m_IsInbound (isInbound), m_NumReceivedBytes (0) {};
~TunnelEndpoint ();
size_t GetNumReceivedBytes () const { return m_NumReceivedBytes; };

Expand All @@ -34,6 +34,7 @@ namespace tunnel
private:

std::map<uint32_t, TunnelMessageBlockEx> m_IncompleteMessages;
bool m_IsInbound;
size_t m_NumReceivedBytes;
};
}
Expand Down

0 comments on commit 4de9ed8

Please sign in to comment.