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; LinkInfo info;
info.port = 0; info.port = 0;
info.addressFamily = AF_INET; info.addressFamily = AF_INET;
info.interface = name;
std::vector<std::string_view> splits = split(value, ','); if (name == "address")
for (std::string_view str : splits)
{ {
int asNum = std::atoi(str.data()); const IpAddress addr{value};
if (asNum > 0) if (not addr.hasPort())
info.port = asNum; 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; return info;

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

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

Loading…
Cancel
Save