Просмотр исходного кода

ClientLibrary: add client platform

mirokuratczyk 7 лет назад
Родитель
Сommit
bf7aefedac
2 измененных файлов с 34 добавлено и 5 удалено
  1. 22 2
      ClientLibrary/PsiphonTunnel.go
  2. 12 3
      ClientLibrary/example/main.c

+ 22 - 2
ClientLibrary/PsiphonTunnel.go

@@ -84,9 +84,26 @@ var managedStartResult *C.char
 //     "error": <error message>
 //   }
 //
+// clientPlatform should be of the form OS_OSVersion_BundleIdentifier where both the OSVersion and BundleIdentifier 
+// fields are optional.
+//
+// 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 should be not be blank and should 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 {
+func Start(configJSON, embeddedServerEntryList, clientPlatform, networkID string, timeout int64) *C.char {
 
 	// Load provided config
 
@@ -101,8 +118,11 @@ func Start(configJSON, embeddedServerEntryList, networkID string, timeout int64)
 		config.NetworkID = networkID
 	}
 
-	// All config fields should be set before calling commit
+	// Set client platform
+
+	config.ClientPlatform = clientPlatform;
 
+	// All config fields should be set before calling commit
 	err = config.Commit()
 	if err != nil {
 		return startErrorJson(err)

+ 12 - 3
ClientLibrary/example/main.c

@@ -48,15 +48,24 @@ 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);
+    char *result = Start(psiphon_config, serverList, client_platform, network_id, timeout);
     Stop();
 
     // print results