Browse Source

pass const I2NP message to HandleTunnelDataMsg

pull/225/head
orignal 10 years ago
parent
commit
be1a4548e6
  1. 7
      I2NPProtocol.cpp
  2. 1
      I2NPProtocol.h
  3. 20
      TransitTunnel.cpp
  4. 6
      TransitTunnel.h
  5. 11
      Tunnel.cpp
  6. 4
      Tunnel.h
  7. 2
      TunnelBase.h

7
I2NPProtocol.cpp

@ -433,6 +433,13 @@ namespace i2p @@ -433,6 +433,13 @@ namespace i2p
return msg;
}
std::shared_ptr<I2NPMessage> CreateEmptyTunnelDataMsg ()
{
I2NPMessage * msg = NewI2NPShortMessage ();
msg->len += i2p::tunnel::TUNNEL_DATA_MSG_SIZE;
return ToSharedI2NPMessage (msg);
}
I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, const uint8_t * buf, size_t len)
{
I2NPMessage * msg = NewI2NPMessage (len);

1
I2NPProtocol.h

@ -222,6 +222,7 @@ namespace tunnel @@ -222,6 +222,7 @@ namespace tunnel
I2NPMessage * CreateTunnelDataMsg (const uint8_t * buf);
I2NPMessage * CreateTunnelDataMsg (uint32_t tunnelID, const uint8_t * payload);
std::shared_ptr<I2NPMessage> CreateEmptyTunnelDataMsg ();
I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, const uint8_t * buf, size_t len);
I2NPMessage * CreateTunnelGatewayMsg (uint32_t tunnelID, I2NPMessageType msgType,

20
TransitTunnel.cpp

@ -29,14 +29,15 @@ namespace tunnel @@ -29,14 +29,15 @@ namespace tunnel
{
}
void TransitTunnelParticipant::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> tunnelMsg)
void TransitTunnelParticipant::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
{
EncryptTunnelMsg (tunnelMsg, tunnelMsg);
auto newMsg = CreateEmptyTunnelDataMsg ();
EncryptTunnelMsg (tunnelMsg, newMsg);
m_NumTransmittedBytes += tunnelMsg->GetLength ();
htobe32buf (tunnelMsg->GetPayload (), GetNextTunnelID ());
FillI2NPMessageHeader (tunnelMsg.get (), eI2NPTunnelData); // TODO
m_TunnelDataMsgs.push_back (tunnelMsg);
htobe32buf (newMsg->GetPayload (), GetNextTunnelID ());
FillI2NPMessageHeader (newMsg.get (), eI2NPTunnelData); // TODO
m_TunnelDataMsgs.push_back (newMsg);
}
void TransitTunnelParticipant::FlushTunnelDataMsgs ()
@ -56,7 +57,7 @@ namespace tunnel @@ -56,7 +57,7 @@ namespace tunnel
LogPrint (eLogError, "We are not a gateway for transit tunnel ", m_TunnelID);
}
void TransitTunnel::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> tunnelMsg)
void TransitTunnel::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
{
LogPrint (eLogError, "Incoming tunnel message is not supported ", m_TunnelID);
}
@ -76,12 +77,13 @@ namespace tunnel @@ -76,12 +77,13 @@ namespace tunnel
m_Gateway.SendBuffer ();
}
void TransitTunnelEndpoint::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> tunnelMsg)
void TransitTunnelEndpoint::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
{
EncryptTunnelMsg (tunnelMsg, tunnelMsg);
auto newMsg = CreateEmptyTunnelDataMsg ();
EncryptTunnelMsg (tunnelMsg, newMsg);
LogPrint (eLogDebug, "TransitTunnel endpoint for ", GetTunnelID ());
m_Endpoint.HandleDecryptedTunnelDataMsg (tunnelMsg);
m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg);
}
TransitTunnel * CreateTransitTunnel (uint32_t receiveTunnelID,

6
TransitTunnel.h

@ -29,7 +29,7 @@ namespace tunnel @@ -29,7 +29,7 @@ namespace tunnel
// implements TunnelBase
void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg);
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> tunnelMsg);
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out);
uint32_t GetNextTunnelID () const { return m_NextTunnelID; };
const i2p::data::IdentHash& GetNextIdentHash () const { return m_NextIdent; };
@ -54,7 +54,7 @@ namespace tunnel @@ -54,7 +54,7 @@ namespace tunnel
~TransitTunnelParticipant ();
size_t GetNumTransmittedBytes () const { return m_NumTransmittedBytes; };
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> tunnelMsg);
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
void FlushTunnelDataMsgs ();
private:
@ -93,7 +93,7 @@ namespace tunnel @@ -93,7 +93,7 @@ namespace tunnel
TransitTunnel (receiveTunnelID, nextIdent, nextTunnelID, layerKey, ivKey),
m_Endpoint (false) {}; // transit endpoint is always outbound
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> tunnelMsg);
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
size_t GetNumTransmittedBytes () const { return m_Endpoint.GetNumReceivedBytes (); }
private:

