mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
propagate strict-connect to tun handler for hooks
This commit is contained in:
parent
69ffef30bb
commit
728c6005a3
|
@ -13,6 +13,7 @@
|
|||
#include <router/abstractrouter.hpp>
|
||||
#include <service/context.hpp>
|
||||
#include <util/logic.hpp>
|
||||
#include <nodedb.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -92,6 +93,30 @@ namespace llarp
|
|||
bool
|
||||
TunEndpoint::SetOption(const std::string &k, const std::string &v)
|
||||
{
|
||||
if(k == "strict-connect")
|
||||
{
|
||||
RouterID connect;
|
||||
if(!connect.FromString(v))
|
||||
{
|
||||
LogError(Name(), " invalid snode for strict-connect: ", v);
|
||||
return false;
|
||||
}
|
||||
|
||||
RouterContact rc;
|
||||
if(!router->nodedb()->Get(connect, rc))
|
||||
{
|
||||
LogError(Name(), " we don't have the RC for ", v,
|
||||
" so we can't use it in strict-connect");
|
||||
return false;
|
||||
}
|
||||
for(const auto &ai : rc.addrs)
|
||||
{
|
||||
m_StrictConnectAddrs.emplace_back(ai);
|
||||
LogInfo(Name(), " added ", m_StrictConnectAddrs.back(),
|
||||
" to strict connect");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Name won't be set because we need to read the config before we can read
|
||||
// the keyfile
|
||||
if(k == "exit-node")
|
||||
|
@ -554,6 +579,10 @@ namespace llarp
|
|||
env.emplace("IP_ADDR", m_OurIP.ToString());
|
||||
env.emplace("IF_ADDR", m_OurRange.ToString());
|
||||
env.emplace("IF_NAME", tunif.ifname);
|
||||
std::string strictConnect;
|
||||
for(const auto &addr : m_StrictConnectAddrs)
|
||||
strictConnect += addr.ToString() + " ";
|
||||
env.emplace("STRICT_CONNECT_ADDRS", strictConnect);
|
||||
return env;
|
||||
}
|
||||
|
||||
|
|
|
@ -244,6 +244,8 @@ namespace llarp
|
|||
std::vector< llarp::Addr > m_UpstreamResolvers;
|
||||
/// local dns
|
||||
llarp::Addr m_LocalResolverAddr;
|
||||
/// list of strict connect addresses for hooks
|
||||
std::vector< llarp::Addr > m_StrictConnectAddrs;
|
||||
};
|
||||
} // namespace handlers
|
||||
} // namespace llarp
|
||||
|
|
|
@ -856,7 +856,10 @@ namespace llarp
|
|||
else if(snode.FromString(val))
|
||||
{
|
||||
if(strictConnectPubkeys.insert(snode).second)
|
||||
{
|
||||
llarp::LogInfo("added ", snode, " to strict connect list");
|
||||
netConfig.emplace(key, val);
|
||||
}
|
||||
else
|
||||
llarp::LogWarn("duplicate key for strict connect: ", snode);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue