-
Notifications
You must be signed in to change notification settings - Fork 194
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
[WIP] Portname validation #1508
Conversation
This commit add Contact::isValidRegistrationName() and Contact::isValidRegisteredName() functions as an attempt to standardize what YARP accepts as input for opening and connecting ports.
'#' syntax allowed only "+" and "-" categories while other syntaxes '@' and '=' allow an optional trailing "1" on the contegory.
I think that all this nice information about the allowed port names (basically the description of the PR after ---) should go in an appropriate documentation page such as https://github.com/robotology/yarp/blob/master/doc/yarp_env_variables.md , that can be linked from the isValidRegisteredName and isValidRegistrationName doxygen documentation method. |
Related issues and PRs : |
Just out of curiosity, do you have any idea about the order of magnitude of the time spent on performing the regex ? |
Seems you carried out quite a deep investigation @damn1 |
} | ||
else // basic error reporting: | ||
{ | ||
std::cout << "\"" << port_name_s << "\" does not match the correct pattern for port definition.\n"; |
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.
Given that this is an error, perhaps it is better to use std::cerr
or one of the countless logging mechanism that can be used in libYARP_OS
?
} | ||
else | ||
{ | ||
std::cout << "There is no matching pattern. Check the correct syntax --> where <-- for port names.\n"; |
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.
I do not fully understand this message.
bool Contact::isValidRegisteredName(const char* name) | ||
{ | ||
const std::string port_name_s(name); | ||
std::regex port_exp( |
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.
Do you have any idea about the order of magnitute necessary to build the std::regex
object? If it is not trivial, we could think about having a regex singleton to avoid rebuilding the regex for each check.
Thanks @damn1 for this thorough test. I'd propose a pit fight ... I mean, a meeting, to write down a rule set and publish it online as @traversaro suggested. @pattacini i think |
@traversaro for sure if this PR is going to be accepted I would keep the task of report the documentation in the proper place. About the time of parsing I actually have no idea at the moment. I can try to collect some info about that. |
@damn1 yep the syntax Take home messageStandardization is quite a nice tool to make a product more mature. However, when we want to standardize a software that is already used since years, standardization becomes somewhat difficult. That's exactly the reason why we should call for a meeting as @barbalberto said since a PR alone is not enough (I might have missed it) to elicit the number of observations and suggestions required to keep the error probability low 😉 |
@pattacini I fully understand the necessities of a meeting, I made a PR just because I had some work done and wanted to make it public to see if there's interest in this question, and if it was being done in a correct way (technically speaking), otherwise I would drop the work or change direction. |
Clear, thanks @damn1 |
+1 for the meeting |
As discussed with @damn1, I will close this and add the |
While fixing YARP crashes on wrong inputs, after #1470, I tried to define a whitelist of accepted and correctly parsed inputs.
So I would like to propose this PR as an attempt to standardize YARP port names and to start to supply (hopefully) clear documentation about
yarp::os::NestedContact
and other ROS related classes ( #1501).Consists of adding two functions and calling them on input port names to
Port::open()
andNetwork::connect()
.These two functions together should define the policies to define port names. There should be anything new, I just checked what YARP supports and tried to formalize the input formats accepted.
To define the allowed syntax I checked the code in
Port::open()
,Contact::fromString()
andNestedContact::fromString()
, besides the port names used in the tests as a reference for common names.Let me know if this could be useful or not.
So here are the names accepted on registration:
""
- blank name is accepted to open anonymous ports.some_topic_name
- no leading slash, this name is accepted and then discarded if there's no active node....
- this is assigned a temporary port in the sequence /tmp/port/N.Following syntaxes are accepted both as registration and registered names, and checked by Network::connect()
carrier:/port[cat]@node~wire
carrier:/node[cat]#port~wire
carrier:/node=[cat]port~wire
carrier:/machine:NNN/
Clearly carriers, nodes, wires and category are optional.
Syntax rules for ports and nodes:
/p1/p2/p3:s1/p_4/p_5_and_6:s2
Syntax rules for category ([cat]):
+
,-
,+1
,-1
.Syntax rules for carriers and wires:
~wire is used to specify the type of the communication on topics.
Syntax rules for machines:
Behaviour:
The '=', '#' symbols should be equivalent but the position of the category.
'@' syntax is still equivalent with inverted position of node and topic.
Registration names assumed by ports with these syntaxes could be different if you specify or not the category (#1470 (comment))
One explicit difference with this patch is that @ allows
""
as node name (a node like/tmp/port/N
is assigned)while node can't be blank with
yarp read #/port
#/port
is taken as bash comment.Error reporting on wrong matches is very basic but in many cases could be useful, if a part of the expression is matched: