Browse Source

pass delivery intructions to tunnel gateway

pull/46/head
orignal 11 years ago
parent
commit
154105a059
  1. 2
      I2NPProtocol.cpp
  2. 2
      NTCPSession.h
  3. 6
      TransitTunnel.cpp
  4. 4
      TransitTunnel.h
  5. 17
      Tunnel.cpp
  6. 2
      Tunnel.h
  7. 50
      TunnelGateway.cpp
  8. 6
      TunnelGateway.h

2
I2NPProtocol.cpp

@ -392,7 +392,7 @@ namespace i2p
LogPrint ("TunnelGateway of ", (int)len, " bytes for tunnel ", (unsigned int)tunnelID, ". Msg type ", (int)msg->GetHeader()->typeID); LogPrint ("TunnelGateway of ", (int)len, " bytes for tunnel ", (unsigned int)tunnelID, ". Msg type ", (int)msg->GetHeader()->typeID);
i2p::tunnel::TransitTunnel * tunnel = i2p::tunnel::tunnels.GetTransitTunnel (tunnelID); i2p::tunnel::TransitTunnel * tunnel = i2p::tunnel::tunnels.GetTransitTunnel (tunnelID);
if (tunnel) if (tunnel)
tunnel->SendTunnelDataMsg (nullptr, 0, msg); tunnel->SendTunnelDataMsg (msg);
else else
{ {
LogPrint ("Tunnel ", (unsigned int)tunnelID, " not found"); LogPrint ("Tunnel ", (unsigned int)tunnelID, " not found");

2
NTCPSession.h

@ -60,7 +60,7 @@ namespace ntcp
#pragma pack() #pragma pack()
const int TERMINATION_TIMEOUT = 60; // 1 minute const int TERMINATION_TIMEOUT = 150; // 2.5 minutes
class NTCPSession class NTCPSession
{ {
public: public:

6
TransitTunnel.cpp

@ -47,15 +47,15 @@ namespace tunnel
m_NumTransmittedBytes += tunnelMsg->GetLength (); m_NumTransmittedBytes += tunnelMsg->GetLength ();
} }
void TransitTunnel::SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg) void TransitTunnel::SendTunnelDataMsg (i2p::I2NPMessage * msg)
{ {
LogPrint ("We are not a gateway for transit tunnel ", m_TunnelID); LogPrint ("We are not a gateway for transit tunnel ", m_TunnelID);
i2p::DeleteI2NPMessage (msg); i2p::DeleteI2NPMessage (msg);
} }
void TransitTunnelGateway::SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg) void TransitTunnelGateway::SendTunnelDataMsg (i2p::I2NPMessage * msg)
{ {
m_Gateway.SendTunnelDataMsg (gwHash, gwTunnel, msg); m_Gateway.SendTunnelDataMsg (msg);
} }
void TransitTunnelEndpoint::HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg) void TransitTunnelEndpoint::HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg)

4
TransitTunnel.h

@ -22,7 +22,7 @@ namespace tunnel
const uint8_t * layerKey,const uint8_t * ivKey); const uint8_t * layerKey,const uint8_t * ivKey);
virtual void HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg); virtual void HandleTunnelDataMsg (i2p::I2NPMessage * tunnelMsg);
virtual void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg); virtual void SendTunnelDataMsg (i2p::I2NPMessage * msg);
virtual size_t GetNumTransmittedBytes () const { return m_NumTransmittedBytes; }; virtual size_t GetNumTransmittedBytes () const { return m_NumTransmittedBytes; };
uint32_t GetTunnelID () const { return m_TunnelID; }; uint32_t GetTunnelID () const { return m_TunnelID; };
@ -54,7 +54,7 @@ namespace tunnel
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID, TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID,
layerKey, ivKey), m_Gateway(this) {}; layerKey, ivKey), m_Gateway(this) {};
void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg); void SendTunnelDataMsg (i2p::I2NPMessage * msg);
size_t GetNumTransmittedBytes () const { return m_Gateway.GetNumSentBytes (); }; size_t GetNumTransmittedBytes () const { return m_Gateway.GetNumSentBytes (); };
private: private:

17
Tunnel.cpp

@ -142,22 +142,7 @@ namespace tunnel
void OutboundTunnel::SendTunnelDataMsg (std::vector<TunnelMessageBlock> msgs) void OutboundTunnel::SendTunnelDataMsg (std::vector<TunnelMessageBlock> msgs)
{ {
for (auto& it : msgs) for (auto& it : msgs)
{ m_Gateway.PutTunnelDataMsg (it);
switch (it.deliveryType)
{
case eDeliveryTypeLocal:
m_Gateway.SendTunnelDataMsg (nullptr, 0, it.data);
break;
case eDeliveryTypeTunnel:
m_Gateway.SendTunnelDataMsg (it.hash, it.tunnelID, it.data);
break;
case eDeliveryTypeRouter:
m_Gateway.SendTunnelDataMsg (it.hash, 0, it.data);
break;
default:
LogPrint ("Unexpected delivery type ", (int)it.deliveryType);
}
}
m_Gateway.SendBuffer (); m_Gateway.SendBuffer ();
} }

2
Tunnel.h

