Răsfoiți Sursa

Repurpose measurement library as client library

mirokuratczyk 7 ani în urmă
părinte
comite
5be8cf6021

+ 0 - 0
MeasurementLibrary/Makefile → ClientLibrary/Makefile


+ 15 - 15
MeasurementLibrary/PsiphonTunnel.go → ClientLibrary/PsiphonTunnel.go

@@ -36,7 +36,7 @@ type StartResult struct {
 	SocksProxyPort int             `json:"socks_proxy_port,omitempty"`
 }
 
-type MeasurementTest struct {
+type PsiphonTunnel struct {
 	controllerWaitGroup sync.WaitGroup
 	controllerCtx       context.Context
 	stopController      context.CancelFunc
@@ -44,7 +44,7 @@ type MeasurementTest struct {
 	socksProxyPort      int
 }
 
-var measurementTest MeasurementTest
+var psiphonTunnel PsiphonTunnel
 
 //export Start
 // 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" {
 				port := event.Data["port"].(float64)
-				measurementTest.httpProxyPort = int(port)
+				psiphonTunnel.httpProxyPort = int(port)
 			} else if event.NoticeType == "ListeningSocksProxyPort" {
 				port := event.Data["port"].(float64)
-				measurementTest.socksProxyPort = int(port)
+				psiphonTunnel.socksProxyPort = int(port)
 			} else if event.NoticeType == "Tunnels" {
 				count := event.Data["count"].(float64)
 				if count > 0 {
@@ -164,7 +164,7 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
 		return startErrorJson(err)
 	}
 
-	measurementTest.controllerCtx, measurementTest.stopController = context.WithCancel(context.Background())
+	psiphonTunnel.controllerCtx, psiphonTunnel.stopController = context.WithCancel(context.Background())
 
 	// Set start time
 
@@ -181,10 +181,10 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
 
 	var result StartResult
 
-	measurementTest.controllerWaitGroup.Add(1)
+	psiphonTunnel.controllerWaitGroup.Add(1)
 	go func() {
-		defer measurementTest.controllerWaitGroup.Done()
-		controller.Run(measurementTest.controllerCtx)
+		defer psiphonTunnel.controllerWaitGroup.Done()
+		controller.Run(psiphonTunnel.controllerCtx)
 
 		select {
 		case testError <- errors.New("controller.Run exited unexpectedly"):
@@ -198,19 +198,19 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
 	case <-connected:
 		result.Code = StartResultCodeSuccess
 		result.BootstrapTime = secondsBeforeNow(startTime)
-		result.HttpProxyPort = measurementTest.httpProxyPort
-		result.SocksProxyPort = measurementTest.socksProxyPort
+		result.HttpProxyPort = psiphonTunnel.httpProxyPort
+		result.SocksProxyPort = psiphonTunnel.socksProxyPort
 	case <-timeoutSignal.Done():
 		result.Code = StartResultCodeTimeout
 		err = timeoutSignal.Err()
 		if err != nil {
 			result.ErrorString = fmt.Sprintf("Timeout occured before Psiphon connected: %s", err.Error())
 		}
-		measurementTest.stopController()
+		psiphonTunnel.stopController()
 	case err := <-testError:
 		result.Code = StartResultCodeOtherError
 		result.ErrorString = err.Error()
-		measurementTest.stopController()
+		psiphonTunnel.stopController()
 	}
 
 	// 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
 // controller is not left running.
 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.

+ 9 - 0
ClientLibrary/README.md

@@ -0,0 +1,9 @@
+# Psiphon Client Library README
+
+## Mobile
+
+If you are planning to embed Psiphon in a mobile application, please use the [MobileLibrary](../MobileLibrary).
+
+## Usage
+
+If you are using the Library in your app, please read the [USAGE.md](USAGE.md) instructions.

+ 16 - 0
ClientLibrary/USAGE.md

@@ -0,0 +1,16 @@
+# Using the Psiphon Client Library
+
+## Overview
+
+The Psiphon Client Library enables you to easily embed Psiphon in your app.
+
+## Using the Psiphon network
+
+In order to use the Psiphon Client Library over the Psiphon network, you need to contact Psiphon to obtain connection parameters to use with your application. Please email us at [info@psiphon.ca](mailto:info@psiphon.ca).
+
+## Using the Library in your App
+
+**First step:** Review the sample code, located under `example`.
+This code provides an example of how to correctly use the client library.
+
+**Second step:** Review the comments for `Start` and `Stop` in [`PsiphonTunnel.go`](PsiphonTunnel.go). They describe the client interface.

+ 0 - 0
MeasurementLibrary/example/.gitignore → ClientLibrary/example/.gitignore


+ 0 - 0
MeasurementLibrary/example/Makefile → ClientLibrary/example/Makefile


+ 0 - 0
MeasurementLibrary/example/main.c → ClientLibrary/example/main.c


+ 0 - 12
MeasurementLibrary/README.md

@@ -1,12 +0,0 @@
-Psiphon Measurement Library README
-================================================================================
-
-Overview
---------------------------------------------------------------------------------
-
-The Psiphon Measurement Library is specifically intended for use by network measurement tools, such as [OONI](https://ooni.io/), and is not intended for general use and distribution.
-
-Usage
---------------------------------------------------------------------------------
-
-If you are using the Library in your app, please read the [USAGE.md](USAGE.md) instructions.

+ 0 - 16
MeasurementLibrary/USAGE.md

@@ -1,16 +0,0 @@
-# Using the Psiphon Measurement Library
-
-## Overview
-
-The Psiphon Measurement Library enables you to easily embed a test of Psiphon in your app.
-
-## Using the Psiphon network
-
-In order to use the Psiphon Measurement Library for testing the Psiphon network, you need to contact Psiphon to obtain connection parameters to use with your application. Please email us at [info@psiphon.ca](mailto:info@psiphon.ca).
-
-## Using the Library in your App
-
-**First step:** Review the sample code, located under `example`.
-This code provides an example of how to correctly use the measurement library.
-
-**Second step:** Review the comments for `Start` and `Stop` in [`PsiphonTunnel.go`](PsiphonTunnel.go). These functions make up the testing interface.