11
Tunnel.cpp

@ -158,12 +158,13 @@ namespace tunnel @@ -158,12 +158,13 @@ namespace tunnel
LogPrint (eLogInfo, "Can't send I2NP messages without delivery instructions");
}
void InboundTunnel::HandleTunnelDataMsg (std::shared_ptr<I2NPMessage> msg)
void InboundTunnel::HandleTunnelDataMsg (std::shared_ptr<const I2NPMessage> msg)
{
if (IsFailed ()) SetState (eTunnelStateEstablished); // incoming messages means a tunnel is alive
msg->from = shared_from_this ();
EncryptTunnelMsg (msg, msg);
m_Endpoint.HandleDecryptedTunnelDataMsg (msg);
auto newMsg = CreateEmptyTunnelDataMsg ();
EncryptTunnelMsg (msg, newMsg);
newMsg->from = shared_from_this ();
m_Endpoint.HandleDecryptedTunnelDataMsg (newMsg);
}
void OutboundTunnel::SendTunnelDataMsg (const uint8_t * gwHash, uint32_t gwTunnel, std::shared_ptr<i2p::I2NPMessage> msg)
@ -196,7 +197,7 @@ namespace tunnel @@ -196,7 +197,7 @@ namespace tunnel
m_Gateway.SendBuffer ();
}
void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> tunnelMsg)
void OutboundTunnel::HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg)
{
LogPrint (eLogError, "Incoming message for outbound tunnel ", GetTunnelID ());
}

4
Tunnel.h

@ -90,7 +90,7 @@ namespace tunnel @@ -90,7 +90,7 @@ namespace tunnel
size_t GetNumSentBytes () const { return m_Gateway.GetNumSentBytes (); };
// implements TunnelBase
void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> tunnelMsg);
void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg);
uint32_t GetTunnelID () const { return GetNextTunnelID (); };
private:
@ -104,7 +104,7 @@ namespace tunnel @@ -104,7 +104,7 @@ namespace tunnel
public:
InboundTunnel (std::shared_ptr<const TunnelConfig> config): Tunnel (config), m_Endpoint (true) {};
void HandleTunnelDataMsg (std::shared_ptr<I2NPMessage> msg);
void HandleTunnelDataMsg (std::shared_ptr<const I2NPMessage> msg);
size_t GetNumReceivedBytes () const { return m_Endpoint.GetNumReceivedBytes (); };
// implements TunnelBase

2
TunnelBase.h

@ -37,7 +37,7 @@ namespace tunnel @@ -37,7 +37,7 @@ namespace tunnel
TunnelBase (): m_CreationTime (i2p::util::GetSecondsSinceEpoch ()) {};
virtual ~TunnelBase () {};
virtual void HandleTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> tunnelMsg) = 0;
virtual void HandleTunnelDataMsg (std::shared_ptr<const i2p::I2NPMessage> tunnelMsg) = 0;
virtual void SendTunnelDataMsg (std::shared_ptr<i2p::I2NPMessage> msg) = 0;
virtual void FlushTunnelDataMsgs () {};
virtual void EncryptTunnelMsg (std::shared_ptr<const I2NPMessage> in, std::shared_ptr<I2NPMessage> out) = 0;

Loading…
Cancel
Save