p2p/nat: remove the "default" string

This commit is contained in:
pengzhen 2025-01-24 16:26:37 +08:00
parent fa76319cd0
commit ab6d1d291e
4 changed files with 21 additions and 5 deletions

View file

@ -760,7 +760,7 @@ var (
} }
NATFlag = &cli.StringFlag{ NATFlag = &cli.StringFlag{
Name: "nat", Name: "nat",
Usage: "NAT port mapping mechanism (any|none|upnp|pmp|pmp:<IP>|extip:<IP>|stun:default|stun:<IP:PORT>)", Usage: "NAT port mapping mechanism (any|none|upnp|pmp|pmp:<IP>|extip:<IP>|stun:<IP:PORT>)",
Value: "any", Value: "any",
Category: flags.NetworkingCategory, Category: flags.NetworkingCategory,
} }

View file

@ -59,7 +59,7 @@ type Interface interface {
// "upnp" uses the Universal Plug and Play protocol // "upnp" uses the Universal Plug and Play protocol
// "pmp" uses NAT-PMP with an auto-detected gateway address // "pmp" uses NAT-PMP with an auto-detected gateway address
// "pmp:192.168.0.1" uses NAT-PMP with the given gateway address // "pmp:192.168.0.1" uses NAT-PMP with the given gateway address
// "stun:default" uses stun protocol with default stun server // "stun" uses stun protocol with default stun server
// "stun:192.168.0.1:1234" uses stun protocol with stun server address 192.168.0.1:1234 // "stun:192.168.0.1:1234" uses stun protocol with stun server address 192.168.0.1:1234
func Parse(spec string) (Interface, error) { func Parse(spec string) (Interface, error) {
var ( var (

View file

@ -1,4 +1,4 @@
// Copyright 2024 The go-ethereum Authors // Copyright 2025 The go-ethereum Authors
// This file is part of the go-ethereum library. // This file is part of the go-ethereum library.
// //
// The go-ethereum library is free software: you can redistribute it and/or modify // The go-ethereum library is free software: you can redistribute it and/or modify
@ -42,7 +42,7 @@ type stun struct {
func newSTUN(serverAddr string) (Interface, error) { func newSTUN(serverAddr string) (Interface, error) {
s := new(stun) s := new(stun)
if serverAddr == "default" || serverAddr == "" { if serverAddr == "" {
s.serverList = strings.Split(stunDefaultServers, "\n") s.serverList = strings.Split(stunDefaultServers, "\n")
} else { } else {
_, err := net.ResolveUDPAddr("udp4", serverAddr) _, err := net.ResolveUDPAddr("udp4", serverAddr)

View file

@ -1,3 +1,19 @@
// Copyright 2025 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package nat package nat
import ( import (
@ -7,7 +23,7 @@ import (
) )
func TestNatStun(t *testing.T) { func TestNatStun(t *testing.T) {
nat, err := newSTUN("default") nat, err := newSTUN("")
assert.NoError(t, err) assert.NoError(t, err)
_, err = nat.ExternalIP() _, err = nat.ExternalIP()
assert.NoError(t, err) assert.NoError(t, err)