Files
Igor Sirotin fc894011a8 fix: keep allocating test ports, and move that out of the library
Removing GetFreePortIfNeeded also removed the allocation StartWakuNode
did, and the library does not treat a zero DiscV5 UDP port as "pick one":
every node tried the same default and all but the first failed to bind.

StartWakuNode is test scaffolding, so it moves to the test helpers along
with the port allocation. Neither is part of the package surface now.
2026-08-25 14:31:42 +01:00

33 lines
933 B
Go

package kernel
import (
"context"
"fmt"
"time"
)
// requestTimeout is the deadline applied to a context that carries none of its
// own. It has to be a real number: the library passes the value straight to
// chronos' withTimeout, where zero milliseconds expires immediately.
const requestTimeout = 30 * time.Second
// timeoutMillis renders a context's remaining time as the millisecond timeout
// the library expects, falling back to def when the context has no deadline.
func timeoutMillis(ctx context.Context, def time.Duration) int {
deadline, ok := ctx.Deadline()
if !ok {
return int(def.Milliseconds())
}
remaining := time.Until(deadline)
if remaining <= 0 {
return 0
}
return int(remaining.Milliseconds())
}
// FormatWakuRelayTopic renders the pubsub topic for a cluster's shard.
func FormatWakuRelayTopic(clusterID uint16, shard uint16) string {
return fmt.Sprintf("/waku/2/rs/%d/%d", clusterID, shard)
}