Browse Source

generate LeaseSet from tunnel pool

pull/46/head
orignal 11 years ago
parent
commit
3313a5af5c
  1. 33
      Streaming.cpp
  2. 6
      Streaming.h
  3. 7
      TunnelPool.cpp
  4. 3
      i2p.cpp

33
Streaming.cpp

@ -308,13 +308,15 @@ namespace stream
m_IdentHash = i2p::data::CalculateIdentHash (m_Identity); m_IdentHash = i2p::data::CalculateIdentHash (m_Identity);
m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag, m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag,
CryptoPP::Integer (m_Keys.signingPrivateKey, 20)); CryptoPP::Integer (m_Keys.signingPrivateKey, 20));
i2p::tunnel::tunnels.CreateTunnelPool (this); m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (this);
} }
StreamingDestination::~StreamingDestination () StreamingDestination::~StreamingDestination ()
{ {
if (m_LeaseSet) if (m_LeaseSet)
DeleteI2NPMessage (m_LeaseSet); DeleteI2NPMessage (m_LeaseSet);
if (m_Pool)
i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool);
} }
void StreamingDestination::HandleNextPacket (Packet * packet) void StreamingDestination::HandleNextPacket (Packet * packet)
@ -346,12 +348,20 @@ namespace stream
} }
} }
I2NPMessage * StreamingDestination::GetLeaseSet () void StreamingDestination::UpdateLeaseSet ()
{ {
if (m_LeaseSet) // temporary always create new LeaseSet auto newLeaseSet = CreateLeaseSet ();
DeleteI2NPMessage (m_LeaseSet); // TODO: make it atomic
m_LeaseSet = CreateLeaseSet (); auto oldLeaseSet = m_LeaseSet;
m_LeaseSet = newLeaseSet;
if (oldLeaseSet)
DeleteI2NPMessage (oldLeaseSet);
}
I2NPMessage * StreamingDestination::GetLeaseSet ()
{
if (!m_LeaseSet)
m_LeaseSet = CreateLeaseSet ();
return m_LeaseSet; return m_LeaseSet;
} }
@ -371,7 +381,7 @@ 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 tunnels = i2p::tunnel::tunnels.GetInboundTunnels (5); // 5 tunnels maximum auto tunnels = m_Pool->GetInboundTunnels (5); // 5 tunnels maximum
buf[size] = tunnels.size (); // num leases buf[size] = tunnels.size (); // num leases
size++; // num size++; // num
for (auto it: tunnels) for (auto it: tunnels)
@ -412,6 +422,17 @@ namespace stream
if (sharedLocalDestination) if (sharedLocalDestination)
sharedLocalDestination->DeleteStream (stream); sharedLocalDestination->DeleteStream (stream);
} }
void StartStreaming ()
{
if (!sharedLocalDestination)
sharedLocalDestination = new StreamingDestination ();
}
void StopStreaming ()
{
delete sharedLocalDestination;
}
void HandleDataMessage (i2p::data::IdentHash * destination, const uint8_t * buf, size_t len) void HandleDataMessage (i2p::data::IdentHash * destination, const uint8_t * buf, size_t len)
{ {

6
Streaming.h

@ -11,6 +11,7 @@
#include "LeaseSet.h" #include "LeaseSet.h"
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "Tunnel.h" #include "Tunnel.h"
#include "TunnelPool.h"
namespace i2p namespace i2p
{ {
@ -114,7 +115,7 @@ namespace stream
void HandleNextPacket (Packet * packet); void HandleNextPacket (Packet * packet);
// implements LocalDestination // implements LocalDestination
void UpdateLeaseSet () {}; // TODO: void UpdateLeaseSet ();
private: private:
@ -127,6 +128,7 @@ namespace stream
i2p::data::Identity m_Identity; i2p::data::Identity m_Identity;
i2p::data::IdentHash m_IdentHash; i2p::data::IdentHash m_IdentHash;
i2p::tunnel::TunnelPool * m_Pool;
I2NPMessage * m_LeaseSet; I2NPMessage * m_LeaseSet;
CryptoPP::DSA::PrivateKey m_SigningPrivateKey; CryptoPP::DSA::PrivateKey m_SigningPrivateKey;
@ -134,6 +136,8 @@ namespace stream
Stream * CreateStream (const i2p::data::LeaseSet& remote); Stream * CreateStream (const i2p::data::LeaseSet& remote);
void DeleteStream (Stream * stream); void DeleteStream (Stream * stream);
void StartStreaming ();
void StopStreaming ();
// assuming data is I2CP message // assuming data is I2CP message
void HandleDataMessage (i2p::data::IdentHash * destination, const uint8_t * buf, size_t len); void HandleDataMessage (i2p::data::IdentHash * destination, const uint8_t * buf, size_t len);

7
TunnelPool.cpp

@ -21,6 +21,8 @@ namespace tunnel
void TunnelPool::TunnelCreated (InboundTunnel * createdTunnel) void TunnelPool::TunnelCreated (InboundTunnel * createdTunnel)
{ {
m_InboundTunnels.insert (createdTunnel); m_InboundTunnels.insert (createdTunnel);
if (m_Owner)
m_Owner->UpdateLeaseSet ();
} }
void TunnelPool::TunnelExpired (InboundTunnel * expiredTunnel) void TunnelPool::TunnelExpired (InboundTunnel * expiredTunnel)
@ -60,8 +62,9 @@ namespace tunnel
new TunnelConfig (std::vector<const i2p::data::RouterInfo *> new TunnelConfig (std::vector<const i2p::data::RouterInfo *>
{ {
firstHop, firstHop,
secondHop, secondHop
i2p::data::netdb.GetRandomRouter (secondHop) // TODO: swithc to 3-hops later
/*i2p::data::netdb.GetRandomRouter (secondHop) */
}), }),
outboundTunnel); outboundTunnel);
tunnel->SetTunnelPool (this); tunnel->SetTunnelPool (this);

3
i2p.cpp

@ -24,6 +24,7 @@
#include "HTTPServer.h" #include "HTTPServer.h"
#include "Garlic.h" #include "Garlic.h"
#include "util.h" #include "util.h"
#include "Streaming.h"
// Global // Global
@ -154,6 +155,7 @@ int main( int argc, char* argv[] )
i2p::transports.Start (); i2p::transports.Start ();
i2p::tunnel::tunnels.Start (); i2p::tunnel::tunnels.Start ();
i2p::garlic::routing.Start (); i2p::garlic::routing.Start ();
i2p::stream::StartStreaming ();
while (running) while (running)
{ {
@ -162,6 +164,7 @@ int main( int argc, char* argv[] )
} }
LogPrint("Shutdown started."); LogPrint("Shutdown started.");
i2p::stream::StopStreaming ();
i2p::garlic::routing.Stop (); i2p::garlic::routing.Stop ();
i2p::tunnel::tunnels.Stop (); i2p::tunnel::tunnels.Stop ();
i2p::transports.Stop (); i2p::transports.Stop ();

Loading…
Cancel
Save