Add option to disable listen for incoming conns.
This commit provide support for a new nolisten option which disables listening for incoming connections. It also disable listening when the --connect option is used.
This commit is contained in:
parent
58055a0b5c
commit
c9502f0932
2 changed files with 15 additions and 12 deletions
|
@ -38,6 +38,7 @@ type config struct {
|
|||
AddPeers []string `short:"a" long:"addpeer" description:"Add a peer to connect with at startup"`
|
||||
ConnectPeers []string `long:"connect" description:"Connect only to the specified peers at startup"`
|
||||
SeedPeer string `short:"s" long:"seedpeer" description:"Retrieve peer addresses from this peer and then disconnect"`
|
||||
DisableListen bool `long:"nolisten" description:"Disable listening for incoming connections -- NOTE: Listening is automatically disabled if the --connect option is used"`
|
||||
Port string `short:"p" long:"port" description:"Listen for connections on this port (default: 8333, testnet: 18333)"`
|
||||
MaxPeers int `long:"maxpeers" description:"Max number of inbound and outbound peers"`
|
||||
BanDuration time.Duration `long:"banduration" description:"How long to ban misbehaving peers. Valid time units are {s, m, h}. Minimum 1 second"`
|
||||
|
@ -258,7 +259,7 @@ func loadConfig() (*config, []string, error) {
|
|||
// Connect means no seeding or listening.
|
||||
if len(cfg.ConnectPeers) > 0 {
|
||||
cfg.DisableDNSSeed = true
|
||||
// XXX turn off server listening.
|
||||
cfg.DisableListen = true
|
||||
}
|
||||
|
||||
// The RPC server is disabled if no username or password is provided.
|
||||
|
|
|
@ -379,20 +379,22 @@ func newServer(addr string, db btcdb.Db, btcnet btcwire.BitcoinNet) (*server, er
|
|||
return nil, err
|
||||
}
|
||||
|
||||
// IPv4 listener.
|
||||
var listeners []net.Listener
|
||||
listener4, err := net.Listen("tcp4", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
listeners = append(listeners, listener4)
|
||||
if !cfg.DisableListen {
|
||||
// IPv4 listener.
|
||||
listener4, err := net.Listen("tcp4", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
listeners = append(listeners, listener4)
|
||||
|
||||
// IPv6 listener.
|
||||
listener6, err := net.Listen("tcp6", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
// IPv6 listener.
|
||||
listener6, err := net.Listen("tcp6", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
listeners = append(listeners, listener6)
|
||||
}
|
||||
listeners = append(listeners, listener6)
|
||||
|
||||
s := server{
|
||||
nonce: nonce,
|
||||
|
|
Loading…
Reference in a new issue