chore(all): replace net.IP with netip.Addr

This commit is contained in:
Quentin McGaw
2023-05-20 19:58:18 +00:00
parent 00ee6ff9a7
commit 0a29337c3b
91 changed files with 525 additions and 590 deletions

View File

@@ -3,8 +3,8 @@ package windscribe
import (
"errors"
"math/rand"
"net"
"net/http"
"net/netip"
"testing"
"github.com/golang/mock/gomock"
@@ -42,7 +42,7 @@ func Test_Provider_GetConnection(t *testing.T) {
},
"default OpenVPN TCP port": {
filteredServers: []models.Server{
{IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}},
},
selection: settings.ServerSelection{
OpenVPN: settings.OpenVPNSelection{
@@ -51,14 +51,14 @@ func Test_Provider_GetConnection(t *testing.T) {
}.WithDefaults(provider),
connection: models.Connection{
Type: vpn.OpenVPN,
IP: net.IPv4(1, 1, 1, 1),
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Port: 443,
Protocol: constants.TCP,
},
},
"default OpenVPN UDP port": {
filteredServers: []models.Server{
{IPs: []net.IP{net.IPv4(1, 1, 1, 1)}},
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}},
},
selection: settings.ServerSelection{
OpenVPN: settings.OpenVPNSelection{
@@ -67,21 +67,21 @@ func Test_Provider_GetConnection(t *testing.T) {
}.WithDefaults(provider),
connection: models.Connection{
Type: vpn.OpenVPN,
IP: net.IPv4(1, 1, 1, 1),
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Port: 1194,
Protocol: constants.UDP,
},
},
"default Wireguard port": {
filteredServers: []models.Server{
{IPs: []net.IP{net.IPv4(1, 1, 1, 1)}, WgPubKey: "x"},
{IPs: []netip.Addr{netip.AddrFrom4([4]byte{1, 1, 1, 1})}, WgPubKey: "x"},
},
selection: settings.ServerSelection{
VPN: vpn.Wireguard,
}.WithDefaults(provider),
connection: models.Connection{
Type: vpn.Wireguard,
IP: net.IPv4(1, 1, 1, 1),
IP: netip.AddrFrom4([4]byte{1, 1, 1, 1}),
Port: 1194,
Protocol: constants.UDP,
PubKey: "x",

View File

@@ -5,8 +5,8 @@ import (
"encoding/json"
"errors"
"fmt"
"net"
"net/http"
"net/netip"
"strconv"
"time"
)
@@ -32,10 +32,10 @@ type groupData struct {
}
type serverData struct {
Hostname string `json:"hostname"`
IP net.IP `json:"ip"`
IP2 net.IP `json:"ip2"`
IP3 net.IP `json:"ip3"`
Hostname string `json:"hostname"`
IP netip.Addr `json:"ip"`
IP2 netip.Addr `json:"ip2"`
IP3 netip.Addr `json:"ip3"`
}
func fetchAPI(ctx context.Context, client *http.Client) (

View File

@@ -4,7 +4,7 @@ import (
"context"
"errors"
"fmt"
"net"
"net/netip"
"sort"
"github.com/qdm12/gluetun/internal/constants/vpn"
@@ -30,11 +30,11 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) (
x5090Name := group.OvpnX509
wgPubKey := group.WgPubKey
for _, node := range group.Nodes {
ips := make([]net.IP, 0, 2) //nolint:gomnd
if node.IP != nil {
ips := make([]netip.Addr, 0, 2) //nolint:gomnd
if node.IP.IsValid() {
ips = append(ips, node.IP)
}
if node.IP2 != nil {
if node.IP2.IsValid() {
ips = append(ips, node.IP2)
}
server := models.Server{
@@ -49,7 +49,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) (
}
servers = append(servers, server)
if node.IP3 == nil { // Wireguard + Stealth
if !node.IP3.IsValid() { // Wireguard + Stealth
continue
} else if wgPubKey == "" {
return nil, fmt.Errorf("%w: for node %s", ErrNoWireguardKey, node.Hostname)
@@ -60,7 +60,7 @@ func (u *Updater) FetchServers(ctx context.Context, minServers int) (
server.TCP = false
server.OvpnX509 = ""
server.WgPubKey = wgPubKey
server.IPs = []net.IP{node.IP3}
server.IPs = []netip.Addr{node.IP3}
servers = append(servers, server)
}
}