Skip to content

Commit

Permalink
fix ipv6 problem
Browse files Browse the repository at this point in the history
  • Loading branch information
uoosef committed Aug 22, 2023
1 parent 827ee49 commit 8802ad4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"ChunksLengthAfterSni": [2000, 2000],
"DelayBetweenChunks": [10, 20],
"WorkerAddress": "https://hello-world-rapid-boat-c250.uoosef.workers.dev/dns-query",
"WorkerIPPortAddress": "104.20.27.92:2096",
"WorkerIPPortAddress": "104.17.196.93:2096",
"WorkerEnabled": true,
"WorkerDNSOnly": false,
"EnableLowLevelSockets": false,
Expand Down
5 changes: 4 additions & 1 deletion dialer/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ func (d *Dialer) makeTLSHelloPacketWithPadding(plainConn net.Conn, config *tls.C
}

func (d *Dialer) TLSDial(plainDialer PlainTCPDial, network, addr, hostPort string) (net.Conn, error) {
sni := strings.Split(addr, ":")[0]
sni, _, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
}
plainConn, err := plainDialer(network, addr, hostPort)
if err != nil {
return nil, err
Expand Down
10 changes: 9 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,15 @@ func (s *Server) sendChunks(dst io.Writer, src io.Reader, shouldSplit bool, wg *
func (s *Server) Resolve(fqdn string) (string, error) {
if s.WorkerConfig.WorkerEnabled &&
strings.Contains(s.WorkerConfig.WorkerAddress, fqdn) {
return strings.Split(s.WorkerConfig.WorkerIPPortAddress, ":")[0], nil
dh, _, err := net.SplitHostPort(s.WorkerConfig.WorkerIPPortAddress)
if strings.Contains(dh, ":") {
// its ipv6
dh = "[" + dh + "]"
}
if err != nil {
return "", err
}
return dh, nil
}

if h := s.LocalResolver.CheckHosts(fqdn); h != "" {
Expand Down
14 changes: 12 additions & 2 deletions transport/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,18 @@ func TunnelToWorkerThroughWs(ctx context.Context, w io.Writer, req *socks5.Reque
if err != nil {
return err
}
dp := req.DstAddr.String()[strings.LastIndex(req.DstAddr.String(), ":")+1:]
dh := req.DstAddr.String()[:strings.LastIndex(req.DstAddr.String(), ":")]
dh, dp, err := net.SplitHostPort(req.DstAddr.String())
if strings.Contains(dh, ":") {
// its ipv6
dh = "[" + dh + "]"
}
if err != nil {
if err := socks5.SendReply(w, statute.RepServerFailure, nil); err != nil {
return err
}
logger.Printf("Could not split host and port: %v\n", err)
return err
}
endpoint := fmt.Sprintf("wss://%s/connect?host=%s&port=%s", u.Host, dh, dp)
wsConn, err := wsDialer(endpoint, socks5BindAddress, dialer)
if err != nil {
Expand Down

0 comments on commit 8802ad4

Please sign in to comment.