Skip to content
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

Closed

Conversation

mbeards
Copy link
Contributor

@mbeards mbeards commented Apr 30, 2024

This change allows users to configure relays from code without having to setenv(GZ_RELAY).

🎉 New feature

Summary

This change allows users to configure relays from code without having to setenv(GZ_RELAY).

Test it

This can be tested by starting a Node across a boundary where multicast isn't enabled, and setting the relay IP via NodeOptions.

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

This change allows users to configure relays from code without having to
`setenv(GZ_RELAY)`.

Signed-off-by: Michael Beardsworth <[email protected]>
@mbeards mbeards requested a review from caguero as a code owner April 30, 2024 18:33
@github-actions github-actions bot added the 🎵 harmonic Gazebo Harmonic label Apr 30, 2024
}

sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include <cstring>

Copy link
Contributor Author

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?

src/NodeOptions.cc Show resolved Hide resolved
Signed-off-by: Michael Beardsworth <[email protected]>
Copy link

codecov bot commented May 1, 2024

Codecov Report

Attention: Patch coverage is 17.64706% with 14 lines in your changes are missing coverage. Please review.

Project coverage is 87.64%. Comparing base (eac2e69) to head (9b823d8).
Report is 16 commits behind head on gz-transport13.

❗ Current head 9b823d8 differs from pull request most recent head 472dde4. Consider uploading reports for the commit 472dde4 to get more accurate results

Files Patch % Lines
include/gz/transport/Discovery.hh 0.00% 9 Missing ⚠️
src/NodeOptions.cc 40.00% 3 Missing ⚠️
src/Node.cc 33.33% 2 Missing ⚠️
Additional details and impacted files
@@                Coverage Diff                 @@
##           gz-transport13     #497      +/-   ##
==================================================
- Coverage           87.69%   87.64%   -0.05%     
==================================================
  Files                  59       59              
  Lines                5704     5716      +12     
==================================================
+ Hits                 5002     5010       +8     
- Misses                702      706       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Michael Beardsworth <[email protected]>
Copy link
Collaborator

@caguero caguero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My main problem with this patch is that so far NodeOptions are all options that affect a single node. However, adding relays will have a global impact in all the nodes.

I understand that we don't have a way to set global options besides using environment variables right now. Perhaps an alternative could be to not use NodeOptions and just create an AddGlobalRelay() / GlobalRelays() functions in Node to preserve the semantics of NodeOptions? What do you think?

@@ -1420,26 +1440,6 @@ namespace gz
return true;
}

/// \brief Register a new relay address.
Copy link
Collaborator

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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)

/// 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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rename this function to AddRelays() to be more precise. You're not replacing the current relays, just adding extra ones.


/// \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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have two options here:

  1. Do not create a member variable this->dataPtr->relayIPs when adding the relays. Then, just add the relays using AddRelayAddress() as you're doing it right now. Then, in this function, read the entire list of relays from Discovery.
  2. Keep it as it's documenting that the returned vector of relays is the contribution from this node. Other relays could be happening.

I suspect (1) is going to be less confusing and will make debugging easier.

@mbeards
Copy link
Contributor Author

mbeards commented May 6, 2024

My main problem with this patch is that so far NodeOptions are all options that affect a single node. However, adding relays will have a global impact in all the nodes.

Agreed that this is weird / gross. I guess ideally I'd want to have accessors for the global Discovery instances, but threading that through seems difficult.

I understand that we don't have a way to set global options besides using environment variables right now. Perhaps an alternative could be to not use NodeOptions and just create an AddGlobalRelay() / GlobalRelays() functions in Node to preserve the semantics of NodeOptions? What do you think?

You're thinking something like the following?

class Node {
  // ...
  public: static void AddGlobalRelay(const std::string&);
  public: static std::vector<std::string>& Relays();
  // ...
}

@caguero
Copy link
Collaborator

caguero commented May 6, 2024

You're thinking something like the following?

class Node {
  // ...
  public: static void AddGlobalRelay(const std::string&);
  public: static std::vector<std::string>& Relays();
  // ...
}

Probably AddGlobalRelay() and GlobalRelays().

@mbeards
Copy link
Contributor Author

mbeards commented May 7, 2024

You're thinking something like the following?

class Node {
  // ...
  public: static void AddGlobalRelay(const std::string&);
  public: static std::vector<std::string>& Relays();
  // ...
}

Probably AddGlobalRelay() and GlobalRelays().

Done in #498

@mbeards mbeards closed this May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎵 harmonic Gazebo Harmonic
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants