Skip to content

Commit

Permalink
Force ipv4 when determining public IP (#77)
Browse files Browse the repository at this point in the history
* Force ipv4 when determining public IP

* Fix linter
  • Loading branch information
galt-tr authored Mar 27, 2024
1 parent 9288b40 commit a100a12
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions app/p2p/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,16 @@ func NewServer(o ServerOptions) (*Server, error) {

// GetPublicIP fetches the public IP address from ifconfig.me
func GetPublicIP(ctx context.Context) (string, error) {
client := &http.Client{}

transport := &http.Transport{
DialContext: func(ctx context.Context, _, addr string) (net.Conn, error) {
// Force the use of IPv4 by specifying 'tcp4' as the network
return (&net.Dialer{}).DialContext(ctx, "tcp4", addr)
},
TLSHandshakeTimeout: 10 * time.Second,
}
client := &http.Client{
Transport: transport,
}
req, err := http.NewRequestWithContext(ctx, "GET", "https://ifconfig.me/ip", nil)
if err != nil {
return "", err
Expand Down

0 comments on commit a100a12

Please sign in to comment.