forked from Psiphon-Labs/psiphon-tunnel-core
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update C measurement lib and add example
- Loading branch information
1 parent
4045955
commit 7f59151
Showing
9 changed files
with
144 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ AndroidLibrary/psi.aar | |
*.o | ||
*.a | ||
*.so | ||
*.dylib | ||
|
||
# Folders | ||
_obj | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
shared: | ||
go build -buildmode=c-shared -o PsiphonTunnel.dylib PsiphonTunnel.go | ||
.PHONY: shared | ||
|
||
static: | ||
go build -buildmode=c-archive -o PsiphonTunnel.a PsiphonTunnel.go | ||
|
||
.PHONY: static |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
main: main.o PsiphonTunnel.dylib | ||
gcc PsiphonTunnel.dylib -o main main.o | ||
|
||
main.o: main.c | ||
gcc -I.. -c main.c | ||
|
||
PsiphonTunnel.dylib: ../PsiphonTunnel.go | ||
go build -buildmode=c-shared -o PsiphonTunnel.dylib ../PsiphonTunnel.go | ||
|
||
clean: | ||
rm PsiphonTunnel.dylib PsiphonTunnel.h main main.o | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include "PsiphonTunnel.h" | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
char *read_file(char *filename) { | ||
char *buffer = NULL; | ||
size_t size = 0; | ||
|
||
FILE *fp = fopen(filename, "r"); | ||
|
||
if (!fp) { | ||
return NULL; | ||
} | ||
|
||
fseek(fp, 0, SEEK_END); | ||
size = ftell(fp); | ||
|
||
rewind(fp); | ||
buffer = malloc((size + 1) * sizeof(*buffer)); | ||
|
||
fread(buffer, size, 1, fp); | ||
buffer[size] = '\0'; | ||
|
||
return buffer; | ||
} | ||
|
||
int main(int argc, char *argv[]) { | ||
|
||
// load config | ||
char * const default_config = "psiphon_config"; | ||
|
||
char * config = argv[1]; | ||
|
||
if (!config) { | ||
config = default_config; | ||
printf("Using default config file: %s\n", default_config); | ||
} | ||
|
||
char *file_contents = read_file(config); | ||
if (!file_contents) { | ||
printf("Could not find config file: %s\n", config); | ||
return 1; | ||
} | ||
|
||
GoString psiphon_config = {file_contents, strlen(file_contents)}; | ||
|
||
// set server list | ||
GoString serverList = {}; | ||
|
||
// set timout | ||
long long timeout = 10; | ||
|
||
// set network ID | ||
char * const test_network_id = "TEST"; | ||
GoString network_id = {test_network_id, strlen(test_network_id)}; | ||
|
||
// start will return once Psiphon connects or does not connect for timeout seconds | ||
char *result = Start(psiphon_config, serverList, network_id, timeout); | ||
Stop(); | ||
|
||
// print results | ||
printf("Result: %s\n", result); | ||
|
||
// cleanup | ||
free(result); | ||
} | ||
|