Browse Source

use shared_ptr for inbound tunnels

pull/157/head
orignal 10 years ago
parent
commit
b9e3931e80
  1. 2
      Destination.cpp
  2. 2
      Destination.h
  3. 4
      Garlic.cpp
  4. 6
      Garlic.h
  5. 2
      I2NPProtocol.cpp
  6. 7
      I2NPProtocol.h
  7. 2
      NetDb.cpp
  8. 2
      NetDb.h
  9. 2
      RouterContext.cpp
  10. 2
      RouterContext.h
  11. 2
      Tunnel.cpp
  12. 2
      Tunnel.h

2
Destination.cpp

@ -192,7 +192,7 @@ namespace client @@ -192,7 +192,7 @@ namespace client
m_Service.post (std::bind (&ClientDestination::HandleDeliveryStatusMessage, this, msg));
}
void ClientDestination::HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from)
void ClientDestination::HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from)
{
uint8_t typeID = buf[I2NP_HEADER_TYPEID_OFFSET];
switch (typeID)

2
Destination.h

@ -86,7 +86,7 @@ namespace client @@ -86,7 +86,7 @@ namespace client
// implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet ();
void HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from);
void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);
// override GarlicDestination
bool SubmitSessionKey (const uint8_t * key, const uint8_t * tag);

4
Garlic.cpp

@ -400,7 +400,7 @@ namespace garlic @@ -400,7 +400,7 @@ namespace garlic
}
void GarlicDestination::HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr<i2p::crypto::CBCDecryption> decryption,
i2p::tunnel::InboundTunnel * from)
std::shared_ptr<i2p::tunnel::InboundTunnel> from)
{
uint16_t tagCount = bufbe16toh (buf);
buf += 2; len -= 2;
@ -439,7 +439,7 @@ namespace garlic @@ -439,7 +439,7 @@ namespace garlic
HandleGarlicPayload (buf, payloadSize, from);
}
void GarlicDestination::HandleGarlicPayload (uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from)
void GarlicDestination::HandleGarlicPayload (uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from)
{
int numCloves = buf[0];
LogPrint (numCloves," cloves");

6
Garlic.h

@ -121,7 +121,7 @@ namespace garlic @@ -121,7 +121,7 @@ namespace garlic
virtual void SetLeaseSetUpdated ();
virtual const i2p::data::LeaseSet * GetLeaseSet () = 0; // TODO
virtual void HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from) = 0;
virtual void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from) = 0;
protected:
@ -131,8 +131,8 @@ namespace garlic @@ -131,8 +131,8 @@ namespace garlic
private:
void HandleAESBlock (uint8_t * buf, size_t len, std::shared_ptr<i2p::crypto::CBCDecryption> decryption,
i2p::tunnel::InboundTunnel * from);
void HandleGarlicPayload (uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from);
std::shared_ptr<i2p::tunnel::InboundTunnel> from);
void HandleGarlicPayload (uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);
private:

2
I2NPProtocol.cpp

