Skip to content

Commit

Permalink
fix: correct the logic of converting SocksAddr into net.Destination.
Browse files Browse the repository at this point in the history
  • Loading branch information
cty123 authored and yuhan6665 committed Jul 19, 2023
1 parent 7aeca33 commit b68a43f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion common/singbridge/destination.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,25 @@ func ToNetwork(network string) net.Network {
}

func ToDestination(socksaddr M.Socksaddr, network net.Network) net.Destination {
// IsFqdn() implicitly checks if the domain name is valid
if socksaddr.IsFqdn() {
return net.Destination{
Network: network,
Address: net.DomainAddress(socksaddr.Fqdn),
Port: net.Port(socksaddr.Port),
}
} else {
}

// IsIP() implicitly checks if the IP address is valid
if socksaddr.IsIP() {
return net.Destination{
Network: network,
Address: net.IPAddress(socksaddr.Addr.AsSlice()),
Port: net.Port(socksaddr.Port),
}
}

return net.Destination{}
}

func ToSocksaddr(destination net.Destination) M.Socksaddr {
Expand Down
7 changes: 6 additions & 1 deletion proxy/shadowsocks_2022/inbound_multi.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,12 @@ func (i *MultiUserInbound) NewConnection(ctx context.Context, conn net.Conn, met
})
newError("tunnelling request to tcp:", metadata.Destination).WriteToLog(session.ExportIDToError(ctx))
dispatcher := session.DispatcherFromContext(ctx)
link, err := dispatcher.Dispatch(ctx, singbridge.ToDestination(metadata.Destination, net.Network_TCP))
destination := singbridge.ToDestination(metadata.Destination, net.Network_TCP)
if !destination.IsValid() {
return newError("invalid destination")
}

link, err := dispatcher.Dispatch(ctx, destination)
if err != nil {
return err
}
Expand Down

0 comments on commit b68a43f

Please sign in to comment.