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

Generate Unique Stanza ID #184

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

psycotica0
Copy link

I'm using Blather to build a tool that runs periodically, which means it starts up, runs some XMPP commands, and then exits.

This means that my IDs are basically always blather0001, which also means my sessionIDs are basically always the same, which is confusing to the remote side who doesn't know I've restarted and just sees sessionIDs it already knows about, some of which may be ongoing if the script exited in error.

I've tried to make this as minimal of a change as possible because I don't know what lead us to making this choice in the first-place. So there's still just a simple counter, but it's just that the counter is put on the end of a different static string for each run of the script.

I chose 8 hex pairs somewhat arbitrarily because it felt like a round number that was big enough that the liklihood of getting duplicates was vanishingly small, but 4 would have been a more similar length to "blather" which we had before. As it stands, with 8 pairs, the total length of the ID is 20 characters long (4 character counter), which I figure is probably fine.

I'm using Blather to build a tool that runs periodically, which means it
starts up, runs some XMPP commands, and then exits.

This means that my IDs are basically always blather0001, which also
means my sessionIDs are basically always the same, which is confusing to
the remote side who doesn't know I've restarted and just sees sessionIDs
it already knows about, some of which may be ongoing if the script
exited in error.

I've tried to make this as minimal of a change as possible because I
don't know what lead us to making this choice in the first-place. So
there's still just a simple counter, but it's just that the counter is
put on the end of a different static string for each run of the script.

I chose 8 hex pairs somewhat arbitrarily because it felt like a round
number that was big enough that the liklihood of getting duplicates was
vanishingly small, but 4 would have been a more similar length to
"blather" which we had before. As it stands, with 8 pairs, the total
length of the ID is 20 characters long (4 character counter), which I
figure is probably fine.
@singpolyma
Copy link
Contributor

LGTM

I think we could go further and just use SecureRandom.uuid and also for command session id use that instead of the current SHA1 hack.

@psycotica0
Copy link
Author

Yeah, I was going to just make both of those simply return SecureRandom.uuid, but then I wasn't sure if there was some reason people wanted to have them increment rather than be random, so I tried to minimize it.

But if everyone would prefer the fully-random version it would be both more random and less code 😄

@singpolyma
Copy link
Contributor

Based on results in production, I think this should be closed in favour of #183

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.

2 participants