mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
fix: start packet capture immediately on speedtest (#13128)
I initially made this change when hacking wgengine to also capture wireguard packets going into the magicsock, so that we could capture the initial wireguard handshake. I don't think we should ship that additional capture logic, but... it seems generally useful to capture packets from the get go on speedtest, so that you can see disco and pings before the TCP speedtest session starts.
This commit is contained in:
+15
-15
@@ -60,10 +60,22 @@ func (r *RootCmd) speedtest() *serpent.Command {
|
||||
if r.disableDirect {
|
||||
_, _ = fmt.Fprintln(inv.Stderr, "Direct connections disabled.")
|
||||
}
|
||||
opts := &workspacesdk.DialAgentOptions{
|
||||
Logger: logger,
|
||||
}
|
||||
if pcapFile != "" {
|
||||
s := capture.New()
|
||||
opts.CaptureHook = s.LogPacket
|
||||
f, err := os.OpenFile(pcapFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
unregister := s.RegisterOutput(f)
|
||||
defer unregister()
|
||||
}
|
||||
conn, err := workspacesdk.New(client).
|
||||
DialAgent(ctx, workspaceAgent.ID, &workspacesdk.DialAgentOptions{
|
||||
Logger: logger,
|
||||
})
|
||||
DialAgent(ctx, workspaceAgent.ID, opts)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -102,18 +114,6 @@ func (r *RootCmd) speedtest() *serpent.Command {
|
||||
conn.AwaitReachable(ctx)
|
||||
}
|
||||
|
||||
if pcapFile != "" {
|
||||
s := capture.New()
|
||||
conn.InstallCaptureHook(s.LogPacket)
|
||||
f, err := os.OpenFile(pcapFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
unregister := s.RegisterOutput(f)
|
||||
defer unregister()
|
||||
}
|
||||
|
||||
var tsDir tsspeedtest.Direction
|
||||
switch direction {
|
||||
case "up":
|
||||
|
||||
Reference in New Issue
Block a user