mirror of
https://github.com/schollz/croc.git
synced 2024-11-30 23:52:07 +03:00
parent
2b8f581ca4
commit
aefb15105a
@ -74,8 +74,8 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
|||||||
// start a spinner
|
// start a spinner
|
||||||
spin := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
|
spin := spinner.New(spinner.CharSets[9], 100*time.Millisecond)
|
||||||
spin.Writer = os.Stderr
|
spin.Writer = os.Stderr
|
||||||
spin.Suffix = " performing PAKE..."
|
spin.Suffix = " connecting..."
|
||||||
cr.StateString = "Performing PAKE..."
|
cr.StateString = "Connecting as recipient..."
|
||||||
spin.Start()
|
spin.Start()
|
||||||
defer spin.Stop()
|
defer spin.Stop()
|
||||||
|
|
||||||
@ -98,10 +98,28 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
|||||||
|
|
||||||
step := 0
|
step := 0
|
||||||
for {
|
for {
|
||||||
websocketMessage := <-websocketMessages
|
var websocketMessageMain WebSocketMessage
|
||||||
messageType := websocketMessage.messageType
|
// websocketMessageMain = <-websocketMessages
|
||||||
message := websocketMessage.message
|
timeWaitingForMessage := time.Now()
|
||||||
err := websocketMessage.err
|
for {
|
||||||
|
done := false
|
||||||
|
select {
|
||||||
|
case websocketMessageMain = <-websocketMessages:
|
||||||
|
done = true
|
||||||
|
default:
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
if done {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if time.Since(timeWaitingForMessage).Seconds() > 3 && step == 0 {
|
||||||
|
return fmt.Errorf("You are trying to receive a file with no sender.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
messageType := websocketMessageMain.messageType
|
||||||
|
message := websocketMessageMain.message
|
||||||
|
err := websocketMessageMain.err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -115,6 +133,10 @@ func (cr *Croc) receive(forceSend int, serverAddress string, tcpPorts []string,
|
|||||||
log.Debugf("got %d: %s", messageType, message)
|
log.Debugf("got %d: %s", messageType, message)
|
||||||
switch step {
|
switch step {
|
||||||
case 0:
|
case 0:
|
||||||
|
spin.Stop()
|
||||||
|
spin.Suffix = " performing PAKE..."
|
||||||
|
cr.StateString = "Performing PAKE..."
|
||||||
|
spin.Start()
|
||||||
// sender has initiated, sends their initial data
|
// sender has initiated, sends their initial data
|
||||||
var initialData models.Initial
|
var initialData models.Initial
|
||||||
err = json.Unmarshal(message, &initialData)
|
err = json.Unmarshal(message, &initialData)
|
||||||
|
Loading…
Reference in New Issue
Block a user