diff --git a/README.md b/README.md index 68ea3758..0f90e331 100644 --- a/README.md +++ b/README.md @@ -127,7 +127,7 @@ Beta features: - Integration resources - For Mobile apps - - [x] Library to run a local SOCKS5 or HTTP-Connect proxy ([source](./x/appproxy/appproxy.go), [example Go usage](./x/examples/fetch-proxy/main.go), [example mobile usage](./x/examples/mobileproxy)). + - [x] Library to run a local SOCKS5 or HTTP-Connect proxy ([source](./x/mobileproxy/mobileproxy.go), [example Go usage](./x/examples/fetch-proxy/main.go), [example mobile usage](./x/examples/mobileproxy)). - [x] Documentation on how to integrate the SDK into mobile apps - [ ] Connectivity Test mobile app using [Capacitor](https://capacitorjs.com/) - For Go apps diff --git a/x/examples/fetch-proxy/main.go b/x/examples/fetch-proxy/main.go index d1166cf7..e9b8c5c5 100644 --- a/x/examples/fetch-proxy/main.go +++ b/x/examples/fetch-proxy/main.go @@ -22,7 +22,7 @@ import ( "net/url" "os" - "github.com/Jigsaw-Code/outline-sdk/x/appproxy" + "github.com/Jigsaw-Code/outline-sdk/x/mobileproxy" ) func main() { @@ -34,9 +34,9 @@ func main() { log.Fatal("Need to pass the URL to fetch in the command-line") } - proxy, err := appproxy.RunProxy("localhost:0", *transportFlag) + proxy, err := mobileproxy.RunProxy("localhost:0", *transportFlag) if err != nil { - log.Fatalf("Could not start proxy: %v", err) + log.Fatalf("Cmobileproxy start proxy: %v", err) } httpClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(&url.URL{Scheme: "http", Host: proxy.Address()})}} diff --git a/x/examples/mobileproxy/.gitignore b/x/examples/mobileproxy/.gitignore deleted file mode 100644 index 6a3417b8..00000000 --- a/x/examples/mobileproxy/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/out/ diff --git a/x/examples/mobileproxy/README.md b/x/mobileproxy/README.md similarity index 71% rename from x/examples/mobileproxy/README.md rename to x/mobileproxy/README.md index ab30eb5e..c8e885c3 100644 --- a/x/examples/mobileproxy/README.md +++ b/x/mobileproxy/README.md @@ -1,6 +1,6 @@ # Local Proxy Library for Mobile Apps -This package illustrates the use Go Mobile to generate a mobile library to run a local proxy and configure your app networking libraries. +This package enabled the use Go Mobile to generate a mobile library to run a local proxy and configure your app networking libraries. ### Build the Go Mobile binaries with [`go build`](https://pkg.go.dev/cmd/go#hdr-Compile_packages_and_dependencies) @@ -11,8 +11,8 @@ go build -o ./out/ golang.org/x/mobile/cmd/gomobile golang.org/x/mobile/cmd/gobi ### Build the iOS and Android libraries with [`gomobile bind`](https://pkg.go.dev/golang.org/x/mobile/cmd/gomobile#hdr-Build_a_library_for_Android_and_iOS) ```bash -PATH="$(pwd)/out:$PATH" gomobile bind -target=ios -o "$(pwd)/out/LocalProxy.xcframework" github.com/Jigsaw-Code/outline-sdk/x/appproxy -PATH="$(pwd)/out:$PATH" gomobile bind -target=android -o "$(pwd)/out/LocalProxy.aar" github.com/Jigsaw-Code/outline-sdk/x/appproxy +PATH="$(pwd)/out:$PATH" gomobile bind -target=ios -o "$(pwd)/out/mobileproxy.xcframework" github.com/Jigsaw-Code/outline-sdk/x/mobileproxy +PATH="$(pwd)/out:$PATH" gomobile bind -target=android -o "$(pwd)/out/mobileproxy.aar" github.com/Jigsaw-Code/outline-sdk/x/mobileproxy ``` Note: Gomobile expects gobind to be in the PATH, that's why we need to prebuild it, and set up the PATH accordingly. @@ -20,28 +20,28 @@ Note: Gomobile expects gobind to be in the PATH, that's why we need to prebuild
iOS generated Code -`Appproxy.objc.h`: +`Mobileproxy.objc.h`: ```objc -// Objective-C API for talking to github.com/Jigsaw-Code/outline-sdk/x/appproxy Go package. -// gobind -lang=objc github.com/Jigsaw-Code/outline-sdk/x/appproxy +// Objective-C API for talking to github.com/Jigsaw-Code/outline-sdk/x/mobileproxy Go package. +// gobind -lang=objc github.com/Jigsaw-Code/outline-sdk/x/mobileproxy // // File is generated by gobind. Do not edit. -#ifndef __Appproxy_H__ -#define __Appproxy_H__ +#ifndef __Mobileproxy_H__ +#define __Mobileproxy_H__ @import Foundation; #include "ref.h" #include "Universe.objc.h" -@class AppproxyProxy; +@class MobileproxyProxy; /** * Proxy enables you to get the actual address bound by the server and stop the service when no longer needed. */ -@interface AppproxyProxy : NSObject { +@interface MobileproxyProxy : NSObject { } @property(strong, readonly) _Nonnull id _ref; @@ -52,16 +52,17 @@ Note: Gomobile expects gobind to be in the PATH, that's why we need to prebuild */ - (NSString* _Nonnull)address; /** - * Stops gracefully stops the proxy service, waiting for at most timeout seconds before forcefully closing it. + * Stop gracefully stops the proxy service, waiting for at most timeout seconds before forcefully closing it. +The function takes a timeoutSeconds number instead of a [time.Duration] so it's compatible with Go Mobile. */ - (void)stop:(long)timeoutSeconds; @end /** * RunProxy runs a local web proxy that listens on localAddress, and uses the transportConfig to -create the [transport.StreamDialer] to use to connect to the destination from the proxy requests. +create a [transport.StreamDialer] that is used to connect to the requested destination. */ -FOUNDATION_EXPORT AppproxyProxy* _Nullable AppproxyRunProxy(NSString* _Nullable localAddress, NSString* _Nullable transportConfig, NSError* _Nullable* _Nullable error); +FOUNDATION_EXPORT MobileproxyProxy* _Nullable MobileproxyRunProxy(NSString* _Nullable localAddress, NSString* _Nullable transportConfig, NSError* _Nullable* _Nullable error); #endif ``` @@ -71,25 +72,25 @@ FOUNDATION_EXPORT AppproxyProxy* _Nullable AppproxyRunProxy(NSString* _Nullable
Android generated Code -`Appproxy.java`: +`mobileproxy.java`: ```java // Code generated by gobind. DO NOT EDIT. -// Java class appproxy.Appproxy is a proxy for talking to a Go program. +// Java class mobileproxy.mobileproxy is a proxy for talking to a Go program. // -// autogenerated by gobind -lang=java github.com/Jigsaw-Code/outline-sdk/x/appproxy -package appproxy; +// autogenerated by gobind -lang=java github.com/Jigsaw-Code/outline-sdk/x/mobileproxy +package mobileproxy; import go.Seq; -public abstract class Appproxy { +public abstract class mobileproxy { static { Seq.touch(); // for loading the native library _init(); } - private Appproxy() {} // uninstantiable + private mobileproxy() {} // uninstantiable // touch is called from other bound packages to initialize this package public static void touch() {} @@ -112,10 +113,10 @@ public abstract class Appproxy { ```java // Code generated by gobind. DO NOT EDIT. -// Java class appproxy.Proxy is a proxy for talking to a Go program. +// Java class mobileproxy.Proxy is a proxy for talking to a Go program. // -// autogenerated by gobind -lang=java github.com/Jigsaw-Code/outline-sdk/x/appproxy -package appproxy; +// autogenerated by gobind -lang=java github.com/Jigsaw-Code/outline-sdk/x/mobileproxy +package mobileproxy; import go.Seq; @@ -123,7 +124,7 @@ import go.Seq; * Proxy enables you to get the actual address bound by the server and stop the service when no longer needed. */ public final class Proxy implements Seq.Proxy { - static { Appproxy.touch(); } + static { mobileproxy.touch(); } private final int refnum; diff --git a/x/appproxy/appproxy.go b/x/mobileproxy/mobileproxy.go similarity index 95% rename from x/appproxy/appproxy.go rename to x/mobileproxy/mobileproxy.go index 10526a47..f413dd15 100644 --- a/x/appproxy/appproxy.go +++ b/x/mobileproxy/mobileproxy.go @@ -12,11 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package appproxy provides convenience utilities to help applications run a local proxy +// Package mobileproxy provides convenience utilities to help applications run a local proxy // and use that to configure their networking libraries. // // This package is suitable for use with Go Mobile, making it a convenient way to integrate with mobile apps. -package appproxy +package mobileproxy import ( "context" diff --git a/x/examples/mobileproxy/tools.go b/x/mobileproxy/tools.go similarity index 94% rename from x/examples/mobileproxy/tools.go rename to x/mobileproxy/tools.go index 1ce91d69..4db3a2d0 100644 --- a/x/examples/mobileproxy/tools.go +++ b/x/mobileproxy/tools.go @@ -21,7 +21,7 @@ package tools import ( - _ "github.com/Jigsaw-Code/outline-sdk/x/appproxy" + _ "github.com/Jigsaw-Code/outline-sdk/x/mobileproxy" _ "golang.org/x/mobile/cmd/gobind" _ "golang.org/x/mobile/cmd/gomobile" )