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

fix: don't try to marshal a nil record #943

Merged
merged 1 commit into from May 20, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 1 addition & 4 deletions p2p/protocol/identify/id.go
Expand Up @@ -428,9 +428,6 @@ func (ids *IDService) getSnapshot() *identifySnapshot {
if !ids.disableSignedPeerRecord {
if cab, ok := peerstore.GetCertifiedAddrBook(ids.Host.Peerstore()); ok {
snapshot.record = cab.GetPeerRecord(ids.Host.ID())
if snapshot.record == nil {
log.Errorf("latest peer record does not exist. identify message incomplete!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not worth a log when this occurs? seems at least debug worthy

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, maybe as a debug entry. However, it'll happen whenever we don't have addresses.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You know, I'm going to be petty. It's not worth the extra indent I'd need to handle that case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our debug logging is to verbose to be useful anyways.

}
}
}
snapshot.addrs = ids.Host.Addrs()
Expand Down Expand Up @@ -465,7 +462,7 @@ func (ids *IDService) populateMessage(
mes.ListenAddrs = append(mes.ListenAddrs, addr.Bytes())
}

if !ids.disableSignedPeerRecord {
if !ids.disableSignedPeerRecord && snapshot.record != nil {
recBytes, err := snapshot.record.Marshal()
if err != nil {
log.Errorf("error marshaling peer record: %v", err)
Expand Down
31 changes: 31 additions & 0 deletions p2p/protocol/identify/id_test.go
Expand Up @@ -686,6 +686,37 @@ func TestUserAgent(t *testing.T) {
}
}

func TestNotListening(t *testing.T) {
// Make sure we don't panic if we're not listening on any addresses.
//
// https://github.com/libp2p/go-libp2p/issues/939
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

h1, err := libp2p.New(
ctx,
libp2p.NoListenAddrs,
)
if err != nil {
t.Fatal(err)
}
defer h1.Close()

h2, err := libp2p.New(
ctx,
libp2p.ListenAddrStrings("/ip4/127.0.0.1/tcp/0"),
)
if err != nil {
t.Fatal(err)
}
defer h2.Close()

err = h1.Connect(ctx, peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()})
if err != nil {
t.Fatal(err)
}
}

func TestSendPushIfDeltaNotSupported(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
Expand Down