Browse Source

handle NTCP2 RouterInfo flag

pull/1274/head
orignal 6 years ago
parent
commit
42ed312384
  1. 4
      libi2pd/NTCP2.cpp
  2. 2
      libi2pd/NTCP2.h
  3. 15
      libi2pd/NetDb.cpp
  4. 3
      libi2pd/NetDb.hpp

4
libi2pd/NTCP2.cpp

@ -695,7 +695,7 @@ namespace transport
SendTerminationAndTerminate (eNTCP2IncorrectSParameter); SendTerminationAndTerminate (eNTCP2IncorrectSParameter);
return; return;
} }
i2p::data::netdb.PostI2NPMsg (CreateI2NPMessage (eI2NPDummyMsg, buf.data () + 4, size - 1)); // TODO: should insert ri and not parse it twice i2p::data::netdb.PostI2NPMsg (CreateI2NPMessage (eI2NPDummyMsg, buf.data () + 3, size)); // TODO: should insert ri and not parse it twice
// TODO: process options // TODO: process options
// ready to communicate // ready to communicate
@ -860,7 +860,7 @@ namespace transport
case eNTCP2BlkRouterInfo: case eNTCP2BlkRouterInfo:
{ {
LogPrint (eLogDebug, "NTCP2: RouterInfo flag=", (int)frame[offset]); LogPrint (eLogDebug, "NTCP2: RouterInfo flag=", (int)frame[offset]);
i2p::data::netdb.PostI2NPMsg (CreateI2NPMessage (eI2NPDummyMsg, frame + offset + 1, size - 1)); i2p::data::netdb.PostI2NPMsg (CreateI2NPMessage (eI2NPDummyMsg, frame + offset, size));
break; break;
} }
case eNTCP2BlkI2NPMessage: case eNTCP2BlkI2NPMessage:

2
libi2pd/NTCP2.h

@ -73,6 +73,8 @@ namespace transport
eNTCP2Banned, // 17 eNTCP2Banned, // 17
}; };
// RouterInfo flags
const uint8_t NTCP2_ROUTER_INFO_FLAG_REQUEST_FLOOD = 0x01;
typedef std::array<uint8_t, NTCP2_UNENCRYPTED_FRAME_MAX_SIZE> NTCP2FrameBuffer; typedef std::array<uint8_t, NTCP2_UNENCRYPTED_FRAME_MAX_SIZE> NTCP2FrameBuffer;
struct NTCP2Establisher struct NTCP2Establisher

15
libi2pd/NetDb.cpp

@ -12,6 +12,7 @@
#include "I2NPProtocol.h" #include "I2NPProtocol.h"
#include "Tunnel.h" #include "Tunnel.h"
#include "Transports.h" #include "Transports.h"
#include "NTCP2.h"
#include "RouterContext.h" #include "RouterContext.h"
#include "Garlic.h" #include "Garlic.h"
#include "NetDb.hpp" #include "NetDb.hpp"
@ -99,8 +100,8 @@ namespace data
HandleDatabaseLookupMsg (msg); HandleDatabaseLookupMsg (msg);
break; break;
case eI2NPDummyMsg: case eI2NPDummyMsg:
// plain RouterInfo from NTCP2 for now // plain RouterInfo from NTCP2 with flag for now
AddRouterInfo (msg->GetPayload (), msg->GetPayloadLength ()); HandleNTCP2RouterInfoMsg (msg);
break; break;
default: // WTF? default: // WTF?
LogPrint (eLogError, "NetDb: unexpected message type ", (int) msg->GetTypeID ()); LogPrint (eLogError, "NetDb: unexpected message type ", (int) msg->GetTypeID ());
@ -574,6 +575,16 @@ namespace data
transports.SendMessage (from, dest->CreateRequestMessage (nullptr, nullptr)); transports.SendMessage (from, dest->CreateRequestMessage (nullptr, nullptr));
} }
void NetDb::HandleNTCP2RouterInfoMsg (std::shared_ptr<const I2NPMessage> m)
{
uint8_t flood = m->GetPayload ()[0] & NTCP2_ROUTER_INFO_FLAG_REQUEST_FLOOD;
bool updated = AddRouterInfo (m->GetPayload () + 1, m->GetPayloadLength () - 1); // without flag
if (flood && updated && context.IsFloodfill ())
{
// TODO: flood
LogPrint (eLogInfo, "NetDb: NTCP RouterInfo flood is not implemented");
}
}
void NetDb::HandleDatabaseStoreMsg (std::shared_ptr<const I2NPMessage> m) void NetDb::HandleDatabaseStoreMsg (std::shared_ptr<const I2NPMessage> m)
{ {

3
libi2pd/NetDb.hpp

@ -65,7 +65,8 @@ namespace data
void HandleDatabaseStoreMsg (std::shared_ptr<const I2NPMessage> msg); void HandleDatabaseStoreMsg (std::shared_ptr<const I2NPMessage> msg);
void HandleDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg); void HandleDatabaseSearchReplyMsg (std::shared_ptr<const I2NPMessage> msg);
void HandleDatabaseLookupMsg (std::shared_ptr<const I2NPMessage> msg); void HandleDatabaseLookupMsg (std::shared_ptr<const I2NPMessage> msg);
void HandleNTCP2RouterInfoMsg (std::shared_ptr<const I2NPMessage> m);
std::shared_ptr<const RouterInfo> GetRandomRouter () const; std::shared_ptr<const RouterInfo> GetRandomRouter () const;
std::shared_ptr<const RouterInfo> GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const; std::shared_ptr<const RouterInfo> GetRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const;
std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const; std::shared_ptr<const RouterInfo> GetHighBandwidthRandomRouter (std::shared_ptr<const RouterInfo> compatibleWith) const;

Loading…
Cancel
Save