diff --git a/src/cli/cli.go b/src/cli/cli.go index fa20cb43..4d2a2246 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -21,7 +21,7 @@ import ( var Version string func Run() (err error) { -// use all of the processors + // use all of the processors runtime.GOMAXPROCS(runtime.NumCPU()) app := cli.NewApp() @@ -42,6 +42,7 @@ func Run() (err error) { ArgsUsage: "[filename]", Flags: []cli.Flag{ cli.StringFlag{Name: "code, c", Usage: "codephrase used to connect to relay"}, + cli.BoolFlag{Name: "no-local", Usage: "disable local relay when sending"}, cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013", Usage: "ports of the local relay (optional)"}, }, HelpName: "croc send", @@ -167,6 +168,7 @@ func send(c *cli.Context) (err error) { NoPrompt: c.GlobalBool("yes"), RelayAddress: c.GlobalString("relay"), Stdout: c.GlobalBool("stdout"), + DisableLocal: c.Bool("no-local"), RelayPorts: strings.Split(c.String("ports"), ","), }) if err != nil { diff --git a/src/comm/comm.go b/src/comm/comm.go index a19f5e64..49761268 100644 --- a/src/comm/comm.go +++ b/src/comm/comm.go @@ -16,8 +16,12 @@ type Comm struct { } // NewConnection gets a new comm to a tcp address -func NewConnection(address string) (c *Comm, err error) { - connection, err := net.DialTimeout("tcp", address, 30*time.Second) +func NewConnection(address string, timelimit ...time.Duration) (c *Comm, err error) { + tlimit := 30 * time.Second + if len(timelimit) > 0 { + tlimit = timelimit[0] + } + connection, err := net.DialTimeout("tcp", address, tlimit) if err != nil { return } diff --git a/src/croc/croc.go b/src/croc/croc.go index 0ef07f33..f37ff7be 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -306,11 +306,13 @@ func (c *Client) Send(options TransferOptions) (err error) { data, _ := conn.Receive() if bytes.Equal(data, []byte("ips?")) { var ips []string - ips, err = utils.GetLocalIPs() - if err != nil { - log.Debugf("error getting local ips: %s", err.Error()) + if !c.Options.DisableLocal { + ips, err = utils.GetLocalIPs() + if err != nil { + log.Debugf("error getting local ips: %s", err.Error()) + } + ips = append([]string{c.Options.RelayPorts[0]}, ips...) } - ips = append([]string{c.Options.RelayPorts[0]}, ips...) bips, _ := json.Marshal(ips) conn.Send(bips) } @@ -378,7 +380,7 @@ func (c *Client) Receive() (err error) { ips = ips[1:] for _, ip := range ips { serverTry := fmt.Sprintf("%s:%s", ip, port) - conn, banner2, externalIP, errConn := tcp.ConnectToTCPServer(serverTry, c.Options.SharedSecret) + conn, banner2, externalIP, errConn := tcp.ConnectToTCPServer(serverTry, c.Options.SharedSecret, 50*time.Millisecond) if errConn != nil { log.Debugf("could not connect to " + serverTry) continue diff --git a/src/tcp/tcp.go b/src/tcp/tcp.go index 441367b8..c9a67acf 100644 --- a/src/tcp/tcp.go +++ b/src/tcp/tcp.go @@ -59,7 +59,7 @@ func (s *server) start() (err error) { s.rooms.Lock() for room := range s.rooms.rooms { if time.Since(s.rooms.rooms[room].opened) > 3*time.Hour { - roomsToDelete = append(roomsToDelete,room) + roomsToDelete = append(roomsToDelete, room) } } s.rooms.Unlock() @@ -248,8 +248,12 @@ func pipe(conn1 net.Conn, conn2 net.Conn) { } } -func ConnectToTCPServer(address, room string) (c *comm.Comm, banner string, ipaddr string, err error) { - c, err = comm.NewConnection(address) +func ConnectToTCPServer(address, room string, timelimit ...time.Duration) (c *comm.Comm, banner string, ipaddr string, err error) { + if len(timelimit) > 0 { + c, err = comm.NewConnection(address, timelimit[0]) + } else { + c, err = comm.NewConnection(address) + } if err != nil { return }