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

feat: ✨ add new OutlineDevice API that uses Outline SDK #118

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
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
17 changes: 12 additions & 5 deletions outline/shadowsocks/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ 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/Jigsaw-Code/outline-internal-sdk/transport/shadowsocks/client"
"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
//
// Somehow redundant because from it seems gomobile only recognizes a struct,
// but not a type alias (i.e. type Client = outline.Client).
type Client struct {
jyyi1 marked this conversation as resolved.
Show resolved Hide resolved
outline.Client
}

// NewClient creates a new Shadowsocks client from a non-nil configuration.
//
Expand Down Expand Up @@ -98,7 +102,7 @@ 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{outline.Client{StreamDialer: streamDialer, PacketListener: packetListener}}, nil
}

const reachabilityTimeout = 10 * time.Second
Expand All @@ -107,8 +111,11 @@ const reachabilityTimeout = 10 * time.Second
// 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)
//
// Note: please make sure the return type is (int, error) for backward compatibility reason.
func CheckConnectivity(client *Client) (int, error) {
netErr, err := connectivity.CheckConnectivity(&client.Client)
return netErr.Number(), err
}

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