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) if (arg <= 0)
throw std::invalid_argument("public-port must be > 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_ip4addr.sin_port = arg;
m_addrInfo.port = arg; m_addrInfo.port = arg;
m_publicOverride = true; m_publicOverride = true;

@ -123,8 +123,19 @@ namespace llarp
if (!AllInterfaces(af, m_ourAddr)) if (!AllInterfaces(af, m_ourAddr))
return false; return false;
} }
else if (!GetIFAddr(ifname, m_ourAddr, af)) else
m_ourAddr = Addr(ifname); {
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); m_ourAddr.port(port);
return llarp_ev_add_udp(m_Loop.get(), &m_udp, m_ourAddr) != -1; return llarp_ev_add_udp(m_Loop.get(), &m_udp, m_ourAddr) != -1;
} }

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

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

@ -14,6 +14,8 @@
#define inet_aton(x, y) inet_pton(AF_INET, x, y) #define inet_aton(x, y) inet_pton(AF_INET, x, y)
#endif #endif
#include <util/str.hpp>
namespace llarp namespace llarp
{ {
Addr::Addr() Addr::Addr()
@ -58,11 +60,14 @@ namespace llarp
Addr::Addr(std::string_view str) : Addr() 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); this->port(p_port);
} }
@ -271,7 +276,7 @@ namespace llarp
break; break;
// TODO : sockaddr_ll // TODO : sockaddr_ll
default: default:
break; throw std::invalid_argument("bad address family");
} }
} }

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

Loading…
Cancel
Save