Browse Source

multi-tunnels LeaseSet

pull/11/merge
orignal 11 years ago
parent
commit
5856310cd6
  1. 21
      Streaming.cpp
  2. 17
      Tunnel.cpp
  3. 1
      Tunnel.h

21
Streaming.cpp

@ -77,15 +77,14 @@ namespace stream
m_ReceiveQueue.Put (packet); m_ReceiveQueue.Put (packet);
else else
delete packet; delete packet;
SendQuickAck ();
if (flags & PACKET_FLAG_CLOSE) if (flags & PACKET_FLAG_CLOSE)
{ {
LogPrint ("Closed"); LogPrint ("Closed");
m_IsOpen = false; m_IsOpen = false;
m_ReceiveQueue.WakeUp (); m_ReceiveQueue.WakeUp ();
} }
else
SendQuickAck ();
} }
size_t Stream::Send (uint8_t * buf, size_t len, int timeout) size_t Stream::Send (uint8_t * buf, size_t len, int timeout)
@ -325,11 +324,12 @@ namespace stream
size += 256; // encryption key size += 256; // encryption key
memset (buf + size, 0, 128); memset (buf + size, 0, 128);
size += 128; // signing key size += 128; // signing key
auto tunnel = i2p::tunnel::tunnels.GetNextInboundTunnel (); auto tunnels = i2p::tunnel::tunnels.GetInboundTunnels (5); // 5 tunnels maximum
if (tunnel) buf[size] = tunnels.size (); // num leases
size++; // num
for (auto it: tunnels)
{ {
buf[size] = 1; // 1 lease auto tunnel = it;
size++; // num
memcpy (buf + size, (const uint8_t *)tunnel->GetNextIdentHash (), 32); memcpy (buf + size, (const uint8_t *)tunnel->GetNextIdentHash (), 32);
size += 32; // tunnel_gw size += 32; // tunnel_gw
*(uint32_t *)(buf + size) = htobe32 (tunnel->GetNextTunnelID ()); *(uint32_t *)(buf + size) = htobe32 (tunnel->GetNextTunnelID ());
@ -339,11 +339,6 @@ namespace stream
*(uint64_t *)(buf + size) = htobe64 (ts); *(uint64_t *)(buf + size) = htobe64 (ts);
size += 8; // end_date size += 8; // end_date
} }
else
{
buf[size] = 0; // zero leases
size++; // num
}
Sign (buf, size, buf+ size); Sign (buf, size, buf+ size);
size += 40; // signature size += 40; // signature

17
Tunnel.cpp

@ -211,6 +211,23 @@ namespace tunnel
} }
return tunnel; return tunnel;
} }
std::vector<InboundTunnel *> Tunnels::GetInboundTunnels (int num) const
{
std::vector<InboundTunnel *> v;
int i = 0;
for (auto it : m_InboundTunnels)
{
if (i >= num) break;
if (it.second->GetNextIdentHash () != i2p::context.GetRouterInfo ().GetIdentHash ())
{
// exclude one hop tunnels
v.push_back (it.second);
i++;
}
}
return v;
}
OutboundTunnel * Tunnels::GetNextOutboundTunnel () OutboundTunnel * Tunnels::GetNextOutboundTunnel ()
{ {

1
Tunnel.h

@ -107,6 +107,7 @@ namespace tunnel
InboundTunnel * GetInboundTunnel (uint32_t tunnelID); InboundTunnel * GetInboundTunnel (uint32_t tunnelID);
Tunnel * GetPendingTunnel (uint32_t replyMsgID); Tunnel * GetPendingTunnel (uint32_t replyMsgID);
InboundTunnel * GetNextInboundTunnel (); InboundTunnel * GetNextInboundTunnel ();
std::vector<InboundTunnel *> GetInboundTunnels (int num) const;
OutboundTunnel * GetNextOutboundTunnel (); OutboundTunnel * GetNextOutboundTunnel ();
TransitTunnel * GetTransitTunnel (uint32_t tunnelID); TransitTunnel * GetTransitTunnel (uint32_t tunnelID);
void AddTransitTunnel (TransitTunnel * tunnel); void AddTransitTunnel (TransitTunnel * tunnel);

Loading…
Cancel
Save