Skip to content

RSDK-10720 support TCP mode based on flag #435

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

Merged

Conversation

stuqdog
Copy link
Member

@stuqdog stuqdog commented May 16, 2025

No description provided.

@stuqdog stuqdog changed the title POC PSDK-10720 use TCP if colon in address POC RSDK-10720 use TCP if colon in address May 16, 2025
@@ -269,7 +269,11 @@ ModuleService::~ModuleService() {

void ModuleService::serve() {
server_->register_service(impl_.get());
const std::string address = "unix:" + module_->addr();
std::string address;
if (module_->addr().find(':') == std::string::npos) {
Copy link
Member

@acmorrow acmorrow May 16, 2025

Choose a reason for hiding this comment

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

I realize this is PoC and may not ever get merged, but this means of deciding that the intention is not to use AF_UNIX is potentially in conflict with fully solving RSDK-10642, because the presence of a : may be involved in helping a module determine whether it has been invoked in a way that is intended to be interpreted as a gRPC endpoint URI (e.g. dns:... or ipv4:... or unix:...), per https://grpc.github.io/grpc/cpp/md_doc_naming.html

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep! Totally agree, this was just to get something that works today available quickly. I will definitely clean this up if/when we want to merge it.

Copy link
Member Author

Choose a reason for hiding this comment

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

@acmorrow if you're interested this is now ready for actual review, based on scope doc discussion.

@penguinland
Copy link
Member

For my own later reference: to get the tflite_cpu module to build with this, I needed to give it a different version number, so that the compiler couldn't just use the cached version. So, the branch I actually used is in https://github.com/viamrobotics/viam-cpp-sdk/compare/main...penguinland:viam-cpp-sdk:ethan_tcp_branch?expand=1

This is not a "real" problem: when this is merged and deployed, it will get a different version anyway, and all will be well.

@stuqdog stuqdog marked this pull request as ready for review June 16, 2025 19:25
@stuqdog stuqdog requested a review from a team as a code owner June 16, 2025 19:25
@stuqdog stuqdog requested review from njooma, lia-viam and acmorrow and removed request for a team June 16, 2025 19:25
@stuqdog
Copy link
Member Author

stuqdog commented Jun 16, 2025

Actual, non-POC C++ SDK changes. cc @penguinland @bhaney

@stuqdog stuqdog changed the title POC RSDK-10720 use TCP if colon in address RSDK-10720 support TCP mode based on flag Jun 16, 2025
impl_ = std::make_unique<ServiceImpl>(*this);
}

namespace {
Copy link
Member

Choose a reason for hiding this comment

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

minor style nit: generally, make one unnamed namespace up at the top of the file, after you've opened the file's main namespace:

#include <my_header.hpp>

#include <stuff>

namespace my {
namespace thing {

namespace {

// put get_protocol here

}  // namespace

...

}  // namespace thing
}  // namespace my

It's a convention, there is no real harm to opening and closing the unnamed namespace as often as you need, but keeping all the little utilities up together in the unnamed namespace up at the top prevents a proliferation of tiny namespace blocks.

std::string get_protocol(int argc, char** argv) {
for (int i = 0; i < argc; ++i) {
if (strcmp(argv[i], "--tcp-mode") == 0) {
return "dns:";
Copy link
Member

Choose a reason for hiding this comment

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

Curious why this is dns:. Are we expecting hostnames here? Are we allowing cross host between modules and RDK?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think we're expecting hostnames here, but in testing I got dns to work and I recall having issues with ipv4 . Also, this line (The following schemes are supported by the gRPC C-core implementation, but may not be supported in other languages:) about ipv4 had me worried.

Copy link
Member

Choose a reason for hiding this comment

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

That's fair, I'd forgotten about that caveat in the docs.

@stuqdog stuqdog requested a review from acmorrow June 18, 2025 13:48
namespace {
std::string get_protocol(int argc, char** argv) {
for (int i = 0; i < argc; ++i) {
if (strcmp(argv[i], "--tcp-mode") == 0) {
Copy link
Member

Choose a reason for hiding this comment

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

In future work, I'd like to see this argc/argv stuff entirely removed from ModuleService, and I'd like to see our command line parsing move to boost::program options rather than writing our own.

I've also been wondering whether we should have a libviamsdk_module_main library which defines a main which does the proper arg parsing, and delegates to a viam_module_main or viam_module_describe which exists only to populate a module registration vector.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah strongly agree about refactoring the arg parsing logic. I didn't want to overcomplicate here this PR but it's definitely something I'd like to see.

Haven't thought much about the libviamsdk_module_main idea but I like the sound of it.

Copy link
Member

Choose a reason for hiding this comment

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

Broad strokes here but roughly I think most modules shouldn't need to do anything more than:

  • Define some number of classes implementing Resource
  • Have a well-known entry point that returns a std::vector<ModelRegistration> for each Model they offer, each of which constructs an instance of the appropriate class.

I got here after doing some work on the UR arm driver, where I was able to make main sort of trivial:

And then give the relevant class a static method that generates the relevant registrations:

Some thought would need to go into how to arrange symbols between libraries and how the well known points wired up, but I don't think it would be too hard, and it would eliminate a lot of boilerplate from modules. It would also make it easier to adjust the command line parsing in all modules that made use of the facility as part of an SDK upgrade.

If you and @lia-viam like this idea let me know and I'll write up a quick ticket.

Copy link
Member Author

Choose a reason for hiding this comment

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

I mean, I definitely like the look of this. Unfortunately Lia is out until Friday, and I'm out starting on Friday, so we won't be able to speak about this until July 7th. But I'm more than happy to see a ticket made for this.

Copy link
Member

Choose a reason for hiding this comment

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

@stuqdog stuqdog merged commit 74575e2 into viamrobotics:main Jun 18, 2025
4 checks passed
@stuqdog stuqdog deleted the RSDK-10720-support-tcp-module-connections branch June 18, 2025 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants