mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 21:30:16 +02:00
use only local
This commit is contained in:
parent
1967ef57be
commit
3129b097af
2 changed files with 88 additions and 77 deletions
|
@ -84,6 +84,7 @@ func Run() (err error) {
|
||||||
&cli.BoolFlag{Name: "stdout", Usage: "redirect file to stdout"},
|
&cli.BoolFlag{Name: "stdout", Usage: "redirect file to stdout"},
|
||||||
&cli.BoolFlag{Name: "no-compress", Usage: "disable compression"},
|
&cli.BoolFlag{Name: "no-compress", Usage: "disable compression"},
|
||||||
&cli.BoolFlag{Name: "ask", Usage: "make sure sender and recipient are prompted"},
|
&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: "relay", Value: models.DEFAULT_RELAY, Usage: "address of the relay", EnvVars: []string{"CROC_RELAY"}},
|
&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: "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"},
|
&cli.StringFlag{Name: "out", Value: ".", Usage: "specify an output folder to receive the file"},
|
||||||
|
@ -174,6 +175,7 @@ func send(c *cli.Context) (err error) {
|
||||||
RelayAddress6: c.String("relay6"),
|
RelayAddress6: c.String("relay6"),
|
||||||
Stdout: c.Bool("stdout"),
|
Stdout: c.Bool("stdout"),
|
||||||
DisableLocal: c.Bool("no-local"),
|
DisableLocal: c.Bool("no-local"),
|
||||||
|
OnlyLocal: c.Bool("local"),
|
||||||
RelayPorts: strings.Split(c.String("ports"), ","),
|
RelayPorts: strings.Split(c.String("ports"), ","),
|
||||||
Ask: c.Bool("ask"),
|
Ask: c.Bool("ask"),
|
||||||
NoMultiplexing: c.Bool("no-multi"),
|
NoMultiplexing: c.Bool("no-multi"),
|
||||||
|
@ -373,6 +375,7 @@ func receive(c *cli.Context) (err error) {
|
||||||
Stdout: c.Bool("stdout"),
|
Stdout: c.Bool("stdout"),
|
||||||
Ask: c.Bool("ask"),
|
Ask: c.Bool("ask"),
|
||||||
RelayPassword: determinePass(c),
|
RelayPassword: determinePass(c),
|
||||||
|
OnlyLocal: c.Bool("local"),
|
||||||
}
|
}
|
||||||
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
||||||
crocOptions.RelayAddress6 = ""
|
crocOptions.RelayAddress6 = ""
|
||||||
|
|
|
@ -60,6 +60,7 @@ type Options struct {
|
||||||
NoPrompt bool
|
NoPrompt bool
|
||||||
NoMultiplexing bool
|
NoMultiplexing bool
|
||||||
DisableLocal bool
|
DisableLocal bool
|
||||||
|
OnlyLocal bool
|
||||||
Ask bool
|
Ask bool
|
||||||
SendingText bool
|
SendingText bool
|
||||||
NoCompress bool
|
NoCompress bool
|
||||||
|
@ -372,6 +373,7 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
||||||
go c.transferOverLocalRelay(options, errchan)
|
go c.transferOverLocalRelay(options, errchan)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !c.Options.OnlyLocal {
|
||||||
go func() {
|
go func() {
|
||||||
var ipaddr, banner string
|
var ipaddr, banner string
|
||||||
var conn *comm.Comm
|
var conn *comm.Comm
|
||||||
|
@ -454,6 +456,7 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
||||||
log.Debug("exchanged header message")
|
log.Debug("exchanged header message")
|
||||||
errchan <- c.transfer(options)
|
errchan <- c.transfer(options)
|
||||||
}()
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
err = <-errchan
|
err = <-errchan
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
@ -480,6 +483,10 @@ func (c *Client) Receive() (err error) {
|
||||||
// recipient will look for peers first
|
// recipient will look for peers first
|
||||||
// and continue if it doesn't find any within 100 ms
|
// and continue if it doesn't find any within 100 ms
|
||||||
usingLocal := false
|
usingLocal := false
|
||||||
|
if c.Options.OnlyLocal {
|
||||||
|
c.Options.RelayAddress = ""
|
||||||
|
c.Options.RelayAddress6 = ""
|
||||||
|
}
|
||||||
if !c.Options.DisableLocal {
|
if !c.Options.DisableLocal {
|
||||||
log.Debug("attempt to discover peers")
|
log.Debug("attempt to discover peers")
|
||||||
var discoveries []peerdiscovery.Discovered
|
var discoveries []peerdiscovery.Discovered
|
||||||
|
@ -544,6 +551,7 @@ func (c *Client) Receive() (err error) {
|
||||||
}
|
}
|
||||||
var banner string
|
var banner string
|
||||||
durations := []time.Duration{100 * time.Millisecond, 5 * time.Second}
|
durations := []time.Duration{100 * time.Millisecond, 5 * time.Second}
|
||||||
|
err = fmt.Errorf("found no addresses to connect")
|
||||||
for i, address := range []string{c.Options.RelayAddress6, c.Options.RelayAddress} {
|
for i, address := range []string{c.Options.RelayAddress6, c.Options.RelayAddress} {
|
||||||
if address == "" {
|
if address == "" {
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue