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

add timestamp to handshake #183

Closed
wants to merge 3 commits into from
Closed

add timestamp to handshake #183

wants to merge 3 commits into from

Conversation

billiegoose
Copy link
Contributor

Supercedes #167 . It's better because:

  • it invalidates old streams without requiring any old state, meaning if the program crashes and restarts, it'll invalidate any old streams as long as timestamp is monotonically increasing ¹ ²
  • it's also simpler and requires less book-keeping code in hyperswarm
  • a timestamp is shorter than a noise stream id
  • a timestamp is the same length as a udx stream id, but doesn't suffer from relays changing the udx stream id

¹ Date.now() is not guaranteed to be monotonically increasing, but since fast reconnects are not mission critical, it should suffice, since it'll succeed "all" the time for practical purposes.

² According to MDN, performance.timeOrigin + performance.now() is guaranteed to be monotonically increasing. But I don't think the performance global is available in bare JS environments.

relayKeepAlive: opts.relayKeepAlive || 5000,

// Used by the server when tie-breaking between two connections from the same peer
timestamp: opts.timestamp ?? -1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this default of -1 makes the timestamp behavior opt in... which may be a pain-in-the-butt for most users, who'll not benefit from this change until they modify their code to pass { timestamp: Date.now() } in the options to connect.

However, I tend to be very conservative when it comes to breaking changes, and my philosophy is usually to make all enhancements "opt in" until the next major version bump, at which time I update the defaults.

Copy link
Contributor

Choose a reason for hiding this comment

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

just use 0 as the default, then the uint can be unsigned, and 0 is pretty appropriate for that. also means we can just do || 0

lib/connect.js Outdated Show resolved Hide resolved
lib/messages.js Outdated Show resolved Hide resolved
@billiegoose
Copy link
Contributor Author

Closed in favor of holepunchto/hyperswarm#178

@billiegoose billiegoose deleted the handshake-timestamp branch June 28, 2024 12:32
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