Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don't return nil multiaddrs from dht messages #2710

Merged
merged 1 commit into from
May 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions routing/dht/pb/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,15 @@ func (m *Message_Peer) Addresses() []ma.Multiaddr {
return nil
}

var err error
maddrs := make([]ma.Multiaddr, len(m.Addrs))
for i, addr := range m.Addrs {
maddrs[i], err = ma.NewMultiaddrBytes(addr)
maddrs := make([]ma.Multiaddr, 0, len(m.Addrs))
for _, addr := range m.Addrs {
maddr, err := ma.NewMultiaddrBytes(addr)
if err != nil {
log.Debugf("error decoding Multiaddr for peer: %s", m.GetId())
log.Warningf("error decoding Multiaddr for peer: %s", m.GetId())
continue
}

maddrs = append(maddrs, maddr)
}
return maddrs
}
Expand Down
15 changes: 15 additions & 0 deletions routing/dht/pb/message_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package dht_pb

import (
"testing"
)

func TestBadAddrsDontReturnNil(t *testing.T) {
mp := new(Message_Peer)
mp.Addrs = [][]byte{[]byte("NOT A VALID MULTIADDR")}

addrs := mp.Addresses()
if len(addrs) > 0 {
t.Fatal("shouldnt have any multiaddrs")
}
}