Skip to content

Commit

Permalink
A reworking of the tshark pcap loaders
Browse files Browse the repository at this point in the history
This is an attempt to split the responsibilities of the loader from one
giant struct into several structs with mostly distinct roles - there is
still some coordination between them, of course. Furthermore, the
original loader was re-used, so it was essentially a collection of
global variables.

Some of the consequences of this change are:

- various UI handlers, invokved on loader events, are now run in the
  main UI goroutine. Every handler simply used app.Run() to make that
  happen anyway, so this is a simplification. These handlers are also
  run serially, not launched in parallel, guaranteeing an execution
  order. The exception are the error handlers - they still manually
  invoked app.Run() when needed.

- UI handlers are also provided a simple enum to show the source of the
  invocation. This allows e.g. BeforeBegin() handlers to distinguish
  whether this is being called from the PSML loader, PDML loader, etc
  etc. This seemed simpler than muliplying the various handler
  interfaces (BeforeBeginPsml, BeforeBeginPdml, etc etc).

- loaders only change state - Loading <-> NotLoading - in the main
  goroutine. This means I can safely query the loader state from
  anything else running in the main goroutine - no race condition.

- Process lifetimes are managed from a dedicated goroutine per loader -
  so there is no race between termshark invoking kill on a tshark
  process and termshark calling Wait() on the same process.
  • Loading branch information
gcla committed Jan 3, 2021
1 parent 78a426a commit 709b15f
Show file tree
Hide file tree
Showing 12 changed files with 2,415 additions and 2,214 deletions.
14 changes: 9 additions & 5 deletions capinfo/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (c *Loader) loadCapinfoAsync(pcapf string, app gowid.IApp, cb ICapinfoCallb
"command": c.capinfoCmd.String(),
"error": err,
})
pcap.HandleError(cerr, cb)
pcap.HandleError(pcap.CapinfoCode, app, cerr, cb)
}
}

Expand Down Expand Up @@ -154,23 +154,27 @@ func (c *Loader) loadCapinfoAsync(pcapf string, app gowid.IApp, cb ICapinfoCallb

capinfoOut, err := c.capinfoCmd.StdoutReader()
if err != nil {
pcap.HandleError(err, cb)
pcap.HandleError(pcap.CapinfoCode, app, err, cb)
return
}

defer func() {
cb.AfterCapinfoEnd(true)
}()

pcap.HandleBegin(cb)
app.Run(gowid.RunFunction(func(app gowid.IApp) {
pcap.HandleBegin(pcap.CapinfoCode, app, cb)
}))
defer func() {
pcap.HandleEnd(cb)
app.Run(gowid.RunFunction(func(app gowid.IApp) {
pcap.HandleEnd(pcap.CapinfoCode, app, cb)
}))
}()

err = c.capinfoCmd.Start()
if err != nil {
err = fmt.Errorf("Error starting capinfo %v: %v", c.capinfoCmd, err)
pcap.HandleError(err, cb)
pcap.HandleError(pcap.CapinfoCode, app, err, cb)
return
}

Expand Down
Loading

0 comments on commit 709b15f

Please sign in to comment.