-
Notifications
You must be signed in to change notification settings - Fork 771
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
Random ID should beginning with 1 #1637
Conversation
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.
Looks good
what about
IOW: what I want to say, the above line can spill out IDs outside the allowed domain |
Added parentheses, should works now |
I don't think your last change fixes the problem. There is a value
will exceed the allowed scope which |
Only |
>>> import struct
>>> from autobahn.util import _WAMP_ID_MASK
>>>
>>> val = b"\x00\x00\x00\x00\x00\x00\x00\x00"
>>> struct.unpack("@Q", val)[0] & _WAMP_ID_MASK
0
>>> struct.unpack("@Q", val)[0] & _WAMP_ID_MASK + 1
0
>>> struct.unpack("@Q", val)[0] + 1 & _WAMP_ID_MASK
1
>>>
>>> val = b"\x00\x1f\xff\xff\xff\xff\xff\xff"
>>> struct.unpack("@Q", val)[0] & _WAMP_ID_MASK
9007199254683392
>>> struct.unpack("@Q", val)[0] & _WAMP_ID_MASK + 1
9007199254740992
>>> struct.unpack("@Q", val)[0] + 1 & _WAMP_ID_MASK
9007199254683393
>>>
>>> 2**53
9007199254740992
>>>
fwiw, I'd felt much more comfortable with sth along (ideally added as a new CI test):
|
oh, shit! how did
ever get into the code? independent of the actual issue, ++1 for forcing a machine independent byte order, and +1 for big endian;) |
Yes, you realize, in fact, things are much more serious! |
luckily, it doesn't seem to be used anyways:
the word "Performance" hints at why it might have been thought of desirable (native byte order) in the first place ... bad bad |
In fact, we can also change |
sorry, I won't merge such "hacks" it obfuscates things further (the -1), and the comment is now wrong (as the value misses values which are indeed allowed, and hence it is no longer a mask) just make the function check for 0, and if so, self-call/iterate .. straight forward, easy to understand, no magic, no obfuscation, .. it's just 1-2 lines .. I don't care at all about the "loss of performance" because of an additional branch or what. buy a faster machine is easier;) |
how about >>> val = 0
>>> while not val:
... val = secrets.randbits(53)
...
>>> return val
5543878694689356 |
I don't think it's clear than mine last push |
autobahn-python/autobahn/util.py Line 301 in f084051
of course that's a matter of taste;) but in any case, I like your change too! it has the advantage of not changing the underlying python functions used so much (as mine) so let me have a last look before merge ... couple of minutes, I'm busy with sth .. |
alright: #1639 sorry, the discussion takes longer than coding;) but I'd also be cool with you changing your PR and we merge that, or we merge mine, doesn't matter .. but if you update, pls note eg
and pls also the other bits (eg changelog) ... |
cool, thank you! looks almost ready. I promise;)
people are actually relying on / asking for proper changelog the first word should be ideally with link to an issue number - in this case, there is none .. only a PR number ... which is "ok for me", but let me emphasize: I did have discussions .. people want and expect proper docs ... follow strict rules like: no change at all without an issue first .. anyways, just saying;) |
Sorry, just now found you've already pushed PR #1639 |
awesome! thank you very much! I'll let the CI finish, and then merge!
it's ok, just leave it for now. I do want to push a release soonish .. and the version number actually is already prepared for that new release the handling of the version numbers, and also when a new release is actually published is not as I ideally would wish for:(
sth like that;) |
Right, if the last update change log leave |
have dev processes and clear rules, avoiding "wasting your OR my time": ++1 couldn't agree more=) that should be the goal and yes, it is neither properly documented (for "unwritten" rules we do have and use) nor complete (for rules we should have, but don't have agreed on) ... well, that would be another issue;) "define and document development and release process and rules for library developers" |
Fix both in
id
andrid
function.