Skip to content

Implement ping for smux sessions#359

Merged
0pcom merged 1 commit intoskycoin:developfrom
0pcom:fix/smux-ping
Mar 30, 2026
Merged

Implement ping for smux sessions#359
0pcom merged 1 commit intoskycoin:developfrom
0pcom:fix/smux-ping

Conversation

@0pcom
Copy link
Copy Markdown
Collaborator

@0pcom 0pcom commented Mar 30, 2026

smux (unlike yamux) has no built-in ping. Implement it using a lightweight stream-level ping protocol:

Client side (SessionCommon.Ping):

  • Opens a temporary smux stream
  • Writes a 2-byte zero marker [0x00, 0x00] (ping)
  • Reads 2-byte echo, measures RTT
  • Closes stream (5s deadline)

Server side (serveStream):

  • Reads first 2 bytes of each new stream
  • If [0x00, 0x00]: echoes the marker back and closes (ping response)
  • Otherwise: passes the bytes through to readRequest via MultiReader

The [0x00, 0x00] marker is safe because it represents a zero-length object, which cannot occur in normal session traffic (valid SignedObjects always have length > 0).

Yamux sessions continue to use the built-in yamux.Ping().

smux (unlike yamux) has no built-in ping. Implement it using a
lightweight stream-level ping protocol:

Client side (SessionCommon.Ping):
- Opens a temporary smux stream
- Writes a 2-byte zero marker [0x00, 0x00] (ping)
- Reads 2-byte echo, measures RTT
- Closes stream (5s deadline)

Server side (serveStream):
- Reads first 2 bytes of each new stream
- If [0x00, 0x00]: echoes the marker back and closes (ping response)
- Otherwise: passes the bytes through to readRequest via MultiReader

The [0x00, 0x00] marker is safe because it represents a zero-length
object, which cannot occur in normal session traffic (valid
SignedObjects always have length > 0).

Yamux sessions continue to use the built-in yamux.Ping().
@0pcom 0pcom merged commit bfa7df7 into skycoin:develop Mar 30, 2026
3 checks passed
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.

1 participant