mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
use machine ID
This commit is contained in:
parent
42c2d5c6c1
commit
9aa327a0a4
3 changed files with 36 additions and 13 deletions
|
@ -17,6 +17,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/denisbrodbeck/machineid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/schollz/croc/v6/src/comm"
|
||||
"github.com/schollz/croc/v6/src/compress"
|
||||
|
@ -124,11 +125,13 @@ type FileInfo struct {
|
|||
type RemoteFileRequest struct {
|
||||
CurrentFileChunkRanges []int64
|
||||
FilesToTransferCurrentNum int
|
||||
MachineID string
|
||||
}
|
||||
|
||||
// SenderInfo lists the files to be transferred
|
||||
type SenderInfo struct {
|
||||
FilesToTransfer []FileInfo
|
||||
MachineID string
|
||||
}
|
||||
|
||||
// New establishes a new connection for transferring files between two instances.
|
||||
|
@ -304,6 +307,10 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
|||
otherRelay = "--relay " + c.Options.RelayAddress + " "
|
||||
}
|
||||
fmt.Fprintf(os.Stderr, "Code is: %s\nOn the other computer run\n\ncroc %s%s\n", c.Options.SharedSecret, otherRelay, c.Options.SharedSecret)
|
||||
if c.Options.Ask {
|
||||
machid, _ := machineid.ID()
|
||||
fmt.Fprintf(os.Stderr, "\nYour machine ID is '%s'\n", machid)
|
||||
}
|
||||
// // c.spinner.Suffix = " waiting for recipient..."
|
||||
// c.spinner.Start()
|
||||
// create channel for quitting
|
||||
|
@ -521,7 +528,12 @@ func (c *Client) processMessageFileInfo(m message.Message) (done bool, err error
|
|||
}
|
||||
// c.spinner.Stop()
|
||||
if !c.Options.NoPrompt || c.Options.Ask {
|
||||
fmt.Fprintf(os.Stderr, "\rAccept %s (%s)? (y/n) ", fname, utils.ByteCountDecimal(totalSize))
|
||||
if c.Options.Ask && senderInfo.MachineID != "" {
|
||||
machID, _ := machineid.ID()
|
||||
fmt.Fprintf(os.Stderr, "\rYour machine id is '%s'.\nAccept %s (%s) from '%s'? (y/n) ", machID, fname, utils.ByteCountDecimal(totalSize), senderInfo.MachineID)
|
||||
} else {
|
||||
fmt.Fprintf(os.Stderr, "\rAccept %s (%s)? (y/n) ", fname, utils.ByteCountDecimal(totalSize))
|
||||
}
|
||||
if strings.ToLower(strings.TrimSpace(utils.GetInput(""))) != "y" {
|
||||
err = message.Send(c.conn[0], c.Key, message.Message{
|
||||
Type: "error",
|
||||
|
@ -667,6 +679,19 @@ func (c *Client) processMessage(payload []byte) (done bool, err error) {
|
|||
c.chunkMap[uint64(chunk)] = struct{}{}
|
||||
}
|
||||
c.Step3RecipientRequestFile = true
|
||||
|
||||
if c.Options.Ask {
|
||||
fmt.Fprintf(os.Stderr, "\rSend to machine '%s'? (y/n) ", remoteFile.MachineID)
|
||||
if strings.ToLower(strings.TrimSpace(utils.GetInput(""))) != "y" {
|
||||
err = message.Send(c.conn[0], c.Key, message.Message{
|
||||
Type: "error",
|
||||
Message: "refusing files",
|
||||
})
|
||||
done = true
|
||||
err = fmt.Errorf("refused files")
|
||||
return
|
||||
}
|
||||
}
|
||||
case "close-sender":
|
||||
c.bar.Finish()
|
||||
log.Debug("close-sender received...")
|
||||
|
@ -695,8 +720,10 @@ func (c *Client) processMessage(payload []byte) (done bool, err error) {
|
|||
func (c *Client) updateIfSenderChannelSecured() (err error) {
|
||||
if c.Options.IsSender && c.Step1ChannelSecured && !c.Step2FileInfoTransfered {
|
||||
var b []byte
|
||||
machID, _ := machineid.ID()
|
||||
b, err = json.Marshal(SenderInfo{
|
||||
FilesToTransfer: c.FilesToTransfer,
|
||||
MachineID: machID,
|
||||
})
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
|
@ -785,9 +812,11 @@ func (c *Client) recipientGetFileReady(finished bool) (err error) {
|
|||
}
|
||||
|
||||
c.TotalSent = 0
|
||||
machID, _ := machineid.ID()
|
||||
bRequest, _ := json.Marshal(RemoteFileRequest{
|
||||
CurrentFileChunkRanges: c.CurrentFileChunkRanges,
|
||||
FilesToTransferCurrentNum: c.FilesToTransferCurrentNum,
|
||||
MachineID: machID,
|
||||
})
|
||||
log.Debug("converting to chunk range")
|
||||
c.CurrentFileChunks = utils.ChunkRangesToChunks(c.CurrentFileChunkRanges)
|
||||
|
@ -901,17 +930,6 @@ func (c *Client) updateState() (err error) {
|
|||
}
|
||||
|
||||
if c.Options.IsSender && c.Step3RecipientRequestFile && !c.Step4FileTransfer {
|
||||
if c.Options.Ask {
|
||||
fmt.Fprintf(os.Stderr, "\rSend to X? (y/n) ")
|
||||
if strings.ToLower(strings.TrimSpace(utils.GetInput(""))) != "y" {
|
||||
err = message.Send(c.conn[0], c.Key, message.Message{
|
||||
Type: "error",
|
||||
Message: "refusing files",
|
||||
})
|
||||
return fmt.Errorf("refused files")
|
||||
}
|
||||
}
|
||||
|
||||
log.Debug("start sending data!")
|
||||
|
||||
if !c.firstSend {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue