Skip to content

Generate Unique Stanza ID#184

Open
psycotica0 wants to merge 1 commit into
adhearsion:developfrom
psycotica0:cv_new_id
Open

Generate Unique Stanza ID#184
psycotica0 wants to merge 1 commit into
adhearsion:developfrom
psycotica0:cv_new_id

Conversation

@psycotica0

Copy link
Copy Markdown

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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