Skip to content

Commit

Permalink
Merge mobileproxy
Browse files Browse the repository at this point in the history
  • Loading branch information
fortuna committed Sep 6, 2023
1 parent 606a43c commit ec9229d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions x/examples/fetch-proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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()})}}
Expand Down
1 change: 0 additions & 1 deletion x/examples/mobileproxy/.gitignore

This file was deleted.

47 changes: 24 additions & 23 deletions x/examples/mobileproxy/README.md → x/mobileproxy/README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand All @@ -11,37 +11,37 @@ 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.

<details>
<summary>iOS generated Code</summary>

`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 <goSeqRefInterface> {
@interface MobileproxyProxy : NSObject <goSeqRefInterface> {
}
@property(strong, readonly) _Nonnull id _ref;

Expand All @@ -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
```
Expand All @@ -71,25 +72,25 @@ FOUNDATION_EXPORT AppproxyProxy* _Nullable AppproxyRunProxy(NSString* _Nullable
<details>
<summary>Android generated Code</summary>

`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() {}
Expand All @@ -112,18 +113,18 @@ 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;

/**
* 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;

Expand Down
4 changes: 2 additions & 2 deletions x/appproxy/appproxy.go → x/mobileproxy/mobileproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion x/examples/mobileproxy/tools.go → x/mobileproxy/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit ec9229d

Please sign in to comment.