mirror of https://github.com/schollz/croc.git
Merge pull request #310 from vzlcn0/master
add new cmd option to set sender ip
This commit is contained in:
commit
235f065a9c
|
@ -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?")
|
||||
|
|
Loading…
Reference in New Issue