cmd/peerserver: add some command line switches

This commit is contained in:
Felix Lange 2015-01-06 11:15:37 +01:00
parent 4c8c115a76
commit 36e1e5f151

@ -18,6 +18,7 @@ package main
import ( import (
"crypto/elliptic" "crypto/elliptic"
"flag"
"log" "log"
"os" "os"
@ -26,7 +27,19 @@ import (
"github.com/ethereum/go-ethereum/p2p" "github.com/ethereum/go-ethereum/p2p"
) )
var (
natType = flag.String("nat", "", "NAT traversal implementation")
pmpGateway = flag.String("gateway", "", "gateway address for NAT-PMP")
listenAddr = flag.String("addr", ":30301", "listen address")
)
func main() { func main() {
flag.Parse()
nat, err := p2p.ParseNAT(*natType, *pmpGateway)
if err != nil {
log.Fatal("invalid nat:", err)
}
logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.InfoLevel)) logger.AddLogSystem(logger.NewStdLogSystem(os.Stdout, log.LstdFlags, logger.InfoLevel))
key, _ := crypto.GenerateKey() key, _ := crypto.GenerateKey()
marshaled := elliptic.Marshal(crypto.S256(), key.PublicKey.X, key.PublicKey.Y) marshaled := elliptic.Marshal(crypto.S256(), key.PublicKey.X, key.PublicKey.Y)
@ -34,8 +47,8 @@ func main() {
srv := p2p.Server{ srv := p2p.Server{
MaxPeers: 100, MaxPeers: 100,
Identity: p2p.NewSimpleClientIdentity("Ethereum(G)", "0.1", "Peer Server Two", marshaled), Identity: p2p.NewSimpleClientIdentity("Ethereum(G)", "0.1", "Peer Server Two", marshaled),
ListenAddr: ":30301", ListenAddr: *listenAddr,
NAT: p2p.UPNP(), NAT: nat,
NoDial: true, NoDial: true,
} }
if err := srv.Start(); err != nil { if err := srv.Start(); err != nil {