commit
d334b903e4
3 files changed
+16
-29
No files matched your search
@@ -245,8 +245,9 @@ func (peer *LocalPeer) broadcastPeerUpdate(peers ...*Peer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (peer *LocalPeer) checkConnectionLimit() error {
|
func (peer *LocalPeer) checkConnectionLimit() error {
|
||||||
if 0 != peer.router.ConnLimit && peer.ConnectionCount() >= peer.router.ConnLimit {
|
limit := peer.router.ConnLimit
|
||||||
return fmt.Errorf("Connection limit reached (%v)", peer.router.ConnLimit)
|
if 0 != limit && peer.ConnectionCount() >= limit {
|
||||||
|
return fmt.Errorf("Connection limit reached (%v)", limit)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
+4
-18
@@ -22,8 +22,6 @@ type LogFrameFunc func(string, []byte, *layers.Ethernet)
|
|||||||
type RouterConfig struct {
|
type RouterConfig struct {
|
||||||
Port int
|
Port int
|
||||||
Iface *net.Interface
|
Iface *net.Interface
|
||||||
Name PeerName
|
|
||||||
NickName string
|
|
||||||
Password []byte
|
Password []byte
|
||||||
ConnLimit int
|
ConnLimit int
|
||||||
BufSz int
|
BufSz int
|
||||||
@@ -31,8 +29,7 @@ type RouterConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Router struct {
|
type Router struct {
|
||||||
Port int
|
RouterConfig
|
||||||
Iface *net.Interface
|
|
||||||
Ourself *LocalPeer
|
Ourself *LocalPeer
|
||||||
Macs *MacCache
|
Macs *MacCache
|
||||||
Peers *Peers
|
Peers *Peers
|
||||||
@@ -41,10 +38,6 @@ type Router struct {
|
|||||||
GossipChannels map[uint32]*GossipChannel
|
GossipChannels map[uint32]*GossipChannel
|
||||||
TopologyGossip Gossip
|
TopologyGossip Gossip
|
||||||
UDPListener *net.UDPConn
|
UDPListener *net.UDPConn
|
||||||
Password []byte
|
|
||||||
ConnLimit int
|
|
||||||
BufSz int
|
|
||||||
LogFrame LogFrameFunc
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type PacketSource interface {
|
type PacketSource interface {
|
||||||
@@ -60,15 +53,8 @@ type PacketSourceSink interface {
|
|||||||
PacketSink
|
PacketSink
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewRouter(config RouterConfig) *Router {
|
func NewRouter(config RouterConfig, name PeerName, nickName string) *Router {
|
||||||
router := &Router{
|
router := &Router{RouterConfig: config, GossipChannels: make(map[uint32]*GossipChannel)}
|
||||||
Port: config.Port,
|
|
||||||
Iface: config.Iface,
|
|
||||||
GossipChannels: make(map[uint32]*GossipChannel),
|
|
||||||
Password: config.Password,
|
|
||||||
ConnLimit: config.ConnLimit,
|
|
||||||
BufSz: config.BufSz,
|
|
||||||
LogFrame: config.LogFrame}
|
|
||||||
onMacExpiry := func(mac net.HardwareAddr, peer *Peer) {
|
onMacExpiry := func(mac net.HardwareAddr, peer *Peer) {
|
||||||
log.Println("Expired MAC", mac, "at", peer.FullName())
|
log.Println("Expired MAC", mac, "at", peer.FullName())
|
||||||
}
|
}
|
||||||
@@ -76,7 +62,7 @@ func NewRouter(config RouterConfig) *Router {
|
|||||||
router.Macs.Delete(peer)
|
router.Macs.Delete(peer)
|
||||||
log.Println("Removed unreachable peer", peer.FullName())
|
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.Macs = NewMacCache(macMaxAge, onMacExpiry)
|
||||||
router.Peers = NewPeers(router.Ourself.Peer, onPeerGC)
|
router.Peers = NewPeers(router.Ourself.Peer, onPeerGC)
|
||||||
router.Peers.FetchWithDefault(router.Ourself.Peer)
|
router.Peers.FetchWithDefault(router.Ourself.Peer)
|
||||||
|
|||||||
+9
-9
@@ -39,6 +39,7 @@ func main() {
|
|||||||
justVersion bool
|
justVersion bool
|
||||||
ifaceName string
|
ifaceName string
|
||||||
routerName string
|
routerName string
|
||||||
|
nickName string
|
||||||
password string
|
password string
|
||||||
wait int
|
wait int
|
||||||
debug bool
|
debug bool
|
||||||
@@ -52,7 +53,7 @@ func main() {
|
|||||||
flag.IntVar(&config.Port, "port", weave.Port, "router port")
|
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(&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(&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.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.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")
|
flag.BoolVar(&debug, "debug", false, "enable debug logging")
|
||||||
@@ -86,19 +87,18 @@ func main() {
|
|||||||
}
|
}
|
||||||
routerName = config.Iface.HardwareAddr.String()
|
routerName = config.Iface.HardwareAddr.String()
|
||||||
}
|
}
|
||||||
|
name, err := weave.PeerNameFromUserInput(routerName)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
if config.NickName == "" {
|
if nickName == "" {
|
||||||
config.NickName, err = os.Hostname()
|
nickName, err = os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
config.Name, err = weave.PeerNameFromUserInput(routerName)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if password == "" {
|
if password == "" {
|
||||||
password = os.Getenv("WEAVE_PASSWORD")
|
password = os.Getenv("WEAVE_PASSWORD")
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ func main() {
|
|||||||
config.BufSz = bufSzMB * 1024 * 1024
|
config.BufSz = bufSzMB * 1024 * 1024
|
||||||
config.LogFrame = logFrameFunc(debug)
|
config.LogFrame = logFrameFunc(debug)
|
||||||
|
|
||||||
router := weave.NewRouter(config)
|
router := weave.NewRouter(config, name, nickName)
|
||||||
log.Println("Our name is", router.Ourself.FullName())
|
log.Println("Our name is", router.Ourself.FullName())
|
||||||
router.Start()
|
router.Start()
|
||||||
initiateConnections(router, peers)
|
initiateConnections(router, peers)
|
||||||
|
|||||||
Reference in new issue
Block a user