Ver Fonte

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

Rod Hynes há 7 anos atrás
pai
commit
11f225bc15
2 ficheiros alterados com 46 adições e 9 exclusões
  1. 32 3
      ClientLibrary/PsiphonTunnel.go
  2. 14 6
      ClientLibrary/example/main.c

+ 32 - 3
ClientLibrary/PsiphonTunnel.go

@@ -84,9 +84,33 @@ var managedStartResult *C.char
 //     "error": <error message>
 //   }
 //
-// networkID should be not be blank and should follow the format specified by
+// clientPlatform should be of the form OS_OSVersion_BundleIdentifier where both the OSVersion and BundleIdentifier 
+// fields are optional. If clientPlatform is set to an empty string the "ClientPlatform" field in the provided json
+// config will be used instead.
+//
+// Provided below are links to platform specific code which can be used to find some of the above fields:
+//   Android:
+//     - OSVersion: https://github.com/Psiphon-Labs/psiphon-tunnel-core/blob/3d344194d21b250e0f18ededa4b4459a373b0690/MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java#L573
+//     - BundleIdentifier: https://github.com/Psiphon-Labs/psiphon-tunnel-core/blob/3d344194d21b250e0f18ededa4b4459a373b0690/MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java#L575
+//   iOS:
+//     - OSVersion: https://github.com/Psiphon-Labs/psiphon-tunnel-core/blob/3d344194d21b250e0f18ededa4b4459a373b0690/MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m#L612
+//     - BundleIdentifier: https://github.com/Psiphon-Labs/psiphon-tunnel-core/blob/3d344194d21b250e0f18ededa4b4459a373b0690/MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m#L622
+//
+// Some examples of valid client platform strings are:
+//
+//   "Android_4.2.2_com.example.exampleApp"
+//   "iOS_11.4_com.example.exampleApp"
+//   "Windows"
+//
+// networkID must be a non-empty string and follow the format specified by
 // https://godoc.org/github.com/Psiphon-Labs/psiphon-tunnel-core/psiphon#NetworkIDGetter.
-func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64) *C.char {
+//
+// Provided below are links to platform specific code which can be used to generate valid network identifier strings:
+//   Android:
+//     - https://github.com/Psiphon-Labs/psiphon-tunnel-core/blob/3d344194d21b250e0f18ededa4b4459a373b0690/MobileLibrary/Android/PsiphonTunnel/PsiphonTunnel.java#L371
+//   iOS:
+//     - https://github.com/Psiphon-Labs/psiphon-tunnel-core/blob/3d344194d21b250e0f18ededa4b4459a373b0690/MobileLibrary/iOS/PsiphonTunnel/PsiphonTunnel/PsiphonTunnel.m#L1105
+func Start(configJSON, embeddedServerEntryList, clientPlatform, networkID string, timeout int64) *C.char {
 
 	// Load provided config
 
@@ -101,8 +125,13 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
 		config.NetworkID = networkID
 	}
 
-	// All config fields should be set before calling commit
+	// Set client platform
+
+	if clientPlatform != "" {
+		 config.ClientPlatform = clientPlatform;
+	}
 
+	// All config fields should be set before calling commit
 	err = config.Commit()
 	if err != nil {
 		return startErrorJson(err)

+ 14 - 6
ClientLibrary/example/main.c

@@ -48,21 +48,29 @@ int main(int argc, char *argv[]) {
     // set server list
     GoString serverList = {};
 
-    // set timout
-    long long timeout = 60;
+    // set client platform
+    char * const os = "OSName"; // "Android", "iOS", "Windows", etc.
+    char * const os_version = "OSVersion"; // "4.0.4", "10.3", "10.0.10240", etc.
+    char * const bundle_identifier = "com.example.exampleClientLibraryApp";
+    char * test_client_platform = (char *)malloc(sizeof(char) * (strlen(os) + strlen(os_version) + strlen(bundle_identifier) + 4)); // 4 for 3 underscores and null terminating character
+
+    int n = sprintf(test_client_platform, "%s_%s_%s", os, os_version, bundle_identifier);
+    GoString client_platform = {test_client_platform, n};
 
     // set network ID
     char * const test_network_id = "TEST";
     GoString network_id = {test_network_id, strlen(test_network_id)};
 
+    // set timout
+    long long timeout = 60;
+
     // start will return once Psiphon connects or does not connect for timeout seconds
-    char *result = Start(psiphon_config, serverList, network_id, timeout);
-    Stop();
+    char *result = Start(psiphon_config, serverList, client_platform, network_id, timeout);
 
     // print results
     printf("Result: %s\n", result);
 
-    // The underlying memory of `result` is managed by PsiphonTunnel and will
-    // have been freed in Stop.
+    // The underlying memory of `result` is managed by PsiphonTunnel and is freed in Stop
+    Stop();
 }