Skip to content

Commit 35e6739

Browse files
authored
Merge pull request #15 from sargonas/peering-overhaul
Peering overhaul
2 parents 14eb099 + 933daf7 commit 35e6739

3 files changed

Lines changed: 270 additions & 115 deletions

File tree

dev-cluster.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CLUSTER_DIR=".dev-cluster"
88
NODES=${STELLAR_DEV_NODES:-5}
99
BASE_WEB_PORT=8081
1010
BASE_DHT_PORT=7871
11-
BINARY="./stellar-mesh"
11+
BINARY="./stellar-lab"
1212

1313
# Colors for output
1414
RED='\033[0;31m'

routing_table.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,46 @@ func (rt *RoutingTable) GetUnverifiedCount() int {
363363
return count
364364
}
365365

366+
// PeerStateBreakdown provides a clear view of peer states
367+
type PeerStateBreakdown struct {
368+
Total int `json:"total"` // All known systems (not including self)
369+
Active int `json:"active"` // Verified, recent, responding (fail=0)
370+
Degraded int `json:"degraded"` // Verified but failing (0 < fail < max)
371+
Pending int `json:"pending"` // Heard via gossip, not yet verified
372+
Stale int `json:"stale"` // Was verified but outside cutoff window
373+
}
374+
375+
// GetPeerStateBreakdown returns counts of peers in each state
376+
func (rt *RoutingTable) GetPeerStateBreakdown() PeerStateBreakdown {
377+
rt.cacheMu.RLock()
378+
defer rt.cacheMu.RUnlock()
379+
380+
now := time.Now()
381+
cutoff := now.Add(-VerificationCutoff)
382+
383+
breakdown := PeerStateBreakdown{
384+
Total: len(rt.systemCache),
385+
}
386+
387+
for _, cached := range rt.systemCache {
388+
if !cached.Verified {
389+
// Never verified - pending
390+
breakdown.Pending++
391+
} else if cached.LastVerified.IsZero() || cached.LastVerified.Before(cutoff) {
392+
// Verified but too long ago - stale
393+
breakdown.Stale++
394+
} else if cached.FailCount > 0 {
395+
// Recently verified but now failing - degraded
396+
breakdown.Degraded++
397+
} else {
398+
// Verified, recent, responding - active
399+
breakdown.Active++
400+
}
401+
}
402+
403+
return breakdown
404+
}
405+
366406
// GetCacheSize returns the number of cached systems
367407
func (rt *RoutingTable) GetCacheSize() int {
368408
rt.cacheMu.RLock()

0 commit comments

Comments
 (0)