From 1b07faea8f291c92352c0b6fd3b004328520cb0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Fri, 29 Jun 2018 13:27:29 +0300 Subject: [PATCH 1/6] tor: pass explicitly given control ports to starter --- tor/tor.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tor/tor.go b/tor/tor.go index f736b41..d486169 100644 --- a/tor/tor.go +++ b/tor/tor.go @@ -207,6 +207,8 @@ func (t *Tor) startProcess(ctx context.Context, conf *StartConf) error { return err } args = append(args, "--ControlPort", "auto", "--ControlPortWriteToFile", controlPortFile.Name()) + } else { + args = append(args, "--ControlPort", strconv.Itoa(conf.ControlPort)) } // Start process with the args var processCtx context.Context From 97366c4e45e5bb65356b8ebcfe38cda4cce86f98 Mon Sep 17 00:00:00 2001 From: Chad Retz Date: Fri, 29 Jun 2018 15:34:28 -0500 Subject: [PATCH 2/6] Change Windows gcc recommendation from TDM to MSYS2 --- process/embedded/process.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/process/embedded/process.go b/process/embedded/process.go index 7aa0784..3f05ea6 100644 --- a/process/embedded/process.go +++ b/process/embedded/process.go @@ -9,8 +9,9 @@ // $GOPATH/src/github.com/cretz/tor-static as if it was fetched with go get. To // build the needed static libs, follow the README in that project. Once the // static libs are built, this uses CGO to statically link them here. For -// Windows this means something like http://tdm-gcc.tdragon.net/ needs to be -// present with gcc.exe on the PATH. +// Windows this means something like http://www.msys2.org/ needs to be +// installed with gcc.exe on the PATH (i.e. the same gcc that was used to build +// the static Tor lib). package embedded import ( From cbd288d20bac758b15b5430aec13ad702f4aab33 Mon Sep 17 00:00:00 2001 From: Chad Retz Date: Fri, 29 Jun 2018 15:34:51 -0500 Subject: [PATCH 3/6] Use version 3 onion services for embedded file server example --- examples/embeddedfileserver/main.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/examples/embeddedfileserver/main.go b/examples/embeddedfileserver/main.go index 83acda2..96924b6 100644 --- a/examples/embeddedfileserver/main.go +++ b/examples/embeddedfileserver/main.go @@ -48,8 +48,9 @@ func run() error { // Wait at most a few minutes to publish the service listenCtx, listenCancel := context.WithTimeout(context.Background(), 3*time.Minute) defer listenCancel() - // Create an onion service to listen on a random local port but show as 80 - onion, err := t.Listen(listenCtx, &tor.ListenConf{RemotePorts: []int{80}}) + // Create an onion service to listen on a random local port but show as + // Do version 3, it's faster to set up + onion, err := t.Listen(listenCtx, &tor.ListenConf{RemotePorts: []int{80}, Version3: true}) if err != nil { return err } From ba5dbc955de46ce3ccc5f89f6a6bc85e77037718 Mon Sep 17 00:00:00 2001 From: csucu Date: Sun, 22 Jul 2018 17:15:54 +0100 Subject: [PATCH 4/6] Modified parsing of eventcode in relayAsyncEvents --- control/cmd_event.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/control/cmd_event.go b/control/cmd_event.go index 2500b0b..1e054e3 100644 --- a/control/cmd_event.go +++ b/control/cmd_event.go @@ -271,11 +271,17 @@ func (c *Conn) relayAsyncEvents(resp *Response) { var dataArray []string if len(resp.Data) == 1 { // If there is a single line of data, first line of it is the code, rest of the first line is data - firstNewline := strings.Index(resp.Data[0], "\r\n") - if firstNewline == -1 { + // Find the index which specfies the char after the event code, either space or newline + index := strings.Index(resp.Data[0], " ") + if index == -1 { + index = strings.Index(resp.Data[0], "\r\n") + } + + if index == -1 { return } - code, data = resp.Data[0][:firstNewline], resp.Data[0][firstNewline+2:] + + code, data = resp.Data[0][:index], resp.Data[0][index+2:] } else if len(resp.Data) > 0 { // If there are multiple lines, the entire first line is the code code, dataArray = resp.Data[0], resp.Data[1:] From 4aedc493a335b3029cad478d3ded5e3764daa5c4 Mon Sep 17 00:00:00 2001 From: csucu Date: Sun, 22 Jul 2018 17:32:29 +0100 Subject: [PATCH 5/6] Moved -1 check --- control/cmd_event.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/control/cmd_event.go b/control/cmd_event.go index 1e054e3..3c9856f 100644 --- a/control/cmd_event.go +++ b/control/cmd_event.go @@ -275,10 +275,9 @@ func (c *Conn) relayAsyncEvents(resp *Response) { index := strings.Index(resp.Data[0], " ") if index == -1 { index = strings.Index(resp.Data[0], "\r\n") - } - - if index == -1 { - return + if index == -1 { + return + } } code, data = resp.Data[0][:index], resp.Data[0][index+2:] From f77fae492feebb69407d2daa3497da8417f72fb6 Mon Sep 17 00:00:00 2001 From: Chad Retz Date: Tue, 24 Jul 2018 10:41:49 -0500 Subject: [PATCH 6/6] Clean up single-line event and new hs_desc_content test for #8 and #9 --- control/cmd_event.go | 17 +++++------ tests/control_cmd_hiddenservice_test.go | 38 +++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 tests/control_cmd_hiddenservice_test.go diff --git a/control/cmd_event.go b/control/cmd_event.go index 3c9856f..578a800 100644 --- a/control/cmd_event.go +++ b/control/cmd_event.go @@ -270,17 +270,14 @@ func (c *Conn) relayAsyncEvents(resp *Response) { var code, data string var dataArray []string if len(resp.Data) == 1 { - // If there is a single line of data, first line of it is the code, rest of the first line is data - // Find the index which specfies the char after the event code, either space or newline - index := strings.Index(resp.Data[0], " ") - if index == -1 { - index = strings.Index(resp.Data[0], "\r\n") - if index == -1 { - return - } + // On single line, part up to space, newline, or EOL is the code, rest is data + if index := strings.Index(resp.Data[0], " "); index != -1 { + code, data = resp.Data[0][:index], resp.Data[0][index+1:] + } else if index := strings.Index(resp.Data[0], "\r\n"); index != -1 { + code, data = resp.Data[0][:index], resp.Data[0][index+2:] + } else { + code, data = resp.Data[0], "" } - - code, data = resp.Data[0][:index], resp.Data[0][index+2:] } else if len(resp.Data) > 0 { // If there are multiple lines, the entire first line is the code code, dataArray = resp.Data[0], resp.Data[1:] diff --git a/tests/control_cmd_hiddenservice_test.go b/tests/control_cmd_hiddenservice_test.go new file mode 100644 index 0000000..270909b --- /dev/null +++ b/tests/control_cmd_hiddenservice_test.go @@ -0,0 +1,38 @@ +package tests + +import ( + "context" + "strings" + "testing" + "time" + + "github.com/cretz/bine/control" +) + +func TestHSFetch(t *testing.T) { + ctx := GlobalEnabledNetworkContext(t) + // Add listener + eventCh := make(chan control.Event) + defer close(eventCh) + err := ctx.Control.AddEventListener(eventCh, control.EventCodeHSDescContent) + ctx.Require.NoError(err) + defer ctx.Control.RemoveEventListener(eventCh, control.EventCodeHSDescContent) + // Lookup HS + err = ctx.Control.GetHiddenServiceDescriptorAsync("facebookcorewwwi", "") + ctx.Require.NoError(err) + // Grab events + eventCtx, eventCancel := context.WithTimeout(ctx, 45*time.Second) + defer eventCancel() + errCh := make(chan error, 1) + go func() { errCh <- ctx.Control.HandleEvents(eventCtx) }() + select { + case <-eventCtx.Done(): + ctx.Require.NoError(eventCtx.Err()) + case err := <-errCh: + ctx.Require.NoError(err) + case event := <-eventCh: + hsEvent := event.(*control.HSDescContentEvent) + ctx.Require.Equal("facebookcorewwwi", hsEvent.Address) + ctx.Require.True(strings.HasPrefix(hsEvent.Descriptor, "rendezvous-service-descriptor "+hsEvent.DescID)) + } +}