Browse Source

generate LeaseSet from tunnel pool

pull/46/head
orignal 10 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 @@ -308,13 +308,15 @@ namespace stream
m_IdentHash = i2p::data::CalculateIdentHash (m_Identity);
m_SigningPrivateKey.Initialize (i2p::crypto::dsap, i2p::crypto::dsaq, i2p::crypto::dsag,
CryptoPP::Integer (m_Keys.signingPrivateKey, 20));
i2p::tunnel::tunnels.CreateTunnelPool (this);
m_Pool = i2p::tunnel::tunnels.CreateTunnelPool (this);
}
StreamingDestination::~StreamingDestination ()
{
if (m_LeaseSet)
DeleteI2NPMessage (m_LeaseSet);
if (m_Pool)
i2p::tunnel::tunnels.DeleteTunnelPool (m_Pool);
}
void StreamingDestination::HandleNextPacket (Packet * packet)
@ -346,12 +348,20 @@ namespace stream @@ -346,12 +348,20 @@ namespace stream
}
}
I2NPMessage * StreamingDestination::GetLeaseSet ()
void StreamingDestination::UpdateLeaseSet ()
{
if (m_LeaseSet) // temporary always create new LeaseSet
DeleteI2NPMessage (m_LeaseSet);
m_LeaseSet = CreateLeaseSet ();
auto newLeaseSet = CreateLeaseSet ();
// TODO: make it atomic
auto oldLeaseSet = m_LeaseSet;
m_LeaseSet = newLeaseSet;
if (oldLeaseSet)
DeleteI2NPMessage (oldLeaseSet);
}
I2NPMessage * StreamingDestination::GetLeaseSet ()
{
if (!m_LeaseSet)
m_LeaseSet = CreateLeaseSet ();
return m_LeaseSet;
}
@ -371,7 +381,7 @@ namespace stream @@ -371,7 +381,7 @@ namespace stream
size += 256; // encryption key
memset (buf + size, 0, 128);
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
size++; // num
for (auto it: tunnels)
@ -412,6 +422,17 @@ namespace stream @@ -412,6 +422,17 @@ namespace stream
if (sharedLocalDestination)
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)
{

6
Streaming.h

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

7
TunnelPool.cpp

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

3
i2p.cpp

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

Loading…
Cancel
Save