mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 00:00:29 +03:00
generate LeaseSet from tunnel pool
This commit is contained in:
parent
26c5f6cd77
commit
3313a5af5c
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
void StreamingDestination::UpdateLeaseSet ()
|
||||
{
|
||||
auto newLeaseSet = CreateLeaseSet ();
|
||||
// TODO: make it atomic
|
||||
auto oldLeaseSet = m_LeaseSet;
|
||||
m_LeaseSet = newLeaseSet;
|
||||
if (oldLeaseSet)
|
||||
DeleteI2NPMessage (oldLeaseSet);
|
||||
}
|
||||
|
||||
I2NPMessage * StreamingDestination::GetLeaseSet ()
|
||||
{
|
||||
if (m_LeaseSet) // temporary always create new LeaseSet
|
||||
DeleteI2NPMessage (m_LeaseSet);
|
||||
if (!m_LeaseSet)
|
||||
m_LeaseSet = CreateLeaseSet ();
|
||||
|
||||
return m_LeaseSet;
|
||||
}
|
||||
|
||||
@ -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)
|
||||
@ -413,6 +423,17 @@ namespace 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)
|
||||
{
|
||||
uint32_t length = be32toh (*(uint32_t *)buf);
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include "LeaseSet.h"
|
||||
#include "I2NPProtocol.h"
|
||||
#include "Tunnel.h"
|
||||
#include "TunnelPool.h"
|
||||
|
||||
namespace i2p
|
||||
{
|
||||
@ -114,7 +115,7 @@ namespace stream
|
||||
void HandleNextPacket (Packet * packet);
|
||||
|
||||
// implements LocalDestination
|
||||
void UpdateLeaseSet () {}; // TODO:
|
||||
void UpdateLeaseSet ();
|
||||
|
||||
private:
|
||||
|
||||
@ -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
|
||||
|
||||
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);
|
||||
|
@ -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
|
||||
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
3
i2p.cpp
@ -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[] )
|
||||
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[] )
|
||||
}
|
||||
LogPrint("Shutdown started.");
|
||||
|
||||
i2p::stream::StopStreaming ();
|
||||
i2p::garlic::routing.Stop ();
|
||||
i2p::tunnel::tunnels.Stop ();
|
||||
i2p::transports.Stop ();
|
||||
|
Loading…
Reference in New Issue
Block a user