@ -71,7 +71,7 @@ namespace i2p @@ -71,7 +71,7 @@ namespace i2p
return msg;
}
I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from)
I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len, std::shared_ptr<i2p::tunnel::InboundTunnel> from)
{
I2NPMessage * msg = NewI2NPMessage ();
memcpy (msg->GetBuffer (), buf, len);

7
I2NPProtocol.h

@ -2,9 +2,10 @@ @@ -2,9 +2,10 @@
#define I2NP_PROTOCOL_H__
#include <inttypes.h>
#include <string.h>
#include <set>
#include <memory>
#include <cryptopp/sha.h>
#include <string.h>
#include "I2PEndian.h"
#include "Identity.h"
#include "RouterInfo.h"
@ -108,7 +109,7 @@ namespace tunnel @@ -108,7 +109,7 @@ namespace tunnel
{
uint8_t * buf;
size_t len, offset, maxLen;
i2p::tunnel::InboundTunnel * from;
std::shared_ptr<i2p::tunnel::InboundTunnel> from;
I2NPMessage (): buf (nullptr),len (I2NP_HEADER_SIZE + 2),
offset(2), maxLen (0), from (nullptr) {}; // reserve 2 bytes for NTCP header
@ -195,7 +196,7 @@ namespace tunnel @@ -195,7 +196,7 @@ namespace tunnel
void FillI2NPMessageHeader (I2NPMessage * msg, I2NPMessageType msgType, uint32_t replyMsgID = 0);
void RenewI2NPMessageHeader (I2NPMessage * msg);
I2NPMessage * CreateI2NPMessage (I2NPMessageType msgType, const uint8_t * buf, int len, uint32_t replyMsgID = 0);
I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from = nullptr);
I2NPMessage * CreateI2NPMessage (const uint8_t * buf, int len, std::shared_ptr<i2p::tunnel::InboundTunnel> from = nullptr);
I2NPMessage * CreateDeliveryStatusMsg (uint32_t msgID);
I2NPMessage * CreateRouterInfoDatabaseLookupMsg (const uint8_t * key, const uint8_t * from,

2
NetDb.cpp

@ -239,7 +239,7 @@ namespace data @@ -239,7 +239,7 @@ namespace data
}
void NetDb::AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len,
i2p::tunnel::InboundTunnel * from)
std::shared_ptr<i2p::tunnel::InboundTunnel> from)
{
if (!from) // unsolicited LS must be received directly
{

2
NetDb.h

@ -67,7 +67,7 @@ namespace data @@ -67,7 +67,7 @@ namespace data
void AddRouterInfo (const uint8_t * buf, int len);
void AddRouterInfo (const IdentHash& ident, const uint8_t * buf, int len);
void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, i2p::tunnel::InboundTunnel * from);
void AddLeaseSet (const IdentHash& ident, const uint8_t * buf, int len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);
std::shared_ptr<RouterInfo> FindRouter (const IdentHash& ident) const;
std::shared_ptr<LeaseSet> FindLeaseSet (const IdentHash& destination) const;

2
RouterContext.cpp

@ -215,7 +215,7 @@ namespace i2p @@ -215,7 +215,7 @@ namespace i2p
fk.write ((char *)&keys, sizeof (keys));
}
void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from)
void RouterContext::HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from)
{
i2p::HandleI2NPMessage (CreateI2NPMessage (buf, GetI2NPMessageLength (buf), from));
}

2
RouterContext.h

@ -54,7 +54,7 @@ namespace i2p @@ -54,7 +54,7 @@ namespace i2p
// implements GarlicDestination
const i2p::data::LeaseSet * GetLeaseSet () { return nullptr; };
void HandleI2NPMessage (const uint8_t * buf, size_t len, i2p::tunnel::InboundTunnel * from);
void HandleI2NPMessage (const uint8_t * buf, size_t len, std::shared_ptr<i2p::tunnel::InboundTunnel> from);
private:

2
Tunnel.cpp

@ -160,7 +160,7 @@ namespace tunnel @@ -160,7 +160,7 @@ namespace tunnel
void InboundTunnel::HandleTunnelDataMsg (I2NPMessage * msg)
{
if (IsFailed ()) SetState (eTunnelStateEstablished); // incoming messages means a tunnel is alive
msg->from = this;
msg->from = shared_from_this ();
EncryptTunnelMsg (msg);
m_Endpoint.HandleDecryptedTunnelDataMsg (msg);
}

2
Tunnel.h

@ -95,7 +95,7 @@ namespace tunnel @@ -95,7 +95,7 @@ namespace tunnel
TunnelGateway m_Gateway;
};
class InboundTunnel: public Tunnel
class InboundTunnel: public Tunnel, public std::enable_shared_from_this<InboundTunnel>
{
public:

Loading…
Cancel
Save