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

feat: enable plugin allowlist #264

Merged
merged 9 commits into from
Jul 17, 2023

Conversation

wep21
Copy link
Contributor

@wep21 wep21 commented Nov 19, 2022

I enabled plugin blacklist for image transport publisher.
usage:

ros2 run usb_cam usb_cam_node_exe --ros-args -p image_raw.disable_pub_plugins:=["image_transport/compressed"]
❯ ros2 topic list
/camera_info
/image_raw
/image_raw/compressedDepth
/image_raw/theora
/parameter_events
/rosout

Signed-off-by: Daisuke Nishimatsu <border_goldenmarket@yahoo.co.jp>
@wep21
Copy link
Contributor Author

wep21 commented Nov 19, 2022

@gbiggs @jacobperron @ijnek Could you review this PR? Also, I wolud like to backport this change into humble.

Signed-off-by: Daisuke Nishimatsu <border_goldenmarket@yahoo.co.jp>
Signed-off-by: wep21 <border_goldenmarket@yahoo.co.jp>
@wep21 wep21 force-pushed the enable-plugin-blacklist branch from 52d6751 to c5c1d99 Compare November 22, 2022 01:54
@@ -110,9 +110,23 @@ Publisher::Publisher(
impl_->base_topic_ = image_topic;
impl_->loader_ = loader;

uint ns_len = node->get_effective_namespace().length();
Copy link
Member

@ijnek ijnek Nov 23, 2022

Choose a reason for hiding this comment

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

Can param_base_name just be equal to base_topic, rather than stripping off the namespace here?

Copy link
Contributor Author

@wep21 wep21 Dec 7, 2022

Choose a reason for hiding this comment

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

@gbiggs @ijnek This comes from image_transport_plugins.
Which is better?

  • use base topic name
    This looks like below.
/usb_cam:
 ros__parameters:
   image_raw:
     enable_pub_plugins:
     - image_transport/compressed
     format: jpeg
     jpeg_quality: 95
     png_level: 3
     tiff:
       res_unit: inch
       xdpi: -1
       ydpi: -1
  • use whole topic name
    This looks like below.
/usb_cam:
  ros__parameters:
    image_raw:
      format: jpeg
      jpeg_quality: 95
      png_level: 3
      tiff:
        res_unit: inch
        xdpi: -1
        ydpi: -1
    /aaa/bbb/image_raw:
       enable_pub_plugins:
       - image_transport/compressed

Copy link
Member

Choose a reason for hiding this comment

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

Just the base topic name seems better.

@ijnek
Copy link
Member

ijnek commented Nov 23, 2022

As this seems like a revival of a feature that existed in ROS 1, I'd like the maintainers to decide on these changes. I do agree that a publisher getting created for every image transport plugin installed is annoying, but a whitelist sounds like a better idea than a blacklist.

@wep21
Copy link
Contributor Author

wep21 commented Dec 4, 2022

friendly ping @gbiggs @jacobperron

@gbiggs
Copy link
Contributor

gbiggs commented Dec 4, 2022

Please change this to use a whitelist rather than a blacklist, with an additional option to enable all publishers.

Daisuke Nishimatsu added 2 commits December 8, 2022 00:28
Signed-off-by: Daisuke Nishimatsu <border_goldenmarket@yahoo.co.jp>
Signed-off-by: Daisuke Nishimatsu <border_goldenmarket@yahoo.co.jp>
@wep21 wep21 changed the title feat: enable plugin blacklist feat: enable plugin whitelist Dec 7, 2022
@wep21
Copy link
Contributor Author

wep21 commented Dec 7, 2022

@gbiggs I changed this to whitelist at a6356ca.

Signed-off-by: Daisuke Nishimatsu <border_goldenmarket@yahoo.co.jp>
@ijnek
Copy link
Member

ijnek commented Dec 9, 2022

Should probably add all available transports to the whitelist is there are no plugins listed under enable_pub_plugins. Otherwise, this change would break the default behavior of making all installed transports available (which many users depend on).

@wep21
Copy link
Contributor Author

wep21 commented Dec 9, 2022

@ijnek okay, I will set all the plugins as a default parameter.

Signed-off-by: Daisuke Nishimatsu <border_goldenmarket@yahoo.co.jp>
@ijnek
Copy link
Member

ijnek commented Dec 15, 2022

@wep21 Apologies for the delay. I'm just reviewing again, and I think there is no need for a separate std::set and a std::vector, if you simplify:

  for (const auto & lookup_name : loader->getDeclaredClasses()) {
    const std::string transport_name = erase_last_copy(lookup_name, "_pub");
    if (whitelist.count(transport_name)) {
      try {
        auto pub = loader->createUniqueInstance(lookup_name);
        pub->advertise(node, image_topic, custom_qos, options);
        impl_->publishers_.push_back(std::move(pub));
      } catch (const std::runtime_error & e) {
        RCLCPP_ERROR(
          impl_->logger_, "Failed to load plugin %s, error string: %s\n",
          lookup_name.c_str(), e.what());
      }
    }
  }

to:

for (transport_name : whitelist_vec) {
  try {
    auto pub = loader->createUniqueInstance(transport_name);
    pub->advertise(node, image_topic, custom_qos, options);
    impl_->publishers_.push_back(std::move(pub));
  } catch (const std::runtime_error & e) {
    RCLCPP_ERROR(
      impl_->logger_, "Failed to load plugin %s, error string: %s\n",
      transport_name.c_str(), e.what());
  }
}

Please check that these changes do work, as I haven't tested it.

Signed-off-by: Daisuke Nishimatsu <border_goldenmarket@yahoo.co.jp>
@wep21
Copy link
Contributor Author

wep21 commented Dec 29, 2022

@ijnek I addressed your review here. Could you review my changes? cc @gbiggs

param_base_name +
".enable_pub_plugins").get_value<std::vector<std::string>>();
}
for (size_t i = 0; i < whitelist_vec.size(); ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of copying the contents of the vector into a set if you're then just going to iterate over 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.

@gbiggs This is from original code, but I guess this removes duplicated plugins declared in the parameters.

}

