From 9f784b3c316d557e45345044a96ec5443d7941c4 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 25 Jun 2015 12:22:53 +0100 Subject: [PATCH] Report errors in unicasting gossip --- ipam/allocator.go | 4 ++-- router/gossip_channel.go | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ipam/allocator.go b/ipam/allocator.go index 8b609b96..98f36f3d 100644 --- a/ipam/allocator.go +++ b/ipam/allocator.go @@ -575,14 +575,14 @@ func (alloc *Allocator) propose() { alloc.gossip.GossipBroadcast(alloc.Gossip()) } -func (alloc *Allocator) sendSpaceRequest(dest router.PeerName, r address.Range) { +func (alloc *Allocator) sendSpaceRequest(dest router.PeerName, r address.Range) error { buf := new(bytes.Buffer) enc := gob.NewEncoder(buf) if err := enc.Encode(r); err != nil { panic(err) } msg := router.Concat([]byte{msgSpaceRequest}, buf.Bytes()) - alloc.gossip.GossipUnicast(dest, msg) + return alloc.gossip.GossipUnicast(dest, msg) } func (alloc *Allocator) sendRingUpdate(dest router.PeerName) { diff --git a/router/gossip_channel.go b/router/gossip_channel.go index da7dc0ec..bbc177db 100644 --- a/router/gossip_channel.go +++ b/router/gossip_channel.go @@ -3,6 +3,7 @@ package router import ( "bytes" "encoding/gob" + "fmt" "log" "sync" ) @@ -58,7 +59,10 @@ func (c *GossipChannel) deliverUnicast(srcName PeerName, origPayload []byte, dec return err } if c.ourself.Name != destName { - return c.relayUnicast(destName, origPayload) + c.relayUnicast(destName, origPayload) + // ignore errors in passing on data; a problem between us and destination + // is not enough reason to break the connection from the source + return nil } var payload []byte if err := dec.Decode(&payload); err != nil { @@ -160,15 +164,18 @@ func (c *GossipChannel) GossipBroadcast(update GossipData) error { return c.relayBroadcast(c.ourself.Name, update) } -func (c *GossipChannel) relayUnicast(dstPeerName PeerName, buf []byte) error { +func (c *GossipChannel) relayUnicast(dstPeerName PeerName, buf []byte) (err error) { if relayPeerName, found := c.routes.UnicastAll(dstPeerName); !found { - c.log("unknown relay destination:", dstPeerName) + err = fmt.Errorf("unknown relay destination: %s", dstPeerName) } else if conn, found := c.ourself.ConnectionTo(relayPeerName); !found { - c.log("unable to find connection to relay peer", relayPeerName) + err = fmt.Errorf("unable to find connection to relay peer %s", relayPeerName) } else { conn.(ProtocolSender).SendProtocolMsg(ProtocolMsg{ProtocolGossipUnicast, buf}) } - return nil + if err != nil { + c.log(err) + } + return err } func (c *GossipChannel) relayBroadcast(srcName PeerName, update GossipData) error {