From b9aefce83023e2fc81f312fb677d966d0e2d0dbc Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Fri, 8 Jul 2022 21:58:09 -0400 Subject: [PATCH 01/10] Add a summary of stderr to the dialog displayed when tshark fails If a tshark process - run by termshark - returns a non-zero exit code, termshark will send that code and an error string to a UI dialog. But often this is not enough to help you diagnose the problem, and you have to dig through termshark's log file for more info. This change adds a summary of stderr to the error dialog displayed, specifically the first two and last two lines read from the stderr of the failed tshark process. --- CHANGELOG.md | 2 + capinfo/loader.go | 6 +-- cmd/termshark/termshark.go | 2 + convs/loader.go | 6 +-- pcap/cmds.go | 21 ++++++++- pcap/loader.go | 27 +++++------ pkg/summary/summary.go | 95 ++++++++++++++++++++++++++++++++++++++ streams/loader.go | 12 +---- ui/prochandlers.go | 12 +++-- 9 files changed, 143 insertions(+), 40 deletions(-) create mode 100644 pkg/summary/summary.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f5a9f3..8ea62d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ ### Changed +- Added a summary of standard error to the error dialogs displayed when a tshark process fails to run + correctly (has a non-zero exit code). - Fixed a race condition that caused extcap captures (e.g. randpkt) to sporadically fail. - Dark-mode is now the default in the absence of a specific user-setting. - Fixed a bug that caused mouse-clicks within the hex view to not function correctly if the viewport was not diff --git a/capinfo/loader.go b/capinfo/loader.go index 35847d6..16c9c29 100644 --- a/capinfo/loader.go +++ b/capinfo/loader.go @@ -122,11 +122,7 @@ func (c *Loader) loadCapinfoAsync(pcapf string, app gowid.IApp, cb ICapinfoCallb state = pcap.Terminated if !c.SuppressErrors && err != nil { if _, ok := err.(*exec.ExitError); ok { - cerr := gowid.WithKVs(termshark.BadCommand, map[string]interface{}{ - "command": c.capinfoCmd.String(), - "error": err, - }) - pcap.HandleError(pcap.CapinfoCode, app, cerr, cb) + pcap.HandleError(pcap.CapinfoCode, app, pcap.MakeUsefulError(c.capinfoCmd, err), cb) } } diff --git a/cmd/termshark/termshark.go b/cmd/termshark/termshark.go index 138edfe..16132ca 100644 --- a/cmd/termshark/termshark.go +++ b/cmd/termshark/termshark.go @@ -25,6 +25,7 @@ import ( "github.com/gcla/termshark/v2/configs/profiles" "github.com/gcla/termshark/v2/convs" "github.com/gcla/termshark/v2/pcap" + "github.com/gcla/termshark/v2/pkg/summary" "github.com/gcla/termshark/v2/shark" "github.com/gcla/termshark/v2/streams" "github.com/gcla/termshark/v2/system" @@ -62,6 +63,7 @@ func main() { convs.Goroutinewg = &ensureGoroutinesStopWG ui.Goroutinewg = &ensureGoroutinesStopWG wormhole.Goroutinewg = &ensureGoroutinesStopWG + summary.Goroutinewg = &ensureGoroutinesStopWG res := cmain() ensureGoroutinesStopWG.Wait() diff --git a/convs/loader.go b/convs/loader.go index 544925a..c58641f 100644 --- a/convs/loader.go +++ b/convs/loader.go @@ -134,11 +134,7 @@ func (c *Loader) loadConvAsync(pcapf string, convs []string, filter string, abs state = pcap.Terminated if !c.SuppressErrors && err != nil { if _, ok := err.(*exec.ExitError); ok { - cerr := gowid.WithKVs(termshark.BadCommand, map[string]interface{}{ - "command": c.convsCmd.String(), - "error": err, - }) - pcap.HandleError(pcap.ConvCode, app, cerr, cb) + pcap.HandleError(pcap.ConvCode, app, pcap.MakeUsefulError(c.convsCmd, err), cb) } } diff --git a/pcap/cmds.go b/pcap/cmds.go index cdec87f..75caefd 100644 --- a/pcap/cmds.go +++ b/pcap/cmds.go @@ -14,6 +14,7 @@ import ( "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/configs/profiles" + "github.com/gcla/termshark/v2/pkg/summary" "github.com/gcla/termshark/v2/shark" "github.com/kballard/go-shellquote" ) @@ -35,6 +36,8 @@ func (e ProcessNotStarted) Error() string { type Command struct { sync.Mutex *exec.Cmd + summaryReader *summary.Reader + summaryWriter io.Closer } func (c *Command) String() string { @@ -46,14 +49,21 @@ func (c *Command) String() string { func (c *Command) Start() error { c.Lock() defer c.Unlock() - c.Cmd.Stderr = termshark.ErrLogger("cmd", c.Path) + pr, pw := io.Pipe() + c.summaryWriter = pw + c.summaryReader = summary.New(pr) + c.Cmd.Stderr = io.MultiWriter(pw, termshark.ErrLogger("cmd", c.Path)) c.PutInNewGroupOnUnix() res := c.Cmd.Start() return res } func (c *Command) Wait() error { - return c.Cmd.Wait() + err := c.Cmd.Wait() + c.Lock() + c.summaryWriter.Close() + c.Unlock() + return err } func (c *Command) StdoutReader() (io.ReadCloser, error) { @@ -62,6 +72,13 @@ func (c *Command) StdoutReader() (io.ReadCloser, error) { return c.Cmd.StdoutPipe() } +func (c *Command) StderrSummary() []string { + c.Lock() + defer c.Unlock() + + return c.summaryReader.Summary() +} + func (c *Command) SetStdout(w io.Writer) { c.Lock() defer c.Unlock() diff --git a/pcap/loader.go b/pcap/loader.go index d5cc777..50aa2f8 100644 --- a/pcap/loader.go +++ b/pcap/loader.go @@ -93,6 +93,15 @@ type IBasicCommand interface { Wait() error Pid() int Kill() error + StderrSummary() []string +} + +func MakeUsefulError(cmd IBasicCommand, err error) gowid.KeyValueError { + return gowid.WithKVs(termshark.BadCommand, map[string]interface{}{ + "command": cmd.String(), + "error": err, + "stderr": strings.Join(cmd.StderrSummary(), "\n"), + }) } type ITailCommand interface { @@ -1548,11 +1557,7 @@ func (p *PsmlLoader) loadPsmlSync(iloader *InterfaceLoader, e iPsmlLoaderEnv, cb if !p.psmlStoppedDeliberately_ { if err != nil { if _, ok := err.(*exec.ExitError); ok { - cerr := gowid.WithKVs(termshark.BadCommand, map[string]interface{}{ - "command": psmlCmd.String(), - "error": err, - }) - HandleError(PsmlCode, app, cerr, cb) + HandleError(PsmlCode, app, MakeUsefulError(psmlCmd, err), cb) } } } @@ -1676,11 +1681,7 @@ func (p *PsmlLoader) loadPsmlSync(iloader *InterfaceLoader, e iPsmlLoaderEnv, cb if !p.psmlStoppedDeliberately_ && !e.TailStoppedDeliberately() { if err != nil { if _, ok := err.(*exec.ExitError); ok { - cerr := gowid.WithKVs(termshark.BadCommand, map[string]interface{}{ - "command": tailCmd.String(), - "error": err, - }) - HandleError(PsmlCode, app, cerr, cb) + HandleError(PsmlCode, app, MakeUsefulError(tailCmd, err), cb) } } } @@ -2144,11 +2145,7 @@ func (i *InterfaceLoader) loadIfacesSync(e iIfaceLoaderEnv, cb interface{}, app // This could be if termshark is started like this: cat nosuchfile.pcap | termshark -i - // Then dumpcap will be started with /dev/fd/3 as its stdin, but will fail with EOF and // exit status 1. - cerr := gowid.WithKVs(termshark.BadCommand, map[string]interface{}{ - "command": ifaceCmd.String(), - "error": err, - }) - HandleError(IfaceCode, app, cerr, cb) + HandleError(IfaceCode, app, MakeUsefulError(ifaceCmd, err), cb) } } diff --git a/pkg/summary/summary.go b/pkg/summary/summary.go new file mode 100644 index 0000000..62e7542 --- /dev/null +++ b/pkg/summary/summary.go @@ -0,0 +1,95 @@ +// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source +// code is governed by the MIT license that can be found in the LICENSE +// file. + +package summary + +import ( + "bufio" + "io" + "sync" + + "github.com/gcla/termshark/v2" +) + +//====================================================================== + +// Reader maintains the first two and last two lines read from a source io.Reader. +// At any point, the Summary() function can be called to extract a summary of +// what's been read so far. I'm using this to create a summary of the stderr of +// a termshark command. +type Reader struct { + source io.Reader + first *string + second *string + penultimate *string + last *string + num int + lock sync.Mutex +} + +func New(source io.Reader) *Reader { + res := &Reader{ + source: source, + } + + termshark.TrackedGo(func() { + res.start() + }, Goroutinewg) + + return res +} + +func (h *Reader) Summary() []string { + h.lock.Lock() + defer h.lock.Unlock() + + res := make([]string, 0, 5) + if h.num >= 1 { + res = append(res, *h.first) + } + if h.num >= 2 { + res = append(res, *h.second) + } + if h.num >= 5 { + res = append(res, "...") + } + if h.num >= 4 { + res = append(res, *h.penultimate) + } + if h.num >= 3 { + res = append(res, *h.last) + } + + return res +} + +func (h *Reader) start() { + scanner := bufio.NewScanner(h.source) + for scanner.Scan() { + line := scanner.Text() + h.lock.Lock() + h.num += 1 + if h.first == nil { + h.first = &line + } else if h.second == nil { + h.second = &line + } + + h.penultimate = h.last + h.last = &line + h.lock.Unlock() + } +} + +//====================================================================== + +// This is a debugging aid - I use it to ensure goroutines stop as expected. If they don't +// the main program will hang at termination. +var Goroutinewg *sync.WaitGroup + +//====================================================================== +// Local Variables: +// mode: Go +// fill-column: 78 +// End: diff --git a/streams/loader.go b/streams/loader.go index 604cd2d..eb9ff7b 100644 --- a/streams/loader.go +++ b/streams/loader.go @@ -155,11 +155,7 @@ func (c *Loader) loadStreamReassemblyAsync(pcapf string, proto string, idx int, state = pcap.Terminated if !c.SuppressErrors && err != nil { if _, ok := err.(*exec.ExitError); ok { - cerr := gowid.WithKVs(termshark.BadCommand, map[string]interface{}{ - "command": c.streamCmd.String(), - "error": err, - }) - pcap.HandleError(pcap.StreamCode, app, cerr, cb) + pcap.HandleError(pcap.StreamCode, app, pcap.MakeUsefulError(c.streamCmd, err), cb) } } @@ -274,11 +270,7 @@ func (c *Loader) startStreamIndexerAsync(pcapf string, proto string, idx int, ap state = pcap.Terminated if !c.SuppressErrors && err != nil { if _, ok := err.(*exec.ExitError); ok { - cerr := gowid.WithKVs(termshark.BadCommand, map[string]interface{}{ - "command": c.indexerCmd.String(), - "error": err, - }) - pcap.HandleError(pcap.StreamCode, app, cerr, cb) + pcap.HandleError(pcap.StreamCode, app, pcap.MakeUsefulError(c.indexerCmd, err), cb) } } streamOut.Close() diff --git a/ui/prochandlers.go b/ui/prochandlers.go index 4dc53a5..b06251b 100644 --- a/ui/prochandlers.go +++ b/ui/prochandlers.go @@ -8,6 +8,7 @@ package ui import ( "fmt" "os" + "sort" "strings" "time" @@ -126,10 +127,15 @@ func (t updatePacketViews) OnError(code pcap.HandlerCode, app gowid.IApp, err er if kverr, ok := err.(gowid.KeyValueError); ok { errstr = fmt.Sprintf("%v\n\n", kverr.Cause()) kvs := make([]string, 0, len(kverr.KeyVals)) - for k, v := range kverr.KeyVals { - kvs = append(kvs, fmt.Sprintf("%v: %v", k, v)) + ks := make([]string, 0, len(kverr.KeyVals)) + for k := range kverr.KeyVals { + ks = append(ks, k) } - errstr = errstr + strings.Join(kvs, "\n") + sort.Sort(sort.StringSlice(ks)) + for _, k := range ks { + kvs = append(kvs, fmt.Sprintf("%v: %v", k, kverr.KeyVals[k])) + } + errstr = errstr + strings.Join(kvs, "\n\n") } else { errstr = fmt.Sprintf("%v", err) } From 785fd48872e874f08f1dbcd21d0a9751ea9bcf1a Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Fri, 8 Jul 2022 22:22:37 -0400 Subject: [PATCH 02/10] Move capinfo under pkg This follows the golang repo guide better and also starts to clean up the top-level which is more than a page when you open termshark on github... --- cmd/termshark/termshark.go | 2 +- {capinfo => pkg/capinfo}/loader.go | 0 ui/capinfoui.go | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename {capinfo => pkg/capinfo}/loader.go (100%) diff --git a/cmd/termshark/termshark.go b/cmd/termshark/termshark.go index 16132ca..2c46a1f 100644 --- a/cmd/termshark/termshark.go +++ b/cmd/termshark/termshark.go @@ -20,7 +20,7 @@ import ( "github.com/blang/semver" "github.com/gcla/gowid" "github.com/gcla/termshark/v2" - "github.com/gcla/termshark/v2/capinfo" + "github.com/gcla/termshark/v2/pkg/capinfo" "github.com/gcla/termshark/v2/cli" "github.com/gcla/termshark/v2/configs/profiles" "github.com/gcla/termshark/v2/convs" diff --git a/capinfo/loader.go b/pkg/capinfo/loader.go similarity index 100% rename from capinfo/loader.go rename to pkg/capinfo/loader.go diff --git a/ui/capinfoui.go b/ui/capinfoui.go index 5be2a1c..8699903 100644 --- a/ui/capinfoui.go +++ b/ui/capinfoui.go @@ -12,7 +12,7 @@ import ( "github.com/gcla/gowid" "github.com/gcla/termshark/v2" - "github.com/gcla/termshark/v2/capinfo" + "github.com/gcla/termshark/v2/pkg/capinfo" "github.com/gcla/termshark/v2/pcap" log "github.com/sirupsen/logrus" ) From a09eb2a09931245ddb5bb5154e5c31a7e63dbcfc Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Fri, 8 Jul 2022 22:24:56 -0400 Subject: [PATCH 03/10] Move more top-level packages under pkg --- cmd/termshark/termshark.go | 12 ++++++------ pkg/capinfo/loader.go | 2 +- {convs => pkg/convs}/loader.go | 2 +- {convs => pkg/convs}/types.go | 0 {format => pkg/format}/hexdump.go | 0 {format => pkg/format}/hexdump_test.go | 0 {format => pkg/format}/printable.go | 0 {pcap => pkg/pcap}/cmds.go | 2 +- {pcap => pkg/pcap}/cmds_unix.go | 0 {pcap => pkg/pcap}/cmds_windows.go | 0 {pcap => pkg/pcap}/handlers.go | 0 {pcap => pkg/pcap}/loader.go | 2 +- {pcap => pkg/pcap}/loader_tshark_test.go | 0 {pcap => pkg/pcap}/pdml.go | 0 {pcap => pkg/pcap}/source.go | 2 +- {pcap => pkg/pcap}/testdata/1.hexdump | 0 {pcap => pkg/pcap}/testdata/1.pcap | Bin {pcap => pkg/pcap}/testdata/1.pdml | 0 {pcap => pkg/pcap}/testdata/1.psml | 0 {pcap => pkg/pcap}/testdata/2.hexdump-body | 0 {pcap => pkg/pcap}/testdata/2.hexdump-footer | 0 {pcap => pkg/pcap}/testdata/2.hexdump-header | 0 {pcap => pkg/pcap}/testdata/2.pcap-body | Bin {pcap => pkg/pcap}/testdata/2.pcap-footer | 0 {pcap => pkg/pcap}/testdata/2.pcap-header | Bin {pcap => pkg/pcap}/testdata/2.pdml-body | 0 {pcap => pkg/pcap}/testdata/2.pdml-footer | 0 {pcap => pkg/pcap}/testdata/2.pdml-header | 0 {pcap => pkg/pcap}/testdata/2.psml-body | 0 {pcap => pkg/pcap}/testdata/2.psml-footer | 0 {pcap => pkg/pcap}/testdata/2.psml-header | 0 {pcap => pkg/pcap}/utils.go | 0 {pdmltree => pkg/pdmltree}/pdmltree.go | 0 {pdmltree => pkg/pdmltree}/pdmltree_test.go | 0 {psmlmodel => pkg/psmlmodel}/model.go | 0 {shark => pkg/shark}/columnformat.go | 0 {shark => pkg/shark}/columnformat_test.go | 0 {shark => pkg/shark}/wiresharkcfg/cfg.go | 0 {shark => pkg/shark}/wiresharkcfg/parser.go | 0 {shark => pkg/shark}/wiresharkcfg/parser.peg | 0 {shark => pkg/shark}/wiresharkcfg/parser_test.go | 0 {streams => pkg/streams}/follow.go | 0 {streams => pkg/streams}/follow.peg | 0 {streams => pkg/streams}/follow_test.go | 0 {streams => pkg/streams}/loader.go | 2 +- {streams => pkg/streams}/loader_test.go | 0 {streams => pkg/streams}/parse.go | 0 {system => pkg/system}/dumpcapext.go | 0 {system => pkg/system}/dumpcapext_arm64.go | 0 {system => pkg/system}/dumpcapext_darwin.go | 0 {system => pkg/system}/dumpcapext_windows.go | 0 {system => pkg/system}/dup.go | 0 {system => pkg/system}/dup_linux_arm64.go | 0 {system => pkg/system}/dup_linux_riscv64.go | 0 {system => pkg/system}/errors.go | 0 {system => pkg/system}/extcmds.go | 0 {system => pkg/system}/extcmds_android.go | 0 {system => pkg/system}/extcmds_darwin.go | 0 {system => pkg/system}/extcmds_windows.go | 0 {system => pkg/system}/fd.go | 0 {system => pkg/system}/fd_windows.go | 0 {system => pkg/system}/fdinfo.go | 0 {system => pkg/system}/have_fdinfo.go | 0 {system => pkg/system}/have_fdinfo_linux.go | 0 {system => pkg/system}/picker.go | 0 {system => pkg/system}/picker_android.go | 0 {system => pkg/system}/signals.go | 0 {system => pkg/system}/signals_windows.go | 0 {theme => pkg/theme}/modeswap/modeswap.go | 0 {theme => pkg/theme}/utils.go | 0 {tty => pkg/tty}/tty.go | 0 {tty => pkg/tty}/tty_windows.go | 0 ui/capinfoui.go | 2 +- ui/convscallbacks.go | 2 +- ui/convsui.go | 6 +++--- ui/lastline.go | 2 +- ui/palette.go | 2 +- ui/prochandlers.go | 2 +- ui/psmlcols.go | 4 ++-- ui/psmlcolsmodel.go | 4 ++-- ui/searchalg.go | 2 +- ui/searchbyfilter.go | 4 ++-- ui/searchpktbytes.go | 2 +- ui/searchpktstruct.go | 2 +- ui/streamui.go | 6 +++--- ui/ui.go | 12 ++++++------ utils.go | 2 +- utils_test.go | 2 +- widgets/copymodetree/copymodetree.go | 2 +- widgets/hexdumper/hexdumper.go | 2 +- widgets/hexdumper2/hexdumper2.go | 2 +- widgets/streamwidget/streamwidget.go | 4 ++-- 92 files changed, 45 insertions(+), 45 deletions(-) rename {convs => pkg/convs}/loader.go (99%) rename {convs => pkg/convs}/types.go (100%) rename {format => pkg/format}/hexdump.go (100%) rename {format => pkg/format}/hexdump_test.go (100%) rename {format => pkg/format}/printable.go (100%) rename {pcap => pkg/pcap}/cmds.go (99%) rename {pcap => pkg/pcap}/cmds_unix.go (100%) rename {pcap => pkg/pcap}/cmds_windows.go (100%) rename {pcap => pkg/pcap}/handlers.go (100%) rename {pcap => pkg/pcap}/loader.go (99%) rename {pcap => pkg/pcap}/loader_tshark_test.go (100%) rename {pcap => pkg/pcap}/pdml.go (100%) rename {pcap => pkg/pcap}/source.go (98%) rename {pcap => pkg/pcap}/testdata/1.hexdump (100%) rename {pcap => pkg/pcap}/testdata/1.pcap (100%) rename {pcap => pkg/pcap}/testdata/1.pdml (100%) rename {pcap => pkg/pcap}/testdata/1.psml (100%) rename {pcap => pkg/pcap}/testdata/2.hexdump-body (100%) rename {pcap => pkg/pcap}/testdata/2.hexdump-footer (100%) rename {pcap => pkg/pcap}/testdata/2.hexdump-header (100%) rename {pcap => pkg/pcap}/testdata/2.pcap-body (100%) rename {pcap => pkg/pcap}/testdata/2.pcap-footer (100%) rename {pcap => pkg/pcap}/testdata/2.pcap-header (100%) rename {pcap => pkg/pcap}/testdata/2.pdml-body (100%) rename {pcap => pkg/pcap}/testdata/2.pdml-footer (100%) rename {pcap => pkg/pcap}/testdata/2.pdml-header (100%) rename {pcap => pkg/pcap}/testdata/2.psml-body (100%) rename {pcap => pkg/pcap}/testdata/2.psml-footer (100%) rename {pcap => pkg/pcap}/testdata/2.psml-header (100%) rename {pcap => pkg/pcap}/utils.go (100%) rename {pdmltree => pkg/pdmltree}/pdmltree.go (100%) rename {pdmltree => pkg/pdmltree}/pdmltree_test.go (100%) rename {psmlmodel => pkg/psmlmodel}/model.go (100%) rename {shark => pkg/shark}/columnformat.go (100%) rename {shark => pkg/shark}/columnformat_test.go (100%) rename {shark => pkg/shark}/wiresharkcfg/cfg.go (100%) rename {shark => pkg/shark}/wiresharkcfg/parser.go (100%) rename {shark => pkg/shark}/wiresharkcfg/parser.peg (100%) rename {shark => pkg/shark}/wiresharkcfg/parser_test.go (100%) rename {streams => pkg/streams}/follow.go (100%) rename {streams => pkg/streams}/follow.peg (100%) rename {streams => pkg/streams}/follow_test.go (100%) rename {streams => pkg/streams}/loader.go (99%) rename {streams => pkg/streams}/loader_test.go (100%) rename {streams => pkg/streams}/parse.go (100%) rename {system => pkg/system}/dumpcapext.go (100%) rename {system => pkg/system}/dumpcapext_arm64.go (100%) rename {system => pkg/system}/dumpcapext_darwin.go (100%) rename {system => pkg/system}/dumpcapext_windows.go (100%) rename {system => pkg/system}/dup.go (100%) rename {system => pkg/system}/dup_linux_arm64.go (100%) rename {system => pkg/system}/dup_linux_riscv64.go (100%) rename {system => pkg/system}/errors.go (100%) rename {system => pkg/system}/extcmds.go (100%) rename {system => pkg/system}/extcmds_android.go (100%) rename {system => pkg/system}/extcmds_darwin.go (100%) rename {system => pkg/system}/extcmds_windows.go (100%) rename {system => pkg/system}/fd.go (100%) rename {system => pkg/system}/fd_windows.go (100%) rename {system => pkg/system}/fdinfo.go (100%) rename {system => pkg/system}/have_fdinfo.go (100%) rename {system => pkg/system}/have_fdinfo_linux.go (100%) rename {system => pkg/system}/picker.go (100%) rename {system => pkg/system}/picker_android.go (100%) rename {system => pkg/system}/signals.go (100%) rename {system => pkg/system}/signals_windows.go (100%) rename {theme => pkg/theme}/modeswap/modeswap.go (100%) rename {theme => pkg/theme}/utils.go (100%) rename {tty => pkg/tty}/tty.go (100%) rename {tty => pkg/tty}/tty_windows.go (100%) diff --git a/cmd/termshark/termshark.go b/cmd/termshark/termshark.go index 2c46a1f..7f968d9 100644 --- a/cmd/termshark/termshark.go +++ b/cmd/termshark/termshark.go @@ -23,13 +23,13 @@ import ( "github.com/gcla/termshark/v2/pkg/capinfo" "github.com/gcla/termshark/v2/cli" "github.com/gcla/termshark/v2/configs/profiles" - "github.com/gcla/termshark/v2/convs" - "github.com/gcla/termshark/v2/pcap" + "github.com/gcla/termshark/v2/pkg/convs" + "github.com/gcla/termshark/v2/pkg/pcap" "github.com/gcla/termshark/v2/pkg/summary" - "github.com/gcla/termshark/v2/shark" - "github.com/gcla/termshark/v2/streams" - "github.com/gcla/termshark/v2/system" - "github.com/gcla/termshark/v2/tty" + "github.com/gcla/termshark/v2/pkg/shark" + "github.com/gcla/termshark/v2/pkg/streams" + "github.com/gcla/termshark/v2/pkg/system" + "github.com/gcla/termshark/v2/pkg/tty" "github.com/gcla/termshark/v2/ui" "github.com/gcla/termshark/v2/widgets/filter" "github.com/gcla/termshark/v2/widgets/wormhole" diff --git a/pkg/capinfo/loader.go b/pkg/capinfo/loader.go index 16c9c29..bd2a83b 100644 --- a/pkg/capinfo/loader.go +++ b/pkg/capinfo/loader.go @@ -13,7 +13,7 @@ import ( "github.com/gcla/gowid" "github.com/gcla/termshark/v2" - "github.com/gcla/termshark/v2/pcap" + "github.com/gcla/termshark/v2/pkg/pcap" log "github.com/sirupsen/logrus" ) diff --git a/convs/loader.go b/pkg/convs/loader.go similarity index 99% rename from convs/loader.go rename to pkg/convs/loader.go index c58641f..c9b281b 100644 --- a/convs/loader.go +++ b/pkg/convs/loader.go @@ -13,7 +13,7 @@ import ( "github.com/gcla/gowid" "github.com/gcla/termshark/v2" - "github.com/gcla/termshark/v2/pcap" + "github.com/gcla/termshark/v2/pkg/pcap" log "github.com/sirupsen/logrus" ) diff --git a/convs/types.go b/pkg/convs/types.go similarity index 100% rename from convs/types.go rename to pkg/convs/types.go diff --git a/format/hexdump.go b/pkg/format/hexdump.go similarity index 100% rename from format/hexdump.go rename to pkg/format/hexdump.go diff --git a/format/hexdump_test.go b/pkg/format/hexdump_test.go similarity index 100% rename from format/hexdump_test.go rename to pkg/format/hexdump_test.go diff --git a/format/printable.go b/pkg/format/printable.go similarity index 100% rename from format/printable.go rename to pkg/format/printable.go diff --git a/pcap/cmds.go b/pkg/pcap/cmds.go similarity index 99% rename from pcap/cmds.go rename to pkg/pcap/cmds.go index 75caefd..1653a15 100644 --- a/pcap/cmds.go +++ b/pkg/pcap/cmds.go @@ -15,7 +15,7 @@ import ( "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/configs/profiles" "github.com/gcla/termshark/v2/pkg/summary" - "github.com/gcla/termshark/v2/shark" + "github.com/gcla/termshark/v2/pkg/shark" "github.com/kballard/go-shellquote" ) diff --git a/pcap/cmds_unix.go b/pkg/pcap/cmds_unix.go similarity index 100% rename from pcap/cmds_unix.go rename to pkg/pcap/cmds_unix.go diff --git a/pcap/cmds_windows.go b/pkg/pcap/cmds_windows.go similarity index 100% rename from pcap/cmds_windows.go rename to pkg/pcap/cmds_windows.go diff --git a/pcap/handlers.go b/pkg/pcap/handlers.go similarity index 100% rename from pcap/handlers.go rename to pkg/pcap/handlers.go diff --git a/pcap/loader.go b/pkg/pcap/loader.go similarity index 99% rename from pcap/loader.go rename to pkg/pcap/loader.go index 50aa2f8..1267276 100644 --- a/pcap/loader.go +++ b/pkg/pcap/loader.go @@ -22,7 +22,7 @@ import ( "github.com/gcla/gowid" "github.com/gcla/gowid/gwutil" "github.com/gcla/termshark/v2" - "github.com/gcla/termshark/v2/format" + "github.com/gcla/termshark/v2/pkg/format" lru "github.com/hashicorp/golang-lru" log "github.com/sirupsen/logrus" fsnotify "gopkg.in/fsnotify/fsnotify.v1" diff --git a/pcap/loader_tshark_test.go b/pkg/pcap/loader_tshark_test.go similarity index 100% rename from pcap/loader_tshark_test.go rename to pkg/pcap/loader_tshark_test.go diff --git a/pcap/pdml.go b/pkg/pcap/pdml.go similarity index 100% rename from pcap/pdml.go rename to pkg/pcap/pdml.go diff --git a/pcap/source.go b/pkg/pcap/source.go similarity index 98% rename from pcap/source.go rename to pkg/pcap/source.go index c5788b1..660631a 100644 --- a/pcap/source.go +++ b/pkg/pcap/source.go @@ -9,7 +9,7 @@ import ( "os" "strings" - "github.com/gcla/termshark/v2/system" + "github.com/gcla/termshark/v2/pkg/system" ) //====================================================================== diff --git a/pcap/testdata/1.hexdump b/pkg/pcap/testdata/1.hexdump similarity index 100% rename from pcap/testdata/1.hexdump rename to pkg/pcap/testdata/1.hexdump diff --git a/pcap/testdata/1.pcap b/pkg/pcap/testdata/1.pcap similarity index 100% rename from pcap/testdata/1.pcap rename to pkg/pcap/testdata/1.pcap diff --git a/pcap/testdata/1.pdml b/pkg/pcap/testdata/1.pdml similarity index 100% rename from pcap/testdata/1.pdml rename to pkg/pcap/testdata/1.pdml diff --git a/pcap/testdata/1.psml b/pkg/pcap/testdata/1.psml similarity index 100% rename from pcap/testdata/1.psml rename to pkg/pcap/testdata/1.psml diff --git a/pcap/testdata/2.hexdump-body b/pkg/pcap/testdata/2.hexdump-body similarity index 100% rename from pcap/testdata/2.hexdump-body rename to pkg/pcap/testdata/2.hexdump-body diff --git a/pcap/testdata/2.hexdump-footer b/pkg/pcap/testdata/2.hexdump-footer similarity index 100% rename from pcap/testdata/2.hexdump-footer rename to pkg/pcap/testdata/2.hexdump-footer diff --git a/pcap/testdata/2.hexdump-header b/pkg/pcap/testdata/2.hexdump-header similarity index 100% rename from pcap/testdata/2.hexdump-header rename to pkg/pcap/testdata/2.hexdump-header diff --git a/pcap/testdata/2.pcap-body b/pkg/pcap/testdata/2.pcap-body similarity index 100% rename from pcap/testdata/2.pcap-body rename to pkg/pcap/testdata/2.pcap-body diff --git a/pcap/testdata/2.pcap-footer b/pkg/pcap/testdata/2.pcap-footer similarity index 100% rename from pcap/testdata/2.pcap-footer rename to pkg/pcap/testdata/2.pcap-footer diff --git a/pcap/testdata/2.pcap-header b/pkg/pcap/testdata/2.pcap-header similarity index 100% rename from pcap/testdata/2.pcap-header rename to pkg/pcap/testdata/2.pcap-header diff --git a/pcap/testdata/2.pdml-body b/pkg/pcap/testdata/2.pdml-body similarity index 100% rename from pcap/testdata/2.pdml-body rename to pkg/pcap/testdata/2.pdml-body diff --git a/pcap/testdata/2.pdml-footer b/pkg/pcap/testdata/2.pdml-footer similarity index 100% rename from pcap/testdata/2.pdml-footer rename to pkg/pcap/testdata/2.pdml-footer diff --git a/pcap/testdata/2.pdml-header b/pkg/pcap/testdata/2.pdml-header similarity index 100% rename from pcap/testdata/2.pdml-header rename to pkg/pcap/testdata/2.pdml-header diff --git a/pcap/testdata/2.psml-body b/pkg/pcap/testdata/2.psml-body similarity index 100% rename from pcap/testdata/2.psml-body rename to pkg/pcap/testdata/2.psml-body diff --git a/pcap/testdata/2.psml-footer b/pkg/pcap/testdata/2.psml-footer similarity index 100% rename from pcap/testdata/2.psml-footer rename to pkg/pcap/testdata/2.psml-footer diff --git a/pcap/testdata/2.psml-header b/pkg/pcap/testdata/2.psml-header similarity index 100% rename from pcap/testdata/2.psml-header rename to pkg/pcap/testdata/2.psml-header diff --git a/pcap/utils.go b/pkg/pcap/utils.go similarity index 100% rename from pcap/utils.go rename to pkg/pcap/utils.go diff --git a/pdmltree/pdmltree.go b/pkg/pdmltree/pdmltree.go similarity index 100% rename from pdmltree/pdmltree.go rename to pkg/pdmltree/pdmltree.go diff --git a/pdmltree/pdmltree_test.go b/pkg/pdmltree/pdmltree_test.go similarity index 100% rename from pdmltree/pdmltree_test.go rename to pkg/pdmltree/pdmltree_test.go diff --git a/psmlmodel/model.go b/pkg/psmlmodel/model.go similarity index 100% rename from psmlmodel/model.go rename to pkg/psmlmodel/model.go diff --git a/shark/columnformat.go b/pkg/shark/columnformat.go similarity index 100% rename from shark/columnformat.go rename to pkg/shark/columnformat.go diff --git a/shark/columnformat_test.go b/pkg/shark/columnformat_test.go similarity index 100% rename from shark/columnformat_test.go rename to pkg/shark/columnformat_test.go diff --git a/shark/wiresharkcfg/cfg.go b/pkg/shark/wiresharkcfg/cfg.go similarity index 100% rename from shark/wiresharkcfg/cfg.go rename to pkg/shark/wiresharkcfg/cfg.go diff --git a/shark/wiresharkcfg/parser.go b/pkg/shark/wiresharkcfg/parser.go similarity index 100% rename from shark/wiresharkcfg/parser.go rename to pkg/shark/wiresharkcfg/parser.go diff --git a/shark/wiresharkcfg/parser.peg b/pkg/shark/wiresharkcfg/parser.peg similarity index 100% rename from shark/wiresharkcfg/parser.peg rename to pkg/shark/wiresharkcfg/parser.peg diff --git a/shark/wiresharkcfg/parser_test.go b/pkg/shark/wiresharkcfg/parser_test.go similarity index 100% rename from shark/wiresharkcfg/parser_test.go rename to pkg/shark/wiresharkcfg/parser_test.go diff --git a/streams/follow.go b/pkg/streams/follow.go similarity index 100% rename from streams/follow.go rename to pkg/streams/follow.go diff --git a/streams/follow.peg b/pkg/streams/follow.peg similarity index 100% rename from streams/follow.peg rename to pkg/streams/follow.peg diff --git a/streams/follow_test.go b/pkg/streams/follow_test.go similarity index 100% rename from streams/follow_test.go rename to pkg/streams/follow_test.go diff --git a/streams/loader.go b/pkg/streams/loader.go similarity index 99% rename from streams/loader.go rename to pkg/streams/loader.go index eb9ff7b..23209fc 100644 --- a/streams/loader.go +++ b/pkg/streams/loader.go @@ -15,7 +15,7 @@ import ( "github.com/gcla/gowid" "github.com/gcla/termshark/v2" - "github.com/gcla/termshark/v2/pcap" + "github.com/gcla/termshark/v2/pkg/pcap" log "github.com/sirupsen/logrus" ) diff --git a/streams/loader_test.go b/pkg/streams/loader_test.go similarity index 100% rename from streams/loader_test.go rename to pkg/streams/loader_test.go diff --git a/streams/parse.go b/pkg/streams/parse.go similarity index 100% rename from streams/parse.go rename to pkg/streams/parse.go diff --git a/system/dumpcapext.go b/pkg/system/dumpcapext.go similarity index 100% rename from system/dumpcapext.go rename to pkg/system/dumpcapext.go diff --git a/system/dumpcapext_arm64.go b/pkg/system/dumpcapext_arm64.go similarity index 100% rename from system/dumpcapext_arm64.go rename to pkg/system/dumpcapext_arm64.go diff --git a/system/dumpcapext_darwin.go b/pkg/system/dumpcapext_darwin.go similarity index 100% rename from system/dumpcapext_darwin.go rename to pkg/system/dumpcapext_darwin.go diff --git a/system/dumpcapext_windows.go b/pkg/system/dumpcapext_windows.go similarity index 100% rename from system/dumpcapext_windows.go rename to pkg/system/dumpcapext_windows.go diff --git a/system/dup.go b/pkg/system/dup.go similarity index 100% rename from system/dup.go rename to pkg/system/dup.go diff --git a/system/dup_linux_arm64.go b/pkg/system/dup_linux_arm64.go similarity index 100% rename from system/dup_linux_arm64.go rename to pkg/system/dup_linux_arm64.go diff --git a/system/dup_linux_riscv64.go b/pkg/system/dup_linux_riscv64.go similarity index 100% rename from system/dup_linux_riscv64.go rename to pkg/system/dup_linux_riscv64.go diff --git a/system/errors.go b/pkg/system/errors.go similarity index 100% rename from system/errors.go rename to pkg/system/errors.go diff --git a/system/extcmds.go b/pkg/system/extcmds.go similarity index 100% rename from system/extcmds.go rename to pkg/system/extcmds.go diff --git a/system/extcmds_android.go b/pkg/system/extcmds_android.go similarity index 100% rename from system/extcmds_android.go rename to pkg/system/extcmds_android.go diff --git a/system/extcmds_darwin.go b/pkg/system/extcmds_darwin.go similarity index 100% rename from system/extcmds_darwin.go rename to pkg/system/extcmds_darwin.go diff --git a/system/extcmds_windows.go b/pkg/system/extcmds_windows.go similarity index 100% rename from system/extcmds_windows.go rename to pkg/system/extcmds_windows.go diff --git a/system/fd.go b/pkg/system/fd.go similarity index 100% rename from system/fd.go rename to pkg/system/fd.go diff --git a/system/fd_windows.go b/pkg/system/fd_windows.go similarity index 100% rename from system/fd_windows.go rename to pkg/system/fd_windows.go diff --git a/system/fdinfo.go b/pkg/system/fdinfo.go similarity index 100% rename from system/fdinfo.go rename to pkg/system/fdinfo.go diff --git a/system/have_fdinfo.go b/pkg/system/have_fdinfo.go similarity index 100% rename from system/have_fdinfo.go rename to pkg/system/have_fdinfo.go diff --git a/system/have_fdinfo_linux.go b/pkg/system/have_fdinfo_linux.go similarity index 100% rename from system/have_fdinfo_linux.go rename to pkg/system/have_fdinfo_linux.go diff --git a/system/picker.go b/pkg/system/picker.go similarity index 100% rename from system/picker.go rename to pkg/system/picker.go diff --git a/system/picker_android.go b/pkg/system/picker_android.go similarity index 100% rename from system/picker_android.go rename to pkg/system/picker_android.go diff --git a/system/signals.go b/pkg/system/signals.go similarity index 100% rename from system/signals.go rename to pkg/system/signals.go diff --git a/system/signals_windows.go b/pkg/system/signals_windows.go similarity index 100% rename from system/signals_windows.go rename to pkg/system/signals_windows.go diff --git a/theme/modeswap/modeswap.go b/pkg/theme/modeswap/modeswap.go similarity index 100% rename from theme/modeswap/modeswap.go rename to pkg/theme/modeswap/modeswap.go diff --git a/theme/utils.go b/pkg/theme/utils.go similarity index 100% rename from theme/utils.go rename to pkg/theme/utils.go diff --git a/tty/tty.go b/pkg/tty/tty.go similarity index 100% rename from tty/tty.go rename to pkg/tty/tty.go diff --git a/tty/tty_windows.go b/pkg/tty/tty_windows.go similarity index 100% rename from tty/tty_windows.go rename to pkg/tty/tty_windows.go diff --git a/ui/capinfoui.go b/ui/capinfoui.go index 8699903..b14135f 100644 --- a/ui/capinfoui.go +++ b/ui/capinfoui.go @@ -13,7 +13,7 @@ import ( "github.com/gcla/gowid" "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/pkg/capinfo" - "github.com/gcla/termshark/v2/pcap" + "github.com/gcla/termshark/v2/pkg/pcap" log "github.com/sirupsen/logrus" ) diff --git a/ui/convscallbacks.go b/ui/convscallbacks.go index 332df46..ec7a947 100644 --- a/ui/convscallbacks.go +++ b/ui/convscallbacks.go @@ -11,7 +11,7 @@ import ( "github.com/gcla/gowid" "github.com/gcla/termshark/v2" - "github.com/gcla/termshark/v2/pcap" + "github.com/gcla/termshark/v2/pkg/pcap" ) //====================================================================== diff --git a/ui/convsui.go b/ui/convsui.go index 3f7f62e..825d633 100644 --- a/ui/convsui.go +++ b/ui/convsui.go @@ -32,9 +32,9 @@ import ( "github.com/gcla/gowid/widgets/vpadding" "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/configs/profiles" - "github.com/gcla/termshark/v2/convs" - "github.com/gcla/termshark/v2/pcap" - "github.com/gcla/termshark/v2/psmlmodel" + "github.com/gcla/termshark/v2/pkg/convs" + "github.com/gcla/termshark/v2/pkg/pcap" + "github.com/gcla/termshark/v2/pkg/psmlmodel" "github.com/gcla/termshark/v2/ui/tableutil" "github.com/gcla/termshark/v2/widgets/appkeys" "github.com/gcla/termshark/v2/widgets/copymodetable" diff --git a/ui/lastline.go b/ui/lastline.go index ed8ed07..9993a61 100644 --- a/ui/lastline.go +++ b/ui/lastline.go @@ -17,7 +17,7 @@ import ( "github.com/gcla/gowid/vim" "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/configs/profiles" - "github.com/gcla/termshark/v2/theme" + "github.com/gcla/termshark/v2/pkg/theme" "github.com/gcla/termshark/v2/widgets/mapkeys" "github.com/gcla/termshark/v2/widgets/minibuffer" "github.com/rakyll/statik/fs" diff --git a/ui/palette.go b/ui/palette.go index b8ee21f..ccb4cb1 100644 --- a/ui/palette.go +++ b/ui/palette.go @@ -9,7 +9,7 @@ import ( "fmt" "github.com/gcla/gowid" - "github.com/gcla/termshark/v2/theme" + "github.com/gcla/termshark/v2/pkg/theme" log "github.com/sirupsen/logrus" ) diff --git a/ui/prochandlers.go b/ui/prochandlers.go index b06251b..a0401de 100644 --- a/ui/prochandlers.go +++ b/ui/prochandlers.go @@ -16,7 +16,7 @@ import ( "github.com/gcla/gowid/widgets/table" "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/configs/profiles" - "github.com/gcla/termshark/v2/pcap" + "github.com/gcla/termshark/v2/pkg/pcap" log "github.com/sirupsen/logrus" ) diff --git a/ui/psmlcols.go b/ui/psmlcols.go index 3b4de19..808d700 100644 --- a/ui/psmlcols.go +++ b/ui/psmlcols.go @@ -26,8 +26,8 @@ import ( "github.com/gcla/gowid/widgets/table" "github.com/gcla/gowid/widgets/text" "github.com/gcla/termshark/v2/configs/profiles" - "github.com/gcla/termshark/v2/shark" - "github.com/gcla/termshark/v2/shark/wiresharkcfg" + "github.com/gcla/termshark/v2/pkg/shark" + "github.com/gcla/termshark/v2/pkg/shark/wiresharkcfg" "github.com/gcla/termshark/v2/ui/menuutil" "github.com/gdamore/tcell/v2" log "github.com/sirupsen/logrus" diff --git a/ui/psmlcolsmodel.go b/ui/psmlcolsmodel.go index 88a627e..e79517e 100644 --- a/ui/psmlcolsmodel.go +++ b/ui/psmlcolsmodel.go @@ -22,8 +22,8 @@ import ( "github.com/gcla/gowid/widgets/table" "github.com/gcla/gowid/widgets/text" "github.com/gcla/gowid/widgets/vpadding" - "github.com/gcla/termshark/v2/shark" - "github.com/gcla/termshark/v2/shark/wiresharkcfg" + "github.com/gcla/termshark/v2/pkg/shark" + "github.com/gcla/termshark/v2/pkg/shark/wiresharkcfg" "github.com/gcla/termshark/v2/widgets/filter" "github.com/gcla/termshark/v2/widgets/number" log "github.com/sirupsen/logrus" diff --git a/ui/searchalg.go b/ui/searchalg.go index 9e00935..e45d508 100644 --- a/ui/searchalg.go +++ b/ui/searchalg.go @@ -11,7 +11,7 @@ import ( "github.com/gcla/gowid" "github.com/gcla/termshark/v2" - "github.com/gcla/termshark/v2/pcap" + "github.com/gcla/termshark/v2/pkg/pcap" "github.com/gcla/termshark/v2/widgets/search" ) diff --git a/ui/searchbyfilter.go b/ui/searchbyfilter.go index f6a1567..bea2939 100644 --- a/ui/searchbyfilter.go +++ b/ui/searchbyfilter.go @@ -19,8 +19,8 @@ import ( "github.com/gcla/gowid/widgets/table" "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/configs/profiles" - "github.com/gcla/termshark/v2/format" - "github.com/gcla/termshark/v2/pcap" + "github.com/gcla/termshark/v2/pkg/format" + "github.com/gcla/termshark/v2/pkg/pcap" "github.com/gcla/termshark/v2/widgets/search" log "github.com/sirupsen/logrus" "gitlab.com/jonas.jasas/condchan" diff --git a/ui/searchpktbytes.go b/ui/searchpktbytes.go index eaba783..475965c 100644 --- a/ui/searchpktbytes.go +++ b/ui/searchpktbytes.go @@ -10,7 +10,7 @@ import ( "github.com/gcla/gowid" "github.com/gcla/gowid/widgets/table" - "github.com/gcla/termshark/v2/pcap" + "github.com/gcla/termshark/v2/pkg/pcap" "github.com/gcla/termshark/v2/widgets/search" ) diff --git a/ui/searchpktstruct.go b/ui/searchpktstruct.go index bcaf13d..ec9b7b7 100644 --- a/ui/searchpktstruct.go +++ b/ui/searchpktstruct.go @@ -11,7 +11,7 @@ import ( "github.com/gcla/gowid" "github.com/gcla/gowid/widgets/table" "github.com/gcla/gowid/widgets/tree" - "github.com/gcla/termshark/v2/pdmltree" + "github.com/gcla/termshark/v2/pkg/pdmltree" "github.com/gcla/termshark/v2/widgets/search" ) diff --git a/ui/streamui.go b/ui/streamui.go index f4516b6..ca4d8ef 100644 --- a/ui/streamui.go +++ b/ui/streamui.go @@ -20,9 +20,9 @@ import ( "github.com/gcla/gowid/widgets/table" "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/configs/profiles" - "github.com/gcla/termshark/v2/pcap" - "github.com/gcla/termshark/v2/pdmltree" - "github.com/gcla/termshark/v2/streams" + "github.com/gcla/termshark/v2/pkg/pcap" + "github.com/gcla/termshark/v2/pkg/pdmltree" + "github.com/gcla/termshark/v2/pkg/streams" "github.com/gcla/termshark/v2/widgets/appkeys" "github.com/gcla/termshark/v2/widgets/streamwidget" "github.com/gdamore/tcell/v2" diff --git a/ui/ui.go b/ui/ui.go index f5af9d0..3b8d793 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -47,12 +47,12 @@ import ( "github.com/gcla/gowid/widgets/vpadding" "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/configs/profiles" - "github.com/gcla/termshark/v2/pcap" - "github.com/gcla/termshark/v2/pdmltree" - "github.com/gcla/termshark/v2/psmlmodel" - "github.com/gcla/termshark/v2/shark" - "github.com/gcla/termshark/v2/system" - "github.com/gcla/termshark/v2/theme" + "github.com/gcla/termshark/v2/pkg/pcap" + "github.com/gcla/termshark/v2/pkg/pdmltree" + "github.com/gcla/termshark/v2/pkg/psmlmodel" + "github.com/gcla/termshark/v2/pkg/system" + "github.com/gcla/termshark/v2/pkg/shark" + "github.com/gcla/termshark/v2/pkg/theme" "github.com/gcla/termshark/v2/ui/menuutil" "github.com/gcla/termshark/v2/ui/tableutil" "github.com/gcla/termshark/v2/widgets" diff --git a/utils.go b/utils.go index cd501c1..8c9e674 100644 --- a/utils.go +++ b/utils.go @@ -38,7 +38,7 @@ import ( "github.com/gcla/gowid/vim" "github.com/gcla/gowid/widgets/table" "github.com/gcla/termshark/v2/configs/profiles" - "github.com/gcla/termshark/v2/system" + "github.com/gcla/termshark/v2/pkg/system" "github.com/gcla/termshark/v2/widgets/resizable" "github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2/terminfo" diff --git a/utils_test.go b/utils_test.go index 58ff77b..9deb465 100644 --- a/utils_test.go +++ b/utils_test.go @@ -10,7 +10,7 @@ import ( "testing" "github.com/blang/semver" - "github.com/gcla/termshark/v2/format" + "github.com/gcla/termshark/v2/pkg/format" "github.com/stretchr/testify/assert" ) diff --git a/widgets/copymodetree/copymodetree.go b/widgets/copymodetree/copymodetree.go index 8b0cc8a..dbd2b84 100644 --- a/widgets/copymodetree/copymodetree.go +++ b/widgets/copymodetree/copymodetree.go @@ -16,7 +16,7 @@ import ( "github.com/gcla/gowid/widgets/list" "github.com/gcla/gowid/widgets/tree" "github.com/gcla/termshark/v2" - "github.com/gcla/termshark/v2/pdmltree" + "github.com/gcla/termshark/v2/pkg/pdmltree" ) //====================================================================== diff --git a/widgets/hexdumper/hexdumper.go b/widgets/hexdumper/hexdumper.go index c5e48ed..5ffe541 100644 --- a/widgets/hexdumper/hexdumper.go +++ b/widgets/hexdumper/hexdumper.go @@ -21,7 +21,7 @@ import ( "github.com/gcla/gowid/widgets/styled" "github.com/gcla/gowid/widgets/text" "github.com/gcla/termshark/v2" - "github.com/gcla/termshark/v2/format" + "github.com/gcla/termshark/v2/pkg/format" "github.com/gcla/termshark/v2/widgets/renderfocused" "github.com/gdamore/tcell/v2" "github.com/pkg/errors" diff --git a/widgets/hexdumper2/hexdumper2.go b/widgets/hexdumper2/hexdumper2.go index 94b43d6..4126dc9 100644 --- a/widgets/hexdumper2/hexdumper2.go +++ b/widgets/hexdumper2/hexdumper2.go @@ -18,7 +18,7 @@ import ( "github.com/gcla/gowid/vim" "github.com/gcla/gowid/widgets/list" "github.com/gcla/gowid/widgets/styled" - "github.com/gcla/termshark/v2/format" + "github.com/gcla/termshark/v2/pkg/format" "github.com/gdamore/tcell/v2" ) diff --git a/widgets/streamwidget/streamwidget.go b/widgets/streamwidget/streamwidget.go index 8bead61..35f5624 100644 --- a/widgets/streamwidget/streamwidget.go +++ b/widgets/streamwidget/streamwidget.go @@ -37,8 +37,8 @@ import ( "github.com/gcla/gowid/widgets/text" "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/configs/profiles" - "github.com/gcla/termshark/v2/format" - "github.com/gcla/termshark/v2/streams" + "github.com/gcla/termshark/v2/pkg/format" + "github.com/gcla/termshark/v2/pkg/streams" "github.com/gcla/termshark/v2/ui/menuutil" "github.com/gcla/termshark/v2/ui/tableutil" "github.com/gcla/termshark/v2/widgets" From 73953a85e873ccb6a9d87b71d23099a8dbe827df Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Fri, 8 Jul 2022 22:36:18 -0400 Subject: [PATCH 04/10] Some more involved refactoring to move confwatcher to pkg --- cmd/termshark/termshark.go | 9 +++++---- .../confwatcher/confwatcher.go | 17 ++++++++++------- 2 files changed, 15 insertions(+), 11 deletions(-) rename confwatcher.go => pkg/confwatcher/confwatcher.go (86%) diff --git a/cmd/termshark/termshark.go b/cmd/termshark/termshark.go index 7f968d9..607a7cc 100644 --- a/cmd/termshark/termshark.go +++ b/cmd/termshark/termshark.go @@ -20,14 +20,15 @@ import ( "github.com/blang/semver" "github.com/gcla/gowid" "github.com/gcla/termshark/v2" - "github.com/gcla/termshark/v2/pkg/capinfo" "github.com/gcla/termshark/v2/cli" "github.com/gcla/termshark/v2/configs/profiles" + "github.com/gcla/termshark/v2/pkg/capinfo" + "github.com/gcla/termshark/v2/pkg/confwatcher" "github.com/gcla/termshark/v2/pkg/convs" "github.com/gcla/termshark/v2/pkg/pcap" - "github.com/gcla/termshark/v2/pkg/summary" "github.com/gcla/termshark/v2/pkg/shark" "github.com/gcla/termshark/v2/pkg/streams" + "github.com/gcla/termshark/v2/pkg/summary" "github.com/gcla/termshark/v2/pkg/system" "github.com/gcla/termshark/v2/pkg/tty" "github.com/gcla/termshark/v2/ui" @@ -56,7 +57,6 @@ func main() { // stopped. Any exception is a bug. var ensureGoroutinesStopWG sync.WaitGroup filter.Goroutinewg = &ensureGoroutinesStopWG - termshark.Goroutinewg = &ensureGoroutinesStopWG pcap.Goroutinewg = &ensureGoroutinesStopWG streams.Goroutinewg = &ensureGoroutinesStopWG capinfo.Goroutinewg = &ensureGoroutinesStopWG @@ -64,6 +64,7 @@ func main() { ui.Goroutinewg = &ensureGoroutinesStopWG wormhole.Goroutinewg = &ensureGoroutinesStopWG summary.Goroutinewg = &ensureGoroutinesStopWG + confwatcher.Goroutinewg = &ensureGoroutinesStopWG res := cmain() ensureGoroutinesStopWG.Wait() @@ -695,7 +696,7 @@ func cmain() int { } } - watcher, err := termshark.NewConfigWatcher() + watcher, err := confwatcher.New() if err != nil { fmt.Fprintf(os.Stderr, "Problem constructing config file watcher: %v", err) return 1 diff --git a/confwatcher.go b/pkg/confwatcher/confwatcher.go similarity index 86% rename from confwatcher.go rename to pkg/confwatcher/confwatcher.go index 5f07420..3400bd2 100644 --- a/confwatcher.go +++ b/pkg/confwatcher/confwatcher.go @@ -2,20 +2,19 @@ // code is governed by the MIT license that can be found in the LICENSE // file. -package termshark +package confwatcher import ( "os" "sync" + "github.com/gcla/termshark/v2" log "github.com/sirupsen/logrus" fsnotify "gopkg.in/fsnotify/fsnotify.v1" ) //====================================================================== -var Goroutinewg *sync.WaitGroup - type ConfigWatcher struct { watcher *fsnotify.Watcher change chan struct{} @@ -23,7 +22,7 @@ type ConfigWatcher struct { closeWait sync.WaitGroup } -func NewConfigWatcher() (*ConfigWatcher, error) { +func New() (*ConfigWatcher, error) { watcher, err := fsnotify.NewWatcher() if err != nil { panic(err) @@ -39,7 +38,7 @@ func NewConfigWatcher() (*ConfigWatcher, error) { res.closeWait.Add(1) - TrackedGo(func() { + termshark.TrackedGo(func() { defer func() { res.watcher.Close() close(change) @@ -60,7 +59,7 @@ func NewConfigWatcher() (*ConfigWatcher, error) { } }, Goroutinewg) - if err := watcher.Add(ConfFile("termshark.toml")); err != nil && !os.IsNotExist(err) { + if err := watcher.Add(termshark.ConfFile("termshark.toml")); err != nil && !os.IsNotExist(err) { return nil, err } @@ -73,7 +72,7 @@ func (c *ConfigWatcher) Close() { // drain the change channel to ensure the goroutine above can process the close. This // is safe because I know, at this point, there are no other readers because termshark // has exited its select loop. - TrackedGo(func() { + termshark.TrackedGo(func() { // This might block because the goroutine above might not be blocked sending // to c.change. But then that means the goroutine's for loop above will terminate, // c.change will be closed, and then this goroutine will end. If the above @@ -90,6 +89,10 @@ func (c *ConfigWatcher) ConfigChanged() <-chan struct{} { return c.change } +//====================================================================== + +var Goroutinewg *sync.WaitGroup + //====================================================================== // Local Variables: // mode: Go From 3b8f1ca2ca1f3bd20e616b2e35f6a3e4656fdea4 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Fri, 8 Jul 2022 22:40:31 -0400 Subject: [PATCH 05/10] Move file tailing logic under pkg too --- cmd/termshark/termshark.go | 3 ++- tailfile.go => pkg/tailfile/tailfile.go | 4 ++-- tailfile_windows.go => pkg/tailfile/tailfile_windows.go | 4 ++-- 3 files changed, 6 insertions(+), 5 deletions(-) rename tailfile.go => pkg/tailfile/tailfile.go (90%) rename tailfile_windows.go => pkg/tailfile/tailfile_windows.go (92%) diff --git a/cmd/termshark/termshark.go b/cmd/termshark/termshark.go index 607a7cc..def1d9d 100644 --- a/cmd/termshark/termshark.go +++ b/cmd/termshark/termshark.go @@ -30,6 +30,7 @@ import ( "github.com/gcla/termshark/v2/pkg/streams" "github.com/gcla/termshark/v2/pkg/summary" "github.com/gcla/termshark/v2/pkg/system" + "github.com/gcla/termshark/v2/pkg/tailfile" "github.com/gcla/termshark/v2/pkg/tty" "github.com/gcla/termshark/v2/ui" "github.com/gcla/termshark/v2/widgets/filter" @@ -182,7 +183,7 @@ func cmain() int { // On Windows, termshark itself is used to tail the pcap generated by dumpcap, and the output // is fed into tshark -T psml ... if tsopts.TailFileValue() != "" { - err = termshark.TailFile(tsopts.TailFileValue()) + err = tailfile.Tail(tsopts.TailFileValue()) if err != nil { fmt.Fprintf(os.Stderr, "Error: %v", err) return 1 diff --git a/tailfile.go b/pkg/tailfile/tailfile.go similarity index 90% rename from tailfile.go rename to pkg/tailfile/tailfile.go index c3b8941..5de8d5c 100644 --- a/tailfile.go +++ b/pkg/tailfile/tailfile.go @@ -4,7 +4,7 @@ //+build !windows -package termshark +package tailfile import ( "os" @@ -13,7 +13,7 @@ import ( //====================================================================== -func TailFile(file string) error { +func Tail(file string) error { cmd := exec.Command("tail", "-f", file) cmd.Stdout = os.Stdout return cmd.Run() diff --git a/tailfile_windows.go b/pkg/tailfile/tailfile_windows.go similarity index 92% rename from tailfile_windows.go rename to pkg/tailfile/tailfile_windows.go index 9e74a4a..d588441 100644 --- a/tailfile_windows.go +++ b/pkg/tailfile/tailfile_windows.go @@ -2,7 +2,7 @@ // code is governed by the MIT license that can be found in the LICENSE // file. -package termshark +package tailfile import ( "os" @@ -12,7 +12,7 @@ import ( //====================================================================== -func TailFile(file string) error { +func Tail(file string) error { t, err := tail.TailFile(file, tail.Config{ Follow: true, ReOpen: true, From 8add110468813319cf256918e894ceda3dbb7925 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Fri, 8 Jul 2022 22:45:22 -0400 Subject: [PATCH 06/10] Move the tshark fields extracting code to pkg too --- cmd/termshark/termshark.go | 3 ++- fields.go => pkg/fields/fields.go | 15 +++++++------- fields_test.go => pkg/fields/fields_test.go | 4 ++-- ui/ui.go | 23 +++++++++++---------- widgets/filter/filter.go | 15 +++++++------- widgets/search/search.go | 12 +++++------ 6 files changed, 38 insertions(+), 34 deletions(-) rename fields.go => pkg/fields/fields.go (95%) rename fields_test.go => pkg/fields/fields_test.go (94%) diff --git a/cmd/termshark/termshark.go b/cmd/termshark/termshark.go index def1d9d..4f8f831 100644 --- a/cmd/termshark/termshark.go +++ b/cmd/termshark/termshark.go @@ -25,6 +25,7 @@ import ( "github.com/gcla/termshark/v2/pkg/capinfo" "github.com/gcla/termshark/v2/pkg/confwatcher" "github.com/gcla/termshark/v2/pkg/convs" + "github.com/gcla/termshark/v2/pkg/fields" "github.com/gcla/termshark/v2/pkg/pcap" "github.com/gcla/termshark/v2/pkg/shark" "github.com/gcla/termshark/v2/pkg/streams" @@ -611,7 +612,7 @@ func cmain() int { // If the last tshark we used isn't the same as the current one, then remove the cached fields // data structure so it can be regenerated. if tsharkBin != profiles.ConfString("main.last-used-tshark", "") { - termshark.DeleteCachedFields() + fields.DeleteCachedFields() } // Write out the last-used tshark path. We do this to make the above fields cache be consistent diff --git a/fields.go b/pkg/fields/fields.go similarity index 95% rename from fields.go rename to pkg/fields/fields.go index 41306f1..474eaa3 100644 --- a/fields.go +++ b/pkg/fields/fields.go @@ -2,7 +2,7 @@ // code is governed by the MIT license that can be found in the LICENSE // file. -package termshark +package fields import ( "bufio" @@ -13,6 +13,7 @@ import ( "strings" "sync" + "github.com/gcla/termshark/v2" log "github.com/sirupsen/logrus" ) @@ -160,25 +161,25 @@ type IPrefixCompleter interface { Completions(prefix string, cb IPrefixCompleterCallback) } -func NewFields() *TSharkFields { +func New() *TSharkFields { return &TSharkFields{} } func DeleteCachedFields() error { - return os.Remove(CacheFile("tsharkfieldsv3.gob.gz")) + return os.Remove(termshark.CacheFile("tsharkfieldsv3.gob.gz")) } // Can be run asynchronously. // This ought to use interfaces to make it testable. func (w *TSharkFields) Init() error { - newer, err := FileNewerThan(CacheFile("tsharkfieldsv3.gob.gz"), DirOfPathCommandUnsafe(TSharkBin())) + newer, err := termshark.FileNewerThan(termshark.CacheFile("tsharkfieldsv3.gob.gz"), termshark.DirOfPathCommandUnsafe(termshark.TSharkBin())) if err == nil && newer { f := &FieldsAndProtos{ Fields: make(map[string]interface{}), Protocols: make(map[string]struct{}), } - err = ReadGob(CacheFile("tsharkfieldsv3.gob.gz"), f) + err = termshark.ReadGob(termshark.CacheFile("tsharkfieldsv3.gob.gz"), f) if err == nil { w.ser = f log.Infof("Read cached tshark fields.") @@ -193,7 +194,7 @@ func (w *TSharkFields) Init() error { return err } - err = WriteGob(CacheFile("tsharkfieldsv3.gob.gz"), w.ser) + err = termshark.WriteGob(termshark.CacheFile("tsharkfieldsv3.gob.gz"), w.ser) if err != nil { return err } @@ -202,7 +203,7 @@ func (w *TSharkFields) Init() error { } func (w *TSharkFields) InitNoCache() error { - cmd := exec.Command(TSharkBin(), []string{"-G", "fields"}...) + cmd := exec.Command(termshark.TSharkBin(), []string{"-G", "fields"}...) out, err := cmd.StdoutPipe() if err != nil { diff --git a/fields_test.go b/pkg/fields/fields_test.go similarity index 94% rename from fields_test.go rename to pkg/fields/fields_test.go index 70792a5..6d8085e 100644 --- a/fields_test.go +++ b/pkg/fields/fields_test.go @@ -1,7 +1,7 @@ // Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source code is governed by the MIT license // that can be found in the LICENSE file. -package termshark +package fields import ( "testing" @@ -13,7 +13,7 @@ import ( func TestFields1(t *testing.T) { - fields := NewFields() + fields := New() err := fields.InitNoCache() assert.NoError(t, err) diff --git a/ui/ui.go b/ui/ui.go index 3b8d793..c8b8f3b 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -47,11 +47,12 @@ import ( "github.com/gcla/gowid/widgets/vpadding" "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/configs/profiles" + "github.com/gcla/termshark/v2/pkg/fields" "github.com/gcla/termshark/v2/pkg/pcap" "github.com/gcla/termshark/v2/pkg/pdmltree" "github.com/gcla/termshark/v2/pkg/psmlmodel" - "github.com/gcla/termshark/v2/pkg/system" "github.com/gcla/termshark/v2/pkg/shark" + "github.com/gcla/termshark/v2/pkg/system" "github.com/gcla/termshark/v2/pkg/theme" "github.com/gcla/termshark/v2/ui/menuutil" "github.com/gcla/termshark/v2/ui/tableutil" @@ -239,7 +240,7 @@ var lastJumpPos int var NoGlobalJump termshark.GlobalJumpPos // leave as default, like a placeholder var Loader *pcap.PacketLoader -var FieldCompleter *termshark.TSharkFields // share this - safe once constructed +var FieldCompleter *fields.TSharkFields // share this - safe once constructed var WriteToSelected bool // true if the user provided the -w flag var WriteToDeleted bool // true if the user deleted the temporary pcap before quitting @@ -366,11 +367,11 @@ func makePdmlFilterMenu(filter string, val string) *menu.Widget { // are needed. if ok { switch field.Type { - case termshark.FT_STRING: + case fields.FT_STRING: needQuotes = true - case termshark.FT_STRINGZ: + case fields.FT_STRINGZ: needQuotes = true - case termshark.FT_STRINGZPAD: + case fields.FT_STRINGZPAD: needQuotes = true } } @@ -3135,10 +3136,10 @@ func UpdateRecentMenu(app gowid.IApp) { type savedCompleterCallback struct { prefix string - comp termshark.IPrefixCompleterCallback + comp fields.IPrefixCompleterCallback } -var _ termshark.IPrefixCompleterCallback = (*savedCompleterCallback)(nil) +var _ fields.IPrefixCompleterCallback = (*savedCompleterCallback)(nil) func (s *savedCompleterCallback) Call(orig []string) { if s.prefix == "" { @@ -3153,12 +3154,12 @@ func (s *savedCompleterCallback) Call(orig []string) { } type savedCompleter struct { - def termshark.IPrefixCompleter + def fields.IPrefixCompleter } -var _ termshark.IPrefixCompleter = (*savedCompleter)(nil) +var _ fields.IPrefixCompleter = (*savedCompleter)(nil) -func (s savedCompleter) Completions(prefix string, cb termshark.IPrefixCompleterCallback) { +func (s savedCompleter) Completions(prefix string, cb fields.IPrefixCompleterCallback) { ncomp := &savedCompleterCallback{ prefix: prefix, comp: cb, @@ -3783,7 +3784,7 @@ func Build(tty string) (*gowid.App, error) { ) // For completing filter expressions - FieldCompleter = termshark.NewFields() + FieldCompleter = fields.New() FieldCompleter.Init() FilterWidget = filter.New("filter", filter.Options{ diff --git a/widgets/filter/filter.go b/widgets/filter/filter.go index f758ce6..8989eff 100644 --- a/widgets/filter/filter.go +++ b/widgets/filter/filter.go @@ -33,6 +33,7 @@ import ( "github.com/gcla/gowid/widgets/styled" "github.com/gcla/gowid/widgets/text" "github.com/gcla/termshark/v2" + "github.com/gcla/termshark/v2/pkg/fields" "github.com/gcla/termshark/v2/widgets/appkeys" "github.com/gdamore/tcell/v2" ) @@ -64,10 +65,10 @@ type Widget struct { edCtx context.Context edCancelFn context.CancelFunc edCtxLock sync.Mutex - fields termshark.IPrefixCompleter // provides completions, given a prefix - completionsList *list.Widget // the filter widget replaces the list walker when new completions are generated - completionsActivator *activatorWidget // used to disable focus going to drop down - completions []string // the current set of completions, used when rendering + fields fields.IPrefixCompleter // provides completions, given a prefix + completionsList *list.Widget // the filter widget replaces the list walker when new completions are generated + completionsActivator *activatorWidget // used to disable focus going to drop down + completions []string // the current set of completions, used when rendering runthisfilterchan chan *filtStruct filterchangedchan chan *filtStruct quitchan chan struct{} @@ -95,7 +96,7 @@ const ( ) type Options struct { - Completer termshark.IPrefixCompleter + Completer fields.IPrefixCompleter MenuOpener menu.IOpener Position Pos Validator IValidator @@ -451,13 +452,13 @@ type fnCallback struct { fn func([]string, gowid.IApp) } -var _ termshark.IPrefixCompleterCallback = fnCallback{} +var _ fields.IPrefixCompleterCallback = fnCallback{} func (f fnCallback) Call(res []string) { f.fn(res, f.app) } -func makeCompletions(comp termshark.IPrefixCompleter, txt string, max int, app gowid.IApp, fn func([]string, gowid.IApp)) { +func makeCompletions(comp fields.IPrefixCompleter, txt string, max int, app gowid.IApp, fn func([]string, gowid.IApp)) { if comp != nil { cb := fnCallback{ app: app, diff --git a/widgets/search/search.go b/widgets/search/search.go index b909613..f09ae70 100644 --- a/widgets/search/search.go +++ b/widgets/search/search.go @@ -26,8 +26,8 @@ import ( "github.com/gcla/gowid/widgets/null" "github.com/gcla/gowid/widgets/styled" "github.com/gcla/gowid/widgets/text" - "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/configs/profiles" + "github.com/gcla/termshark/v2/pkg/fields" "github.com/gcla/termshark/v2/ui/menuutil" "github.com/gcla/termshark/v2/widgets/filter" "github.com/gcla/termshark/v2/widgets/ifwidget" @@ -247,7 +247,7 @@ type Widget struct { filterHolder *holder.Widget filt *filter.Widget menuOpener menu.IOpener - completer termshark.IPrefixCompleter + completer fields.IPrefixCompleter cols *columns.Widget findBtn *disable.Widget searchTargetBtn *button.Widget @@ -338,7 +338,7 @@ func New(alg IAlgorithm, searchPktDetails func() ICallbacks, searchByFilter func() ICallbacks, men menu.IOpener, - comp termshark.IPrefixCompleter, + comp fields.IPrefixCompleter, errHandler IErrorHandler) *Widget { res := &Widget{ @@ -535,8 +535,8 @@ func (w *Widget) invokeSearch(app gowid.IApp) { w.alg.SearchPackets(searchTerm, w.currentAlg, app) } -func (w *Widget) getCompleter() termshark.IPrefixCompleter { - var completer termshark.IPrefixCompleter +func (w *Widget) getCompleter() fields.IPrefixCompleter { + var completer fields.IPrefixCompleter s2 := getSearchType() switch s2 { case "filter": @@ -550,7 +550,7 @@ func (w *Widget) focusOnFilter(app gowid.IApp) { w.cols.SetFocus(app, 6) } -func (w *Widget) setFilter(validator filter.IValidator, completer termshark.IPrefixCompleter, app gowid.IApp) { +func (w *Widget) setFilter(validator filter.IValidator, completer fields.IPrefixCompleter, app gowid.IApp) { filt := filter.New("searchfilter", filter.Options{ MenuOpener: w.menuOpener, Completer: completer, From c37544ae12fba879e783d3315a875e0b1309c8a4 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Fri, 8 Jul 2022 22:50:10 -0400 Subject: [PATCH 07/10] This should also be moved from the top-level It's a simple type wrapped around a tree-walker, and this lets me shorten the name I use to refer to it, too. --- noroot.go => pkg/noroot/noroot.go | 12 ++++++------ ui/ui.go | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) rename noroot.go => pkg/noroot/noroot.go (71%) diff --git a/noroot.go b/pkg/noroot/noroot.go similarity index 71% rename from noroot.go rename to pkg/noroot/noroot.go index 6f5efcb..daa6742 100644 --- a/noroot.go +++ b/pkg/noroot/noroot.go @@ -2,7 +2,7 @@ // code is governed by the MIT license that can be found in the LICENSE // file. -package termshark +package noroot import ( "github.com/gcla/gowid/widgets/list" @@ -11,22 +11,22 @@ import ( //====================================================================== -type NoRootWalker struct { +type Walker struct { *tree.TreeWalker } -func NewNoRootWalker(w *tree.TreeWalker) *NoRootWalker { - return &NoRootWalker{ +func NewWalker(w *tree.TreeWalker) *Walker { + return &Walker{ TreeWalker: w, } } // for omitting top level node -func (f *NoRootWalker) Next(pos list.IWalkerPosition) list.IWalkerPosition { +func (f *Walker) Next(pos list.IWalkerPosition) list.IWalkerPosition { return tree.WalkerNext(f, pos) } -func (f *NoRootWalker) Previous(pos list.IWalkerPosition) list.IWalkerPosition { +func (f *Walker) Previous(pos list.IWalkerPosition) list.IWalkerPosition { fc := pos.(tree.IPos) pp := tree.PreviousPosition(fc, f.Tree()) if pp.Equal(tree.NewPos()) { diff --git a/ui/ui.go b/ui/ui.go index c8b8f3b..7a2ff43 100644 --- a/ui/ui.go +++ b/ui/ui.go @@ -48,6 +48,7 @@ import ( "github.com/gcla/termshark/v2" "github.com/gcla/termshark/v2/configs/profiles" "github.com/gcla/termshark/v2/pkg/fields" + "github.com/gcla/termshark/v2/pkg/noroot" "github.com/gcla/termshark/v2/pkg/pcap" "github.com/gcla/termshark/v2/pkg/pdmltree" "github.com/gcla/termshark/v2/pkg/psmlmodel" @@ -2630,7 +2631,7 @@ func setPacketListWidgets(psml iPsmlInfo, app gowid.IApp) { func expandStructWidgetAtPosition(row int, pos int, app gowid.IApp) { if curPacketStructWidget != nil { - walker := curPacketStructWidget.Walker().(*termshark.NoRootWalker) + walker := curPacketStructWidget.Walker().(*noroot.Walker) curTree := walker.Tree().(*pdmltree.Model) finalPos := make([]int, 0) @@ -2812,7 +2813,7 @@ func getStructWidgetToDisplay(row int, app gowid.IApp) gowid.IWidget { tree.NewCachingMaker(tree.WidgetMakerFunction(makeStructNodeWidget)), tree.NewCachingDecorator(tree.DecoratorFunction(makeStructNodeDecoration))) // Without the caching layer, clicking on a button has no effect - walker := termshark.NewNoRootWalker(rwalker) + walker := noroot.NewWalker(rwalker) // Send the layers represents the tree expansion to hex. // This could be the user clicking inside the tree. Or it might be the position changing From 82249c6595422d0bb690e3c96de46dd843a6c4c9 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sat, 9 Jul 2022 11:52:37 -0400 Subject: [PATCH 08/10] The cli package can also move to pkg It need not be in the top-level, and this helps cleans up the project structure. --- cmd/termshark/termshark.go | 2 +- {cli => pkg/cli}/all.go | 0 {cli => pkg/cli}/flags.go | 0 {cli => pkg/cli}/flags_windows.go | 0 {cli => pkg/cli}/tristate.go | 0 5 files changed, 1 insertion(+), 1 deletion(-) rename {cli => pkg/cli}/all.go (100%) rename {cli => pkg/cli}/flags.go (100%) rename {cli => pkg/cli}/flags_windows.go (100%) rename {cli => pkg/cli}/tristate.go (100%) diff --git a/cmd/termshark/termshark.go b/cmd/termshark/termshark.go index 4f8f831..5b46776 100644 --- a/cmd/termshark/termshark.go +++ b/cmd/termshark/termshark.go @@ -20,7 +20,7 @@ import ( "github.com/blang/semver" "github.com/gcla/gowid" "github.com/gcla/termshark/v2" - "github.com/gcla/termshark/v2/cli" + "github.com/gcla/termshark/v2/pkg/cli" "github.com/gcla/termshark/v2/configs/profiles" "github.com/gcla/termshark/v2/pkg/capinfo" "github.com/gcla/termshark/v2/pkg/confwatcher" diff --git a/cli/all.go b/pkg/cli/all.go similarity index 100% rename from cli/all.go rename to pkg/cli/all.go diff --git a/cli/flags.go b/pkg/cli/flags.go similarity index 100% rename from cli/flags.go rename to pkg/cli/flags.go diff --git a/cli/flags_windows.go b/pkg/cli/flags_windows.go similarity index 100% rename from cli/flags_windows.go rename to pkg/cli/flags_windows.go diff --git a/cli/tristate.go b/pkg/cli/tristate.go similarity index 100% rename from cli/tristate.go rename to pkg/cli/tristate.go From 559e4123e595ac18239eeb564ceb7fe31298f084 Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sat, 9 Jul 2022 20:55:59 -0400 Subject: [PATCH 09/10] Fix a deadlock in the packet list search implementation This code path broke the loop but didn't release the lock... --- ui/searchpktlist.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ui/searchpktlist.go b/ui/searchpktlist.go index 6bd1729..c39376a 100644 --- a/ui/searchpktlist.go +++ b/ui/searchpktlist.go @@ -117,6 +117,7 @@ Loop: resumeAt = &ListResult{ PacketNum: curPacketNumber, } + Loader.PsmlLoader.Unlock() break } From 79fad3d2ba5dcdfdb78669cc468ee6eda7eeb7ee Mon Sep 17 00:00:00 2001 From: Graham Clark Date: Sat, 9 Jul 2022 20:56:45 -0400 Subject: [PATCH 10/10] Bug fix to prevent packet list search not returning The symptom is that the spinner stays active. When the packet list search wraps, it mistakenly moves back to packet 1 to resume the search. But if a display filter is applied, packet 1 may not be loaded. The search implementation will make a request to the loader to load packet 1, but the loader ignores it because as far as it's concerned, the first block of packets have been loaded in their entirety; they just don't include packet 1 because it doesn't match the display filter. This procedure repeated indefinitely. The fix is to loop back to the first packet loaded. --- ui/searchpktlist.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/searchpktlist.go b/ui/searchpktlist.go index c39376a..9ca6950 100644 --- a/ui/searchpktlist.go +++ b/ui/searchpktlist.go @@ -155,7 +155,7 @@ Loop: // 32, 44, 45, 134, 209,... curPacketNumber, ok = Loader.PacketNumberOrder[curPacketNumber] if !ok { - curPacketNumber = 1 + curPacketNumber = Loader.PacketNumberOrder[0] } Loader.PsmlLoader.Unlock()