diff --git a/router/gossip.go b/router/gossip.go index 17201143..4a2b18a2 100644 --- a/router/gossip.go +++ b/router/gossip.go @@ -85,23 +85,22 @@ type GossipChannel struct { ourself *LocalPeer routes *Routes name string - hash uint32 gossiper Gossiper senders connectionSenders broadcasters peerSenders } +type GossipChannels map[string]*GossipChannel + func (router *Router) NewGossip(channelName string, g Gossiper) Gossip { - channelHash := hash(channelName) channel := &GossipChannel{ ourself: router.Ourself, routes: router.Routes, name: channelName, - hash: channelHash, gossiper: g, senders: make(connectionSenders), broadcasters: make(peerSenders)} - router.GossipChannels[channelHash] = channel + router.GossipChannels[channelName] = channel return channel } @@ -123,13 +122,13 @@ func (router *Router) SendAllGossipDown(conn Connection) { func (router *Router) handleGossip(tag ProtocolTag, payload []byte) error { decoder := gob.NewDecoder(bytes.NewReader(payload)) - var channelHash uint32 - if err := decoder.Decode(&channelHash); err != nil { + var channelName string + if err := decoder.Decode(&channelName); err != nil { return err } - channel, found := router.GossipChannels[channelHash] + channel, found := router.GossipChannels[channelName] if !found { - return fmt.Errorf("[gossip] received unknown channel with hash %v", channelHash) + return fmt.Errorf("[gossip] received unknown channel with name %s", channelName) } var srcName PeerName if err := decoder.Decode(&srcName); err != nil { @@ -235,7 +234,7 @@ func (c *GossipChannel) sendDown(conn Connection, data GossipData) { sender, found := c.senders[conn] if !found { sender = NewGossipSender(func(pending GossipData) { - protocolMsg := ProtocolMsg{ProtocolGossip, GobEncode(c.hash, c.ourself.Name, pending.Encode())} + protocolMsg := ProtocolMsg{ProtocolGossip, GobEncode(c.name, c.ourself.Name, pending.Encode())} conn.(ProtocolSender).SendProtocolMsg(protocolMsg) }) c.senders[conn] = sender @@ -245,7 +244,7 @@ func (c *GossipChannel) sendDown(conn Connection, data GossipData) { } func (c *GossipChannel) GossipUnicast(dstPeerName PeerName, msg []byte) error { - return c.relayUnicast(dstPeerName, GobEncode(c.hash, c.ourself.Name, dstPeerName, msg)) + return c.relayUnicast(dstPeerName, GobEncode(c.name, c.ourself.Name, dstPeerName, msg)) } func (c *GossipChannel) GossipBroadcast(update GossipData) error { @@ -302,7 +301,7 @@ func (c *GossipChannel) sendBroadcast(srcName PeerName, update GossipData) { if len(nextHops) == 0 { return } - protocolMsg := ProtocolMsg{ProtocolGossipBroadcast, GobEncode(c.hash, srcName, update.Encode())} + protocolMsg := ProtocolMsg{ProtocolGossipBroadcast, GobEncode(c.name, srcName, update.Encode())} // FIXME a single blocked connection can stall us for _, conn := range c.ourself.ConnectionsTo(nextHops) { conn.(ProtocolSender).SendProtocolMsg(protocolMsg) diff --git a/router/protocol.go b/router/protocol.go index 34373c47..5e9c7036 100644 --- a/router/protocol.go +++ b/router/protocol.go @@ -2,7 +2,7 @@ package router const ( Protocol = "weave" - ProtocolVersion = 17 + ProtocolVersion = 18 ) type ProtocolTag byte diff --git a/router/router.go b/router/router.go index 753853fc..0c467944 100644 --- a/router/router.go +++ b/router/router.go @@ -35,7 +35,7 @@ type Router struct { Peers *Peers Routes *Routes ConnectionMaker *ConnectionMaker - GossipChannels map[uint32]*GossipChannel + GossipChannels GossipChannels TopologyGossip Gossip UDPListener *net.UDPConn } @@ -54,7 +54,7 @@ type PacketSourceSink interface { } func NewRouter(config RouterConfig, name PeerName, nickName string) *Router { - router := &Router{RouterConfig: config, GossipChannels: make(map[uint32]*GossipChannel)} + router := &Router{RouterConfig: config, GossipChannels: make(GossipChannels)} onMacExpiry := func(mac net.HardwareAddr, peer *Peer) { log.Println("Expired MAC", mac, "at", peer) }