mirror of
https://github.com/schollz/croc.git
synced 2024-11-23 23:54:17 +03:00
show spinner
This commit is contained in:
parent
55bd83576a
commit
f709df4d3e
@ -38,8 +38,6 @@ type Croc struct {
|
||||
Filename string
|
||||
Codephrase string
|
||||
|
||||
// private variables
|
||||
|
||||
// localIP address
|
||||
localIP string
|
||||
// is using local relay
|
||||
|
@ -9,6 +9,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/briandowns/spinner"
|
||||
"github.com/schollz/croc/src/zipper"
|
||||
|
||||
log "github.com/cihub/seelog"
|
||||
@ -42,6 +43,11 @@ func receive(c *websocket.Conn, codephrase string) (err error) {
|
||||
var fstats models.FileStats
|
||||
var sessionKey []byte
|
||||
|
||||
// start a spinner
|
||||
spin := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
|
||||
spin.Suffix = " performing PAKE..."
|
||||
spin.Start()
|
||||
|
||||
// pick an elliptic curve
|
||||
curve := siec.SIEC255()
|
||||
// both parties should have a weak key
|
||||
@ -85,6 +91,8 @@ func receive(c *websocket.Conn, codephrase string) (err error) {
|
||||
log.Debugf("%x\n", sessionKey)
|
||||
c.WriteMessage(websocket.BinaryMessage, []byte("ready"))
|
||||
case 2:
|
||||
spin.Stop()
|
||||
|
||||
log.Debugf("[%d] recieve file info", step)
|
||||
err = json.Unmarshal(message, &fstats)
|
||||
if err != nil {
|
||||
@ -97,6 +105,7 @@ func receive(c *websocket.Conn, codephrase string) (err error) {
|
||||
return err
|
||||
}
|
||||
bytesWritten := 0
|
||||
fmt.Fprintf(os.Stderr, "Receiving...\n")
|
||||
bar := progressbar.NewOptions(
|
||||
int(fstats.Size),
|
||||
progressbar.OptionSetRenderBlankState(true),
|
||||
|
@ -10,6 +10,8 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/briandowns/spinner"
|
||||
|
||||
log "github.com/cihub/seelog"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/pkg/errors"
|
||||
@ -52,7 +54,8 @@ func send(c *websocket.Conn, fname string, codephrase string) (err error) {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// get stats
|
||||
|
||||
// get stats about the file
|
||||
fstats := models.FileStats{filename, fstat.Size(), fstat.ModTime(), fstat.IsDir(), fstat.Name()}
|
||||
if fstats.IsDir {
|
||||
// zip the directory
|
||||
@ -80,6 +83,11 @@ func send(c *websocket.Conn, fname string, codephrase string) (err error) {
|
||||
// get ready to generate session key
|
||||
var sessionKey []byte
|
||||
|
||||
// start a spinner
|
||||
spin := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
|
||||
spin.Suffix = " wating for recipient..."
|
||||
spin.Start()
|
||||
|
||||
// pick an elliptic curve
|
||||
curve := siec.SIEC255()
|
||||
// both parties should have a weak key
|
||||
@ -102,6 +110,9 @@ func send(c *websocket.Conn, fname string, codephrase string) (err error) {
|
||||
log.Debugf("got %d: %s", messageType, message)
|
||||
switch step {
|
||||
case 0:
|
||||
spin.Stop()
|
||||
spin.Suffix = " performing PAKE..."
|
||||
spin.Start()
|
||||
log.Debugf("[%d] first, P sends u to Q", step)
|
||||
c.WriteMessage(websocket.BinaryMessage, P.Bytes())
|
||||
case 1:
|
||||
@ -126,10 +137,14 @@ func send(c *websocket.Conn, fname string, codephrase string) (err error) {
|
||||
log.Debugf("%s\n", fstatsBytes)
|
||||
c.WriteMessage(websocket.BinaryMessage, fstatsBytes)
|
||||
case 3:
|
||||
spin.Stop()
|
||||
|
||||
log.Debugf("[%d] recipient declares readiness for file data", step)
|
||||
if !bytes.Equal(message, []byte("ready")) {
|
||||
return errors.New("recipient refused file")
|
||||
}
|
||||
|
||||
fmt.Fprintf(os.Stderr, "Sending...\n")
|
||||
// send file, compure hash simultaneously
|
||||
buffer := make([]byte, 1024*512)
|
||||
bar := progressbar.NewOptions(
|
||||
|
Loading…
Reference in New Issue
Block a user