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. 52
      TunnelGateway.cpp
  8. 6
      TunnelGateway.h

2
I2NPProtocol.cpp

@ -392,7 +392,7 @@ namespace i2p @@ -392,7 +392,7 @@ namespace i2p
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);
if (tunnel)
tunnel->SendTunnelDataMsg (nullptr, 0, msg);
tunnel->SendTunnelDataMsg (msg);
else
{
LogPrint ("Tunnel ", (unsigned int)tunnelID, " not found");

2
NTCPSession.h

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

6
TransitTunnel.cpp

@ -47,15 +47,15 @@ namespace tunnel @@ -47,15 +47,15 @@ namespace tunnel
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);
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)

4
TransitTunnel.h

@ -22,7 +22,7 @@ namespace tunnel @@ -22,7 +22,7 @@ namespace tunnel
const uint8_t * layerKey,const uint8_t * ivKey);
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; };
uint32_t GetTunnelID () const { return m_TunnelID; };
@ -54,7 +54,7 @@ namespace tunnel @@ -54,7 +54,7 @@ namespace tunnel
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID,
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 (); };
private:

17
Tunnel.cpp

@ -142,22 +142,7 @@ namespace tunnel @@ -142,22 +142,7 @@ namespace tunnel
void OutboundTunnel::SendTunnelDataMsg (std::vector<TunnelMessageBlock> msgs)
{
for (auto& it : msgs)
{
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.PutTunnelDataMsg (it);
m_Gateway.SendBuffer ();
}

2
Tunnel.h

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

52
TunnelGateway.cpp

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

6
TunnelGateway.h

@ -15,7 +15,7 @@ namespace tunnel @@ -15,7 +15,7 @@ namespace tunnel
public:
TunnelGatewayBuffer (uint32_t tunnelID): m_TunnelID (tunnelID),
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 ();
private:
@ -37,8 +37,10 @@ namespace tunnel @@ -37,8 +37,10 @@ namespace tunnel
TunnelGateway (TunnelBase * tunnel):
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 PutTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, i2p::I2NPMessage * msg);
void SendTunnelDataMsg (const TunnelMessageBlock& block);
void PutTunnelDataMsg (const TunnelMessageBlock& block);
void SendBuffer ();
size_t GetNumSentBytes () const { return m_NumSentBytes; };

Loading…
Cancel
Save