Browse Source

fixed crash upon I2CP session disconnect

pull/511/head
orignal 9 years ago
parent
commit
21b5f2c96a
  1. 15
      I2CP.cpp
  2. 4
      I2CP.h

15
I2CP.cpp

@ -23,7 +23,7 @@ namespace i2p
namespace client namespace client
{ {
I2CPDestination::I2CPDestination (I2CPSession& owner, std::shared_ptr<const i2p::data::IdentityEx> identity, bool isPublic, const std::map<std::string, std::string>& params): I2CPDestination::I2CPDestination (std::shared_ptr<I2CPSession> owner, std::shared_ptr<const i2p::data::IdentityEx> identity, bool isPublic, const std::map<std::string, std::string>& params):
LeaseSetDestination (isPublic, &params), m_Owner (owner), m_Identity (identity) LeaseSetDestination (isPublic, &params), m_Owner (owner), m_Identity (identity)
{ {
} }
@ -37,7 +37,7 @@ namespace client
{ {
uint32_t length = bufbe32toh (buf); uint32_t length = bufbe32toh (buf);
if (length > len - 4) length = len - 4; if (length > len - 4) length = len - 4;
m_Owner.SendMessagePayloadMessage (buf + 4, length); m_Owner->SendMessagePayloadMessage (buf + 4, length);
} }
void I2CPDestination::CreateNewLeaseSet (std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels) void I2CPDestination::CreateNewLeaseSet (std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels)
@ -46,9 +46,9 @@ namespace client
m_LeaseSetExpirationTime = ls.GetExpirationTime (); m_LeaseSetExpirationTime = ls.GetExpirationTime ();
uint8_t * leases = ls.GetLeases (); uint8_t * leases = ls.GetLeases ();
leases[-1] = tunnels.size (); leases[-1] = tunnels.size ();
htobe16buf (leases - 3, m_Owner.GetSessionID ()); htobe16buf (leases - 3, m_Owner->GetSessionID ());
size_t l = 2/*sessionID*/ + 1/*num leases*/ + i2p::data::LEASE_SIZE*tunnels.size (); size_t l = 2/*sessionID*/ + 1/*num leases*/ + i2p::data::LEASE_SIZE*tunnels.size ();
m_Owner.SendI2CPMessage (I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE, leases - 3, l); m_Owner->SendI2CPMessage (I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE, leases - 3, l);
} }
void I2CPDestination::LeaseSetCreated (const uint8_t * buf, size_t len) void I2CPDestination::LeaseSetCreated (const uint8_t * buf, size_t len)
@ -78,10 +78,10 @@ namespace client
if (ls) if (ls)
{ {
bool sent = s->SendMsg (msg, ls); bool sent = s->SendMsg (msg, ls);
s->m_Owner.SendMessageStatusMessage (nonce, sent ? eI2CPMessageStatusGuaranteedSuccess : eI2CPMessageStatusGuaranteedFailure); s->m_Owner->SendMessageStatusMessage (nonce, sent ? eI2CPMessageStatusGuaranteedSuccess : eI2CPMessageStatusGuaranteedFailure);
} }
else else
s->m_Owner.SendMessageStatusMessage (nonce, eI2CPMessageStatusNoLeaseSet); s->m_Owner->SendMessageStatusMessage (nonce, eI2CPMessageStatusNoLeaseSet);
}); });
} }
} }
@ -134,6 +134,7 @@ namespace client
void I2CPSession::Stop () void I2CPSession::Stop ()
{ {
Terminate ();
} }
void I2CPSession::ReadProtocolByte () void I2CPSession::ReadProtocolByte ()
@ -327,7 +328,7 @@ namespace client
{ {
bool isPublic = true; bool isPublic = true;
if (params[I2CP_PARAM_DONT_PUBLISH_LEASESET] == "true") isPublic = false; if (params[I2CP_PARAM_DONT_PUBLISH_LEASESET] == "true") isPublic = false;
m_Destination = std::make_shared<I2CPDestination>(*this, identity, isPublic, params); m_Destination = std::make_shared<I2CPDestination>(shared_from_this (), identity, isPublic, params);
m_Destination->Start (); m_Destination->Start ();
SendSessionStatusMessage (1); // created SendSessionStatusMessage (1); // created
LogPrint (eLogDebug, "I2CP: session ", m_SessionID, " created"); LogPrint (eLogDebug, "I2CP: session ", m_SessionID, " created");

4
I2CP.h

@ -63,7 +63,7 @@ namespace client
{ {
public: public:
I2CPDestination (I2CPSession& owner, std::shared_ptr<const i2p::data::IdentityEx> identity, bool isPublic, const std::map<std::string, std::string>& params); I2CPDestination (std::shared_ptr<I2CPSession> owner, std::shared_ptr<const i2p::data::IdentityEx> identity, bool isPublic, const std::map<std::string, std::string>& params);
void SetEncryptionPrivateKey (const uint8_t * key); void SetEncryptionPrivateKey (const uint8_t * key);
void LeaseSetCreated (const uint8_t * buf, size_t len); // called from I2CPSession void LeaseSetCreated (const uint8_t * buf, size_t len); // called from I2CPSession
@ -87,7 +87,7 @@ namespace client
private: private:
I2CPSession& m_Owner; std::shared_ptr<I2CPSession> m_Owner;
std::shared_ptr<const i2p::data::IdentityEx> m_Identity; std::shared_ptr<const i2p::data::IdentityEx> m_Identity;
uint8_t m_EncryptionPrivateKey[256]; uint8_t m_EncryptionPrivateKey[256];
uint64_t m_LeaseSetExpirationTime; uint64_t m_LeaseSetExpirationTime;

Loading…
Cancel
Save