Browse Source

find router with specified caps

pull/48/head
orignal 11 years ago
parent
commit
59d195c6da
  1. 4
      NetDb.cpp
  2. 2
      NetDb.h
  3. 4
      RouterInfo.cpp
  4. 3
      RouterInfo.h

4
NetDb.cpp

@ -601,7 +601,7 @@ namespace data
} }
} }
const RouterInfo * NetDb::GetRandomRouter (const RouterInfo * compatibleWith, bool floodfillOnly) const const RouterInfo * NetDb::GetRandomRouter (const RouterInfo * compatibleWith, uint8_t caps) const
{ {
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator (); CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
uint32_t ind = rnd.GenerateWord32 (0, m_RouterInfos.size () - 1); uint32_t ind = rnd.GenerateWord32 (0, m_RouterInfos.size () - 1);
@ -614,7 +614,7 @@ namespace data
{ {
if (!it.second->IsUnreachable () && if (!it.second->IsUnreachable () &&
(!compatibleWith || it.second->IsCompatible (*compatibleWith)) && (!compatibleWith || it.second->IsCompatible (*compatibleWith)) &&
(!floodfillOnly || it.second->IsFloodfill ())) (!caps || (it.second->GetCaps () & caps) == caps))
return it.second; return it.second;
} }
else else

2
NetDb.h

@ -74,7 +74,7 @@ namespace data
void HandleDatabaseStoreMsg (uint8_t * buf, size_t len); void HandleDatabaseStoreMsg (uint8_t * buf, size_t len);
void HandleDatabaseSearchReplyMsg (I2NPMessage * msg); void HandleDatabaseSearchReplyMsg (I2NPMessage * msg);
const RouterInfo * GetRandomRouter (const RouterInfo * compatibleWith = nullptr, bool floodfillOnly = false) const; const RouterInfo * GetRandomRouter (const RouterInfo * compatibleWith = nullptr, uint8_t caps = 0) const;
void PostI2NPMsg (I2NPMessage * msg); void PostI2NPMsg (I2NPMessage * msg);

4
RouterInfo.cpp

@ -200,8 +200,10 @@ namespace data
case 'f': case 'f':
m_Caps |= Caps::eFloodfill; m_Caps |= Caps::eFloodfill;
break; break;
case 'M':
case 'N':
case 'O': case 'O':
m_Caps |= Caps::eHighBanwidth; m_Caps |= Caps::eHighBandwidth;
break; break;
case 'R': case 'R':
m_Caps |= Caps::eReachable; m_Caps |= Caps::eReachable;

3
RouterInfo.h

@ -28,7 +28,7 @@ namespace data
enum Caps enum Caps
{ {
eFloodfill = 0x01, eFloodfill = 0x01,
eHighBanwidth = 0x02, eHighBandwidth = 0x02,
eReachable = 0x04 eReachable = 0x04
}; };
@ -84,6 +84,7 @@ namespace data
bool IsSSU (bool v4only = true) const; bool IsSSU (bool v4only = true) const;
bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; }; bool IsCompatible (const RouterInfo& other) const { return m_SupportedTransports & other.m_SupportedTransports; };
bool UsesIntroducer () const; bool UsesIntroducer () const;
uint8_t GetCaps () const { return m_Caps; };
void SetUnreachable (bool unreachable) { m_IsUnreachable = unreachable; }; void SetUnreachable (bool unreachable) { m_IsUnreachable = unreachable; };
bool IsUnreachable () const { return m_IsUnreachable; }; bool IsUnreachable () const { return m_IsUnreachable; };

Loading…
Cancel
Save