-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow programmatic configuration of unicast relays. #497
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -740,6 +740,26 @@ namespace gz | |
} | ||
} | ||
|
||
/// \brief Register a new relay address. | ||
/// \param[in] _ip New IP address. | ||
public: void AddRelayAddress(const std::string &_ip) | ||
{ | ||
// Sanity check: Make sure that this IP address is not already saved. | ||
for (auto const &addr : this->relayAddrs) | ||
{ | ||
if (addr.sin_addr.s_addr == inet_addr(_ip.c_str())) | ||
return; | ||
} | ||
|
||
sockaddr_in addr; | ||
memset(&addr, 0, sizeof(addr)); | ||
addr.sin_family = AF_INET; | ||
addr.sin_addr.s_addr = inet_addr(_ip.c_str()); | ||
addr.sin_port = htons(static_cast<u_short>(this->port)); | ||
|
||
this->relayAddrs.push_back(addr); | ||
} | ||
|
||
/// \brief Broadcast periodic heartbeats. | ||
private: void UpdateHeartbeat() | ||
{ | ||
|
@@ -1420,26 +1440,6 @@ namespace gz | |
return true; | ||
} | ||
|
||
/// \brief Register a new relay address. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you just moved this function. Out of curiosity, any reason for moving it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved it up to sit with the other public functions. ("Group similar declarations together, placing public parts earlier." https://google.github.io/styleguide/cppguide.html#Declaration_Order) |
||
/// \param[in] _ip New IP address. | ||
private: void AddRelayAddress(const std::string &_ip) | ||
{ | ||
// Sanity check: Make sure that this IP address is not already saved. | ||
for (auto const &addr : this->relayAddrs) | ||
{ | ||
if (addr.sin_addr.s_addr == inet_addr(_ip.c_str())) | ||
return; | ||
} | ||
|
||
sockaddr_in addr; | ||
memset(&addr, 0, sizeof(addr)); | ||
addr.sin_family = AF_INET; | ||
addr.sin_addr.s_addr = inet_addr(_ip.c_str()); | ||
addr.sin_port = htons(static_cast<u_short>(this->port)); | ||
|
||
this->relayAddrs.push_back(addr); | ||
} | ||
|
||
/// \brief Default activity interval value (ms.). | ||
/// \sa ActivityInterval. | ||
/// \sa SetActivityInterval. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
|
||
#include <memory> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "gz/transport/config.hh" | ||
#include "gz/transport/Export.hh" | ||
|
@@ -126,6 +127,19 @@ namespace gz | |
public: bool TopicRemap(const std::string &_fromTopic, | ||
std::string &_toTopic) const; | ||
|
||
/// \brief Add relay IPs. This node will send UDP unicast traffic to these | ||
/// addresses to connect networks when UDP multicast traffic is not | ||
/// forwarded. | ||
/// It's also possible to use the environment variable GZ_RELAY to add | ||
/// relays. | ||
/// \param[in] _relayIPs IPv4 addresses of unicast relays to add. | ||
/// \return True if the relay list is valid or false otherwise. | ||
public: bool SetRelays(const std::vector<std::string>& _relayIPs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rename this function to |
||
|
||
/// \brief Gets the list of relay addresses specified in this NodeOptions. | ||
/// \return The list of relay addresses. | ||
public: const std::vector<std::string>& Relays() const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have two options here:
I suspect (1) is going to be less confusing and will make debugging easier. |
||
|
||
#ifdef _WIN32 | ||
// Disable warning C4251 which is triggered by | ||
// std::unique_ptr | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
include
<cstring>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file already includes <string.h> - should I swap the include?