Browse Source

publish local LeaseSet

pull/93/head
orignal 10 years ago
parent
commit
7e0a2ae5ab
  1. 26
      I2NPProtocol.cpp
  2. 2
      I2NPProtocol.h
  3. 21
      NetDb.cpp
  4. 2
      NetDb.h
  5. 6
      Streaming.cpp
  6. 1
      Streaming.h

26
I2NPProtocol.cpp

@ -215,16 +215,32 @@ namespace i2p
return m; return m;
} }
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet) I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet, uint32_t replyToken)
{ {
if (!leaseSet) return nullptr; if (!leaseSet) return nullptr;
I2NPMessage * m = NewI2NPShortMessage (); I2NPMessage * m = NewI2NPShortMessage ();
I2NPDatabaseStoreMsg * msg = (I2NPDatabaseStoreMsg *)m->GetPayload (); uint8_t * payload = m->GetPayload ();
I2NPDatabaseStoreMsg * msg = (I2NPDatabaseStoreMsg *)payload;
memcpy (msg->key, leaseSet->GetIdentHash (), 32); memcpy (msg->key, leaseSet->GetIdentHash (), 32);
msg->type = 1; // LeaseSet msg->type = 1; // LeaseSet
msg->replyToken = 0; msg->replyToken = htobe32 (replyToken);
memcpy (m->GetPayload () + sizeof (I2NPDatabaseStoreMsg), leaseSet->GetBuffer (), leaseSet->GetBufferLen ()); size_t size = sizeof (I2NPDatabaseStoreMsg);
m->len += leaseSet->GetBufferLen () + sizeof (I2NPDatabaseStoreMsg); if (replyToken)
{
auto leases = leaseSet->GetNonExpiredLeases ();
if (leases.size () > 0)
{
*(uint32_t *)(payload + size) = htobe32 (leases[0].tunnelID);
size += 4; // reply tunnelID
memcpy (payload + size, leases[0].tunnelGateway, 32);
size += 32; // reply tunnel gateway
}
else
msg->replyToken = 0;
}
memcpy (payload + size, leaseSet->GetBuffer (), leaseSet->GetBufferLen ());
size += leaseSet->GetBufferLen ();
m->len += size;
FillI2NPMessageHeader (m, eI2NPDatabaseStore); FillI2NPMessageHeader (m, eI2NPDatabaseStore);
return m; return m;
} }

2
I2NPProtocol.h

@ -172,7 +172,7 @@ namespace tunnel
I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, const i2p::data::RouterInfo * floodfill); I2NPMessage * CreateDatabaseSearchReply (const i2p::data::IdentHash& ident, const i2p::data::RouterInfo * floodfill);
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr); I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::RouterInfo * router = nullptr);
I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet); I2NPMessage * CreateDatabaseStoreMsg (const i2p::data::LeaseSet * leaseSet, uint32_t replyToken = 0);
I2NPBuildRequestRecordClearText CreateBuildRequestRecord ( I2NPBuildRequestRecordClearText CreateBuildRequestRecord (
const uint8_t * ourIdent, uint32_t receiveTunnelID, const uint8_t * ourIdent, uint32_t receiveTunnelID,

21
NetDb.cpp

@ -873,5 +873,26 @@ namespace data
it++; it++;
} }
} }
void NetDb::PublishLeaseSet (const LeaseSet * leaseSet, i2p::tunnel::TunnelPool * pool)
{
if (!leaseSet || !pool) return;
auto outbound = pool->GetNextOutboundTunnel ();
if (!outbound)
{
LogPrint ("Can't publish LeaseSet. No outbound tunnels");
return;
}
std::set<IdentHash> excluded;
auto floodfill = GetClosestFloodfill (leaseSet->GetIdentHash (), excluded);
if (!floodfill)
{
LogPrint ("Can't publish LeaseSet. No floodfills found");
return;
}
uint32_t replyToken = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
auto msg = i2p::garlic::routing.WrapSingleMessage (*floodfill, i2p::CreateDatabaseStoreMsg (leaseSet, replyToken));
outbound->SendTunnelDataMsg (floodfill->GetIdentHash (), 0, msg);
}
} }
} }

2
NetDb.h

@ -13,6 +13,7 @@
#include "RouterInfo.h" #include "RouterInfo.h"
#include "LeaseSet.h" #include "LeaseSet.h"
#include "Tunnel.h" #include "Tunnel.h"
#include "TunnelPool.h"
#include "AddressBook.h" #include "AddressBook.h"
namespace i2p namespace i2p
@ -66,6 +67,7 @@ namespace data
void Subscribe (const IdentHash& ident); // keep LeaseSets upto date void Subscribe (const IdentHash& ident); // keep LeaseSets upto date
void Unsubscribe (const IdentHash& ident); void Unsubscribe (const IdentHash& ident);
void PublishLeaseSet (const LeaseSet * leaseSet, i2p::tunnel::TunnelPool * pool);
void RequestDestination (const IdentHash& destination, bool isLeaseSet = false); void RequestDestination (const IdentHash& destination, bool isLeaseSet = false);
void HandleDatabaseStoreMsg (uint8_t * buf, size_t len); void HandleDatabaseStoreMsg (uint8_t * buf, size_t len);

6
Streaming.cpp

@ -494,7 +494,7 @@ namespace stream
StreamingDestination::StreamingDestination (boost::asio::io_service& service): StreamingDestination::StreamingDestination (boost::asio::io_service& service):
m_Service (service), m_LeaseSet (nullptr) m_Service (service), m_LeaseSet (nullptr), m_IsPublic (false)
{ {
m_Keys = i2p::data::CreateRandomKeys (); m_Keys = i2p::data::CreateRandomKeys ();
@ -507,7 +507,7 @@ namespace stream
} }
StreamingDestination::StreamingDestination (boost::asio::io_service& service, const std::string& fullPath): StreamingDestination::StreamingDestination (boost::asio::io_service& service, const std::string& fullPath):
m_Service (service), m_LeaseSet (nullptr) m_Service (service), m_LeaseSet (nullptr), m_IsPublic (true)
{ {
std::ifstream s(fullPath.c_str (), std::ifstream::binary); std::ifstream s(fullPath.c_str (), std::ifstream::binary);
if (s.is_open ()) if (s.is_open ())
@ -602,6 +602,8 @@ namespace stream
UpdateLeaseSet (); UpdateLeaseSet ();
for (auto it: m_Streams) for (auto it: m_Streams)
it.second->SetLeaseSetUpdated (); it.second->SetLeaseSetUpdated ();
if (m_IsPublic)
i2p::data::netdb.PublishLeaseSet (m_LeaseSet, m_Pool);
} }
void StreamingDestination::Sign (const uint8_t * buf, int len, uint8_t * signature) const void StreamingDestination::Sign (const uint8_t * buf, int len, uint8_t * signature) const

1
Streaming.h

@ -175,6 +175,7 @@ namespace stream
i2p::tunnel::TunnelPool * m_Pool; i2p::tunnel::TunnelPool * m_Pool;
i2p::data::LeaseSet * m_LeaseSet; i2p::data::LeaseSet * m_LeaseSet;
bool m_IsPublic;
CryptoPP::DSA::PrivateKey m_SigningPrivateKey; CryptoPP::DSA::PrivateKey m_SigningPrivateKey;
std::function<void (Stream *)> m_Acceptor; std::function<void (Stream *)> m_Acceptor;

Loading…
Cancel
Save