|
34 | 34 | waitTime = flag.Duration("waitTime", 5*time.Second, "how long to wait between subsequent listings of open connections") |
35 | 35 | poll = flag.Bool("poll", true, "Whether the polling method should be used to see new connections.") |
36 | 36 | tracerType = flagx.Enum{ |
37 | | - Options: []string{"paris-traceroute", "scamper"}, |
| 37 | + Options: []string{"paris-traceroute", "scamper", "scamper-with-paris-backup"}, |
38 | 38 | Value: "scamper", |
39 | 39 | } |
40 | 40 |
|
@@ -63,34 +63,46 @@ func main() { |
63 | 63 | promSrv := prometheusx.MustServeMetrics() |
64 | 64 | defer promSrv.Shutdown(ctx) |
65 | 65 |
|
66 | | - var trace ipcache.Tracer |
| 66 | + scamperDaemon := &tracer.ScamperDaemon{ |
| 67 | + Binary: *scamperBin, |
| 68 | + AttachBinary: *scattachBin, |
| 69 | + Warts2JSONBinary: *scwarts2jsonBin, |
| 70 | + OutputPath: *outputPath, |
| 71 | + ControlSocket: *scamperCtrlSocket, |
| 72 | + ScamperTimeout: *scamperTimeout, |
| 73 | + } |
| 74 | + parisTracer := &tracer.Paris{ |
| 75 | + Binary: *parisBin, |
| 76 | + OutputPath: *outputPath, |
| 77 | + Timeout: *parisTimeout, |
| 78 | + } |
| 79 | + |
| 80 | + var cache *ipcache.RecentIPCache |
| 81 | + |
| 82 | + // Set up the cache three different ways, depending on the trace method requested. |
67 | 83 | switch tracerType.Value { |
68 | 84 | case "scamper": |
69 | | - daemon := &tracer.ScamperDaemon{ |
70 | | - Binary: *scamperBin, |
71 | | - AttachBinary: *scattachBin, |
72 | | - Warts2JSONBinary: *scwarts2jsonBin, |
73 | | - OutputPath: *outputPath, |
74 | | - ControlSocket: *scamperCtrlSocket, |
75 | | - ScamperTimeout: *scamperTimeout, |
76 | | - } |
| 85 | + cache = ipcache.New(ctx, scamperDaemon, *ipcache.IPCacheTimeout, *ipcache.IPCacheUpdatePeriod) |
77 | 86 | wg.Add(1) |
78 | 87 | go func() { |
79 | | - daemon.MustStart(ctx) |
| 88 | + scamperDaemon.MustStart(ctx) |
| 89 | + // When the scamper daemon dies, cancel main() and exit. |
80 | 90 | cancel() |
81 | 91 | wg.Done() |
82 | 92 | }() |
83 | | - trace = daemon |
84 | 93 | case "paris-traceroute": |
85 | | - trace = &tracer.Paris{ |
86 | | - Binary: *parisBin, |
87 | | - OutputPath: *outputPath, |
88 | | - Timeout: *parisTimeout, |
89 | | - } |
| 94 | + cache = ipcache.New(ctx, parisTracer, *ipcache.IPCacheTimeout, *ipcache.IPCacheUpdatePeriod) |
| 95 | + case "scamper-with-paris-backup": |
| 96 | + cache = ipcache.New(ctx, scamperDaemon, *ipcache.IPCacheTimeout, *ipcache.IPCacheUpdatePeriod) |
| 97 | + wg.Add(1) |
| 98 | + go func() { |
| 99 | + scamperDaemon.MustStart(ctx) |
| 100 | + // When the scamper daemon dies, switch to paris-traceroute. |
| 101 | + cache.UpdateTracer(parisTracer) |
| 102 | + wg.Done() |
| 103 | + }() |
90 | 104 | } |
91 | 105 |
|
92 | | - cache := ipcache.New(ctx, trace, *ipcache.IPCacheTimeout, *ipcache.IPCacheUpdatePeriod) |
93 | | - |
94 | 106 | if *poll { |
95 | 107 | wg.Add(1) |
96 | 108 | go func(c *ipcache.RecentIPCache) { |
|
0 commit comments