1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-30 23:52:07 +03:00

recipient quits if trying to connect without sender

Addresses #109
This commit is contained in:
Zack Scholl 2018-11-01 06:56:40 -07:00
parent 2b8f581ca4
commit aefb15105a

View File

@ -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)