std::vector<std::string> whitelist_vec;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use the term "allowlist" instead of "whitelist".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gbiggs I addressed here

Signed-off-by: wep21 <daisuke.nishimatsu1021@gmail.com>
@wep21 wep21 requested a review from gbiggs April 26, 2023 16:22
@wep21 wep21 changed the title feat: enable plugin whitelist feat: enable plugin allowlist Apr 26, 2023
Copy link
Collaborator

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

@gbiggs can we merge this ?

@ahcorde
Copy link
Collaborator

ahcorde commented Jul 17, 2023

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

Copy link
Collaborator

@ahcorde ahcorde left a comment

Choose a reason for hiding this comment

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

can you take a look to this windows failures ? https://ci.ros2.org/job/ci_windows/19910/console

Co-authored-by: Alejandro Hernández Cordero <ahcorde@gmail.com>
@wep21
Copy link
Contributor Author

wep21 commented Jul 17, 2023

@ahcorde Thank you for suggesting the fix. Could you run ci again?

@wep21 wep21 requested a review from ahcorde July 17, 2023 13:51
@ahcorde
Copy link
Collaborator

ahcorde commented Jul 17, 2023

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Windows Build Status

@ahcorde ahcorde merged commit aab4348 into ros-perception:rolling Jul 17, 2023
@wep21 wep21 deleted the enable-plugin-blacklist branch July 17, 2023 20:00
@Sushant-Chavan
Copy link

@gbiggs @jacobperron @ijnek Could you review this PR? Also, I wolud like to backport this change into humble.

@wep21 Thank you for the PR. Do you also plan to merge these changes into humble?

@chrbrcknr
Copy link

Yes, it would be great to have this in humble too!

@juanluishortelano
Copy link

Yes, would also love to have this on humble

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.

7 participants