Merge pull request #748 from dpw/gossip-channel-names

Make gossip use channel names on the wire, not channel name hashes

Closes #745.
This commit is contained in:
Matthias Radestock committed 2015-05-27 13:03:05 +01:00
commit cfbd9dc310
3 files changed
+13 -14

No files matched your search

+10 -11
View File
@@ -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)
+1 -1
View File
@@ -2,7 +2,7 @@ package router
const (
Protocol = "weave"
ProtocolVersion = 17
ProtocolVersion = 18
)
type ProtocolTag byte
+2 -2
View File
@@ -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)
}