1
1
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

handle errors from peer

This commit is contained in:
Zack Scholl 2019-04-12 12:15:09 -07:00
parent 8a843a6a85
commit 93a3ec70e7
2 changed files with 14 additions and 2 deletions

View file

@ -2,6 +2,7 @@ package main
import (
"flag"
"fmt"
"github.com/schollz/croc/v5/src/croc"
)
@ -43,6 +44,6 @@ func main() {
err = c.Receive()
}
if err != nil {
panic(err)
fmt.Println(err)
}
}

View file

@ -392,6 +392,11 @@ func (c *Client) processMessage(m Message) (err error) {
c.log.Debug(c.Pake.SessionKey())
c.Step1ChannelSecured = true
}
case "error":
c.spinner.Stop()
fmt.Print("\r")
err = fmt.Errorf("peer error: %s", m.Message)
return err
case "fileinfo":
var senderInfo SenderInfo
var decryptedBytes []byte
@ -417,7 +422,13 @@ func (c *Client) processMessage(m Message) (err error) {
}
c.spinner.Stop()
fmt.Fprintf(os.Stderr, "\rAccept %s (%s) from machine '%s'? (y/n) ", fname, utils.ByteCountDecimal(totalSize), senderInfo.MachineID)
utils.GetInput("")
if strings.ToLower(strings.TrimSpace(utils.GetInput(""))) != "y" {
err = c.redisdb.Publish(c.nameOutChannel, Message{
Type: "error",
Message: "refusing files",
}.String()).Err()
return fmt.Errorf("refused files")
}
// TODO: accept file question?
c.log.Debug(c.FilesToTransfer)
c.Step2FileInfoTransfered = true