@ -21,7 +21,7 @@ namespace i2p
{ {
namespace tunnel namespace tunnel
{ {
const int TUNNEL_EXPIRATION_TIMEOUT = 600; // 10 minutes const int TUNNEL_EXPIRATION_TIMEOUT = 660; // 11 minutes
class OutboundTunnel; class OutboundTunnel;
class InboundTunnel; class InboundTunnel;

50
TunnelGateway.cpp

@ -10,7 +10,7 @@ namespace i2p
{ {
namespace tunnel namespace tunnel
{ {
void TunnelGatewayBuffer::PutI2NPMsg (const uint8_t * gwHash, uint32_t gwTunnel, I2NPMessage * msg) void TunnelGatewayBuffer::PutI2NPMsg (const TunnelMessageBlock& block)
{ {
if (!m_CurrentTunnelDataMsg) if (!m_CurrentTunnelDataMsg)
CreateCurrentTunnelDataMessage (); CreateCurrentTunnelDataMessage ();
@ -18,24 +18,21 @@ namespace tunnel
// create delivery instructions // create delivery instructions
uint8_t di[43]; // max delivery instruction length is 43 for tunnel uint8_t di[43]; // max delivery instruction length is 43 for tunnel
size_t diLen = 1;// flag size_t diLen = 1;// flag
TunnelDeliveryType dt = eDeliveryTypeLocal; if (block.deliveryType != eDeliveryTypeLocal) // tunnel or router
if (gwHash)
{ {
if (gwTunnel) if (block.deliveryType == eDeliveryTypeTunnel)
{ {
*(uint32_t *)(di + diLen) = htobe32 (gwTunnel); *(uint32_t *)(di + diLen) = htobe32 (block.tunnelID);
diLen += 4; // tunnelID diLen += 4; // tunnelID
dt = eDeliveryTypeTunnel;
} }
else
dt = eDeliveryTypeRouter;
memcpy (di + diLen, gwHash, 32); memcpy (di + diLen, block.hash, 32);
diLen += 32; //len diLen += 32; //len
} }
di[0] = dt << 5; // set delivery type di[0] = block.deliveryType << 5; // set delivery type
// create fragments // create fragments
I2NPMessage * msg = block.data;
if (diLen + msg->GetLength () + 2<= m_RemainingSize) if (diLen + msg->GetLength () + 2<= m_RemainingSize)
{ {
// message fits. First and last fragment // message fits. First and last fragment
@ -104,7 +101,7 @@ namespace tunnel
{ {
// delivery instructions don't fit. Create new message // delivery instructions don't fit. Create new message
CompleteCurrentTunnelDataMessage (); CompleteCurrentTunnelDataMessage ();
PutI2NPMsg (gwHash, gwTunnel, msg); PutI2NPMsg (block);
// don't delete msg because it's taken care inside // don't delete msg because it's taken care inside
} }
} }
@ -152,15 +149,40 @@ namespace tunnel
m_CurrentTunnelDataMsg = nullptr; m_CurrentTunnelDataMsg = nullptr;
} }
void TunnelGateway::SendTunnelDataMsg (i2p::I2NPMessage * msg)
{
SendTunnelDataMsg (nullptr, 0, msg);
}
void TunnelGateway::SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg) void TunnelGateway::SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg)
{ {
PutTunnelDataMsg (gwHash, gwTunnel, msg); TunnelMessageBlock block;
if (gwHash)
{
block.hash = gwHash;
if (gwTunnel)
{
block.deliveryType = eDeliveryTypeTunnel;
block.tunnelID = gwTunnel;
}
else
block.deliveryType = eDeliveryTypeRouter;
}
else
block.deliveryType = eDeliveryTypeLocal;
block.data = msg;
SendTunnelDataMsg (block);
}
void TunnelGateway::SendTunnelDataMsg (const TunnelMessageBlock& block)
{
PutTunnelDataMsg (block);
SendBuffer (); SendBuffer ();
} }
void TunnelGateway::PutTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg) void TunnelGateway::PutTunnelDataMsg (const TunnelMessageBlock& block)
{ {
m_Buffer.PutI2NPMsg (gwHash, gwTunnel, msg); m_Buffer.PutI2NPMsg (block);
} }
void TunnelGateway::SendBuffer () void TunnelGateway::SendBuffer ()

6
TunnelGateway.h

@ -15,7 +15,7 @@ namespace tunnel
public: public:
TunnelGatewayBuffer (uint32_t tunnelID): m_TunnelID (tunnelID), TunnelGatewayBuffer (uint32_t tunnelID): m_TunnelID (tunnelID),
m_CurrentTunnelDataMsg (nullptr), m_RemainingSize (0) {}; m_CurrentTunnelDataMsg (nullptr), m_RemainingSize (0) {};
void PutI2NPMsg (const uint8_t * gwHash, uint32_t gwTunnel, I2NPMessage * msg); void PutI2NPMsg (const TunnelMessageBlock& block);
std::vector<I2NPMessage *> GetTunnelDataMsgs (); std::vector<I2NPMessage *> GetTunnelDataMsgs ();
private: private:
@ -37,8 +37,10 @@ namespace tunnel
TunnelGateway (TunnelBase * tunnel): TunnelGateway (TunnelBase * tunnel):
m_Tunnel (tunnel), m_Buffer (tunnel->GetNextTunnelID ()), m_NumSentBytes (0) {}; m_Tunnel (tunnel), m_Buffer (tunnel->GetNextTunnelID ()), m_NumSentBytes (0) {};
void SendTunnelDataMsg (i2p::I2NPMessage * msg);
void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg); void SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg);
void PutTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg); void SendTunnelDataMsg (const TunnelMessageBlock& block);
void PutTunnelDataMsg (const TunnelMessageBlock& block);
void SendBuffer (); void SendBuffer ();
size_t GetNumSentBytes () const { return m_NumSentBytes; }; size_t GetNumSentBytes () const { return m_NumSentBytes; };

Loading…
Cancel
Save