mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 05:11:06 +02:00
Merge branch 'master' of github.com:schollz/croc
This commit is contained in:
commit
037dbbd4e9
4 changed files with 25 additions and 6 deletions
|
@ -85,6 +85,7 @@ func Run() (err error) {
|
|||
&cli.BoolFlag{Name: "no-compress", Usage: "disable compression"},
|
||||
&cli.BoolFlag{Name: "ask", Usage: "make sure sender and recipient are prompted"},
|
||||
&cli.BoolFlag{Name: "local", Usage: "force to use only local connections"},
|
||||
&cli.StringFlag{Name: "ip", Value: "", Usage: "set sender ip if known e.g. 10.0.0.1:9009, [::1]:9009"},
|
||||
&cli.StringFlag{Name: "relay", Value: models.DEFAULT_RELAY, Usage: "address of the relay", EnvVars: []string{"CROC_RELAY"}},
|
||||
&cli.StringFlag{Name: "relay6", Value: models.DEFAULT_RELAY6, Usage: "ipv6 address of the relay", EnvVars: []string{"CROC_RELAY6"}},
|
||||
&cli.StringFlag{Name: "out", Value: ".", Usage: "specify an output folder to receive the file"},
|
||||
|
@ -376,6 +377,7 @@ func receive(c *cli.Context) (err error) {
|
|||
Ask: c.Bool("ask"),
|
||||
RelayPassword: determinePass(c),
|
||||
OnlyLocal: c.Bool("local"),
|
||||
IP: c.String("ip"),
|
||||
}
|
||||
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
||||
crocOptions.RelayAddress6 = ""
|
||||
|
|
|
@ -64,6 +64,7 @@ type Options struct {
|
|||
Ask bool
|
||||
SendingText bool
|
||||
NoCompress bool
|
||||
IP string
|
||||
}
|
||||
|
||||
// Client holds the state of the croc transfer
|
||||
|
@ -487,11 +488,27 @@ func (c *Client) Receive() (err error) {
|
|||
// recipient will look for peers first
|
||||
// and continue if it doesn't find any within 100 ms
|
||||
usingLocal := false
|
||||
if c.Options.OnlyLocal {
|
||||
isIPset := false
|
||||
|
||||
if c.Options.OnlyLocal || c.Options.IP != "" {
|
||||
c.Options.RelayAddress = ""
|
||||
c.Options.RelayAddress6 = ""
|
||||
}
|
||||
if !c.Options.DisableLocal {
|
||||
|
||||
if c.Options.IP != "" {
|
||||
// check ip version
|
||||
if strings.Count(c.Options.IP, ":") >= 2 {
|
||||
log.Debug("assume ipv6")
|
||||
c.Options.RelayAddress6 = c.Options.IP
|
||||
}
|
||||
if strings.Contains(c.Options.IP, ".") {
|
||||
log.Debug("assume ipv4")
|
||||
c.Options.RelayAddress = c.Options.IP
|
||||
}
|
||||
isIPset = true
|
||||
}
|
||||
|
||||
if !c.Options.DisableLocal && !isIPset {
|
||||
log.Debug("attempt to discover peers")
|
||||
var discoveries []peerdiscovery.Discovered
|
||||
var wgDiscovery sync.WaitGroup
|
||||
|
@ -589,7 +606,7 @@ func (c *Client) Receive() (err error) {
|
|||
log.Debugf("receiver connection established: %+v", c.conn[0])
|
||||
log.Debugf("banner: %s", banner)
|
||||
|
||||
if !usingLocal && !c.Options.DisableLocal {
|
||||
if !usingLocal && !c.Options.DisableLocal && !isIPset {
|
||||
// ask the sender for their local ips and port
|
||||
// and try to connect to them
|
||||
log.Debug("sending ips?")
|
||||
|
|
|
@ -136,7 +136,7 @@ func GetRandomName() string {
|
|||
|
||||
// ByteCountDecimal converts bytes to human readable byte string
|
||||
func ByteCountDecimal(b int64) string {
|
||||
const unit = 1000
|
||||
const unit = 1024
|
||||
if b < unit {
|
||||
return fmt.Sprintf("%d B", b)
|
||||
}
|
||||
|
|
|
@ -88,9 +88,9 @@ func TestSHA256(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestByteCountDecimal(t *testing.T) {
|
||||
assert.Equal(t, "10.0 kB", ByteCountDecimal(10000))
|
||||
assert.Equal(t, "10.0 kB", ByteCountDecimal(10240))
|
||||
assert.Equal(t, "50 B", ByteCountDecimal(50))
|
||||
assert.Equal(t, "12.4 MB", ByteCountDecimal(12378517))
|
||||
assert.Equal(t, "12.4 MB", ByteCountDecimal(13002343))
|
||||
}
|
||||
|
||||
func TestMissingChunks(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue