Skip to content

Commit 863a060

Browse files
authored
client/daemon: route liveness fix var names (#2156)
## Summary of Changes - Fix typos in a couple variable names (`s/PeerDiscrr/PeerDiscr` and `s/LocalDiscrr/LocalDiscr`) - Log `TxMin` and `TxMax` durations on startup with `.String()` ## Testing Verification - Variable name changes only; existing test coverage is sufficient
1 parent ed8015b commit 863a060

File tree

7 files changed

+53
-53
lines changed

7 files changed

+53
-53
lines changed

client/doublezerod/internal/liveness/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func NewManager(ctx context.Context, cfg *ManagerConfig) (*Manager, error) {
180180
}
181181

182182
log := cfg.Logger
183-
log.Info("liveness: manager starting", "localAddr", udp.LocalAddr().String(), "txMin", cfg.TxMin, "rxMin", cfg.RxMin, "detectMult", cfg.DetectMult, "passiveMode", cfg.PassiveMode, "peerMetrics", cfg.PeerMetrics)
183+
log.Info("liveness: manager starting", "localAddr", udp.LocalAddr().String(), "txMin", cfg.TxMin.String(), "rxMin", cfg.RxMin.String(), "detectMult", cfg.DetectMult, "passiveMode", cfg.PassiveMode, "peerMetrics", cfg.PeerMetrics)
184184

185185
ctx, cancel := context.WithCancel(ctx)
186186
m := &Manager{
@@ -412,7 +412,7 @@ func (m *Manager) HandleRx(ctrl *ControlPacket, peer Peer) {
412412
m.unkownPeerErrWarnMu.Lock()
413413
if m.unkownPeerErrWarnLast.IsZero() || time.Since(m.unkownPeerErrWarnLast) >= m.unkownPeerErrWarnEvery {
414414
m.unkownPeerErrWarnLast = time.Now()
415-
m.log.Warn("liveness: received control packet for unknown peer", "peer", peer.String(), "peerDiscrr", ctrl.peerDiscrr, "localDiscrr", ctrl.LocalDiscrr, "state", ctrl.State)
415+
m.log.Warn("liveness: received control packet for unknown peer", "peer", peer.String(), "peerDiscr", ctrl.PeerDiscr, "localDiscr", ctrl.LocalDiscr, "state", ctrl.State)
416416

417417
}
418418
m.unkownPeerErrWarnMu.Unlock()

client/doublezerod/internal/liveness/manager_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,15 @@ func TestClient_LivenessManager_HandleRx_Transitions_AddAndDelete(t *testing.T)
136136
}()
137137
require.NotNil(t, sess)
138138

139-
m.HandleRx(&ControlPacket{peerDiscrr: 0, LocalDiscrr: 1234, State: StateDown}, peer)
139+
m.HandleRx(&ControlPacket{PeerDiscr: 0, LocalDiscr: 1234, State: StateDown}, peer)
140140
func() {
141141
sess.mu.Lock()
142142
defer sess.mu.Unlock()
143143
require.Equal(t, StateInit, sess.state)
144144
require.EqualValues(t, 1234, sess.peerDiscr)
145145
}()
146146

147-
m.HandleRx(&ControlPacket{peerDiscrr: sess.localDiscr, LocalDiscrr: sess.peerDiscr, State: StateInit}, peer)
147+
m.HandleRx(&ControlPacket{PeerDiscr: sess.localDiscr, LocalDiscr: sess.peerDiscr, State: StateInit}, peer)
148148
added := wait(t, addCh, 2*time.Second, "RouteAdd after Up")
149149
require.Equal(t, r.Table, added.Table)
150150
require.Equal(t, r.Src.String(), added.Src.String())
@@ -158,7 +158,7 @@ func TestClient_LivenessManager_HandleRx_Transitions_AddAndDelete(t *testing.T)
158158
require.Equal(t, StateUp, sess.state)
159159
m.mu.Unlock()
160160

161-
m.HandleRx(&ControlPacket{peerDiscrr: sess.localDiscr, LocalDiscrr: sess.peerDiscr, State: StateDown}, peer)
161+
m.HandleRx(&ControlPacket{PeerDiscr: sess.localDiscr, LocalDiscr: sess.peerDiscr, State: StateDown}, peer)
162162
deleted := wait(t, delCh, 2*time.Second, "RouteDelete after Down")
163163
require.Equal(t, r.Table, deleted.Table)
164164
require.Equal(t, r.Src.String(), deleted.Src.String())
@@ -207,9 +207,9 @@ func TestClient_LivenessManager_WithdrawRoute_RemovesSessionAndDeletesIfInstalle
207207
}
208208
}()
209209
// Down -> Init (learn peerDiscr)
210-
m.HandleRx(&ControlPacket{peerDiscrr: 0, LocalDiscrr: 1, State: StateInit}, peer)
211-
// Init -> Up requires explicit echo (peerDiscrr == localDiscr)
212-
m.HandleRx(&ControlPacket{peerDiscrr: sess.localDiscr, LocalDiscrr: sess.peerDiscr, State: StateInit}, peer)
210+
m.HandleRx(&ControlPacket{PeerDiscr: 0, LocalDiscr: 1, State: StateInit}, peer)
211+
// Init -> Up requires explicit echo (PeerDiscr == localDiscr)
212+
m.HandleRx(&ControlPacket{PeerDiscr: sess.localDiscr, LocalDiscr: sess.peerDiscr, State: StateInit}, peer)
213213
wait(t, addCh, 2*time.Second, "RouteAdd before withdraw")
214214

