parent
a3771891b4
commit
f77fae492f
|
@ -270,17 +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
|
||||||
// Find the index which specfies the char after the event code, either space or newline
|
if index := strings.Index(resp.Data[0], " "); index != -1 {
|
||||||
index := strings.Index(resp.Data[0], " ")
|
code, data = resp.Data[0][:index], resp.Data[0][index+1:]
|
||||||
if index == -1 {
|
} else if index := strings.Index(resp.Data[0], "\r\n"); index != -1 {
|
||||||
index = strings.Index(resp.Data[0], "\r\n")
|
code, data = resp.Data[0][:index], resp.Data[0][index+2:]
|
||||||
if index == -1 {
|
} else {
|
||||||
return
|
code, data = resp.Data[0], ""
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
code, data = resp.Data[0][:index], resp.Data[0][index+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:]
|
||||||
|
|
|
@ -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))
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue