additional cleanup of cruft

pull/1256/head
Jeff Becker 4 years ago
parent c425355a6b
commit f1edca9fa1
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -100,7 +100,6 @@ namespace llarp
if (arg <= 0)
throw std::invalid_argument("public-port must be > 0");
// Not needed to flip upside-down - this is done in llarp::Addr(const AddressInfo&)
m_ip4addr.sin_port = arg;
m_addrInfo.port = arg;
m_publicOverride = true;

@ -123,8 +123,19 @@ namespace llarp
if (!AllInterfaces(af, m_ourAddr))
return false;
}
else if (!GetIFAddr(ifname, m_ourAddr, af))
m_ourAddr = Addr(ifname);
else
{
const auto maybe = GetIFAddr(ifname, af);
if (maybe.has_value())
{
m_ourAddr = maybe.value();
}
else
{
if (not m_ourAddr.FromString(ifname))
throw std::invalid_argument(stringify("cannot parse network address: ", ifname));
}
}
m_ourAddr.port(port);
return llarp_ev_add_udp(m_Loop.get(), &m_udp, m_ourAddr) != -1;
}

@ -533,15 +533,14 @@ namespace llarp
return std::nullopt;
}
bool
GetIFAddr(const std::string& ifname, Addr& addr, int af)
std::optional<llarp::Addr>
GetIFAddr(const std::string& ifname, int af)
{
sockaddr_storage s;
auto* sptr = (sockaddr*)&s;
sockaddr* sptr = (sockaddr*)&s;
if (!llarp_getifaddr(ifname.c_str(), af, sptr))
return false;
addr = *sptr;
return true;
return std::nullopt;
return llarp::Addr{*sptr};
}
bool

@ -176,8 +176,8 @@ namespace llarp
FindFreeTun();
/// get network interface address for network interface with ifname
bool
GetIFAddr(const std::string& ifname, Addr& addr, int af = AF_INET);
std::optional<llarp::Addr>
GetIFAddr(const std::string& ifname, int af = AF_INET);
} // namespace llarp

@ -14,6 +14,8 @@
#define inet_aton(x, y) inet_pton(AF_INET, x, y)
#endif
#include <util/str.hpp>
namespace llarp
{
Addr::Addr()
@ -58,11 +60,14 @@ namespace llarp
Addr::Addr(std::string_view str) : Addr()
{
this->FromString(str);
if (not FromString(str))
throw std::invalid_argument(stringify("failed to parse bullshit value: ", str));
}
Addr::Addr(std::string_view str, const uint16_t p_port) : Addr(str)
Addr::Addr(std::string_view str, const uint16_t p_port) : Addr()
{
if (not FromString(str))
throw std::invalid_argument(stringify("failed to parse bullshit value: ", str));
this->port(p_port);
}
@ -271,7 +276,7 @@ namespace llarp
break;
// TODO : sockaddr_ll
default:
break;
throw std::invalid_argument("bad address family");
}
}

@ -848,14 +848,10 @@ namespace llarp
rpcBindAddr = DefaultRPCBindAddr;
}
rpcServer = std::make_unique<rpc::Server>(this);
while (!rpcServer->Start(rpcBindAddr))
if (not rpcServer->Start(rpcBindAddr))
{
LogError("failed to bind jsonrpc to ", rpcBindAddr);
#if defined(ANDROID) || defined(RPI)
sleep(1);
#else
std::this_thread::sleep_for(std::chrono::seconds(1));
#endif
return false;
}
LogInfo("Bound RPC server to ", rpcBindAddr);
}
@ -873,14 +869,10 @@ namespace llarp
{
rpcCaller = std::make_unique<rpc::Caller>(this);
rpcCaller->SetAuth(lokidRPCUser, lokidRPCPassword);
while (!rpcCaller->Start(lokidRPCAddr))
if (not rpcCaller->Start(lokidRPCAddr))
{
LogError("failed to start jsonrpc caller to ", lokidRPCAddr);
#if defined(ANDROID) || defined(RPI)
sleep(1);
#else
std::this_thread::sleep_for(std::chrono::seconds(1));
#endif
LogError("RPC Caller to ", lokidRPCAddr, " failed to start");
return false;
}
LogInfo("RPC Caller to ", lokidRPCAddr, " started");
}
@ -901,11 +893,6 @@ namespace llarp
Addr publicAddr(this->addrInfo);
if (this->publicOverride)
{
LogDebug("public address:port ", publicAddr);
}
// set public signing key
_rc.pubkey = seckey_topublic(identity());
// set router version if service node
@ -914,8 +901,8 @@ namespace llarp
_rc.routerVersion = RouterVersion(llarp::VERSION, LLARP_PROTO_VERSION);
}
AddressInfo ai;
_linkManager.ForEachInboundLink([&](LinkLayer_ptr link) {
AddressInfo ai;
if (link->GetOurAddressInfo(ai))
{
// override ip and port
@ -926,6 +913,7 @@ namespace llarp
}
if (RouterContact::BlockBogons && IsBogon(ai.ip))
return;
LogInfo("adding address: ", ai);
_rc.addrs.push_back(ai);
if (ExitEnabled())
{

Loading…
Cancel
Save