Przeglądaj źródła

Merge branch 'master' of https://github.com/Psiphon-Labs/psiphon-tunnel-core

Rod Hynes 7 lat temu
rodzic
commit
b4bc123ef8

+ 0 - 0
MeasurementLibrary/Makefile → ClientLibrary/Makefile


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

@@ -15,28 +15,28 @@ import (
 	"github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon/common/protocol"
 )
 
-type StartResultCode int
+type startResultCode int
 
 const (
-	StartResultCodeSuccess StartResultCode = iota
-	StartResultCodeTimeout
-	StartResultCodeOtherError
+	startResultCodeSuccess startResultCode = iota
+	startResultCodeTimeout
+	startResultCodeOtherError
 )
 
-type NoticeEvent struct {
+type noticeEvent struct {
 	Data       map[string]interface{} `json:"data"`
 	NoticeType string                 `json:"noticeType"`
 }
 
-type StartResult struct {
-	Code           StartResultCode `json:"result_code"`
+type startResult struct {
+	Code           startResultCode `json:"result_code"`
 	BootstrapTime  float64         `json:"bootstrap_time,omitempty"`
 	ErrorString    string          `json:"error,omitempty"`
 	HttpProxyPort  int             `json:"http_proxy_port,omitempty"`
 	SocksProxyPort int             `json:"socks_proxy_port,omitempty"`
 }
 
-type MeasurementTest struct {
+type psiphonTunnel struct {
 	controllerWaitGroup sync.WaitGroup
 	controllerCtx       context.Context
 	stopController      context.CancelFunc
@@ -44,13 +44,13 @@ type MeasurementTest struct {
 	socksProxyPort      int
 }
 
-var measurementTest MeasurementTest
+var tunnel psiphonTunnel
 
 //export Start
 // Start starts the controller and returns once either of the following has occured: an active tunnel has been
 // established, the timeout has elapsed before an active tunnel could be established or an error has occured.
 //
-// Start returns a StartResult object serialized as a JSON string in the form of a null-terminated buffer of C chars.
+// Start returns a startResult object serialized as a JSON string in the form of a null-terminated buffer of C chars.
 // Start will return,
 // On success:
 //   {
@@ -107,7 +107,7 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
 	psiphon.SetNoticeWriter(psiphon.NewNoticeReceiver(
 		func(notice []byte) {
 
-			var event NoticeEvent
+			var event noticeEvent
 
 			err := json.Unmarshal(notice, &event)
 			if err != nil {
@@ -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)
+				tunnel.httpProxyPort = int(port)
 			} else if event.NoticeType == "ListeningSocksProxyPort" {
 				port := event.Data["port"].(float64)
-				measurementTest.socksProxyPort = int(port)
+				tunnel.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())
+	tunnel.controllerCtx, tunnel.stopController = context.WithCancel(context.Background())
 
 	// Set start time
 
@@ -179,12 +179,12 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
 
 	// Run test
 
-	var result StartResult
+	var result startResult
 
-	measurementTest.controllerWaitGroup.Add(1)
+	tunnel.controllerWaitGroup.Add(1)
 	go func() {
-		defer measurementTest.controllerWaitGroup.Done()
-		controller.Run(measurementTest.controllerCtx)
+		defer tunnel.controllerWaitGroup.Done()
+		controller.Run(tunnel.controllerCtx)
 
 		select {
 		case testError <- errors.New("controller.Run exited unexpectedly"):
@@ -196,26 +196,26 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
 
 	select {
 	case <-connected:
-		result.Code = StartResultCodeSuccess
+		result.Code = startResultCodeSuccess
 		result.BootstrapTime = secondsBeforeNow(startTime)
-		result.HttpProxyPort = measurementTest.httpProxyPort
-		result.SocksProxyPort = measurementTest.socksProxyPort
+		result.HttpProxyPort = tunnel.httpProxyPort
+		result.SocksProxyPort = tunnel.socksProxyPort
 	case <-timeoutSignal.Done():
-		result.Code = StartResultCodeTimeout
+		result.Code = startResultCodeTimeout
 		err = timeoutSignal.Err()
 		if err != nil {
 			result.ErrorString = fmt.Sprintf("Timeout occured before Psiphon connected: %s", err.Error())
 		}
-		measurementTest.stopController()
+		tunnel.stopController()
 	case err := <-testError:
-		result.Code = StartResultCodeOtherError
+		result.Code = startResultCodeOtherError
 		result.ErrorString = err.Error()
-		measurementTest.stopController()
+		tunnel.stopController()
 	}
 
 	// Return result
 
-	return marshalStartResult(result)
+	return marshalstartResult(result)
 }
 
 //export Stop
@@ -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 tunnel.stopController != nil {
+		tunnel.stopController()
 	}
-	measurementTest.controllerWaitGroup.Wait()
+	tunnel.controllerWaitGroup.Wait()
 }
 
 // secondsBeforeNow returns the delta seconds of the current time subtract startTime.
@@ -236,20 +236,20 @@ func secondsBeforeNow(startTime time.Time) float64 {
 	return delta.Seconds()
 }
 
-// marshalStartResult serializes a StartResult object as a JSON string in the form
+// marshalstartResult serializes a startResult object as a JSON string in the form
 // of a null-terminated buffer of C chars.
-func marshalStartResult(result StartResult) *C.char {
+func marshalstartResult(result startResult) *C.char {
 	resultJSON, err := json.Marshal(result)
 	if err != nil {
-		return C.CString(fmt.Sprintf("{\"result_code\":%d, \"error\": \"%s\"}", StartResultCodeOtherError, err.Error()))
+		return C.CString(fmt.Sprintf("{\"result_code\":%d, \"error\": \"%s\"}", startResultCodeOtherError, err.Error()))
 	}
 
 	return C.CString(string(resultJSON))
 }
 
-// startErrorJson returns a StartResult object serialized as a JSON string in the form
+// startErrorJson returns a startResult object serialized as a JSON string in the form
 // of a null-terminated buffer of C chars. The object's return result code will be set to
-// StartResultCodeOtherError (2) and its error string set to the error string of the provided error.
+// startResultCodeOtherError (2) and its error string set to the error string of the provided error.
 //
 // The JSON will be in the form of:
 // {
@@ -257,11 +257,11 @@ func marshalStartResult(result StartResult) *C.char {
 //   "error": <error message>
 // }
 func startErrorJson(err error) *C.char {
-	var result StartResult
-	result.Code = StartResultCodeOtherError
+	var result startResult
+	result.Code = startResultCodeOtherError
 	result.ErrorString = err.Error()
 
-	return marshalStartResult(result)
+	return marshalstartResult(result)
 }
 
 // main is a stub required by cgo.

+ 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.