discriminate stream errors from unsupported protocols

This commit is contained in:
vyzo 2018-12-14 00:33:30 +02:00
parent f31593e883
commit 6d2f8e649c
2 changed files with 16 additions and 1 deletions

11
comm.go
View File

@ -11,6 +11,7 @@ import (
proto "github.com/gogo/protobuf/proto"
inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer"
ms "github.com/multiformats/go-multistream"
)
// get the initial RPC containing all of our subscriptions to send to new peers
@ -58,8 +59,16 @@ func (p *PubSub) handleNewPeer(ctx context.Context, pid peer.ID, outgoing <-chan
s, err := p.host.NewStream(p.ctx, pid, p.rt.Protocols()...)
if err != nil {
log.Warning("opening new stream to peer: ", err, pid)
var ch chan peer.ID
if err == ms.ErrNotSupported {
ch = p.newPeerError
} else {
ch = p.peerDead
}
select {
case p.newPeerError <- pid:
case ch <- pid:
case <-ctx.Done():
}
return

View File

@ -71,6 +71,12 @@
"hash": "QmNiJiXwWE3kRhZrC5ej3kSjWHm337pYfhjLGSCDNKJP2s",
"name": "go-libp2p-crypto",
"version": "2.0.4"
},
{
"author": "whyrusleeping",
"hash": "QmabLh8TrJ3emfAoQk5AbqbLTbMyj7XqumMFmAFxa9epo8",
"name": "go-multistream",
"version": "0.3.9"
}
],
"gxVersion": "0.9.0",