Conversation
| #define RMW_IMPL_INVALID_TOPIC_NAME_TOKEN_STARTS_WITH_NUMBER 6 | ||
| #define RMW_IMPL_INVALID_TOPIC_TOO_LONG 7 | ||
|
|
||
| #define RMW_IMPL_MAX_TOPIC_NAME_LEGNTH 255 /* impl constraint */ - 8 /* reserved for prefixes */ |
There was a problem hiding this comment.
@Karsten1987 I ended going conservative with 255 - 8 (for the prefix) based on our conversation, when in reality we could go for (255 * 2) - 8 or something like that. I'd like to hear from others what they think about this more conservative limit.
I designed the function so that it reports the length as an issue only after all other checks pass. That way we could make the length limit a warning rather than a hard error.
The design doc could, I think, be clarified on this point after we settle on something.
There was a problem hiding this comment.
Given that I was not active in the namespace design review I have a few (maybe obvious) questions in order to understand this:
-
In the case of using
255*2-MAX_PREFIX_LENGTHas the max length, we assume that the thenamespacepart is less than255-MAX_PREFIX_LENGTHand that thebase nameis less than255right ? Will this be enforced by the rmw_implementation itself or by rmw?- if the former we should specify that everything before the last forward slash is the
namespaceand everything after it is thebase name, otherwise according to the implementation the topics won't match and we will lose interoperability - if the latter (what I think makes more sense): We should check that both
base names andnamespaces fulfill the requirement (and not the sum of their length) in the shared code and pass them individually to the rmw_implementations.- Pros:
- That'll cover non mapable scenario
/ns/my_topic_name_that_is_way_too_long_for_some_obscure_reason_and_hypothetically_longer_than_255_characters_for_the_sake_of_this_example - DRY
- Interroperability
- That'll cover non mapable scenario
- Cons:
- prevents rmw specific optimization that could provide more flexibility by splitting the ROS name to fit in 255 for Partition + 255 for topic name even if the namespace or base name doesn't fulfill respectively the 255-character long requirement
- Pros:
- if the former we should specify that everything before the last forward slash is the
Conclusion: I think we should stick with the max length implemented in this PR for now. It leaves us some leg room, will likely be easier if we ever want to plus another protocol under rmw and doesn't restrict users that much. We can always revisit it if someone raises the issue of the allowed length being too restrictive for their use case
There was a problem hiding this comment.
The way I see this is that everything above RMW should not necessarily deal with specific namespace constraints and for sure not with partitions as for whatever reason we may change DDS with something else.
There was a problem hiding this comment.
@mikaelarguedas That's a good point that I had thought about but failed to put in my comment, that allowing more than 255-ish would require the more complicated constraint of 255-ish for the namespace and 255-ish for the basename which is both harder to check and harder to communicate to users. @Karsten1987 I take the meaning of your comment to agree with that idea.
So, I'll leave it as-is and propose a clarification to the design doc with this rationale.
Separately we can still make topic names > 247 characters a warning at the rcl level and let the middleware implementation throw up the error if any real boundary is reached lengthwise. What do you guys think of that?
| if (topic_name_length == 0) { | ||
| *validation_result = RMW_IMPL_INVALID_TOPIC_IS_EMPTY_STRING; | ||
| *invalid_index = 0; | ||
| return RMW_RET_OK; |
There was a problem hiding this comment.
Is this not a potential conflict here? The validation results in an invalid topic, but the return code is ok? Why not returning the validation result directly?
There was a problem hiding this comment.
Even if the topic is invalid, the function succeeds. Please read the documentation for the function.
There was a problem hiding this comment.
+1 for clarifying it inside the documentation.
There was a problem hiding this comment.
@Karsten1987 I think it is pretty clear in the documentation, can you suggest something different if you think it isn't clear enough?
| return RMW_RET_OK; | ||
| } | ||
| // check for unallowed characters | ||
| for (size_t i = 0; i < topic_name_length; ++i) { |
There was a problem hiding this comment.
Why not converting to ascii and check if the value is a valid range?
There was a problem hiding this comment.
The string is ascii? That's what isalnum does I think (compare to a range). Also there is no single range that covers isalnum and underscore and forward slash. If you mean something else please clarify. Are you talking about the todo I left?
There was a problem hiding this comment.
yes, my comment was with respect to the todo, if isalnum is giving us a hard time with the local, we could manually specify the allowed ascii ranges ([a-z][A-Z][0-9]).
There was a problem hiding this comment.
Hmm, yeah I was trying to avoid custom code, but I might do just as you said to avoid locale issues.
rmw/src/impl/validate_topic_name.c
Outdated
| continue; | ||
| } else { | ||
| // if it is none of these, then it is an unallowed character in a FQN topic name | ||
| *validation_result = RMW_IMPL_INVALID_TOPIC_CONTAINS_UNALLOWED_CHARACTERS; |
| return RMW_RET_OK; | ||
| } | ||
| } | ||
| // check for double '/' and tokens that start with a number |
There was a problem hiding this comment.
Is there any problem in giving a topic such as /foo//bar//baz/ ?
There was a problem hiding this comment.
yes... what do mean by problem? It has a double slash twice and a trailing slash. It has several problems which make the topic invalid. This function just stops on the first problem it finds. I'm not sure what you're asking.
There was a problem hiding this comment.
I was thinking about the filesystem analogy, where you can specify file paths with any number of forward slashes and these are being ignored or merged into one. I wonder if we should do the same.
There was a problem hiding this comment.
Collapsing the double slash is an implementation specific assist. https://en.wikipedia.org/wiki/Path_(computing)
I'd suggest we stay strict and if really necessary we can open it up later. It's powerful but also dangerous, if you're using a substitution variable and it's key is typoed you could end up promoting everything by accident.
There was a problem hiding this comment.
I agree, we should not allow repeated slashes. The design doc is pretty clear about this:
- must not be empty [in reference to name tokens], e.g. the name
//baris not allowed
- rationale: it removes the chance for accidental
//from concatenation and thereore the need to collapse//to/
-- http://design.ros2.org/articles/topic_and_service_names.html#name-tokens
(btw fixed the spelling in ros2/design@efc9bf9)
If we decide later that this is not flexible enough, then we can change it.
rmw/src/impl/validate_topic_name.c
Outdated
| } | ||
| } | ||
| // check if the topic name is too long last, since it might be a soft invalidation | ||
| if (topic_name_length > RMW_IMPL_MAX_TOPIC_NAME_LEGNTH) { |
There was a problem hiding this comment.
Typo: Commenting here rather than above to dissociate from discussion: RMW_IMPL_MAX_TOPIC_NAME_LEGNTH => RMW_IMPL_MAX_TOPIC_NAME_LENGTH
|
@dirk-thomas I had to add 2a66f7a in order to address this Linux-only build failure: You can see that a similar thing has been done for the other test here in |
|
Ok, CI looks good. Anyone else have comments before merging? @Karsten1987 I tried to reply to each of your questions/comments. Can you re-review real quick. |
|
I'm going to address #92 (comment), in the meantime does anyone have any comments on the placement of this function? Should it be in the |
|
I don't think we should put this in |
|
Imo If there is no strong reason why these functions are being used in |
The only reason would be so that rmw implementations could "double check" the incoming topics are valid FQN. This should be asserted by |
If it will be used to validate parameters passed through the rmw interface https://github.com/ros2/rmw/blob/master/rmw/include/rmw/sanity_checks.h sounds like a reasonable place. |
|
Ok, so not in the |
Sounds good to me. |
|
I implemented a custom |
|
CI:
|
| } | ||
| } | ||
| } | ||
| // check if the topic name is too long last, since it might be a soft invalidation |
There was a problem hiding this comment.
maybe a nit, but I believe the check for maximum length should be further up in this function for returning quickly before iterating over all characters.
There was a problem hiding this comment.
Please read the documentation or this exact comment for why it is last.
This is the first step in implementing namespaces above the rmw layer. I ended up placing this function in
rmw(or at least that's what I'm proposing here) because I thought it might be a useful check (if only in debug situations) that could be used in the rmw implementations as well as inrclwhere I will use it to support other namespace functionality.I'm interested in feedback on placing it here rather than in
rcl. Also, I've put it in armw/implnamespace, because I feel that it should stand apart from the rmw interface that middleware implementations need to fulfill. In both cases, it is easily moved around or re-namespaced, so please let me know if you think it would be better elsewhere.I feel that this function's purpose and rules (set out from the design doc) are self contained enough and well defined enough to merge ahead of more namespace work, so I'm going to go ahead and put it in review.