Skip to content

Commit

Permalink
fix dns issues, performance improvements and minor bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
uoosef committed Feb 1, 2024
1 parent fdd1912 commit 511125e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ replace github.com/Psiphon-Labs/psiphon-tunnel-core => github.com/uoosef/psiphon
require (
github.com/MakeNowJust/heredoc/v2 v2.0.1
github.com/Psiphon-Labs/psiphon-tunnel-core v0.0.0-00010101000000-000000000000
github.com/bepass-org/proxy v0.0.0-20240103080554-a7e12466f91f
github.com/bepass-org/proxy v0.0.0-20240201095508-c86216dd0aea
github.com/go-ini/ini v1.67.0
github.com/refraction-networking/conjure v0.7.10-0.20231110193225-e4749a9dedc9
github.com/refraction-networking/utls v1.3.3
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func runWarp(bindAddress, endpoint, confPath string, verbose, wait bool, startPr

// Wait for interrupt signal
if wait {
log.Printf("Serving on %s\n", bindAddress)
<-sigChan
}

Expand All @@ -114,6 +115,7 @@ func runWarpWithPsiphon(bindAddress, endpoint, country string, verbose bool) {
// run psiphon
psiphonCtx := psiphon.RunPsiphon(warpBindAddress, bindAddress, country)

log.Printf("Serving on %s\n", bindAddress)
// Wait for interrupt signal
<-sigChan

Expand Down
5 changes: 4 additions & 1 deletion warp/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const (
var (
identityFile = "wgcf-identity.json"
profileFile = "wgcf-profile.ini"
dnsAddresses = []string{"8.8.8.8", "8.8.4.4"}
dc = 0
)

var defaultHeaders = makeDefaultHeaders()
Expand Down Expand Up @@ -470,7 +472,8 @@ func getWireguardConfig(privateKey, address1, address2, publicKey, endpoint stri

buffer.WriteString("[Interface]\n")
buffer.WriteString(fmt.Sprintf("PrivateKey = %s\n", privateKey))
buffer.WriteString("DNS = 1.1.1.1\n")
buffer.WriteString(fmt.Sprintf("DNS = %s\n", dnsAddresses[dc%len(dnsAddresses)]))
dc++
buffer.WriteString(fmt.Sprintf("Address = %s\n", address1+"/24"))
buffer.WriteString(fmt.Sprintf("Address = %s\n", address2+"/128"))

Expand Down
9 changes: 9 additions & 0 deletions wiresocks/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ type Configuration struct {
Device *DeviceConfig
}

var (
dnsAddresses = []string{"8.8.8.8", "8.8.4.4"}
dc = 0
)

func parseString(section *ini.Section, keyName string) (string, error) {
key := section.Key(strings.ToLower(keyName))
if key == nil {
Expand Down Expand Up @@ -79,6 +84,10 @@ func parseNetIP(section *ini.Section, keyName string) ([]netip.Addr, error) {
var ips []netip.Addr
for _, str := range key.StringsWithShadows(",") {
str = strings.TrimSpace(str)
if str == "1.1.1.1" {
str = dnsAddresses[dc%len(dnsAddresses)]
dc++
}
ip, err := netip.ParseAddr(str)
if err != nil {
return nil, err
Expand Down
18 changes: 17 additions & 1 deletion wiresocks/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,28 @@ type VirtualTun struct {
Tnet *netstack.Net
SystemDNS bool
Verbose bool
Logger DefaultLogger
}

type DefaultLogger struct {
verbose bool
}

func (l DefaultLogger) Debug(v ...interface{}) {
if l.verbose {
log.Println(v...)
}
}

func (l DefaultLogger) Error(v ...interface{}) {
log.Println(v...)
}

// StartProxy spawns a socks5 server.
func (vt *VirtualTun) StartProxy(bindAddress string) {
proxy := mixed.NewProxy(
mixed.WithBinAddress(bindAddress),
mixed.WithBindAddress(bindAddress),
mixed.WithLogger(vt.Logger),
mixed.WithUserHandler(func(request *statute.ProxyRequest) error {
return vt.generalHandler(request)
}),
Expand Down
4 changes: 3 additions & 1 deletion wiresocks/udpfw.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ func NewVtunUDPForwarder(localBind, dest string, vtun *VirtualTun, mtu int) erro
fmt.Println("Error reading from connection:", err)
continue
}
listener.WriteMsgUDP(buffer[:n], nil, remoteAddr)
if remoteAddr != nil {
listener.WriteMsgUDP(buffer[:n], nil, remoteAddr)
}
}
}()
return nil
Expand Down
3 changes: 3 additions & 0 deletions wiresocks/wiresocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,8 @@ func StartWireguard(conf *DeviceConfig, verbose bool) (*VirtualTun, error) {
Tnet: tnet,
SystemDNS: len(setting.dns) == 0,
Verbose: verbose,
Logger: DefaultLogger{
verbose: verbose,
},
}, nil
}

0 comments on commit 511125e

Please sign in to comment.