Merge pull request #29 from libp2p/fix/handle-conns-async

notify: handle new connections asynchronously
This commit is contained in:
Steven Allen 2017-07-27 20:27:04 -07:00 committed by GitHub
commit 570f474bc4
4 changed files with 15 additions and 15 deletions

View File

@ -1 +1 @@
0.8.16: QmatoKaefBS5hopnDyMqZUgCjbBRPEi4ktZP5FVruiczbB
0.8.17: QmYFCNMYp7fR9p2pHDXPGtawfoAYEwrR9GLQbihkB96Krs

View File

@ -4,7 +4,7 @@ os:
language: go
go:
- 1.7
- 1.8
install: true

View File

@ -1,8 +1,6 @@
package floodsub
import (
"context"
inet "github.com/libp2p/go-libp2p-net"
ma "github.com/multiformats/go-multiaddr"
)
@ -18,17 +16,19 @@ func (p *PubSubNotif) ClosedStream(n inet.Network, s inet.Stream) {
}
func (p *PubSubNotif) Connected(n inet.Network, c inet.Conn) {
s, err := p.host.NewStream(context.Background(), c.RemotePeer(), ID)
if err != nil {
log.Warning("opening new stream to peer: ", err, c.LocalPeer(), c.RemotePeer())
return
}
go func() {
s, err := p.host.NewStream(p.ctx, c.RemotePeer(), ID)
if err != nil {
log.Warning("opening new stream to peer: ", err, c.LocalPeer(), c.RemotePeer())
return
}
select {
case p.newPeers <- s:
case <-p.ctx.Done():
s.Close()
}
select {
case p.newPeers <- s:
case <-p.ctx.Done():
s.Close()
}
}()
}
func (p *PubSubNotif) Disconnected(n inet.Network, c inet.Conn) {

View File

@ -72,6 +72,6 @@
"license": "",
"name": "floodsub",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "0.8.16"
"version": "0.8.17"
}