Browse Source

RequestVariableLeaseSetMessage

pull/509/merge
orignal 9 years ago
parent
commit
09a80ed654
  1. 15
      I2CP.cpp
  2. 9
      I2CP.h
  3. 1
      LeaseSet.cpp
  4. 5
      LeaseSet.h

15
I2CP.cpp

@ -2,6 +2,7 @@
#include "I2PEndian.h" #include "I2PEndian.h"
#include "Log.h" #include "Log.h"
#include "Timestamp.h" #include "Timestamp.h"
#include "LeaseSet.h"
#include "I2CP.h" #include "I2CP.h"
namespace i2p namespace i2p
@ -14,9 +15,21 @@ namespace client
{ {
} }
void I2CPDestination::CreateNewLeaseSet (std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels)
{
i2p::data::LocalLeaseSet ls (m_Identity, m_EncryptionPublicKey, tunnels);
uint8_t * leases = ls.GetLeases ();
leases[-1] = tunnels.size ();
htobe16buf (leases - 3, m_Owner.GetSessionID ());
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);
}
I2CPSession::I2CPSession (I2CPServer& owner, std::shared_ptr<boost::asio::ip::tcp::socket> socket): I2CPSession::I2CPSession (I2CPServer& owner, std::shared_ptr<boost::asio::ip::tcp::socket> socket):
m_Owner (owner), m_Socket (socket), m_Owner (owner), m_Socket (socket),
m_NextMessage (nullptr), m_NextMessageLen (0), m_NextMessageOffset (0) m_NextMessage (nullptr), m_NextMessageLen (0), m_NextMessageOffset (0),
m_SessionID (0)
{ {
ReadProtocolByte (); ReadProtocolByte ();
} }

9
I2CP.h

@ -21,6 +21,7 @@ namespace client
const uint8_t I2CP_GET_DATE_MESSAGE = 32; const uint8_t I2CP_GET_DATE_MESSAGE = 32;
const uint8_t I2CP_SET_DATE_MESSAGE = 33; const uint8_t I2CP_SET_DATE_MESSAGE = 33;
const uint8_t I2CP_CREATE_SESSION_MESSAGE = 1; const uint8_t I2CP_CREATE_SESSION_MESSAGE = 1;
const uint8_t I2CP_REQUEST_VARIABLE_LEASESET_MESSAGE = 37;
class I2CPSession; class I2CPSession;
class I2CPDestination: public LeaseSetDestination class I2CPDestination: public LeaseSetDestination
@ -38,7 +39,7 @@ namespace client
// I2CP // I2CP
void HandleDataMessage (const uint8_t * buf, size_t len) { /* TODO */ }; void HandleDataMessage (const uint8_t * buf, size_t len) { /* TODO */ };
void CreateNewLeaseSet (std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels) { /* TODO */ }; void CreateNewLeaseSet (std::vector<std::shared_ptr<i2p::tunnel::InboundTunnel> > tunnels);
private: private:
@ -55,6 +56,9 @@ namespace client
I2CPSession (I2CPServer& owner, std::shared_ptr<boost::asio::ip::tcp::socket> socket); I2CPSession (I2CPServer& owner, std::shared_ptr<boost::asio::ip::tcp::socket> socket);
~I2CPSession (); ~I2CPSession ();
uint16_t GetSessionID () const { return m_SessionID; };
void SendI2CPMessage (uint8_t type, const uint8_t * payload, size_t len);
// message handlers // message handlers
void GetDateMessageHandler (const uint8_t * buf, size_t len); void GetDateMessageHandler (const uint8_t * buf, size_t len);
void CreateSessionMessageHandler (const uint8_t * buf, size_t len); void CreateSessionMessageHandler (const uint8_t * buf, size_t len);
@ -67,9 +71,7 @@ namespace client
void HandleNextMessage (const uint8_t * buf); void HandleNextMessage (const uint8_t * buf);
void Terminate (); void Terminate ();
void SendI2CPMessage (uint8_t type, const uint8_t * payload, size_t len);
void HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, const uint8_t * buf); void HandleI2CPMessageSent (const boost::system::error_code& ecode, std::size_t bytes_transferred, const uint8_t * buf);
std::string ExtractString (const uint8_t * buf, size_t len); std::string ExtractString (const uint8_t * buf, size_t len);
size_t PutString (uint8_t * buf, size_t len, const std::string& str); size_t PutString (uint8_t * buf, size_t len, const std::string& str);
@ -81,6 +83,7 @@ namespace client
size_t m_NextMessageLen, m_NextMessageOffset; size_t m_NextMessageLen, m_NextMessageOffset;
std::shared_ptr<I2CPDestination> m_Destination; std::shared_ptr<I2CPDestination> m_Destination;
uint16_t m_SessionID;
}; };
typedef void (I2CPSession::*I2CPMessageHandler)(const uint8_t * buf, size_t len); typedef void (I2CPSession::*I2CPMessageHandler)(const uint8_t * buf, size_t len);

1
LeaseSet.cpp

@ -213,6 +213,7 @@ namespace data
m_Buffer[offset] = num; m_Buffer[offset] = num;
offset++; offset++;
// leases // leases
m_Leases = m_Buffer + offset;
auto currentTime = i2p::util::GetMillisecondsSinceEpoch (); auto currentTime = i2p::util::GetMillisecondsSinceEpoch ();
for (int i = 0; i < num; i++) for (int i = 0; i < num; i++)
{ {

5
LeaseSet.h

@ -4,6 +4,7 @@
#include <inttypes.h> #include <inttypes.h>
#include <string.h> #include <string.h>
#include <vector> #include <vector>
#include <set>
#include <memory> #include <memory>
#include "Identity.h" #include "Identity.h"
@ -94,6 +95,8 @@ namespace data
uint8_t * GetSignature () { return m_Buffer + m_BufferLen - GetSignatureLen (); }; uint8_t * GetSignature () { return m_Buffer + m_BufferLen - GetSignatureLen (); };
size_t GetBufferLen () const { return m_BufferLen; }; size_t GetBufferLen () const { return m_BufferLen; };
size_t GetSignatureLen () const { return m_Identity->GetSignatureLen (); }; size_t GetSignatureLen () const { return m_Identity->GetSignatureLen (); };
uint8_t * GetLeases () { return m_Leases; };
const IdentHash& GetIdentHash () const { return m_Identity->GetIdentHash (); }; const IdentHash& GetIdentHash () const { return m_Identity->GetIdentHash (); };
bool IsExpired () const; bool IsExpired () const;
bool operator== (const LeaseSet& other) const bool operator== (const LeaseSet& other) const
@ -104,7 +107,7 @@ namespace data
uint64_t m_ExpirationTime; // in milliseconds uint64_t m_ExpirationTime; // in milliseconds
std::shared_ptr<const IdentityEx> m_Identity; std::shared_ptr<const IdentityEx> m_Identity;
uint8_t * m_Buffer; uint8_t * m_Buffer, * m_Leases;
size_t m_BufferLen; size_t m_BufferLen;
}; };
} }

Loading…
Cancel
Save