From 4c5b7bf535b647ac4f81f2bd6880c2195dd56809 Mon Sep 17 00:00:00 2001
From: "J. Yi" <93548144+jyyi1@users.noreply.github.com>
Date: Tue, 25 Jul 2023 13:01:59 -0400
Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=92=8A=20re-export=20APIs=20used?=
=?UTF-8?q?=20by=20Outline=20Client=20(#122)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Outline Client is referencing the following APIs (Android JNI interface as an example) exported by `gomobile`.
But due to the recent refactoring, we introduced types that are not recognized by `gomobile`. This is the only function exported in `master` branch now:
In this PR, I re-exported these functions (together with the new `NewClientFromJSON`) by using the built-in types. Here is the exported Android JNI interface:
/cc @sbruens , although the required APIs are re-exported, some of the data types still need to be updated:
* [`OutlineTunnel`](https://github.com/Jigsaw-Code/outline-client/blob/master/src/cordova/android/OutlineAndroidLib/outline/src/main/java/org/outline/vpn/VpnTunnel.java#L49) -> `Tunnel`
* [`Tun2socksOutlineTunnel`](https://github.com/Jigsaw-Code/outline-client/blob/master/src/cordova/apple/OutlineAppleLib/Sources/PacketTunnelProviderSources/PacketTunnelProvider.m#L39) -> `Tun2socksTunnel`
Related PR: #118
---
outline/electron/main.go | 2 +-
outline/shadowsocks/client.go | 27 ++++++++++++++++++++++-----
2 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/outline/electron/main.go b/outline/electron/main.go
index fb5b220..921e6b9 100644
--- a/outline/electron/main.go
+++ b/outline/electron/main.go
@@ -103,7 +103,7 @@ func main() {
if err != nil {
log.Errorf("Failed to perform connectivity checks: %v", err)
}
- os.Exit(connErrCode.Number())
+ os.Exit(connErrCode)
}
// Open TUN device
diff --git a/outline/shadowsocks/client.go b/outline/shadowsocks/client.go
index 9df263c..d0eb118 100644
--- a/outline/shadowsocks/client.go
+++ b/outline/shadowsocks/client.go
@@ -28,14 +28,13 @@ import (
"github.com/Jigsaw-Code/outline-go-tun2socks/outline"
"github.com/Jigsaw-Code/outline-go-tun2socks/outline/connectivity"
"github.com/Jigsaw-Code/outline-go-tun2socks/outline/internal/utf8"
- "github.com/Jigsaw-Code/outline-go-tun2socks/outline/neterrors"
"github.com/Jigsaw-Code/outline-internal-sdk/transport"
"github.com/Jigsaw-Code/outline-internal-sdk/transport/shadowsocks"
"github.com/eycorsican/go-tun2socks/common/log"
)
// A client object that can be used to connect to a remote Shadowsocks proxy.
-type Client = outline.Client
+type Client outline.Client
// NewClient creates a new Shadowsocks client from a non-nil configuration.
//
@@ -96,17 +95,35 @@ func newShadowsocksClient(host string, port int, cipherName, password string, pr
return nil, fmt.Errorf("failed to create PacketListener: %w", err)
}
- return &outline.Client{StreamDialer: streamDialer, PacketListener: packetListener}, nil
+ return &Client{StreamDialer: streamDialer, PacketListener: packetListener}, nil
}
+// Error number constants exported through gomobile
+const (
+ NoError = 0
+ Unexpected = 1
+ NoVPNPermissions = 2 // Unused
+ AuthenticationFailure = 3
+ UDPConnectivity = 4
+ Unreachable = 5
+ VpnStartFailure = 6 // Unused
+ IllegalConfiguration = 7 // Electron only
+ ShadowsocksStartFailure = 8 // Unused
+ ConfigureSystemProxyFailure = 9 // Unused
+ NoAdminPermissions = 10 // Unused
+ UnsupportedRoutingTable = 11 // Unused
+ SystemMisconfigured = 12 // Electron only
+)
+
const reachabilityTimeout = 10 * time.Second
// CheckConnectivity determines whether the Shadowsocks proxy can relay TCP and UDP traffic under
// the current network. Parallelizes the execution of TCP and UDP checks, selects the appropriate
// error code to return accounting for transient network failures.
// Returns an error if an unexpected error ocurrs.
-func CheckConnectivity(client *Client) (neterrors.Error, error) {
- return connectivity.CheckConnectivity(client)
+func CheckConnectivity(client *Client) (int, error) {
+ errCode, err := connectivity.CheckConnectivity((*outline.Client)(client))
+ return errCode.Number(), err
}
// CheckServerReachable determines whether the server at `host:port` is reachable over TCP.