Implement routing table snapshotter with automatic loading on startup

- Create snapshotter package with periodic (10 min) and on-demand snapshots
- Add JSON serialization with gzip compression and atomic file writes
- Update routing table to track AddedAt time for each route
- Load snapshots on startup, filtering out stale routes (>30 minutes old)
- Add ROUTEWATCH_DISABLE_SNAPSHOTTER env var for tests
- Use OS-appropriate state directories (macOS: ~/Library/Application Support, Linux: /var/lib or XDG_STATE_HOME)
This commit is contained in:
2025-07-28 00:03:19 +02:00
parent 283f2ddbf2
commit ae2ef2ae0c
6 changed files with 258 additions and 32 deletions
+4 -1
View File
@@ -156,6 +156,9 @@ func (m *mockStore) GetStats() (database.Stats, error) {
}
func TestRouteWatchLiveFeed(t *testing.T) {
// Disable snapshotter for tests
t.Setenv("ROUTEWATCH_DISABLE_SNAPSHOTTER", "1")
// Create mock database
mockDB := newMockStore()
defer mockDB.Close()
@@ -169,7 +172,7 @@ func TestRouteWatchLiveFeed(t *testing.T) {
s := streamer.New(logger, metricsTracker)
// Create routing table
rt := routingtable.New()
rt := routingtable.New(logger)
// Create server
srv := server.New(mockDB, rt, s, logger)