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
|
||||
|
||||
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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue