From 1ae7a2ff97b0d7452870b0ff3546b092cc0cb5cf Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Sun, 17 Nov 2019 15:32:47 -0800 Subject: [PATCH] allow disabling the multiplexing --- src/cli/cli.go | 42 +++++++++++++++++++++++++++++++++--------- src/croc/croc.go | 31 ++++++++++++++++++++++--------- 2 files changed, 55 insertions(+), 18 deletions(-) diff --git a/src/cli/cli.go b/src/cli/cli.go index 64fe78e1..19837bbd 100644 --- a/src/cli/cli.go +++ b/src/cli/cli.go @@ -17,6 +17,7 @@ import ( "github.com/schollz/croc/v6/src/models" "github.com/schollz/croc/v6/src/tcp" "github.com/schollz/croc/v6/src/utils" + "github.com/schollz/croc/v6/src/webrelay" log "github.com/schollz/logger" "github.com/urfave/cli" ) @@ -51,6 +52,7 @@ func Run() (err error) { 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.BoolFlag{Name: "no-multi", Usage: "disable multiplexing"}, cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013", Usage: "ports of the local relay (optional)"}, }, HelpName: "croc send", @@ -70,6 +72,18 @@ func Run() (err error) { cli.StringFlag{Name: "ports", Value: "9009,9010,9011,9012,9013", Usage: "ports of the relay"}, }, }, + { + Name: "web", + Usage: "start your own web relay (optional)", + Description: "start web relay", + HelpName: "croc web", + Action: func(c *cli.Context) error { + return startWebRelay(c) + }, + Flags: []cli.Flag{ + cli.StringFlag{Name: "port", Value: "9014", Usage: "port of the web relay"}, + }, + }, } app.Flags = []cli.Flag{ cli.BoolFlag{Name: "remember", Usage: "save these settings to reuse next time"}, @@ -136,15 +150,16 @@ func getConfigFile() string { func send(c *cli.Context) (err error) { setDebugLevel(c) crocOptions := croc.Options{ - SharedSecret: c.String("code"), - IsSender: true, - Debug: c.GlobalBool("debug"), - NoPrompt: c.GlobalBool("yes"), - RelayAddress: c.GlobalString("relay"), - Stdout: c.GlobalBool("stdout"), - DisableLocal: c.Bool("no-local"), - RelayPorts: strings.Split(c.String("ports"), ","), - Ask: c.GlobalBool("ask"), + SharedSecret: c.String("code"), + IsSender: true, + Debug: c.GlobalBool("debug"), + NoPrompt: c.GlobalBool("yes"), + RelayAddress: c.GlobalString("relay"), + Stdout: c.GlobalBool("stdout"), + DisableLocal: c.Bool("no-local"), + RelayPorts: strings.Split(c.String("ports"), ","), + Ask: c.GlobalBool("ask"), + NoMultiplexing: c.Bool("no-multi"), } b, errOpen := ioutil.ReadFile(getConfigFile()) if errOpen == nil && !c.GlobalBool("remember") { @@ -381,3 +396,12 @@ func relay(c *cli.Context) (err error) { } return tcp.Run(debugString, ports[0], tcpPorts) } + +func startWebRelay(c *cli.Context) (err error) { + debugString := "info" + if c.GlobalBool("debug") { + debugString = "debug" + } + + return webrelay.Run(debugString, c.String("port")) +} diff --git a/src/croc/croc.go b/src/croc/croc.go index bd0301ef..64c6b138 100644 --- a/src/croc/croc.go +++ b/src/croc/croc.go @@ -48,15 +48,16 @@ func Debug(debug bool) { // Options specifies user specific options type Options struct { - IsSender bool - SharedSecret string - Debug bool - RelayAddress string - RelayPorts []string - Stdout bool - NoPrompt bool - DisableLocal bool - Ask bool + IsSender bool + SharedSecret string + Debug bool + RelayAddress string + RelayPorts []string + Stdout bool + NoPrompt bool + NoMultiplexing bool + DisableLocal bool + Ask bool } // Client holds the state of the croc transfer @@ -286,6 +287,10 @@ func (c *Client) transferOverLocalRelay(options TransferOptions, errchan chan<- log.Debug("exchanged header message") c.Options.RelayAddress = "localhost" c.Options.RelayPorts = strings.Split(banner, ",") + if c.Options.NoMultiplexing { + log.Debug("no multiplexing") + c.Options.RelayPorts = []string{c.Options.RelayPorts[0]} + } c.ExternalIP = ipaddr errchan <- c.transfer(options) } @@ -363,6 +368,10 @@ func (c *Client) Send(options TransferOptions) (err error) { c.conn[0] = conn c.Options.RelayPorts = strings.Split(banner, ",") + if c.Options.NoMultiplexing { + log.Debug("no multiplexing") + c.Options.RelayPorts = []string{c.Options.RelayPorts[0]} + } c.ExternalIP = ipaddr log.Debug("exchanged header message") errchan <- c.transfer(options) @@ -464,6 +473,10 @@ func (c *Client) Receive() (err error) { c.conn[0].Send([]byte("handshake")) c.Options.RelayPorts = strings.Split(banner, ",") + if c.Options.NoMultiplexing { + log.Debug("no multiplexing") + c.Options.RelayPorts = []string{c.Options.RelayPorts[0]} + } log.Debug("exchanged header message") fmt.Fprintf(os.Stderr, "\rsecuring channel...") return c.transfer(TransferOptions{})