Skip to content

Commit d0a2e65

Browse files
committed
cmd/ethereum, cmd/mist, eth, p2p: use package p2p/nat
This deletes the old NAT implementation.
1 parent 1543833 commit d0a2e65

9 files changed

Lines changed: 54 additions & 522 deletions

File tree

‎cmd/ethereum/flags.go‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
"github.com/ethereum/go-ethereum/crypto"
3333
"github.com/ethereum/go-ethereum/logger"
34+
"github.com/ethereum/go-ethereum/p2p/nat"
3435
"github.com/ethereum/go-ethereum/vm"
3536
)
3637

@@ -44,15 +45,14 @@ var (
4445
StartWebSockets bool
4546
RpcPort int
4647
WsPort int
47-
NatType string
48-
PMPGateway string
4948
OutboundPort string
5049
ShowGenesis bool
5150
AddPeer string
5251
MaxPeer int
5352
GenAddr bool
5453
BootNodes string
5554
NodeKey *ecdsa.PrivateKey
55+
NAT nat.Interface
5656
SecretFile string
5757
ExportDir string
5858
NonInteractive bool
@@ -127,18 +127,21 @@ func Init() {
127127
var (
128128
nodeKeyFile = flag.String("nodekey", "", "network private key file")
129129
nodeKeyHex = flag.String("nodekeyhex", "", "network private key (for testing)")
130+
natstr = flag.String("nat", "any", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)")
130131
)
131132
flag.BoolVar(&Dial, "dial", true, "dial out connections (default on)")
132133
flag.BoolVar(&SHH, "shh", true, "run whisper protocol (default on)")
133134
flag.StringVar(&OutboundPort, "port", "30303", "listening port")
134-
flag.StringVar(&NatType, "nat", "", "NAT support (UPNP|PMP) (none)")
135-
flag.StringVar(&PMPGateway, "pmp", "", "Gateway IP for NAT-PMP")
135+
136136
flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap")
137137
flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers")
138138

139139
flag.Parse()
140140

141141
var err error
142+
if NAT, err = nat.Parse(*natstr); err != nil {
143+
log.Fatalf("-nat: %v", err)
144+
}
142145
switch {
143146
case *nodeKeyFile != "" && *nodeKeyHex != "":
144147
log.Fatal("Options -nodekey and -nodekeyhex are mutually exclusive")

‎cmd/ethereum/main.go‎

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,19 @@ func main() {
6262
utils.InitConfig(VmType, ConfigFile, Datadir, "ETH")
6363

6464
ethereum, err := eth.New(&eth.Config{
65-
Name: p2p.MakeName(ClientIdentifier, Version),
66-
KeyStore: KeyStore,
67-
DataDir: Datadir,
68-
LogFile: LogFile,
69-
LogLevel: LogLevel,
70-
MaxPeers: MaxPeer,
71-
Port: OutboundPort,
72-
NATType: PMPGateway,
73-
PMPGateway: PMPGateway,
74-
KeyRing: KeyRing,
75-
Shh: SHH,
76-
Dial: Dial,
77-
BootNodes: BootNodes,
78-
NodeKey: NodeKey,
65+
Name: p2p.MakeName(ClientIdentifier, Version),
66+
KeyStore: KeyStore,
67+
DataDir: Datadir,
68+
LogFile: LogFile,
69+
LogLevel: LogLevel,
70+
MaxPeers: MaxPeer,
71+
Port: OutboundPort,
72+
NAT: NAT,
73+
KeyRing: KeyRing,
74+
Shh: SHH,
75+
Dial: Dial,
76+
BootNodes: BootNodes,
77+
NodeKey: NodeKey,
7978
})
8079

8180
if err != nil {

‎cmd/mist/flags.go‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,26 @@ import (
3434
"bitbucket.org/kardianos/osext"
3535
"github.com/ethereum/go-ethereum/crypto"
3636
"github.com/ethereum/go-ethereum/logger"
37+
"github.com/ethereum/go-ethereum/p2p/nat"
3738
"github.com/ethereum/go-ethereum/vm"
3839
)
3940

4041
var (
4142
Identifier string
4243
KeyRing string
4344
KeyStore string
44-
PMPGateway string
4545
StartRpc bool
4646
StartWebSockets bool
4747
RpcPort int
4848
WsPort int
49-
NatType string
5049
OutboundPort string
5150
ShowGenesis bool
5251
AddPeer string
5352
MaxPeer int
5453
GenAddr bool
5554
BootNodes string
5655
NodeKey *ecdsa.PrivateKey
56+
NAT nat.Interface
5757
SecretFile string
5858
ExportDir string
5959
NonInteractive bool
@@ -117,7 +117,6 @@ func Init() {
117117
flag.BoolVar(&StartWebSockets, "ws", false, "start websocket server")
118118
flag.BoolVar(&NonInteractive, "y", false, "non-interactive mode (say yes to confirmations)")
119119
flag.BoolVar(&GenAddr, "genaddr", false, "create a new priv/pub key")
120-
flag.StringVar(&NatType, "nat", "", "NAT support (UPNP|PMP) (none)")
121120
flag.StringVar(&SecretFile, "import", "", "imports the file given (hex or mnemonic formats)")
122121
flag.StringVar(&ExportDir, "export", "", "exports the session keyring to files in the directory given")
123122
flag.StringVar(&LogFile, "logfile", "", "log file (defaults to standard output)")
@@ -132,15 +131,18 @@ func Init() {
132131
var (
133132
nodeKeyFile = flag.String("nodekey", "", "network private key file")
134133
nodeKeyHex = flag.String("nodekeyhex", "", "network private key (for testing)")
134+
natstr = flag.String("nat", "any", "port mapping mechanism (any|none|upnp|pmp|extip:<IP>)")
135135
)
136136
flag.StringVar(&OutboundPort, "port", "30303", "listening port")
137-
flag.StringVar(&PMPGateway, "pmp", "", "Gateway IP for NAT-PMP")
138137
flag.StringVar(&BootNodes, "bootnodes", "", "space-separated node URLs for discovery bootstrap")
139138
flag.IntVar(&MaxPeer, "maxpeer", 30, "maximum desired peers")
140139

141140
flag.Parse()
142141

143142
var err error
143+
if NAT, err = nat.Parse(*natstr); err != nil {
144+
log.Fatalf("-nat: %v", err)
145+
}
144146
switch {
145147
case *nodeKeyFile != "" && *nodeKeyHex != "":
146148
log.Fatal("Options -nodekey and -nodekeyhex are mutually exclusive")

‎cmd/mist/main.go‎

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,18 @@ func run() error {
5252
config := utils.InitConfig(VmType, ConfigFile, Datadir, "ETH")
5353

5454
ethereum, err := eth.New(&eth.Config{
55-
Name: p2p.MakeName(ClientIdentifier, Version),
56-
KeyStore: KeyStore,
57-
DataDir: Datadir,
58-
LogFile: LogFile,
59-
LogLevel: LogLevel,
60-
MaxPeers: MaxPeer,
61-
Port: OutboundPort,
62-
NATType: NatType,
63-
PMPGateway: PMPGateway,
64-
BootNodes: BootNodes,
65-
NodeKey: NodeKey,
66-
KeyRing: KeyRing,
67-
Dial: true,
55+
Name: p2p.MakeName(ClientIdentifier, Version),
56+
KeyStore: KeyStore,
57+
DataDir: Datadir,
58+
LogFile: LogFile,
59+
LogLevel: LogLevel,
60+
MaxPeers: MaxPeer,
61+
Port: OutboundPort,
62+
NAT: NAT,
63+
BootNodes: BootNodes,
64+
NodeKey: NodeKey,
65+
KeyRing: KeyRing,
66+
Dial: true,
6867
})
6968
if err != nil {
7069
mainlogger.Fatalln(err)

‎eth/backend.go‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
ethlogger "github.com/ethereum/go-ethereum/logger"
1414
"github.com/ethereum/go-ethereum/p2p"
1515
"github.com/ethereum/go-ethereum/p2p/discover"
16+
"github.com/ethereum/go-ethereum/p2p/nat"
1617
"github.com/ethereum/go-ethereum/pow/ezp"
1718
"github.com/ethereum/go-ethereum/rpc"
1819
"github.com/ethereum/go-ethereum/whisper"
@@ -28,10 +29,8 @@ type Config struct {
2829
LogLevel int
2930
KeyRing string
3031

31-
MaxPeers int
32-
Port string
33-
NATType string
34-
PMPGateway string
32+
MaxPeers int
33+
Port string
3534

3635
// This should be a space-separated list of
3736
// discovery node URLs.
@@ -41,6 +40,7 @@ type Config struct {
4140
// If nil, an ephemeral key is used.
4241
NodeKey *ecdsa.PrivateKey
4342

43+
NAT nat.Interface
4444
Shh bool
4545
Dial bool
4646

@@ -147,10 +147,6 @@ func New(config *Config) (*Ethereum, error) {
147147

148148
ethProto := EthProtocol(eth.txPool, eth.chainManager, eth.blockPool)
149149
protocols := []p2p.Protocol{ethProto, eth.whisper.Protocol()}
150-
nat, err := p2p.ParseNAT(config.NATType, config.PMPGateway)
151-
if err != nil {
152-
return nil, err
153-
}
154150
netprv := config.NodeKey
155151
if netprv == nil {
156152
if netprv, err = crypto.GenerateKey(); err != nil {
@@ -163,7 +159,7 @@ func New(config *Config) (*Ethereum, error) {
163159
MaxPeers: config.MaxPeers,
164160
Protocols: protocols,
165161
Blacklist: eth.blacklist,
166-
NAT: nat,
162+
NAT: config.NAT,
167163
NoDial: !config.Dial,
168164
BootstrapNodes: config.parseBootNodes(),
169165
}

‎p2p/nat.go‎

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎p2p/natpmp.go‎

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)