Browse Source

pick most recent tunnel from LeaseSet

pull/33/head
orignal 11 years ago
parent
commit
e24795dd41
  1. 6
      LeaseSet.cpp
  2. 11
      LeaseSet.h
  3. 14
      Streaming.cpp

6
LeaseSet.cpp

@ -57,13 +57,13 @@ namespace data
LogPrint ("LeaseSet verification failed"); LogPrint ("LeaseSet verification failed");
} }
std::vector<Lease> LeaseSet::GetNonExpiredLeases () const std::set<Lease> LeaseSet::GetNonExpiredLeases () const
{ {
auto ts = i2p::util::GetMillisecondsSinceEpoch (); auto ts = i2p::util::GetMillisecondsSinceEpoch ();
std::vector<Lease> leases; std::set<Lease> leases;
for (auto& it: m_Leases) for (auto& it: m_Leases)
if (ts < it.endDate) if (ts < it.endDate)
leases.push_back (it); leases.insert (it);
return leases; return leases;
} }

11
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 "Identity.h" #include "Identity.h"
namespace i2p namespace i2p
@ -18,6 +19,14 @@ namespace data
uint8_t tunnelGateway[32]; uint8_t tunnelGateway[32];
uint32_t tunnelID; uint32_t tunnelID;
uint64_t endDate; uint64_t endDate;
bool operator< (const Lease& other) const
{
if (endDate != other.endDate)
return endDate > other.endDate;
else
return tunnelID < other.tunnelID;
}
}; };
#pragma pack() #pragma pack()
@ -34,7 +43,7 @@ namespace data
const Identity& GetIdentity () const { return m_Identity; }; const Identity& GetIdentity () const { return m_Identity; };
const IdentHash& GetIdentHash () const { return m_IdentHash; }; const IdentHash& GetIdentHash () const { return m_IdentHash; };
const std::vector<Lease>& GetLeases () const { return m_Leases; }; const std::vector<Lease>& GetLeases () const { return m_Leases; };
std::vector<Lease> GetNonExpiredLeases () const; std::set<Lease> GetNonExpiredLeases () const;
bool HasExpiredLeases () const; bool HasExpiredLeases () const;
bool HasNonExpiredLeases () const; bool HasNonExpiredLeases () const;
const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionKey; }; const uint8_t * GetEncryptionPublicKey () const { return m_EncryptionKey; };

14
Streaming.cpp

@ -173,9 +173,10 @@ namespace stream
if (!m_OutboundTunnel) if (!m_OutboundTunnel)
m_OutboundTunnel = i2p::tunnel::tunnels.GetNextOutboundTunnel (); m_OutboundTunnel = i2p::tunnel::tunnels.GetNextOutboundTunnel ();
if (m_OutboundTunnel) auto leases = m_RemoteLeaseSet->GetNonExpiredLeases ();
if (m_OutboundTunnel && !leases.empty ())
{ {
auto& lease = m_RemoteLeaseSet->GetLeases ()[0]; // TODO: auto& lease = *leases.begin (); // TODO:
m_OutboundTunnel->SendTunnelDataMsg (lease.tunnelGateway, lease.tunnelID, msg); m_OutboundTunnel->SendTunnelDataMsg (lease.tunnelGateway, lease.tunnelID, msg);
} }
else else
@ -209,7 +210,7 @@ namespace stream
auto leases = m_RemoteLeaseSet->GetNonExpiredLeases (); auto leases = m_RemoteLeaseSet->GetNonExpiredLeases ();
if (!leases.empty ()) if (!leases.empty ())
{ {
auto& lease = leases[0]; // TODO: auto& lease = *leases.begin (); // TODO:
m_OutboundTunnel->SendTunnelDataMsg (lease.tunnelGateway, lease.tunnelID, msg); m_OutboundTunnel->SendTunnelDataMsg (lease.tunnelGateway, lease.tunnelID, msg);
LogPrint ("Quick Ack sent"); LogPrint ("Quick Ack sent");
} }
@ -252,11 +253,12 @@ namespace stream
I2NPMessage * msg = i2p::garlic::routing.WrapSingleMessage (m_RemoteLeaseSet, I2NPMessage * msg = i2p::garlic::routing.WrapSingleMessage (m_RemoteLeaseSet,
CreateDataMessage (this, packet, size)); CreateDataMessage (this, packet, size));
if (m_OutboundTunnel) auto leases = m_RemoteLeaseSet->GetNonExpiredLeases ();
if (m_OutboundTunnel && !leases.empty ())
{ {
auto& lease = m_RemoteLeaseSet->GetLeases ()[0]; // TODO: auto& lease = *leases.begin (); // TODO:
m_OutboundTunnel->SendTunnelDataMsg (lease.tunnelGateway, lease.tunnelID, msg); m_OutboundTunnel->SendTunnelDataMsg (lease.tunnelGateway, lease.tunnelID, msg);
LogPrint ("FIN sent"); LogPrint ("FIN sent");
} }
else else
DeleteI2NPMessage (msg); DeleteI2NPMessage (msg);

Loading…
Cancel
Save