-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ add ProxyTunnel to replace tun2socks
- Loading branch information
Showing
7 changed files
with
197 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Outline Client Backend | ||
|
||
## Environment Preparation | ||
|
||
```sh | ||
go install golang.org/x/mobile/cmd/gomobile@latest | ||
export GOBIN="$HOME/go/bin/" -- or your customized go binary folder | ||
export PATH="$GOBIN:$PATH" | ||
gomobile init | ||
``` | ||
|
||
## Build | ||
|
||
```sh | ||
export ANDROID_HOME="$HOME/Android/Sdk" | ||
gomobile clean | ||
gomobile bind -target android ./outline/client/backend | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2023 The Outline Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package backend | ||
|
||
import ( | ||
"io" | ||
"sync" | ||
) | ||
|
||
type Reader interface { | ||
io.Reader | ||
} | ||
|
||
type Writer interface { | ||
io.Writer | ||
} | ||
|
||
type AsyncCopyResult struct { | ||
wg sync.WaitGroup | ||
copied int64 | ||
err error | ||
} | ||
|
||
func CopyAsync(dest Writer, source Reader) *AsyncCopyResult { | ||
w := &AsyncCopyResult{} | ||
w.wg.Add(1) | ||
go func() { | ||
defer w.wg.Done() | ||
buf := make([]byte, 1500) | ||
w.copied, w.err = io.CopyBuffer(dest, source, buf) | ||
}() | ||
return w | ||
} | ||
|
||
func (w *AsyncCopyResult) Wait() (int64, error) { | ||
w.wg.Wait() | ||
return w.copied, w.err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2023 The Outline Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
///go:build linux & windows | ||
|
||
package electronlegacy | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"os" | ||
"os/signal" | ||
"strings" | ||
"syscall" | ||
|
||
"github.com/Jigsaw-Code/outline-apps/outline/client/backend" | ||
"github.com/eycorsican/go-tun2socks/tun" | ||
) | ||
|
||
var args struct { | ||
// TUN device settings | ||
tunAddr *string | ||
tunGw *string | ||
tunMask *string | ||
tunName *string | ||
tunDNS *string | ||
|
||
// Proxy settings | ||
proxyConfig *string | ||
} | ||
|
||
func main() { | ||
args.tunAddr = flag.String("tunAddr", "10.0.85.2", "TUN interface IP address") | ||
args.tunGw = flag.String("tunGw", "10.0.85.1", "TUN interface gateway") | ||
args.tunMask = flag.String("tunMask", "255.255.255.0", "TUN interface network mask; prefixlen for IPv6") | ||
args.tunDNS = flag.String("tunDNS", "1.1.1.1,9.9.9.9,208.67.222.222", "Comma-separated list of DNS resolvers for the TUN interface (Windows only)") | ||
args.tunName = flag.String("tunName", "tun0", "TUN interface name") | ||
args.proxyConfig = flag.String("config", "", "The Outline configuration in JSON format") | ||
flag.Parse() | ||
|
||
proxy, err := backend.NewProxyTunnel(*args.proxyConfig) | ||
if err != nil { | ||
log.Fatalf("Failed to create Outline ProxyTunnel: %v", err) | ||
} | ||
log.Println("Outline ProxyTunnel created") | ||
defer proxy.Close() // not necessary, but no harm | ||
|
||
dnsResolvers := strings.Split(*args.tunDNS, ",") | ||
tunDev, err := tun.OpenTunDevice(*args.tunName, *args.tunAddr, *args.tunGw, *args.tunMask, dnsResolvers, true) | ||
if err != nil { | ||
log.Fatalf("Failed to open tun device: %v", err) | ||
} | ||
log.Println("Tun device opened") | ||
defer tunDev.Close() // not necessary, but no harm | ||
|
||
defer backend.CopyAsync(tunDev, proxy).Wait() | ||
defer backend.CopyAsync(proxy, tunDev).Wait() | ||
|
||
osSignals := make(chan os.Signal, 1) | ||
signal.Notify(osSignals, os.Interrupt, syscall.SIGTERM, syscall.SIGHUP) | ||
sig := <-osSignals | ||
|
||
log.Printf("Received signal: %v, terminating...", sig) | ||
proxy.Close() | ||
tunDev.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2023 The Outline Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package backend | ||
|
||
import "github.com/Jigsaw-Code/outline-apps/outline/device" | ||
|
||
// ProxyTunnel is an interface that will be exported by gomobile, and be used by Outline Client. | ||
type ProxyTunnel struct { | ||
*device.OutlineDevice | ||
} | ||
|
||
func NewProxyTunnel(configJSON string) (*ProxyTunnel, error) { | ||
d, err := device.NewOutlineDevice(configJSON) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &ProxyTunnel{d}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters