From e51398525ab5c4a7e5e24479ecb6dbe3e3f3aa95 Mon Sep 17 00:00:00 2001 From: Jeromy Date: Tue, 16 Aug 2016 17:35:52 -0700 Subject: [PATCH] host: pre-seed preferred protocols with info from identify --- p2p/host/basic/basic_host.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/p2p/host/basic/basic_host.go b/p2p/host/basic/basic_host.go index 186094c..67a6125 100644 --- a/p2p/host/basic/basic_host.go +++ b/p2p/host/basic/basic_host.go @@ -207,7 +207,17 @@ func (h *BasicHost) preferredProtocol(p peer.ID, pids []protocol.ID) protocol.ID prefs, ok := h.protoPrefs[p] if !ok { - return "" + supported, err := h.Peerstore().GetProtocols(p) + if err != nil { + log.Warningf("error getting protocol for peer %s: %s", p, err) + return "" + } + + prefs = make(map[protocol.ID]struct{}) + for _, proto := range supported { + prefs[protocol.ID(proto)] = struct{}{} + } + h.protoPrefs[p] = prefs } for _, pid := range pids { -- GitLab