Revert "Change iteration over connection decoding to abort after the first error, and let the UnknownPeersError know which peer was unknown"

This reverts commit 978d374820.
This commit is contained in:
Bryan Boreham committed 2014-09-17 13:18:33 +01:00
1 parent 4e7aa85de0
commit c8876e144f
3 files changed
+14 -17

No files matched your search

+13 -15
View File
@@ -177,22 +177,24 @@ func (cache *PeerCache) decodeUpdate(update []byte, router *Router) (newPeers ma
} }
} }
unknownPeers := false
for _, connsBuf := range decodedConns { for _, connsBuf := range decodedConns {
err = connsIterator(connsBuf, func(remoteNameByte []byte, _ string) error { connsIterator(connsBuf, func(remoteNameByte []byte, _ string) {
remoteName := PeerNameFromBin(remoteNameByte) remoteName := PeerNameFromBin(remoteNameByte)
if _, found := newPeers[remoteName]; found { if _, found := newPeers[remoteName]; found {
return nil return
} }
if _, found := cache.table[remoteName]; found { if _, found := cache.table[remoteName]; found {
return nil return
} }
// Update refers to a peer which we have no knowledge // Update refers to a peer which we have no knowledge
// of. Thus we can't apply the update. Abort. // of. Thus we can't apply the update. Abort.
return UnknownPeersError{remoteName} unknownPeers = true
}) })
if err != nil { }
break if unknownPeers {
} err = UnknownPeersError{}
return
} }
return return
} }
@@ -280,7 +282,7 @@ func decodePeerNoConns(dec *gob.Decoder) (nameByte []byte, uid uint64, version u
return return
} }
func connsIterator(input []byte, fun func([]byte, string) error) error { func connsIterator(input []byte, fun func([]byte, string)) {
buf := new(bytes.Buffer) buf := new(bytes.Buffer)
buf.Write(input) buf.Write(input)
dec := gob.NewDecoder(buf) dec := gob.NewDecoder(buf)
@@ -288,26 +290,22 @@ func connsIterator(input []byte, fun func([]byte, string) error) error {
var nameByte []byte var nameByte []byte
err := dec.Decode(&nameByte) err := dec.Decode(&nameByte)
if err == io.EOF { if err == io.EOF {
return nil return
} }
checkFatal(err) checkFatal(err)
var foundAt string var foundAt string
checkFatal(dec.Decode(&foundAt)) checkFatal(dec.Decode(&foundAt))
if err = fun(nameByte, string(foundAt)); err != nil { fun(nameByte, string(foundAt))
return err
}
} }
return nil
} }
func readConnsMap(peer *Peer, buf []byte, table map[PeerName]*Peer) map[PeerName]Connection { func readConnsMap(peer *Peer, buf []byte, table map[PeerName]*Peer) map[PeerName]Connection {
conns := make(map[PeerName]Connection) conns := make(map[PeerName]Connection)
connsIterator(buf, func(nameByte []byte, remoteTCPAddr string) error { connsIterator(buf, func(nameByte []byte, remoteTCPAddr string) {
name := PeerNameFromBin(nameByte) name := PeerNameFromBin(nameByte)
remotePeer := table[name] remotePeer := table[name]
conn := NewRemoteConnection(peer, remotePeer, remoteTCPAddr) conn := NewRemoteConnection(peer, remotePeer, remoteTCPAddr)
conns[name] = conn conns[name] = conn
return nil
}) })
return conns return conns
} }
-1
View File
@@ -123,7 +123,6 @@ type FrameTooBigError struct {
} }
type UnknownPeersError struct { type UnknownPeersError struct {
Name PeerName
} }
type NameCollisionError struct { type NameCollisionError struct {
+1 -1
View File
@@ -39,7 +39,7 @@ func (ftbe FrameTooBigError) Error() string {
} }
func (upe UnknownPeersError) Error() string { func (upe UnknownPeersError) Error() string {
return fmt.Sprint("Reference to unknown peer: ", upe.Name) return fmt.Sprint("Reference to unknown peers")
} }
func (nce NameCollisionError) Error() string { func (nce NameCollisionError) Error() string {