215215
require.NoError(t, m.WithdrawRoute(r, "lo"))
@@ -265,7 +265,7 @@ func TestClient_LivenessManager_HandleRx_UnknownPeer_NoEffect(t *testing.T) {
265265

266266
// Construct a peer key that doesn't exist.
267267
unknown := Peer{Interface: "lo", LocalIP: "127.0.0.2", PeerIP: "127.0.0.3"}
268-
m.HandleRx(&ControlPacket{peerDiscrr: 0, LocalDiscrr: 1, State: StateInit}, unknown)
268+
m.HandleRx(&ControlPacket{PeerDiscr: 0, LocalDiscr: 1, State: StateInit}, unknown)
269269

270270
// Assert no changes.
271271
m.mu.Lock()
@@ -312,8 +312,8 @@ func TestClient_LivenessManager_NetlinkerErrors_NoCrash(t *testing.T) {
312312
require.NotNil(t, sess)
313313

314314
// Drive to Up (RouteAdd returns error but should not crash; installed set true).
315-
m.HandleRx(&ControlPacket{peerDiscrr: 0, LocalDiscrr: 99, State: StateDown}, peer) // Down -> Init
316-
m.HandleRx(&ControlPacket{peerDiscrr: sess.localDiscr, LocalDiscrr: sess.peerDiscr, State: StateUp}, peer) // Init -> Up
315+
m.HandleRx(&ControlPacket{PeerDiscr: 0, LocalDiscr: 99, State: StateDown}, peer) // Down -> Init
316+
m.HandleRx(&ControlPacket{PeerDiscr: sess.localDiscr, LocalDiscr: sess.peerDiscr, State: StateUp}, peer) // Init -> Up
317317

318318
rk := routeKeyFor(peer.Interface, sess.route)
319319
time.Sleep(50 * time.Millisecond) // allow onSessionUp goroutine to run
@@ -323,7 +323,7 @@ func TestClient_LivenessManager_NetlinkerErrors_NoCrash(t *testing.T) {
323323
m.mu.Unlock()
324324

325325
// Drive to Down (RouteDelete returns error; should not crash; installed set false).
326-
m.HandleRx(&ControlPacket{peerDiscrr: sess.localDiscr, LocalDiscrr: sess.peerDiscr, State: StateDown}, peer)
326+
m.HandleRx(&ControlPacket{PeerDiscr: sess.localDiscr, LocalDiscr: sess.peerDiscr, State: StateDown}, peer)
327327
time.Sleep(50 * time.Millisecond)
328328

329329
m.mu.Lock()
@@ -363,9 +363,9 @@ func TestClient_LivenessManager_PassiveMode_ImmediateInstall_NoAutoWithdraw(t *t
363363
break
364364
}
365365
}()
366-
m.HandleRx(&ControlPacket{peerDiscrr: 0, LocalDiscrr: 1, State: StateInit}, peer)
367-
m.HandleRx(&ControlPacket{peerDiscrr: sess.localDiscr, LocalDiscrr: sess.peerDiscr, State: StateUp}, peer)
368-
m.HandleRx(&ControlPacket{peerDiscrr: sess.localDiscr, LocalDiscrr: sess.peerDiscr, State: StateDown}, peer)
366+
m.HandleRx(&ControlPacket{PeerDiscr: 0, LocalDiscr: 1, State: StateInit}, peer)
367+
m.HandleRx(&ControlPacket{PeerDiscr: sess.localDiscr, LocalDiscr: sess.peerDiscr, State: StateUp}, peer)
368+
m.HandleRx(&ControlPacket{PeerDiscr: sess.localDiscr, LocalDiscr: sess.peerDiscr, State: StateDown}, peer)
369369

370370
select {
371371
case <-delCh:

client/doublezerod/internal/liveness/packet.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ type ControlPacket struct {
4747
State State // sender's current session state
4848
DetectMult uint8 // detection multiplier (used by peer for detect timeout)
4949
Length uint8 // total length, always 40 for this fixed-size implementation
50-
LocalDiscrr uint32 // sender's discriminator (unique session ID)
51-
peerDiscrr uint32 // discriminator of the remote session (echo back)
50+
LocalDiscr uint32 // sender's discriminator (unique session ID)
51+
PeerDiscr uint32 // discriminator of the remote session (echo back)
5252
DesiredMinTxUs uint32 // minimum TX interval desired by sender (microseconds)
5353
RequiredMinRxUs uint32 // minimum RX interval the sender can handle (microseconds)
5454
}
@@ -61,8 +61,8 @@ type ControlPacket struct {
6161
// 1: State (2 high bits) | 6 bits unused (zero)
6262
// 2: DetectMult
6363
// 3: Length (always 40)
64-
// 4–7: LocalDiscrr
65-
// 8–11: peerDiscrr
64+
// 4–7: LocalDiscr
65+
// 8–11: PeerDiscr
6666
//
6767
// 12–15: DesiredMinTxUs
6868
// 16–19: RequiredMinRxUs
@@ -77,8 +77,8 @@ func (c *ControlPacket) Marshal() []byte {
7777
sf := (uint8(c.State) & 0x3) << 6
7878
b[0], b[1], b[2], b[3] = vd, sf, c.DetectMult, 40
7979
be := binary.BigEndian
80-
be.PutUint32(b[4:8], c.LocalDiscrr)
81-
be.PutUint32(b[8:12], c.peerDiscrr)
80+
be.PutUint32(b[4:8], c.LocalDiscr)
81+
be.PutUint32(b[8:12], c.PeerDiscr)
8282
be.PutUint32(b[12:16], c.DesiredMinTxUs)
8383
be.PutUint32(b[16:20], c.RequiredMinRxUs)
8484
// Remaining bytes [20:40] are reserved/padding → left zeroed
@@ -109,8 +109,8 @@ func UnmarshalControlPacket(b []byte) (*ControlPacket, error) {
109109
}
110110

111111
rd := func(off int) uint32 { return binary.BigEndian.Uint32(b[off : off+4]) }
112-
c.LocalDiscrr = rd(4)
113-
c.peerDiscrr = rd(8)
112+
c.LocalDiscr = rd(4)
113+
c.PeerDiscr = rd(8)
114114
c.DesiredMinTxUs = rd(12)
115115
c.RequiredMinRxUs = rd(16)
116116
return c, nil

client/doublezerod/internal/liveness/packet_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ func TestClient_Liveness_Packet_MarshalEncodesHeaderAndFields(t *testing.T) {
1414
Version: 5,
1515
State: StateUp,
1616
DetectMult: 3,
17-
LocalDiscrr: 0x11223344,
18-
peerDiscrr: 0x55667788,
17+
LocalDiscr: 0x11223344,
18+
PeerDiscr: 0x55667788,
1919
DesiredMinTxUs: 0x01020304,
2020
RequiredMinRxUs: 0x0A0B0C0D,
2121
}
@@ -41,8 +41,8 @@ func TestClient_Liveness_Packet_UnmarshalRoundTrip(t *testing.T) {
4141
Version: 1,
4242
State: StateInit,
4343
DetectMult: 7,
44-
LocalDiscrr: 1,
45-
peerDiscrr: 2,
44+
LocalDiscr: 1,
45+
PeerDiscr: 2,
4646
DesiredMinTxUs: 3,
4747
RequiredMinRxUs: 4,
4848
}
@@ -54,8 +54,8 @@ func TestClient_Liveness_Packet_UnmarshalRoundTrip(t *testing.T) {
5454
require.Equal(t, StateInit, got.State)
5555
require.Equal(t, uint8(7), got.DetectMult)
5656
require.Equal(t, uint8(40), got.Length)
57-
require.Equal(t, uint32(1), got.LocalDiscrr)
58-
require.Equal(t, uint32(2), got.peerDiscrr)
57+
require.Equal(t, uint32(1), got.LocalDiscr)
58+
require.Equal(t, uint32(2), got.PeerDiscr)
5959
require.Equal(t, uint32(3), got.DesiredMinTxUs)
6060
require.Equal(t, uint32(4), got.RequiredMinRxUs)
6161
}

client/doublezerod/internal/liveness/scheduler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ func (s *Scheduler) doTX(sess *Session) {
333333
State: sess.state,
334334
DetectMult: sess.detectMult,
335335
Length: 40,
336-
LocalDiscrr: sess.localDiscr,
337-
peerDiscrr: sess.peerDiscr,
336+
LocalDiscr: sess.localDiscr,
337+
PeerDiscr: sess.peerDiscr,
338338
DesiredMinTxUs: uint32(sess.localTxMin / time.Microsecond),
339339
RequiredMinRxUs: uint32(sess.localRxMin / time.Microsecond),
340340
}).Marshal()

client/doublezerod/internal/liveness/session.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,15 +161,15 @@ func (s *Session) HandleRx(now time.Time, ctrl *ControlPacket) (changed bool) {
161161
if s.state == StateAdminDown {
162162
return false
163163
}
164-
if ctrl.peerDiscrr != 0 && ctrl.peerDiscrr != s.localDiscr {
164+
if ctrl.PeerDiscr != 0 && ctrl.PeerDiscr != s.localDiscr {
165165
return false
166166
}
167167

168168
prev := s.state
169169

170170
// Learn peer discriminator if not yet known.
171-
if s.peerDiscr == 0 && ctrl.LocalDiscrr != 0 {
172-
s.peerDiscr = ctrl.LocalDiscrr
171+
if s.peerDiscr == 0 && ctrl.LocalDiscr != 0 {
172+
s.peerDiscr = ctrl.LocalDiscr
173173
}
174174

175175
// Update peer timing and clamp within floor/ceiling bounds.
@@ -198,7 +198,7 @@ func (s *Session) HandleRx(now time.Time, ctrl *ControlPacket) (changed bool) {
198198

199199
// Move to Init once peer identified; Up after echo confirmation.
200200
if s.peerDiscr != 0 {
201-
if ctrl.State >= StateInit && ctrl.peerDiscrr == s.localDiscr {
201+
if ctrl.State >= StateInit && ctrl.PeerDiscr == s.localDiscr {
202202
s.state = StateUp
203203
s.backoffFactor = 1
204204
} else {
@@ -209,7 +209,7 @@ func (s *Session) HandleRx(now time.Time, ctrl *ControlPacket) (changed bool) {
209209

210210
case StateInit:
211211
// Promote to Up only after receiving echo referencing our localDiscr.
212-
if s.peerDiscr != 0 && ctrl.State >= StateInit && ctrl.peerDiscrr == s.localDiscr {
212+
if s.peerDiscr != 0 && ctrl.State >= StateInit && ctrl.PeerDiscr == s.localDiscr {
213213
s.state = StateUp
214214
s.backoffFactor = 1
215215
}

client/doublezerod/internal/liveness/session_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func TestClient_Liveness_Session_HandleRxIgnoresMismatchedpeerDiscrr(t *testing.
166166
s := newSess()
167167
s.localDiscr = 111
168168
now := time.Now()
169-
cp := &ControlPacket{peerDiscrr: 222, LocalDiscrr: 333, State: StateInit}
169+
cp := &ControlPacket{PeerDiscr: 222, LocalDiscr: 333, State: StateInit}
170170
changed := s.HandleRx(now, cp)
171171
require.False(t, changed)
172172
require.Equal(t, StateDown, s.state)
@@ -182,8 +182,8 @@ func TestClient_Liveness_Session_HandleRxFromDownToInitOrUpAndArmsDetect(t *test
182182
now := time.Now()
183183
// Peer Down -> go Init
184184
cpDown := &ControlPacket{
185-
peerDiscrr: 0, // acceptable (we only check mismatch if nonzero)
186-
LocalDiscrr: 1001, // learn peer discr
185+
PeerDiscr: 0, // acceptable (we only check mismatch if nonzero)
186+
LocalDiscr: 1001, // learn peer discr
187187
State: StateDown,
188188
DesiredMinTxUs: 30_000, // 30ms
189189
RequiredMinRxUs: 40_000, // 40ms
@@ -197,8 +197,8 @@ func TestClient_Liveness_Session_HandleRxFromDownToInitOrUpAndArmsDetect(t *test
197197

198198
// Next packet peer Init -> go Up
199199
cpInit := &ControlPacket{
200-
peerDiscrr: 42, // matches our localDiscr (explicit echo required)
201-
LocalDiscrr: 1001,
200+
PeerDiscr: 42, // matches our localDiscr (explicit echo required)
201+
LocalDiscr: 1001,
202202
State: StateInit,
203203
DesiredMinTxUs: 20_000,
204204
RequiredMinRxUs: 20_000,
@@ -216,14 +216,14 @@ func TestClient_Liveness_Session_HandleRxFromInitToUpOnPeerInitOrUp(t *testing.T
216216
s.peerDiscr = 777 // already learned
217217
now := time.Now()
218218

219-
// Without explicit echo (peerDiscrr != localDiscr), do NOT promote.
220-
cpNoEcho := &ControlPacket{peerDiscrr: 0, LocalDiscrr: 777, State: StateUp}
219+
// Without explicit echo (PeerDiscr != localDiscr), do NOT promote.
220+
cpNoEcho := &ControlPacket{PeerDiscr: 0, LocalDiscr: 777, State: StateUp}
221221
changed := s.HandleRx(now, cpNoEcho)
222222
require.False(t, changed)
223223
require.Equal(t, StateInit, s.state)
224224

225-
// With explicit echo (peerDiscrr == localDiscr), promote to Up.
226-
cpEcho := &ControlPacket{peerDiscrr: s.localDiscr, LocalDiscrr: s.peerDiscr, State: StateUp}
225+
// With explicit echo (PeerDiscr == localDiscr), promote to Up.
226+
cpEcho := &ControlPacket{PeerDiscr: s.localDiscr, LocalDiscr: s.peerDiscr, State: StateUp}
227227
changed = s.HandleRx(now, cpEcho)
228228
require.True(t, changed)
229229
require.Equal(t, StateUp, s.state)
@@ -237,7 +237,7 @@ func TestClient_Liveness_Session_HandleRxFromUpToDownWhenPeerReportsDownAndStopD
237237
now := time.Now()
238238
s.detectDeadline = now.Add(10 * time.Second)
239239

240-
cp := &ControlPacket{peerDiscrr: 0, LocalDiscrr: 1, State: StateDown}
240+
cp := &ControlPacket{PeerDiscr: 0, LocalDiscr: 1, State: StateDown}
241241
changed := s.HandleRx(now, cp)
242242
require.True(t, changed)
243243
require.Equal(t, StateDown, s.state)
@@ -250,8 +250,8 @@ func TestClient_Liveness_Session_HandleRxSetsPeerTimersAndDetectDeadline(t *test
250250
s := newSess()
251251
now := time.Now()
252252
cp := &ControlPacket{
253-
peerDiscrr: 0,
254-
LocalDiscrr: 9,
253+
PeerDiscr: 0,
254+
LocalDiscr: 9,
255255
State: StateInit,
256256
DesiredMinTxUs: 12_000,
257257
RequiredMinRxUs: 34_000,
@@ -280,7 +280,7 @@ func TestClient_Liveness_Session_HandleRxIgnoredWhenAdminDown(t *testing.T) {
280280
s := newSess()
281281
s.state = StateAdminDown
282282
now := time.Now()
283-
cp := &ControlPacket{peerDiscrr: 0, LocalDiscrr: 9, State: StateUp, DesiredMinTxUs: 1000, RequiredMinRxUs: 2000}
283+
cp := &ControlPacket{PeerDiscr: 0, LocalDiscr: 9, State: StateUp, DesiredMinTxUs: 1000, RequiredMinRxUs: 2000}
284284
changed := s.HandleRx(now, cp)
285285
require.False(t, changed)
286286
require.Equal(t, StateAdminDown, s.state)
@@ -296,8 +296,8 @@ func TestClient_Liveness_Session_HandleRxClampsTimersAndDetectMultZero(t *testin
296296
s.maxTxCeil = 40 * time.Millisecond
297297

298298
cp := &ControlPacket{
299-
peerDiscrr: 0,
300-
LocalDiscrr: 9,
299+
PeerDiscr: 0,
300+
LocalDiscr: 9,
301301
State: StateInit,
302302
DetectMult: 0, // invalid → clamp to 1 (internal)
303303
DesiredMinTxUs: 1_000, // 1ms → clamp up to 7ms
@@ -327,8 +327,8 @@ func TestClient_Liveness_Session_HandleRx_NoChange_RearmsDetect(t *testing.T) {
327327

328328
callNow := now.Add(10 * time.Millisecond)
329329
cp := &ControlPacket{
330-
peerDiscrr: s.localDiscr, // accepted (echo ok)
331-
LocalDiscrr: s.peerDiscr, // may be 0; fine
330+
PeerDiscr: s.localDiscr, // accepted (echo ok)
331+
LocalDiscr: s.peerDiscr, // may be 0; fine
332332
State: StateUp,
333333
DesiredMinTxUs: 20000, // 20ms
334334
RequiredMinRxUs: 20000,

0 commit comments

Comments
 (0)