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:
commit
cfbd9dc310
3 files changed
+13
-14
No files matched your search
+10
-11
@@ -85,23 +85,22 @@ type GossipChannel struct {
|
|||||||
ourself *LocalPeer
|
ourself *LocalPeer
|
||||||
routes *Routes
|
routes *Routes
|
||||||
name string
|
name string
|
||||||
hash uint32
|
|
||||||
gossiper Gossiper
|
gossiper Gossiper
|
||||||
senders connectionSenders
|
senders connectionSenders
|
||||||
broadcasters peerSenders
|
broadcasters peerSenders
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type GossipChannels map[string]*GossipChannel
|
||||||
|
|
||||||
func (router *Router) NewGossip(channelName string, g Gossiper) Gossip {
|
func (router *Router) NewGossip(channelName string, g Gossiper) Gossip {
|
||||||
channelHash := hash(channelName)
|
|
||||||
channel := &GossipChannel{
|
channel := &GossipChannel{
|
||||||
ourself: router.Ourself,
|
ourself: router.Ourself,
|
||||||
routes: router.Routes,
|
routes: router.Routes,
|
||||||
name: channelName,
|
name: channelName,
|
||||||
hash: channelHash,
|
|
||||||
gossiper: g,
|
gossiper: g,
|
||||||
senders: make(connectionSenders),
|
senders: make(connectionSenders),
|
||||||
broadcasters: make(peerSenders)}
|
broadcasters: make(peerSenders)}
|
||||||
router.GossipChannels[channelHash] = channel
|
router.GossipChannels[channelName] = channel
|
||||||
return channel
|
return channel
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,13 +122,13 @@ func (router *Router) SendAllGossipDown(conn Connection) {
|
|||||||
|
|
||||||
func (router *Router) handleGossip(tag ProtocolTag, payload []byte) error {
|
func (router *Router) handleGossip(tag ProtocolTag, payload []byte) error {
|
||||||
decoder := gob.NewDecoder(bytes.NewReader(payload))
|
decoder := gob.NewDecoder(bytes.NewReader(payload))
|
||||||
var channelHash uint32
|
var channelName string
|
||||||
if err := decoder.Decode(&channelHash); err != nil {
|
if err := decoder.Decode(&channelName); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
channel, found := router.GossipChannels[channelHash]
|
channel, found := router.GossipChannels[channelName]
|
||||||
if !found {
|
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
|
var srcName PeerName
|
||||||
if err := decoder.Decode(&srcName); err != nil {
|
if err := decoder.Decode(&srcName); err != nil {
|
||||||
@@ -235,7 +234,7 @@ func (c *GossipChannel) sendDown(conn Connection, data GossipData) {
|
|||||||
sender, found := c.senders[conn]
|
sender, found := c.senders[conn]
|
||||||
if !found {
|
if !found {
|
||||||
sender = NewGossipSender(func(pending GossipData) {
|
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)
|
conn.(ProtocolSender).SendProtocolMsg(protocolMsg)
|
||||||
})
|
})
|
||||||
c.senders[conn] = sender
|
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 {
|
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 {
|
func (c *GossipChannel) GossipBroadcast(update GossipData) error {
|
||||||
@@ -302,7 +301,7 @@ func (c *GossipChannel) sendBroadcast(srcName PeerName, update GossipData) {
|
|||||||
if len(nextHops) == 0 {
|
if len(nextHops) == 0 {
|
||||||
return
|
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
|
// FIXME a single blocked connection can stall us
|
||||||
for _, conn := range c.ourself.ConnectionsTo(nextHops) {
|
for _, conn := range c.ourself.ConnectionsTo(nextHops) {
|
||||||
conn.(ProtocolSender).SendProtocolMsg(protocolMsg)
|
conn.(ProtocolSender).SendProtocolMsg(protocolMsg)
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@ package router
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
Protocol = "weave"
|
Protocol = "weave"
|
||||||
ProtocolVersion = 17
|
ProtocolVersion = 18
|
||||||
)
|
)
|
||||||
|
|
||||||
type ProtocolTag byte
|
type ProtocolTag byte
|
||||||
|
|||||||
+2
-2
@@ -35,7 +35,7 @@ type Router struct {
|
|||||||
Peers *Peers
|
Peers *Peers
|
||||||
Routes *Routes
|
Routes *Routes
|
||||||
ConnectionMaker *ConnectionMaker
|
ConnectionMaker *ConnectionMaker
|
||||||
GossipChannels map[uint32]*GossipChannel
|
GossipChannels GossipChannels
|
||||||
TopologyGossip Gossip
|
TopologyGossip Gossip
|
||||||
UDPListener *net.UDPConn
|
UDPListener *net.UDPConn
|
||||||
}
|
}
|
||||||
@@ -54,7 +54,7 @@ type PacketSourceSink interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRouter(config RouterConfig, name PeerName, nickName string) *Router {
|
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) {
|
onMacExpiry := func(mac net.HardwareAddr, peer *Peer) {
|
||||||
log.Println("Expired MAC", mac, "at", peer)
|
log.Println("Expired MAC", mac, "at", peer)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user