introduce '-nodiscovery' option to disable automatic peer discovery

Closes #847.
This commit is contained in:
Matthias Radestock committed 2015-06-05 15:13:48 +01:00
1 parent 5f5c0079d3
commit 8f85a07ecc
7 files changed
+40 -19

No files matched your search

+6 -2
View File
@@ -20,6 +20,7 @@ type ConnectionMaker struct {
ourself *LocalPeer
peers *Peers
port int
discovery bool
targets map[string]*Target
directPeers peerAddrs
actionChan chan<- ConnectionMakerAction
@@ -35,11 +36,12 @@ type Target struct {
type ConnectionMakerAction func() bool
func NewConnectionMaker(ourself *LocalPeer, peers *Peers, port int) *ConnectionMaker {
func NewConnectionMaker(ourself *LocalPeer, peers *Peers, port int, discovery bool) *ConnectionMaker {
return &ConnectionMaker{
ourself: ourself,
peers: peers,
port: port,
discovery: discovery,
directPeers: peerAddrs{},
targets: make(map[string]*Target)}
}
@@ -217,7 +219,9 @@ func (cm *ConnectionMaker) checkStateAndAttemptConnections() time.Duration {
// Add targets for peers that someone else is connected to, but we
// aren't
cm.addPeerTargets(ourConnectedPeers, addTarget)
if cm.discovery {
cm.addPeerTargets(ourConnectedPeers, addTarget)
}
return cm.connectToTargets(validTarget, directTarget)
}
+10 -9
View File
@@ -8,16 +8,17 @@ import (
func (router *Router) StatusJSON(version string) ([]byte, error) {
return json.Marshal(struct {
Version string
Encryption bool
Name string
NickName string
Interface string
Macs *MacCache
Peers *Peers
Routes *Routes
Version string
Encryption bool
PeerDiscovery bool
Name string
NickName string
Interface string
Macs *MacCache
Peers *Peers
Routes *Routes
ConnectionMakerStatus
}{version, router.UsingPassword(), router.Ourself.Name.String(), router.Ourself.NickName, fmt.Sprintf("%v", router.Iface), router.Macs, router.Peers, router.Routes, router.ConnectionMaker.Status()})
}{version, router.UsingPassword(), router.PeerDiscovery, router.Ourself.Name.String(), router.Ourself.NickName, fmt.Sprintf("%v", router.Iface), router.Macs, router.Peers, router.Routes, router.ConnectionMaker.Status()})
}
func (cache *MacCache) MarshalJSON() ([]byte, error) {
+9 -7
View File
@@ -29,12 +29,13 @@ const (
type LogFrameFunc func(string, []byte, *layers.Ethernet)
type Config struct {
Port int
Iface *net.Interface
Password []byte
ConnLimit int
BufSz int
LogFrame LogFrameFunc
Port int
Iface *net.Interface
Password []byte
ConnLimit int
PeerDiscovery bool
BufSz int
LogFrame LogFrameFunc
}
type Router struct {
@@ -76,7 +77,7 @@ func NewRouter(config Config, name PeerName, nickName string) *Router {
router.Peers = NewPeers(router.Ourself, onPeerGC)
router.Peers.FetchWithDefault(router.Ourself.Peer)
router.Routes = NewRoutes(router.Ourself, router.Peers)
router.ConnectionMaker = NewConnectionMaker(router.Ourself, router.Peers, router.Port)
router.ConnectionMaker = NewConnectionMaker(router.Ourself, router.Peers, router.Port, router.PeerDiscovery)
router.TopologyGossip = router.NewGossip("topology", router)
return router
}
@@ -116,6 +117,7 @@ func (router *Router) Status() string {
var buf bytes.Buffer
fmt.Fprintln(&buf, "Our name is", router.Ourself)
fmt.Fprintln(&buf, "Encryption", OnOff(router.UsingPassword()))
fmt.Fprintln(&buf, "Peer discovery", OnOff(router.PeerDiscovery))
fmt.Fprintln(&buf, "Sniffing traffic on", router.Iface)
fmt.Fprintf(&buf, "MACs:\n%s", router.Macs)
fmt.Fprintf(&buf, "Peers:\n%s", router.Peers)