From 58910a3f34e41b09d3e87a1e2e327c8dedc66e4e Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Thu, 11 Apr 2019 10:19:16 -0700 Subject: [PATCH] start implementing UI --- go.mod | 1 + go.sum | 2 ++ src/croc/croc.go | 28 +++++++++++++++++++-- src/webrtc/pkg/session/receiver/receiver.go | 8 ++++-- src/webrtc/pkg/session/sender/sender.go | 8 ++++-- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 97438c50..54ba87bc 100644 --- a/go.mod +++ b/go.mod @@ -3,6 +3,7 @@ module github.com/schollz/croc/v5 go 1.12 require ( + github.com/denisbrodbeck/machineid v1.0.1 github.com/go-redis/redis v6.15.2+incompatible github.com/mattn/go-colorable v0.1.1 github.com/pion/webrtc/v2 v2.0.2 diff --git a/go.sum b/go.sum index 5ef1b546..6c58be71 100644 --- a/go.sum +++ b/go.sum @@ -3,6 +3,8 @@ github.com/cheekybits/genny v1.0.0/go.mod h1:+tQajlRqAUrPI7DOSpB0XAqZYtQakVtB7wX github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ= +github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/go-redis/redis v6.15.2+incompatible h1:9SpNVG76gr6InJGxoZ6IuuxaCOQwDAhzyXg+Bs+0Sb4= diff --git a/src/croc/croc.go b/src/croc/croc.go index faa543f4..a9e6e9a2 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -15,6 +15,7 @@ import ( "sync" "time" + "github.com/denisbrodbeck/machineid" "github.com/go-redis/redis" "github.com/mattn/go-colorable" "github.com/pions/webrtc" @@ -36,8 +37,16 @@ func init() { log.SetFormatter(&logrus.TextFormatter{ForceColors: true}) log.SetOutput(colorable.NewColorableStdout()) log.SetLevel(logrus.DebugLevel) - receiver.Debug() - sender.Debug() +} + +func Debug(debug bool) { + receiver.Debug(debug) + sender.Debug(debug) + if debug { + log.SetLevel(logrus.DebugLevel) + } else { + log.SetLevel(logrus.WarnLevel) + } } type Client struct { @@ -193,6 +202,7 @@ func (c *Client) Receive() (err error) { func (c *Client) transfer(options TransferOptions) (err error) { if c.IsSender { c.FilesToTransfer = make([]FileInfo, len(options.PathToFiles)) + totalFilesSize := int64(0) for i, pathToFile := range options.PathToFiles { var fstats os.FileInfo var fullPath string @@ -216,6 +226,7 @@ func (c *Client) transfer(options TransferOptions) (err error) { ModTime: fstats.ModTime(), } c.FilesToTransfer[i].Hash, err = utils.HashFile(fullPath) + totalFilesSize += fstats.Size() if err != nil { return } @@ -242,6 +253,19 @@ func (c *Client) transfer(options TransferOptions) (err error) { } log.Debugf("file %d info: %+v", i, c.FilesToTransfer[i]) } + fname := fmt.Sprintf("%d files", len(c.FilesToTransfer)) + if len(c.FilesToTransfer) == 1 { + fname = fmt.Sprintf("'%s'", c.FilesToTransfer[0].Name) + } + machID, macIDerr := machineid.ID() + if macIDerr != nil { + log.Error(macIDerr) + return + } + if len(machID) > 6 { + machID = machID[:6] + } + fmt.Fprintf(os.Stderr, "Sending %s (%s) as '%s'\n", fname, utils.ByteCountDecimal(totalFilesSize), machID) } // create channel for quitting // quit with c.quit <- true diff --git a/src/webrtc/pkg/session/receiver/receiver.go b/src/webrtc/pkg/session/receiver/receiver.go index 8d7c0544..cedddb78 100644 --- a/src/webrtc/pkg/session/receiver/receiver.go +++ b/src/webrtc/pkg/session/receiver/receiver.go @@ -25,8 +25,12 @@ func init() { log.SetLevel(logrus.WarnLevel) } -func Debug() { - log.SetLevel(logrus.DebugLevel) +func Debug(debug bool) { + if debug { + log.SetLevel(logrus.DebugLevel) + } else { + log.SetLevel(logrus.WarnLevel) + } } // Session is a receiver session diff --git a/src/webrtc/pkg/session/sender/sender.go b/src/webrtc/pkg/session/sender/sender.go index 2ea57334..96f66f2c 100644 --- a/src/webrtc/pkg/session/sender/sender.go +++ b/src/webrtc/pkg/session/sender/sender.go @@ -34,8 +34,12 @@ func init() { log.SetLevel(logrus.WarnLevel) } -func Debug() { - log.SetLevel(logrus.DebugLevel) +func Debug(debug bool) { + if debug { + log.SetLevel(logrus.DebugLevel) + } else { + log.SetLevel(logrus.WarnLevel) + } } type outputMsg struct {