fix issue #1320 (allow providing ip/port in bind section of config)

pull/1321/head
Jeff Becker 4 years ago
parent 998d4c4ec3
commit 301cb6d32f
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -345,16 +345,28 @@ namespace llarp
LinkInfo info;
info.port = 0;
info.addressFamily = AF_INET;
info.interface = name;
std::vector<std::string_view> splits = split(value, ',');
for (std::string_view str : splits)
if (name == "address")
{
int asNum = std::atoi(str.data());
if (asNum > 0)
info.port = asNum;
const IpAddress addr{value};
if (not addr.hasPort())
throw std::invalid_argument("no port provided in link address");
info.interface = addr.getIpAddr();
info.port = *addr.getPort();
}
else
{
info.interface = name;
// otherwise, ignore ("future-proofing")
std::vector<std::string_view> splits = split(value, ',');
for (std::string_view str : splits)
{
int asNum = std::atoi(str.data());
if (asNum > 0)
info.port = asNum;
// otherwise, ignore ("future-proofing")
}
}
return info;

@ -137,6 +137,18 @@ namespace llarp
return m_ipAddress; // TODO: port
}
std::string
IpAddress::getIpAddr() const
{
return m_ipAddress;
}
bool
IpAddress::hasPort() const
{
return m_port.has_value();
}
bool
IpAddress::operator<(const IpAddress& other) const
{

@ -69,6 +69,10 @@ namespace llarp
std::optional<uint16_t>
getPort() const;
/// Return true if we have a port set otherwise return false
bool
hasPort() const;
/// Set the port.
///
/// @param port
@ -114,6 +118,10 @@ namespace llarp
std::string
toString() const;
/// get ip address component
std::string
getIpAddr() const;
// TODO: other utility functions left over from Addr which may be useful
// IsBogon() const;
// isPrivate() const;

Loading…
Cancel
Save