From 17cbe2ceb2b814447c325af2de3df056bc251842 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sun, 7 Feb 2021 15:19:08 -0500 Subject: [PATCH] A function to allow the current source to be reloaded directly 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. --- pcap/loader.go | 40 ++++++++++++++++------------------------ ui/ui.go | 24 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/pcap/loader.go b/pcap/loader.go index 4bc8366..a2ae882 100644 --- a/pcap/loader.go +++ b/pcap/loader.go @@ -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) { diff --git a/ui/ui.go b/ui/ui.go index 23ab9f7..4d0e391 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -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) } //======================================================================