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

Problem: can't process ZMTP 3.1 cancel/subscribe commands #3168

Merged
merged 5 commits into from
Jun 25, 2018

Conversation

bluca
Copy link
Member

@bluca bluca commented Jun 16, 2018

There's a bit of a hack to manage to use the existing flag field in msg - it works since a msg can't be more than one command at any time.

This is just to process on receive - to send, it's a bit more complicated so I'll send separately

@bluca bluca requested a review from sigiesec June 19, 2018 17:01
@sigiesec
Copy link
Member

So you intend to add some tests for this when the send side is also added?

I must admit that I cannot really judge the additions. Should someone else have a look before merging? Otherwise, I will merge it.

src/msg.cpp Outdated
data =
static_cast<unsigned char *> (this->data ()) + cancel_cmd_name_size;

return static_cast<void *> (data);
Copy link
Member

Choose a reason for hiding this comment

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

I think this cast is redundant.

src/msg.hpp Outdated
@@ -39,6 +39,9 @@
#include "atomic_counter.hpp"
#include "metadata.hpp"

// bits 2-5
#define CMD_TYPE_MASK 28
Copy link
Member

Choose a reason for hiding this comment

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

maybe define this as a hex literal instead to make the relationship to the bits more obvious?

In c++ style, a constant would be preferable to a preprocessor definition.

Copy link
Member Author

Choose a reason for hiding this comment

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

the problem is storage - msg has to be 64 bytes, but adding a variable would add weight to that, right?

src/xpub.cpp Outdated

// ZMTP 3.1 hack: we need to support sub/cancel commands, but
// we can't give them back to userspace as it would be an API
// breackage since the payload of the message is completely
Copy link
Member

Choose a reason for hiding this comment

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

breakage?

@bluca
Copy link
Member Author

bluca commented Jun 20, 2018

So you intend to add some tests for this when the send side is also added?

Yeah it's a bit hard to do without the sending side - I can try to mock it

@sigiesec
Copy link
Member

I think the best were to have tests for the receiver side only as unittests. However, we do not have any comparable tests until now, so probably this would require quite significant changes to the affected classes to make them unit-testable.

So if you intend to add support for the send side in the near future, and then add API-level tests, this should be fine. Then it is at the same level of tests as comparable existing features.

@laplaceyang
Copy link
Contributor

I am confused, since the rfc document defined:

Subscriptions SHALL be additive and SHALL NOT be idempotent. That is, subscribing to "A" and "" is the same as subscribing to "" alone. Subscribing to "A" and "A" counts as two subscriptions, and would require two CANCEL commands to undo.

If the sub side send "SUB A" to pub side twice, we store the pipe of sub into same node of struct trie, and save into a struct of set inner the node.
If sub side send "UNSUB A" once, the pipe is just removed. No need for the second "UNSUB A" command.

The behavior is different from the definition of rfc doc.

I am not sure whether I'm wrong or not.

@bluca
Copy link
Member Author

bluca commented Jun 21, 2018

That is enforced on the sub side - if you send "subscribe A" "subscribe A" and then "cancel A" "cancel A", the sub will wait for the second cancel before sending

Solution: fix path in Makefile.am
Solution: do it to silence static analysis warnings
@bluca
Copy link
Member Author

bluca commented Jun 22, 2018

Which I guess was done to reduce traffic - but it does breach the protocol. But at this point other implementations are probably doing the same thing, so we can't really change that. Perhaps the RFC should be changed instead to reflect the actual implementations...

@bluca
Copy link
Member Author

bluca commented Jun 23, 2018

@sigiesec I've added a simple mock test

Solution: use the --version-script map on those systems as well, as it
is supported
Solution: add some msg helpers to parse commands, and check for
subscribe or cancel commands and process them accordingly in the xpub
and xsub classes.
@sigiesec
Copy link
Member

Sorry I was AFK for the last few days. Thanks for the test. So is this ready to merge in spite of the discussion on the protocol?

@bluca
Copy link
Member Author

bluca commented Jun 25, 2018

No worries!

Yeah I'm not changing the way the PUB-SUB subscription behaviour works here - it was already like that. This just adds the new on-the-wire format.

@sigiesec sigiesec merged commit 0d66067 into zeromq:master Jun 25, 2018
@bluca bluca deleted the recv_sub_cancel branch June 25, 2018 12:14
bluca added a commit to bluca/libzmq that referenced this pull request Sep 2, 2019
Solution: fix regression introduced by:
zeromq#3168

Correctly fall back to user message if the first byte is neither 0 nor
1, and add a simple unit test
bluca added a commit to bluca/libzmq that referenced this pull request Sep 2, 2019
Solution: fix regression introduced by:
zeromq#3168

Correctly fall back to user message if the first byte is neither 0 nor
1, and add a simple unit test

Fixes zeromq#3656
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