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

Commit

Permalink
fix: 💊 re-export APIs used by Outline Client (#122)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jyyi1 authored Jul 25, 2023
1 parent bf28eea commit 4c5b7bf
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion outline/electron/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 22 additions & 5 deletions outline/shadowsocks/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 4c5b7bf

Please sign in to comment.