summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Whited <sam@samwhited.com>2022-03-16 09:26:06 -0400
committerSam Whited <sam@samwhited.com>2022-03-16 09:26:52 -0400
commitfd68d581c650927e8f4ea430f2638ae43f2b7f15 (patch)
tree4672157da43195885392bca11f22c3171ce77a30
parentebd23e55624184f4a3e7ef51128f5a37eedf0465 (diff)
pkg/vpn: support OBFS4 over KCPobfs4_over_kcp
Signed-off-by: Sam Whited <sam@samwhited.com>
-rw-r--r--gui/components/Preferences.qml5
-rw-r--r--pkg/vpn/openvpn.go22
2 files changed, 18 insertions, 9 deletions
diff --git a/gui/components/Preferences.qml b/gui/components/Preferences.qml
index 4de2f95..40e01be 100644
--- a/gui/components/Preferences.qml
+++ b/gui/components/Preferences.qml
@@ -88,7 +88,6 @@ ThemedPage {
// we need to fallback to "auto" selection if such location does not
// offer bridges
useBridges(checked)
- useUDP.enabled = !checked
}
}
@@ -166,7 +165,6 @@ ThemedPage {
}
onClicked: {
doUseUDP(checked)
- useBridgesCheckBox.enabled = areBridgesAvailable()
}
}
}
@@ -225,8 +223,7 @@ ThemedPage {
function areBridgesAvailable() {
// FIXME check if provider offers it
- let providerSupport = true
- return providerSupport && !useUDP.checked
+ return true
}
function useBridges(value) {
diff --git a/pkg/vpn/openvpn.go b/pkg/vpn/openvpn.go
index c6f4d4b..3b3797a 100644
--- a/pkg/vpn/openvpn.go
+++ b/pkg/vpn/openvpn.go
@@ -31,6 +31,8 @@ import (
"0xacab.org/leap/bitmask-vpn/pkg/config"
"0xacab.org/leap/obfsvpn"
+
+ "github.com/xtaci/kcp-go/v5"
)
const (
@@ -64,7 +66,7 @@ func (b *Bitmask) CanStartVPN() bool {
return !b.bonafide.NeedsCredentials()
}
-func (b *Bitmask) startTransport(host string) (proxy string, err error) {
+func (b *Bitmask) startTransport(host string, udp bool) (proxy string, err error) {
// TODO configure port if not available
proxy = "127.0.0.1:4430"
if b.listener != nil {
@@ -104,21 +106,31 @@ func (b *Bitmask) startTransport(host string) (proxy string, err error) {
continue
}
dialer.IATMode = obfsvpn.IATMode(iatMode)
- go clientHandler(b.listener, dialer, target)
+ go clientHandler(b.listener, dialer, target, udp)
log.Println("Connected via obfs4 to", gw.IPAddress, "(", gw.Host, ")")
return proxy, nil
}
return "", fmt.Errorf("No working gateway for transport %s: %v", b.transport, err)
}
-func clientHandler(ln net.Listener, dialer *obfsvpn.Dialer, target string) {
+func clientHandler(ln net.Listener, dialer *obfsvpn.Dialer, target string, udp bool) {
for {
localConn, err := ln.Accept()
if err != nil {
log.Printf("error accepting connection: %v", err)
return
}
- remoteConn, err := dialer.Dial(context.TODO(), "tcp", target)
+ var remoteConn net.Conn
+ if udp {
+ innerConn, err := kcp.Dial(target)
+ if err != nil {
+ log.Printf("error dialing gateway via kcp: %v", err)
+ return
+ }
+ remoteConn, err = dialer.Wrap(context.TODO(), innerConn)
+ } else {
+ remoteConn, err = dialer.Dial(context.TODO(), "tcp", target)
+ }
if err != nil {
log.Printf("error dialing gateway: %v", err)
return
@@ -156,7 +168,7 @@ func (b *Bitmask) startOpenVPN() error {
}
gw := gateways[0]
- proxy, err := b.startTransport(gw.Host)
+ proxy, err := b.startTransport(gw.Host, b.udp)
if err != nil {
return err
}