mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 13:21:00 +02:00
disable on no local, quick connections
This commit is contained in:
parent
82489c81e8
commit
d7da7ec1e7
4 changed files with 23 additions and 11 deletions
|
@ -21,7 +21,7 @@ import (
|
||||||
var Version string
|
var Version string
|
||||||
|
|
||||||
func Run() (err error) {
|
func Run() (err error) {
|
||||||
// use all of the processors
|
// use all of the processors
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
|
@ -42,6 +42,7 @@ func Run() (err error) {
|
||||||
ArgsUsage: "[filename]",
|
ArgsUsage: "[filename]",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
cli.StringFlag{Name: "code, c", Usage: "codephrase used to connect to relay"},
|
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)"},
|
cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013", Usage: "ports of the local relay (optional)"},
|
||||||
},
|
},
|
||||||
HelpName: "croc send",
|
HelpName: "croc send",
|
||||||
|
@ -167,6 +168,7 @@ func send(c *cli.Context) (err error) {
|
||||||
NoPrompt: c.GlobalBool("yes"),
|
NoPrompt: c.GlobalBool("yes"),
|
||||||
RelayAddress: c.GlobalString("relay"),
|
RelayAddress: c.GlobalString("relay"),
|
||||||
Stdout: c.GlobalBool("stdout"),
|
Stdout: c.GlobalBool("stdout"),
|
||||||
|
DisableLocal: c.Bool("no-local"),
|
||||||
RelayPorts: strings.Split(c.String("ports"), ","),
|
RelayPorts: strings.Split(c.String("ports"), ","),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -16,8 +16,12 @@ type Comm struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConnection gets a new comm to a tcp address
|
// NewConnection gets a new comm to a tcp address
|
||||||
func NewConnection(address string) (c *Comm, err error) {
|
func NewConnection(address string, timelimit ...time.Duration) (c *Comm, err error) {
|
||||||
connection, err := net.DialTimeout("tcp", address, 30*time.Second)
|
tlimit := 30 * time.Second
|
||||||
|
if len(timelimit) > 0 {
|
||||||
|
tlimit = timelimit[0]
|
||||||
|
}
|
||||||
|
connection, err := net.DialTimeout("tcp", address, tlimit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -306,11 +306,13 @@ func (c *Client) Send(options TransferOptions) (err error) {
|
||||||
data, _ := conn.Receive()
|
data, _ := conn.Receive()
|
||||||
if bytes.Equal(data, []byte("ips?")) {
|
if bytes.Equal(data, []byte("ips?")) {
|
||||||
var ips []string
|
var ips []string
|
||||||
ips, err = utils.GetLocalIPs()
|
if !c.Options.DisableLocal {
|
||||||
if err != nil {
|
ips, err = utils.GetLocalIPs()
|
||||||
log.Debugf("error getting local ips: %s", err.Error())
|
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)
|
bips, _ := json.Marshal(ips)
|
||||||
conn.Send(bips)
|
conn.Send(bips)
|
||||||
}
|
}
|
||||||
|
@ -378,7 +380,7 @@ func (c *Client) Receive() (err error) {
|
||||||
ips = ips[1:]
|
ips = ips[1:]
|
||||||
for _, ip := range ips {
|
for _, ip := range ips {
|
||||||
serverTry := fmt.Sprintf("%s:%s", ip, port)
|
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 {
|
if errConn != nil {
|
||||||
log.Debugf("could not connect to " + serverTry)
|
log.Debugf("could not connect to " + serverTry)
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -59,7 +59,7 @@ func (s *server) start() (err error) {
|
||||||
s.rooms.Lock()
|
s.rooms.Lock()
|
||||||
for room := range s.rooms.rooms {
|
for room := range s.rooms.rooms {
|
||||||
if time.Since(s.rooms.rooms[room].opened) > 3*time.Hour {
|
if time.Since(s.rooms.rooms[room].opened) > 3*time.Hour {
|
||||||
roomsToDelete = append(roomsToDelete,room)
|
roomsToDelete = append(roomsToDelete, room)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.rooms.Unlock()
|
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) {
|
func ConnectToTCPServer(address, room string, timelimit ...time.Duration) (c *comm.Comm, banner string, ipaddr string, err error) {
|
||||||
c, err = comm.NewConnection(address)
|
if len(timelimit) > 0 {
|
||||||
|
c, err = comm.NewConnection(address, timelimit[0])
|
||||||
|
} else {
|
||||||
|
c, err = comm.NewConnection(address)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue