mirror of https://github.com/schollz/croc.git
add spinner for recipient
This commit is contained in:
parent
11566c710d
commit
2ce63b5cda
|
@ -29,6 +29,13 @@ func (c *Croc) client(role int, channel string) (err error) {
|
||||||
|
|
||||||
interrupt := make(chan os.Signal, 1)
|
interrupt := make(chan os.Signal, 1)
|
||||||
signal.Notify(interrupt, os.Interrupt)
|
signal.Notify(interrupt, os.Interrupt)
|
||||||
|
if role == 1 {
|
||||||
|
c.cs.Lock()
|
||||||
|
c.cs.channel.spin.Suffix = " connecting..."
|
||||||
|
c.cs.channel.spin.Start()
|
||||||
|
c.cs.Unlock()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// connect to the websocket
|
// connect to the websocket
|
||||||
u := url.URL{Scheme: strings.Split(c.WebsocketAddress, "://")[0], Host: strings.Split(c.WebsocketAddress, "://")[1], Path: "/"}
|
u := url.URL{Scheme: strings.Split(c.WebsocketAddress, "://")[0], Host: strings.Split(c.WebsocketAddress, "://")[1], Path: "/"}
|
||||||
|
@ -50,6 +57,12 @@ func (c *Croc) client(role int, channel string) (err error) {
|
||||||
// add websocket to locked channel
|
// add websocket to locked channel
|
||||||
c.cs.Lock()
|
c.cs.Lock()
|
||||||
c.cs.channel.ws = ws
|
c.cs.channel.ws = ws
|
||||||
|
if role == 1 {
|
||||||
|
c.cs.channel.spin.Stop()
|
||||||
|
c.cs.channel.spin.Suffix = " waiting for other..."
|
||||||
|
c.cs.channel.spin.Start()
|
||||||
|
c.cs.channel.waitingForOther = true
|
||||||
|
}
|
||||||
c.cs.Unlock()
|
c.cs.Unlock()
|
||||||
|
|
||||||
// read in the messages and process them
|
// read in the messages and process them
|
||||||
|
@ -235,6 +248,11 @@ func (c *Croc) processState(cd channelData) (err error) {
|
||||||
log.Debugf("local IP: %s", c.cs.channel.Addresses[0])
|
log.Debugf("local IP: %s", c.cs.channel.Addresses[0])
|
||||||
}
|
}
|
||||||
c.bothConnected = cd.Addresses[0] != "" && cd.Addresses[1] != ""
|
c.bothConnected = cd.Addresses[0] != "" && cd.Addresses[1] != ""
|
||||||
|
if c.cs.channel.Role == 1 && c.cs.channel.waitingForOther {
|
||||||
|
c.cs.channel.waitingForOther = false
|
||||||
|
c.cs.channel.spin.Stop()
|
||||||
|
c.cs.channel.waitingForPake = true
|
||||||
|
}
|
||||||
|
|
||||||
// update the Pake
|
// update the Pake
|
||||||
if cd.Pake != nil && cd.Pake.Role != c.cs.channel.Role {
|
if cd.Pake != nil && cd.Pake.Role != c.cs.channel.Role {
|
||||||
|
@ -262,6 +280,10 @@ func (c *Croc) processState(cd channelData) (err error) {
|
||||||
go c.getFilesReady()
|
go c.getFilesReady()
|
||||||
c.cs.channel.filesReady = true
|
c.cs.channel.filesReady = true
|
||||||
}
|
}
|
||||||
|
if c.cs.channel.Role == 1 && c.cs.channel.Pake.IsVerified() && c.cs.channel.waitingForPake {
|
||||||
|
c.cs.channel.waitingForPake = false
|
||||||
|
c.cs.channel.spin.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
// process the client state
|
// process the client state
|
||||||
if c.cs.channel.Pake.IsVerified() && !c.cs.channel.isReady && c.cs.channel.EncryptedFileMetaData.Encrypted != nil {
|
if c.cs.channel.Pake.IsVerified() && !c.cs.channel.isReady && c.cs.channel.EncryptedFileMetaData.Encrypted != nil {
|
||||||
|
@ -302,6 +324,21 @@ func (c *Croc) processState(cd channelData) (err error) {
|
||||||
c.cs.channel.isReady = true
|
c.cs.channel.isReady = true
|
||||||
go c.spawnConnections(c.cs.channel.Role)
|
go c.spawnConnections(c.cs.channel.Role)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// process spinner
|
||||||
|
if c.cs.channel.Role == 1 && !c.cs.channel.spin.Active() {
|
||||||
|
doStart := true
|
||||||
|
if c.cs.channel.waitingForOther {
|
||||||
|
c.cs.channel.spin.Suffix = " waiting for other..."
|
||||||
|
} else if c.cs.channel.waitingForPake {
|
||||||
|
c.cs.channel.spin.Suffix = " performing PAKE..."
|
||||||
|
} else {
|
||||||
|
doStart = false
|
||||||
|
}
|
||||||
|
if doStart {
|
||||||
|
c.cs.channel.spin.Start()
|
||||||
|
}
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/briandowns/spinner"
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/schollz/pake"
|
"github.com/schollz/pake"
|
||||||
"github.com/schollz/progressbar"
|
"github.com/schollz/progressbar"
|
||||||
|
@ -75,6 +76,7 @@ func Init() (c *Croc) {
|
||||||
c.rs.channel = make(map[string]*channelData)
|
c.rs.channel = make(map[string]*channelData)
|
||||||
c.rs.ips = make(map[string]string)
|
c.rs.ips = make(map[string]string)
|
||||||
c.cs.channel = new(channelData)
|
c.cs.channel = new(channelData)
|
||||||
|
c.cs.channel.spin = spinner.New(spinner.CharSets[9], 100*time.Millisecond)
|
||||||
c.rs.Unlock()
|
c.rs.Unlock()
|
||||||
c.localIP = getLocalIP()
|
c.localIP = getLocalIP()
|
||||||
return
|
return
|
||||||
|
@ -167,6 +169,12 @@ type channelData struct {
|
||||||
startTransfer time.Time
|
startTransfer time.Time
|
||||||
transferTime time.Duration
|
transferTime time.Duration
|
||||||
|
|
||||||
|
// spin is the spinner for the recipient
|
||||||
|
spin *spinner.Spinner
|
||||||
|
waitingForConnection bool
|
||||||
|
waitingForOther bool
|
||||||
|
waitingForPake bool
|
||||||
|
|
||||||
// ws is the connection that the client has to the relay
|
// ws is the connection that the client has to the relay
|
||||||
ws *websocket.Conn
|
ws *websocket.Conn
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue