Skip to content
This repository was archived by the owner on May 6, 2024. It is now read-only.

Commit 4c5b7bf

Browse files
authored
fix: 💊 re-export APIs used by Outline Client (#122)
Outline Client is referencing the following APIs (Android JNI interface as an example) exported by `gomobile`. <img width="642" alt="image" src="https://user-images.githubusercontent.com/93548144/232151618-de7c91eb-2ee6-444e-bbe0-023262af2149.png"> 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: <img width="646" alt="image" src="https://user-images.githubusercontent.com/93548144/232152396-6cf278ab-f45b-448a-adb9-c03b13772eb7.png"> 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: <img width="635" alt="image" src="https://user-images.githubusercontent.com/93548144/232151977-ad6bd330-4bc5-4383-b6ef-49dce4dc1853.png"> /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
1 parent bf28eea commit 4c5b7bf

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

‎outline/electron/main.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func main() {
103103
if err != nil {
104104
log.Errorf("Failed to perform connectivity checks: %v", err)
105105
}
106-
os.Exit(connErrCode.Number())
106+
os.Exit(connErrCode)
107107
}
108108

109109
// Open TUN device

‎outline/shadowsocks/client.go‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,13 @@ import (
2828
"github.com/Jigsaw-Code/outline-go-tun2socks/outline"
2929
"github.com/Jigsaw-Code/outline-go-tun2socks/outline/connectivity"
3030
"github.com/Jigsaw-Code/outline-go-tun2socks/outline/internal/utf8"
31-
"github.com/Jigsaw-Code/outline-go-tun2socks/outline/neterrors"
3231
"github.com/Jigsaw-Code/outline-internal-sdk/transport"
3332
"github.com/Jigsaw-Code/outline-internal-sdk/transport/shadowsocks"
3433
"github.com/eycorsican/go-tun2socks/common/log"
3534
)
3635

3736
// A client object that can be used to connect to a remote Shadowsocks proxy.
38-
type Client = outline.Client
37+
type Client outline.Client
3938

4039
// NewClient creates a new Shadowsocks client from a non-nil configuration.
4140
//
@@ -96,17 +95,35 @@ func newShadowsocksClient(host string, port int, cipherName, password string, pr
9695
return nil, fmt.Errorf("failed to create PacketListener: %w", err)
9796
}
9897

99-
return &outline.Client{StreamDialer: streamDialer, PacketListener: packetListener}, nil
98+
return &Client{StreamDialer: streamDialer, PacketListener: packetListener}, nil
10099
}
101100

101+
// Error number constants exported through gomobile
102+
const (
103+
NoError = 0
104+
Unexpected = 1
105+
NoVPNPermissions = 2 // Unused
106+
AuthenticationFailure = 3
107+
UDPConnectivity = 4
108+
Unreachable = 5
109+
VpnStartFailure = 6 // Unused
110+
IllegalConfiguration = 7 // Electron only
111+
ShadowsocksStartFailure = 8 // Unused
112+
ConfigureSystemProxyFailure = 9 // Unused
113+
NoAdminPermissions = 10 // Unused
114+
UnsupportedRoutingTable = 11 // Unused
115+
SystemMisconfigured = 12 // Electron only
116+
)
117+
102118
const reachabilityTimeout = 10 * time.Second
103119

104120
// CheckConnectivity determines whether the Shadowsocks proxy can relay TCP and UDP traffic under
105121
// the current network. Parallelizes the execution of TCP and UDP checks, selects the appropriate
106122
// error code to return accounting for transient network failures.
107123
// Returns an error if an unexpected error ocurrs.
108-
func CheckConnectivity(client *Client) (neterrors.Error, error) {
109-
return connectivity.CheckConnectivity(client)
124+
func CheckConnectivity(client *Client) (int, error) {
125+
errCode, err := connectivity.CheckConnectivity((*outline.Client)(client))
126+
return errCode.Number(), err
110127
}
111128

112129
// CheckServerReachable determines whether the server at `host:port` is reachable over TCP.

0 commit comments

Comments
 (0)