Skip to content

Commit

Permalink
A function to allow the current source to be reloaded directly
Browse files Browse the repository at this point in the history
I haven't had an API until now because I haven't needed to reload unless
some information has changed - such as the display filter or the pcap
source. However soon the displayed columns will be configurable, so I
want to be able to redisplay. An alternative would be for termshark,
when loading the PSML, to request *every* column; save those internally,
and then just display the columns the user wants to see. I decided
against this because it would use a good deal more memory on larger
pcaps, and I don't imagine changing columns is an operation that is done
on every pcap load. So instead of making every termshark instance pay
the price by loading every column value, I just reload the pcap when the
columns change.
  • Loading branch information
gcla committed Feb 7, 2021
1 parent 260a0ce commit 17cbe2c
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 25 deletions.
40 changes: 16 additions & 24 deletions pcap/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,35 +427,27 @@ func (c *ParentLoader) StopLoadPsmlAndIface(cb interface{}) {

//======================================================================

// NewFilter is essentially a completely new load - psml + pdml. But not iface, if that's running
func (c *PacketLoader) NewFilter(newfilt string, cb interface{}, app gowid.IApp) {

log.Infof("Requested application of display filter '%v'", newfilt)

if c.DisplayFilter() == newfilt {
log.Infof("No operation - same filter applied ('%s').", newfilt)
} else {
c.stopTail()
c.stopLoadPsml()
c.stopLoadPdml()
func (c *PacketLoader) Reload(filter string, cb interface{}, app gowid.IApp) {
c.stopTail()
c.stopLoadPsml()
c.stopLoadPdml()

OpsChan <- gowid.RunFunction(func(app gowid.IApp) {
c.RenewPsmlLoader()
c.RenewPdmlLoader()
OpsChan <- gowid.RunFunction(func(app gowid.IApp) {
c.RenewPsmlLoader()
c.RenewPdmlLoader()

// This is not ideal. I'm clearing the views, but I'm about to
// restart. It's not really a new source, so called the new source
// handler is an untify way of updating the current capture in the
// title bar again
handleClear(NoneCode, app, cb)
// This is not ideal. I'm clearing the views, but I'm about to
// restart. It's not really a new source, so called the new source
// handler is an untify way of updating the current capture in the
// title bar again
handleClear(NoneCode, app, cb)

c.displayFilter = newfilt
c.displayFilter = filter

log.Infof("Applying new display filter '%s'", newfilt)
log.Infof("Applying display filter '%s'", filter)

c.loadPsmlSync(c.InterfaceLoader, c, cb, app)
})
}
c.loadPsmlSync(c.InterfaceLoader, c, cb, app)
})
}

func (c *PacketLoader) LoadPcap(pcap string, displayFilter string, cb interface{}, app gowid.IApp) {
Expand Down
24 changes: 23 additions & 1 deletion ui/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2410,7 +2410,29 @@ func RequestNewFilter(displayFilter string, app gowid.IApp) {
//MakeCancelledMessage(),
}

Loader.NewFilter(displayFilter, handlers, app)
if Loader.DisplayFilter() == displayFilter {
log.Infof("No operation - same filter applied ('%s').", displayFilter)
} else {
Loader.Reload(displayFilter, handlers, app)
}
}

func RequestReload(app gowid.IApp) {
handlers := pcap.HandlerList{
SimpleErrors{},
MakePacketViewUpdater(),
MakeUpdateCurrentCaptureInTitle(),
SetStructWidgets{Loader}, // for OnClear
ClearMarksHandler{},
// Don't use this one - we keep the cancelled flag set so that we
// don't restart live captures on clear if ctrl-c has been issued
// so we don't want this handler on a new filter because we don't
// want to be told again after applying the filter that the load
// was cancelled
//MakeCancelledMessage(),
}

Loader.Reload(Loader.DisplayFilter(), handlers, app)
}

//======================================================================
Expand Down

0 comments on commit 17cbe2c

Please sign in to comment.