mirror of
https://github.com/schollz/croc.git
synced 2024-11-24 08:02:33 +03:00
use machine ID
This commit is contained in:
parent
42c2d5c6c1
commit
9aa327a0a4
3
go.mod
3
go.mod
@ -6,6 +6,7 @@ require (
|
|||||||
github.com/OneOfOne/xxhash v1.2.5 // indirect
|
github.com/OneOfOne/xxhash v1.2.5 // indirect
|
||||||
github.com/cespare/xxhash v1.1.0
|
github.com/cespare/xxhash v1.1.0
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
|
||||||
|
github.com/denisbrodbeck/machineid v1.0.1
|
||||||
github.com/fatih/color v1.7.0 // indirect
|
github.com/fatih/color v1.7.0 // indirect
|
||||||
github.com/kalafut/imohash v1.0.0
|
github.com/kalafut/imohash v1.0.0
|
||||||
github.com/kr/pretty v0.1.0 // indirect
|
github.com/kr/pretty v0.1.0 // indirect
|
||||||
@ -23,7 +24,7 @@ require (
|
|||||||
github.com/urfave/cli v1.22.1
|
github.com/urfave/cli v1.22.1
|
||||||
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc
|
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc
|
||||||
golang.org/x/net v0.0.0-20191003171128-d98b1b443823 // indirect
|
golang.org/x/net v0.0.0-20191003171128-d98b1b443823 // indirect
|
||||||
golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed // indirect
|
golang.org/x/sys v0.0.0-20191023151326-f89234f9a2c2 // indirect
|
||||||
golang.org/x/text v0.3.2 // indirect
|
golang.org/x/text v0.3.2 // indirect
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||||
)
|
)
|
||||||
|
4
go.sum
4
go.sum
@ -12,6 +12,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.0/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsr
|
|||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
|
||||||
|
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
|
||||||
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||||
github.com/kalafut/imohash v1.0.0 h1:LgCJ+p/BwM2HKpOxFopkeddpzVCfm15EtXMroXD1SYE=
|
github.com/kalafut/imohash v1.0.0 h1:LgCJ+p/BwM2HKpOxFopkeddpzVCfm15EtXMroXD1SYE=
|
||||||
@ -83,6 +85,8 @@ golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a h1:aYOabOQFp6Vj6W1F80affTUvO
|
|||||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed h1:5TJcLJn2a55mJjzYk0yOoqN8X1OdvBDUnaZaKKyQtkY=
|
golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed h1:5TJcLJn2a55mJjzYk0yOoqN8X1OdvBDUnaZaKKyQtkY=
|
||||||
golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191002091554-b397fe3ad8ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20191023151326-f89234f9a2c2 h1:I7efaDQAsIQmkTF+WSdcydwVWzK07Yuz8IFF8rNkDe0=
|
||||||
|
golang.org/x/sys v0.0.0-20191023151326-f89234f9a2c2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||||
|
@ -17,6 +17,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/denisbrodbeck/machineid"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/schollz/croc/v6/src/comm"
|
"github.com/schollz/croc/v6/src/comm"
|
||||||
"github.com/schollz/croc/v6/src/compress"
|
"github.com/schollz/croc/v6/src/compress"
|
||||||
@ -124,11 +125,13 @@ type FileInfo struct {
|
|||||||
type RemoteFileRequest struct {
|
type RemoteFileRequest struct {
|
||||||
CurrentFileChunkRanges []int64
|
CurrentFileChunkRanges []int64
|
||||||
FilesToTransferCurrentNum int
|
FilesToTransferCurrentNum int
|
||||||
|
MachineID string
|
||||||
}
|
}
|
||||||
|
|
||||||
// SenderInfo lists the files to be transferred
|
// SenderInfo lists the files to be transferred
|
||||||
type SenderInfo struct {
|
type SenderInfo struct {
|
||||||
FilesToTransfer []FileInfo
|
FilesToTransfer []FileInfo
|
||||||
|
MachineID string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New establishes a new connection for transferring files between two instances.
|
// 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 + " "
|
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)
|
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.Suffix = " waiting for recipient..."
|
||||||
// c.spinner.Start()
|
// c.spinner.Start()
|
||||||
// create channel for quitting
|
// create channel for quitting
|
||||||
@ -521,7 +528,12 @@ func (c *Client) processMessageFileInfo(m message.Message) (done bool, err error
|
|||||||
}
|
}
|
||||||
// c.spinner.Stop()
|
// c.spinner.Stop()
|
||||||
if !c.Options.NoPrompt || c.Options.Ask {
|
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" {
|
if strings.ToLower(strings.TrimSpace(utils.GetInput(""))) != "y" {
|
||||||
err = message.Send(c.conn[0], c.Key, message.Message{
|
err = message.Send(c.conn[0], c.Key, message.Message{
|
||||||
Type: "error",
|
Type: "error",
|
||||||
@ -667,6 +679,19 @@ func (c *Client) processMessage(payload []byte) (done bool, err error) {
|
|||||||
c.chunkMap[uint64(chunk)] = struct{}{}
|
c.chunkMap[uint64(chunk)] = struct{}{}
|
||||||
}
|
}
|
||||||
c.Step3RecipientRequestFile = true
|
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":
|
case "close-sender":
|
||||||
c.bar.Finish()
|
c.bar.Finish()
|
||||||
log.Debug("close-sender received...")
|
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) {
|
func (c *Client) updateIfSenderChannelSecured() (err error) {
|
||||||
if c.Options.IsSender && c.Step1ChannelSecured && !c.Step2FileInfoTransfered {
|
if c.Options.IsSender && c.Step1ChannelSecured && !c.Step2FileInfoTransfered {
|
||||||
var b []byte
|
var b []byte
|
||||||
|
machID, _ := machineid.ID()
|
||||||
b, err = json.Marshal(SenderInfo{
|
b, err = json.Marshal(SenderInfo{
|
||||||
FilesToTransfer: c.FilesToTransfer,
|
FilesToTransfer: c.FilesToTransfer,
|
||||||
|
MachineID: machID,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
@ -785,9 +812,11 @@ func (c *Client) recipientGetFileReady(finished bool) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
c.TotalSent = 0
|
c.TotalSent = 0
|
||||||
|
machID, _ := machineid.ID()
|
||||||
bRequest, _ := json.Marshal(RemoteFileRequest{
|
bRequest, _ := json.Marshal(RemoteFileRequest{
|
||||||
CurrentFileChunkRanges: c.CurrentFileChunkRanges,
|
CurrentFileChunkRanges: c.CurrentFileChunkRanges,
|
||||||
FilesToTransferCurrentNum: c.FilesToTransferCurrentNum,
|
FilesToTransferCurrentNum: c.FilesToTransferCurrentNum,
|
||||||
|
MachineID: machID,
|
||||||
})
|
})
|
||||||
log.Debug("converting to chunk range")
|
log.Debug("converting to chunk range")
|
||||||
c.CurrentFileChunks = utils.ChunkRangesToChunks(c.CurrentFileChunkRanges)
|
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.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!")
|
log.Debug("start sending data!")
|
||||||
|
|
||||||
if !c.firstSend {
|
if !c.firstSend {
|
||||||
|
Loading…
Reference in New Issue
Block a user