Merge branch 'master' of https://github.com/cretz/bine
This commit is contained in:
commit
737419b97a
|
@ -270,12 +270,14 @@ func (c *Conn) relayAsyncEvents(resp *Response) {
|
||||||
var code, data string
|
var code, data string
|
||||||
var dataArray []string
|
var dataArray []string
|
||||||
if len(resp.Data) == 1 {
|
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
|
// On single line, part up to space, newline, or EOL is the code, rest is data
|
||||||
firstNewline := strings.Index(resp.Data[0], "\r\n")
|
if index := strings.Index(resp.Data[0], " "); index != -1 {
|
||||||
if firstNewline == -1 {
|
code, data = resp.Data[0][:index], resp.Data[0][index+1:]
|
||||||
return
|
} 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][:firstNewline], resp.Data[0][firstNewline+2:]
|
|
||||||
} else if len(resp.Data) > 0 {
|
} else if len(resp.Data) > 0 {
|
||||||
// If there are multiple lines, the entire first line is the code
|
// If there are multiple lines, the entire first line is the code
|
||||||
code, dataArray = resp.Data[0], resp.Data[1:]
|
code, dataArray = resp.Data[0], resp.Data[1:]
|
||||||
|
|
|
@ -48,8 +48,9 @@ func run() error {
|
||||||
// Wait at most a few minutes to publish the service
|
// Wait at most a few minutes to publish the service
|
||||||
listenCtx, listenCancel := context.WithTimeout(context.Background(), 3*time.Minute)
|
listenCtx, listenCancel := context.WithTimeout(context.Background(), 3*time.Minute)
|
||||||
defer listenCancel()
|
defer listenCancel()
|
||||||
// Create an onion service to listen on a random local port but show as 80
|
// Create an onion service to listen on a random local port but show as
|
||||||
onion, err := t.Listen(listenCtx, &tor.ListenConf{RemotePorts: []int{80}})
|
// Do version 3, it's faster to set up
|
||||||
|
onion, err := t.Listen(listenCtx, &tor.ListenConf{RemotePorts: []int{80}, Version3: true})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,9 @@
|
||||||
// $GOPATH/src/github.com/cretz/tor-static as if it was fetched with go get. To
|
// $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
|
// 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
|
// 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
|
// Windows this means something like http://www.msys2.org/ needs to be
|
||||||
// present with gcc.exe on the PATH.
|
// installed with gcc.exe on the PATH (i.e. the same gcc that was used to build
|
||||||
|
// the static Tor lib).
|
||||||
package embedded
|
package embedded
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -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))
|
||||||
|
}
|
||||||
|
}
|
|
@ -207,6 +207,8 @@ func (t *Tor) startProcess(ctx context.Context, conf *StartConf) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
args = append(args, "--ControlPort", "auto", "--ControlPortWriteToFile", controlPortFile.Name())
|
args = append(args, "--ControlPort", "auto", "--ControlPortWriteToFile", controlPortFile.Name())
|
||||||
|
} else {
|
||||||
|
args = append(args, "--ControlPort", strconv.Itoa(conf.ControlPort))
|
||||||
}
|
}
|
||||||
// Start process with the args
|
// Start process with the args
|
||||||
var processCtx context.Context
|
var processCtx context.Context
|
||||||
|
|
Loading…
Reference in New Issue