oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package wire
2
3import "slices"
4
5func withoutUsageRefresh(h **Headroom) bool {
6 if *h == nil || !((*h).Fetched || (*h).Unavailable) {
7 return false
8 }
9 v := **h
10 v.Fetched, v.Unavailable = false, false
11 *h = &v
12 return true
13}
14
15func withoutUsageRefreshConnections(cs *[]HeldConnection) bool {
16 out := slices.Clone(*cs)
17 changed := false
18 for i := range out {
19 changed = withoutUsageRefresh(&out[i].Headroom) || changed
20 }
21 if changed {
22 *cs = out
23 }
24 return changed
25}
26
27// WithoutUsageRefresh keeps the initial hello readable before negotiation.
28func WithoutUsageRefresh(h *Hello) bool { return withoutUsageRefreshConnections(&h.Connections) }
29
30func downgradeUsageRefresh(body any) bool {
31 switch v := body.(type) {
32 case *Hello:
33 return WithoutUsageRefresh(v)
34 case *Sync:
35 return withoutUsageRefreshConnections(&v.Connections)
36 case *ConnectionReport:
37 return withoutUsageRefresh(&v.Headroom)
38 }
39 return false
40}
41