Files
plezy/server/relay_protocol_gen.go
T
edde746 ab477c971d chore(relay): generate reconnect token size and version predicate from the protocol spec
The 32-byte reconnect token and its 43-character base64url shape were
pinned by hand in both server/main.go and the Dart peer service, and the
supported-version check was spelled out three times in Go. The spec now
carries reconnectTokenBytes and the generator emits the token size,
encoded length, and validator for Dart plus the size and
supportedRelayProtocolVersion for Go, failing before writing either
target when the key is missing. The last handwritten error code in lib/
('not_in_room') uses the generated constant, and releaseSession's
in-flight join is a FutureCoalescer.
2026-09-03 11:36:29 +02:00

62 lines
1.9 KiB
Go

// Code generated by scripts/codegen/generate_relay_protocol.py. DO NOT EDIT.
package main
const (
relayProtocolVersion = 2
legacyRelayProtocolVersion = 0
relayTypeCreate = "create"
relayTypeJoin = "join"
relayTypeBroadcast = "broadcast"
relayTypeSendTo = "sendTo"
relayTypePing = "ping"
relayTypeLeave = "leave"
relayTypeEndSession = "endSession"
relayTypeTransferHost = "transferHost"
relayTypeCreated = "created"
relayTypeJoined = "joined"
relayTypePeerJoined = "peerJoined"
relayTypePeerLeft = "peerLeft"
relayTypeMessage = "message"
relayTypeError = "error"
relayTypePong = "pong"
relayTypeLeft = "left"
relayTypeEnded = "ended"
relayTypeHostChanged = "hostChanged"
relayErrorRateLimited = "rate_limited"
relayErrorInvalidMessage = "invalid_message"
relayErrorRoomExists = "room_exists"
relayErrorRoomNotFound = "room_not_found"
relayErrorRoomFull = "room_full"
relayErrorNotInRoom = "not_in_room"
relayErrorAlreadyInRoom = "already_in_room"
relayErrorPeerIdUnavailable = "peer_id_unavailable"
relayErrorProtocolMismatch = "protocol_mismatch"
relayErrorNotHost = "not_host"
relayErrorPeerNotFound = "peer_not_found"
maxRoomSize = 8
maxMessageSize = 65536
maxSessionIDLength = 64
maxPeerIDLength = 128
reconnectTokenSize = 32
)
func supportedRelayProtocolVersion(version int) bool {
return version == legacyRelayProtocolVersion || version == relayProtocolVersion
}
func validRelayID(value string, maxLength int) bool {
if len(value) == 0 || len(value) > maxLength {
return false
}
for _, ch := range value {
if (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z') &&
(ch < '0' || ch > '9') && ch != '_' && ch != '-' {
return false
}
}
return true
}