add blacklist-snode option

pull/601/head
Jeff 5 years ago
parent bae926d3d6
commit 06f8bb2f42

@ -57,12 +57,23 @@ namespace llarp
return NumPathsExistingAt(future) < expect && !BuildCooldownHit(now);
}
void
BaseSession::BlacklistSnode(const RouterID snode)
{
m_SnodeBlacklist.insert(std::move(snode));
}
bool
BaseSession::SelectHop(llarp_nodedb* db, const std::set< RouterID >& prev,
RouterContact& cur, size_t hop,
llarp::path::PathRole roles)
{
std::set< RouterID > exclude = prev;
for(const auto& snode : m_SnodeBlacklist)
{
if(snode != m_ExitRouter)
exclude.insert(snode);
}
exclude.insert(m_ExitRouter);
if(hop == numHops - 1)
{

@ -39,6 +39,9 @@ namespace llarp
return shared_from_this();
}
void
BlacklistSnode(const RouterID snode);
util::StatusObject
ExtractStatus() const;
@ -129,6 +132,8 @@ namespace llarp
uint64_t seqno);
private:
std::set< RouterID > m_SnodeBlacklist;
using UpstreamTrafficQueue_t =
std::deque< llarp::routing::TransferTrafficMessage >;
using TieredQueue_t = std::map< uint8_t, UpstreamTrafficQueue_t >;

@ -495,6 +495,11 @@ namespace llarp
llarp::LogWarn("Couldn't start endpoint");
return false;
}
if(m_Exit)
{
for(const auto &snode : m_SnodeBlacklist)
m_Exit->BlacklistSnode(snode);
}
return SetupNetworking();
}

@ -184,15 +184,14 @@ namespace llarp
HopHandler_ptr
PathContext::GetByUpstream(const RouterID& remote, const PathID_t& id)
{
auto own = MapGet(
m_OurPaths, id,
[](const PathSet_ptr) -> bool {
// TODO: is this right?
return true;
},
[remote, id](PathSet_ptr p) -> HopHandler_ptr {
return p->GetByUpstream(remote, id);
});
auto own = MapGet(m_OurPaths, id,
[](const PathSet_ptr) -> bool {
// TODO: is this right?
return true;
},
[remote, id](PathSet_ptr p) -> HopHandler_ptr {
return p->GetByUpstream(remote, id);
});
if(own)
return own;

@ -65,6 +65,22 @@ namespace llarp
{
m_BundleRC = IsTrueValue(v.c_str());
}
if(k == "blacklist-snode")
{
RouterID snode;
if(!snode.FromString(v))
{
LogError(Name(), " invalid snode value: ", v);
return false;
}
const auto result = m_SnodeBlacklist.insert(std::move(snode));
if(!result.second)
{
LogError(Name(), " duplicate blacklist-snode: ", snode.ToString());
return false;
}
LogInfo(Name(), " adding ", snode.ToString(), " to blacklist");
}
if(k == "on-up")
{
m_OnUp = hooks::ExecShellBackend(v);
@ -659,6 +675,17 @@ namespace llarp
self->m_IsolatedLogic);
}
bool
Endpoint::SelectHop(llarp_nodedb* db, const std::set< RouterID >& prev,
RouterContact& cur, size_t hop, path::PathRole roles)
{
std::set< RouterID > exclude = prev;
for(const auto& snode : m_SnodeBlacklist)
exclude.insert(snode);
return path::Builder::SelectHop(db, exclude, cur, hop, roles);
}
bool
Endpoint::ShouldBundleRC() const
{
@ -1135,18 +1162,18 @@ namespace llarp
}
m_PendingTraffic[remote].emplace_back(data, t);
// no converstation
return EnsurePathToService(
remote,
[&](Address r, OutboundContext* c) {
if(c)
{
c->UpdateIntroSet(true);
for(auto& pending : m_PendingTraffic[r])
c->AsyncEncryptAndSendTo(pending.Buffer(), pending.protocol);
}
m_PendingTraffic.erase(r);
},
5000, true);
return EnsurePathToService(remote,
[&](Address r, OutboundContext* c) {
if(c)
{
c->UpdateIntroSet(true);
for(auto& pending : m_PendingTraffic[r])
c->AsyncEncryptAndSendTo(
pending.Buffer(), pending.protocol);
}
m_PendingTraffic.erase(r);
},
5000, true);
}
void

@ -294,6 +294,10 @@ namespace llarp
uint64_t
GetSeqNoForConvo(const ConvoTag& tag);
virtual bool
SelectHop(llarp_nodedb* db, const std::set< RouterID >& prev,
RouterContact& cur, size_t hop, path::PathRole roles) override;
virtual void
IntroSetPublishFail();
virtual void
@ -353,6 +357,9 @@ namespace llarp
return false;
}
public:
std::set< RouterID > m_SnodeBlacklist;
protected:
IDataHandler* m_DataHandler = nullptr;
Identity m_Identity;

@ -305,6 +305,8 @@ namespace llarp
}
std::set< RouterID > exclude = prev;
exclude.insert(m_NextIntro.router);
for(const auto& snode : m_Endpoint->m_SnodeBlacklist)
exclude.insert(snode);
if(hop == numHops - 1)
{
m_Endpoint->EnsureRouterIsKnown(m_NextIntro.router);
@ -394,6 +396,8 @@ namespace llarp
{
if(intro.ExpiresSoon(now))
continue;
if(m_Endpoint->m_SnodeBlacklist.count(intro.router))
continue;
if(m_BadIntros.find(intro) == m_BadIntros.end()
&& remoteIntro.router == intro.router)
{
@ -407,14 +411,16 @@ namespace llarp
/// pick newer intro not on same router
for(const auto& intro : currentIntroSet.I)
{
if(m_Endpoint->m_SnodeBlacklist.count(intro.router))
continue;
m_Endpoint->EnsureRouterIsKnown(intro.router);
if(intro.ExpiresSoon(now))
continue;
if(m_BadIntros.find(intro) == m_BadIntros.end() && m_NextIntro != intro)
{
shifted = intro.router != m_NextIntro.router;
if(intro.expiresAt > m_NextIntro.expiresAt)
{
shifted = intro.router != m_NextIntro.router;
m_NextIntro = intro;
success = true;
}

Loading…
Cancel
Save