Merge pull request #556 from rade/do_not_duplicate_router_config

LGTM
This commit is contained in:
Bryan Boreham committed 2015-04-14 12:58:05 +01:00
commit d334b903e4
3 files changed
+16 -29

No files matched your search

+3 -2
View File
@@ -245,8 +245,9 @@ func (peer *LocalPeer) broadcastPeerUpdate(peers ...*Peer) {
}
func (peer *LocalPeer) checkConnectionLimit() error {
if 0 != peer.router.ConnLimit && peer.ConnectionCount() >= peer.router.ConnLimit {
return fmt.Errorf("Connection limit reached (%v)", peer.router.ConnLimit)
limit := peer.router.ConnLimit
if 0 != limit && peer.ConnectionCount() >= limit {
return fmt.Errorf("Connection limit reached (%v)", limit)
}
return nil
}
+4 -18
View File
@@ -22,8 +22,6 @@ type LogFrameFunc func(string, []byte, *layers.Ethernet)
type RouterConfig struct {
Port int
Iface *net.Interface
Name PeerName
NickName string
Password []byte
ConnLimit int
BufSz int
@@ -31,8 +29,7 @@ type RouterConfig struct {
}
type Router struct {
Port int
Iface *net.Interface
RouterConfig
Ourself *LocalPeer
Macs *MacCache
Peers *Peers
@@ -41,10 +38,6 @@ type Router struct {
GossipChannels map[uint32]*GossipChannel
TopologyGossip Gossip
UDPListener *net.UDPConn
Password []byte
ConnLimit int
BufSz int
LogFrame LogFrameFunc
}
type PacketSource interface {
@@ -60,15 +53,8 @@ type PacketSourceSink interface {
PacketSink
}
func NewRouter(config RouterConfig) *Router {
router := &Router{
Port: config.Port,
Iface: config.Iface,
GossipChannels: make(map[uint32]*GossipChannel),
Password: config.Password,
ConnLimit: config.ConnLimit,
BufSz: config.BufSz,
LogFrame: config.LogFrame}
func NewRouter(config RouterConfig, name PeerName, nickName string) *Router {
router := &Router{RouterConfig: config, GossipChannels: make(map[uint32]*GossipChannel)}
onMacExpiry := func(mac net.HardwareAddr, peer *Peer) {
log.Println("Expired MAC", mac, "at", peer.FullName())
}
@@ -76,7 +62,7 @@ func NewRouter(config RouterConfig) *Router {
router.Macs.Delete(peer)
log.Println("Removed unreachable peer", peer.FullName())
}
router.Ourself = NewLocalPeer(config.Name, config.NickName, router)
router.Ourself = NewLocalPeer(name, nickName, router)
router.Macs = NewMacCache(macMaxAge, onMacExpiry)
router.Peers = NewPeers(router.Ourself.Peer, onPeerGC)
router.Peers.FetchWithDefault(router.Ourself.Peer)
+9 -9
View File
@@ -39,6 +39,7 @@ func main() {
justVersion bool
ifaceName string
routerName string
nickName string
password string
wait int
debug bool
@@ -52,7 +53,7 @@ func main() {
flag.IntVar(&config.Port, "port", weave.Port, "router port")
flag.StringVar(&ifaceName, "iface", "", "name of interface to capture/inject from (disabled if blank)")
flag.StringVar(&routerName, "name", "", "name of router (defaults to MAC of interface)")
flag.StringVar(&config.NickName, "nickname", "", "nickname of peer (defaults to hostname)")
flag.StringVar(&nickName, "nickname", "", "nickname of peer (defaults to hostname)")
flag.StringVar(&password, "password", "", "network password")
flag.IntVar(&wait, "wait", 0, "number of seconds to wait for interface to be created and come up (0 = don't wait)")
flag.BoolVar(&debug, "debug", false, "enable debug logging")
@@ -86,19 +87,18 @@ func main() {
}
routerName = config.Iface.HardwareAddr.String()
}
name, err := weave.PeerNameFromUserInput(routerName)
if err != nil {
log.Fatal(err)
}
if config.NickName == "" {
config.NickName, err = os.Hostname()
if nickName == "" {
nickName, err = os.Hostname()
if err != nil {
log.Fatal(err)
}
}
config.Name, err = weave.PeerNameFromUserInput(routerName)
if err != nil {
log.Fatal(err)
}
if password == "" {
password = os.Getenv("WEAVE_PASSWORD")
}
@@ -119,7 +119,7 @@ func main() {
config.BufSz = bufSzMB * 1024 * 1024
config.LogFrame = logFrameFunc(debug)
router := weave.NewRouter(config)
router := weave.NewRouter(config, name, nickName)
log.Println("Our name is", router.Ourself.FullName())
router.Start()
initiateConnections(router, peers)