|
@@ -36,7 +36,7 @@ type StartResult struct {
|
|
|
SocksProxyPort int `json:"socks_proxy_port,omitempty"`
|
|
SocksProxyPort int `json:"socks_proxy_port,omitempty"`
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-type MeasurementTest struct {
|
|
|
|
|
|
|
+type PsiphonTunnel struct {
|
|
|
controllerWaitGroup sync.WaitGroup
|
|
controllerWaitGroup sync.WaitGroup
|
|
|
controllerCtx context.Context
|
|
controllerCtx context.Context
|
|
|
stopController context.CancelFunc
|
|
stopController context.CancelFunc
|
|
@@ -44,7 +44,7 @@ type MeasurementTest struct {
|
|
|
socksProxyPort int
|
|
socksProxyPort int
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-var measurementTest MeasurementTest
|
|
|
|
|
|
|
+var psiphonTunnel PsiphonTunnel
|
|
|
|
|
|
|
|
//export Start
|
|
//export Start
|
|
|
// Start starts the controller and returns once either of the following has occured: an active tunnel has been
|
|
// Start starts the controller and returns once either of the following has occured: an active tunnel has been
|
|
@@ -120,10 +120,10 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
|
|
|
|
|
|
|
|
if event.NoticeType == "ListeningHttpProxyPort" {
|
|
if event.NoticeType == "ListeningHttpProxyPort" {
|
|
|
port := event.Data["port"].(float64)
|
|
port := event.Data["port"].(float64)
|
|
|
- measurementTest.httpProxyPort = int(port)
|
|
|
|
|
|
|
+ psiphonTunnel.httpProxyPort = int(port)
|
|
|
} else if event.NoticeType == "ListeningSocksProxyPort" {
|
|
} else if event.NoticeType == "ListeningSocksProxyPort" {
|
|
|
port := event.Data["port"].(float64)
|
|
port := event.Data["port"].(float64)
|
|
|
- measurementTest.socksProxyPort = int(port)
|
|
|
|
|
|
|
+ psiphonTunnel.socksProxyPort = int(port)
|
|
|
} else if event.NoticeType == "Tunnels" {
|
|
} else if event.NoticeType == "Tunnels" {
|
|
|
count := event.Data["count"].(float64)
|
|
count := event.Data["count"].(float64)
|
|
|
if count > 0 {
|
|
if count > 0 {
|
|
@@ -164,7 +164,7 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
|
|
|
return startErrorJson(err)
|
|
return startErrorJson(err)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- measurementTest.controllerCtx, measurementTest.stopController = context.WithCancel(context.Background())
|
|
|
|
|
|
|
+ psiphonTunnel.controllerCtx, psiphonTunnel.stopController = context.WithCancel(context.Background())
|
|
|
|
|
|
|
|
// Set start time
|
|
// Set start time
|
|
|
|
|
|
|
@@ -181,10 +181,10 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
|
|
|
|
|
|
|
|
var result StartResult
|
|
var result StartResult
|
|
|
|
|
|
|
|
- measurementTest.controllerWaitGroup.Add(1)
|
|
|
|
|
|
|
+ psiphonTunnel.controllerWaitGroup.Add(1)
|
|
|
go func() {
|
|
go func() {
|
|
|
- defer measurementTest.controllerWaitGroup.Done()
|
|
|
|
|
- controller.Run(measurementTest.controllerCtx)
|
|
|
|
|
|
|
+ defer psiphonTunnel.controllerWaitGroup.Done()
|
|
|
|
|
+ controller.Run(psiphonTunnel.controllerCtx)
|
|
|
|
|
|
|
|
select {
|
|
select {
|
|
|
case testError <- errors.New("controller.Run exited unexpectedly"):
|
|
case testError <- errors.New("controller.Run exited unexpectedly"):
|
|
@@ -198,19 +198,19 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
|
|
|
case <-connected:
|
|
case <-connected:
|
|
|
result.Code = StartResultCodeSuccess
|
|
result.Code = StartResultCodeSuccess
|
|
|
result.BootstrapTime = secondsBeforeNow(startTime)
|
|
result.BootstrapTime = secondsBeforeNow(startTime)
|
|
|
- result.HttpProxyPort = measurementTest.httpProxyPort
|
|
|
|
|
- result.SocksProxyPort = measurementTest.socksProxyPort
|
|
|
|
|
|
|
+ result.HttpProxyPort = psiphonTunnel.httpProxyPort
|
|
|
|
|
+ result.SocksProxyPort = psiphonTunnel.socksProxyPort
|
|
|
case <-timeoutSignal.Done():
|
|
case <-timeoutSignal.Done():
|
|
|
result.Code = StartResultCodeTimeout
|
|
result.Code = StartResultCodeTimeout
|
|
|
err = timeoutSignal.Err()
|
|
err = timeoutSignal.Err()
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
result.ErrorString = fmt.Sprintf("Timeout occured before Psiphon connected: %s", err.Error())
|
|
result.ErrorString = fmt.Sprintf("Timeout occured before Psiphon connected: %s", err.Error())
|
|
|
}
|
|
}
|
|
|
- measurementTest.stopController()
|
|
|
|
|
|
|
+ psiphonTunnel.stopController()
|
|
|
case err := <-testError:
|
|
case err := <-testError:
|
|
|
result.Code = StartResultCodeOtherError
|
|
result.Code = StartResultCodeOtherError
|
|
|
result.ErrorString = err.Error()
|
|
result.ErrorString = err.Error()
|
|
|
- measurementTest.stopController()
|
|
|
|
|
|
|
+ psiphonTunnel.stopController()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Return result
|
|
// Return result
|
|
@@ -224,10 +224,10 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
|
|
|
// Stop should always be called after a successful call to Start to ensure the
|
|
// Stop should always be called after a successful call to Start to ensure the
|
|
|
// controller is not left running.
|
|
// controller is not left running.
|
|
|
func Stop() {
|
|
func Stop() {
|
|
|
- if measurementTest.stopController != nil {
|
|
|
|
|
- measurementTest.stopController()
|
|
|
|
|
|
|
+ if psiphonTunnel.stopController != nil {
|
|
|
|
|
+ psiphonTunnel.stopController()
|
|
|
}
|
|
}
|
|
|
- measurementTest.controllerWaitGroup.Wait()
|
|
|
|
|
|
|
+ psiphonTunnel.controllerWaitGroup.Wait()
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// secondsBeforeNow returns the delta seconds of the current time subtract startTime.
|
|
// secondsBeforeNow returns the delta seconds of the current time subtract startTime.
|