package wire import "slices" func withoutUsageRefresh(h **Headroom) bool { if *h == nil || !((*h).Fetched || (*h).Unavailable) { return false } v := **h v.Fetched, v.Unavailable = false, false *h = &v return true } func withoutUsageRefreshConnections(cs *[]HeldConnection) bool { out := slices.Clone(*cs) changed := false for i := range out { changed = withoutUsageRefresh(&out[i].Headroom) || changed } if changed { *cs = out } return changed } // WithoutUsageRefresh keeps the initial hello readable before negotiation. func WithoutUsageRefresh(h *Hello) bool { return withoutUsageRefreshConnections(&h.Connections) } func downgradeUsageRefresh(body any) bool { switch v := body.(type) { case *Hello: return WithoutUsageRefresh(v) case *Sync: return withoutUsageRefreshConnections(&v.Connections) case *ConnectionReport: return withoutUsageRefresh(&v.Headroom) } return false }