mirror of https://github.com/schollz/croc.git
try ipv6 first
This commit is contained in:
parent
695444159e
commit
50bf003022
|
@ -79,6 +79,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: "ask", Usage: "make sure sender and recipient are prompted"},
|
cli.BoolFlag{Name: "ask", Usage: "make sure sender and recipient are prompted"},
|
||||||
cli.StringFlag{Name: "relay", Value: models.DEFAULT_RELAY, Usage: "address of the relay"},
|
cli.StringFlag{Name: "relay", Value: models.DEFAULT_RELAY, Usage: "address of the relay"},
|
||||||
|
cli.StringFlag{Name: "relay6", Value: models.DEFAULT_RELAY6, Usage: "ipv6 address of the relay"},
|
||||||
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"},
|
||||||
cli.StringFlag{Name: "pass", Value: "pass123", Usage: "password for the relay"},
|
cli.StringFlag{Name: "pass", Value: "pass123", Usage: "password for the relay"},
|
||||||
}
|
}
|
||||||
|
@ -143,6 +144,7 @@ func send(c *cli.Context) (err error) {
|
||||||
Debug: c.GlobalBool("debug"),
|
Debug: c.GlobalBool("debug"),
|
||||||
NoPrompt: c.GlobalBool("yes"),
|
NoPrompt: c.GlobalBool("yes"),
|
||||||
RelayAddress: c.GlobalString("relay"),
|
RelayAddress: c.GlobalString("relay"),
|
||||||
|
RelayAddress6: c.GlobalString("relay6"),
|
||||||
Stdout: c.GlobalBool("stdout"),
|
Stdout: c.GlobalBool("stdout"),
|
||||||
DisableLocal: c.Bool("no-local"),
|
DisableLocal: c.Bool("no-local"),
|
||||||
RelayPorts: strings.Split(c.String("ports"), ","),
|
RelayPorts: strings.Split(c.String("ports"), ","),
|
||||||
|
@ -150,6 +152,11 @@ func send(c *cli.Context) (err error) {
|
||||||
NoMultiplexing: c.Bool("no-multi"),
|
NoMultiplexing: c.Bool("no-multi"),
|
||||||
RelayPassword: c.GlobalString("pass"),
|
RelayPassword: c.GlobalString("pass"),
|
||||||
}
|
}
|
||||||
|
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
||||||
|
crocOptions.RelayAddress6 = ""
|
||||||
|
} else if crocOptions.RelayAddress6 != models.DEFAULT_RELAY6 {
|
||||||
|
crocOptions.RelayAddress = ""
|
||||||
|
}
|
||||||
b, errOpen := ioutil.ReadFile(getConfigFile())
|
b, errOpen := ioutil.ReadFile(getConfigFile())
|
||||||
if errOpen == nil && !c.GlobalBool("remember") {
|
if errOpen == nil && !c.GlobalBool("remember") {
|
||||||
var rememberedOptions croc.Options
|
var rememberedOptions croc.Options
|
||||||
|
@ -300,10 +307,16 @@ func receive(c *cli.Context) (err error) {
|
||||||
Debug: c.GlobalBool("debug"),
|
Debug: c.GlobalBool("debug"),
|
||||||
NoPrompt: c.GlobalBool("yes"),
|
NoPrompt: c.GlobalBool("yes"),
|
||||||
RelayAddress: c.GlobalString("relay"),
|
RelayAddress: c.GlobalString("relay"),
|
||||||
|
RelayAddress6: c.GlobalString("relay6"),
|
||||||
Stdout: c.GlobalBool("stdout"),
|
Stdout: c.GlobalBool("stdout"),
|
||||||
Ask: c.GlobalBool("ask"),
|
Ask: c.GlobalBool("ask"),
|
||||||
RelayPassword: c.GlobalString("pass"),
|
RelayPassword: c.GlobalString("pass"),
|
||||||
}
|
}
|
||||||
|
if crocOptions.RelayAddress != models.DEFAULT_RELAY {
|
||||||
|
crocOptions.RelayAddress6 = ""
|
||||||
|
} else if crocOptions.RelayAddress6 != models.DEFAULT_RELAY6 {
|
||||||
|
crocOptions.RelayAddress = ""
|
||||||
|
}
|
||||||
|
|
||||||
switch len(c.Args()) {
|
switch len(c.Args()) {
|
||||||
case 1:
|
case 1:
|
||||||
|
|
|
@ -53,6 +53,7 @@ type Options struct {
|
||||||
SharedSecret string
|
SharedSecret string
|
||||||
Debug bool
|
Debug bool
|
||||||
RelayAddress string
|
RelayAddress string
|
||||||
|
RelayAddress6 string
|
||||||
RelayPorts []string
|
RelayPorts []string
|
||||||
RelayPassword string
|
RelayPassword string
|
||||||
Stdout bool
|
Stdout bool
|
||||||
|
@ -342,20 +343,32 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
host, port, err := net.SplitHostPort(c.Options.RelayAddress)
|
var ipaddr, banner string
|
||||||
if err != nil {
|
var conn *comm.Comm
|
||||||
log.Errorf("bad relay address %s", c.Options.RelayAddress)
|
durations := []time.Duration{100 * time.Millisecond, 5 * time.Second}
|
||||||
return
|
for i, address := range []string{c.Options.RelayAddress6, c.Options.RelayAddress} {
|
||||||
|
if address == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
host, port, err := net.SplitHostPort(address)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("bad relay address %s", address)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Default port to :9009
|
||||||
|
if port == "" {
|
||||||
|
port = "9009"
|
||||||
|
}
|
||||||
|
log.Debugf("got host '%v' and port '%v'", host, port)
|
||||||
|
address = net.JoinHostPort(host, port)
|
||||||
|
log.Debugf("trying connection to %s", address)
|
||||||
|
conn, banner, ipaddr, err = tcp.ConnectToTCPServer(address, c.Options.RelayPassword, c.Options.SharedSecret[:3], durations[i])
|
||||||
|
if err == nil {
|
||||||
|
c.Options.RelayAddress = address
|
||||||
|
break
|
||||||
|
}
|
||||||
|
log.Debugf("could not establish '%s'", address)
|
||||||
}
|
}
|
||||||
// Default port to :9009
|
|
||||||
if port == "" {
|
|
||||||
port = "9009"
|
|
||||||
}
|
|
||||||
log.Debugf("got host '%v' and port '%v'", host, port)
|
|
||||||
c.Options.RelayAddress = net.JoinHostPort(host, port)
|
|
||||||
log.Debugf("establishing connection to %s", c.Options.RelayAddress)
|
|
||||||
var banner string
|
|
||||||
conn, banner, ipaddr, err := tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.RelayPassword, c.Options.SharedSecret[:3], 5*time.Second)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("could not connect to %s: %w", c.Options.RelayAddress, err)
|
err = fmt.Errorf("could not connect to %s: %w", c.Options.RelayAddress, err)
|
||||||
log.Debug(err)
|
log.Debug(err)
|
||||||
|
@ -486,26 +499,41 @@ func (c *Client) Receive() (err error) {
|
||||||
}
|
}
|
||||||
c.Options.RelayAddress = net.JoinHostPort(discoveries[0].Address, portToUse)
|
c.Options.RelayAddress = net.JoinHostPort(discoveries[0].Address, portToUse)
|
||||||
c.ExternalIPConnected = c.Options.RelayAddress
|
c.ExternalIPConnected = c.Options.RelayAddress
|
||||||
|
c.Options.RelayAddress6 = ""
|
||||||
usingLocal = true
|
usingLocal = true
|
||||||
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Debugf("discoveries: %+v", discoveries)
|
log.Debugf("discoveries: %+v", discoveries)
|
||||||
log.Debug("establishing connection")
|
log.Debug("establishing connection")
|
||||||
}
|
}
|
||||||
host, port, err := net.SplitHostPort(c.Options.RelayAddress)
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("bad relay address %s", c.Options.RelayAddress)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
// Default port to :9009
|
|
||||||
if port == "" {
|
|
||||||
port = "9009"
|
|
||||||
}
|
|
||||||
c.Options.RelayAddress = net.JoinHostPort(host, port)
|
|
||||||
log.Debugf("establishing receiver connection to %s", c.Options.RelayAddress)
|
|
||||||
var banner string
|
var banner string
|
||||||
c.conn[0], banner, c.ExternalIP, err = tcp.ConnectToTCPServer(c.Options.RelayAddress, c.Options.RelayPassword, c.Options.SharedSecret[:3])
|
durations := []time.Duration{100 * time.Millisecond, 5 * time.Second}
|
||||||
|
for i, address := range []string{c.Options.RelayAddress6, c.Options.RelayAddress} {
|
||||||
|
if address == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
host, port, err := net.SplitHostPort(address)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("bad relay address %s", address)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Default port to :9009
|
||||||
|
if port == "" {
|
||||||
|
port = "9009"
|
||||||
|
}
|
||||||
|
log.Debugf("got host '%v' and port '%v'", host, port)
|
||||||
|
address = net.JoinHostPort(host, port)
|
||||||
|
log.Debugf("trying connection to %s", address)
|
||||||
|
c.conn[0], banner, c.ExternalIP, err = tcp.ConnectToTCPServer(address, c.Options.RelayPassword, c.Options.SharedSecret[:3], durations[i])
|
||||||
|
if err == nil {
|
||||||
|
c.Options.RelayAddress = address
|
||||||
|
break
|
||||||
|
}
|
||||||
|
log.Debugf("could not establish '%s'", address)
|
||||||
|
}
|
||||||
|
|
||||||
log.Debugf("banner: %s", banner)
|
log.Debugf("banner: %s", banner)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = fmt.Errorf("could not connect to %s: %w", c.Options.RelayAddress, err)
|
err = fmt.Errorf("could not connect to %s: %w", c.Options.RelayAddress, err)
|
||||||
|
|
Loading…
Reference in New Issue