Skip to content

Commit

Permalink
don't spawn a goroutine for scheduling connections
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Dec 6, 2019
1 parent 2f558ba commit 7da9c75
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions gossipsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ var (
// number of active connection attempts for peers obtained through px
GossipSubConnectors = 16

// maximum number of pending connections for peers attempted through px
GossipSubMaxPendingConnections = 1024

// timeout for connection attempts
GossipSubConnectionTimeout = 30 * time.Second
)
Expand All @@ -61,7 +64,7 @@ func NewGossipSub(ctx context.Context, h host.Host, opts ...Option) (*PubSub, er
gossip: make(map[peer.ID][]*pb.ControlIHave),
control: make(map[peer.ID]*pb.ControlMessage),
backoff: make(map[string]map[peer.ID]time.Time),
connect: make(chan connectInfo, GossipSubConnectors),
connect: make(chan connectInfo, GossipSubMaxPendingConnections),
mcache: NewMessageCache(GossipSubHistoryGossip, GossipSubHistoryLength),
}
return NewPubSub(ctx, h, rt, opts...)
Expand Down Expand Up @@ -323,16 +326,14 @@ func (gs *GossipSubRouter) pxConnect(peers []*pb.PeerInfo) {
return
}

// initiate connections, without blocking the event loop
go func() {
for _, ci := range toconnect {
select {
case gs.connect <- ci:
case <-gs.p.ctx.Done():
return
}
for _, ci := range toconnect {
select {
case gs.connect <- ci:
default:
log.Debugf("ignoring peer connection attempt; too many pending connections")
break
}
}()
}
}

func (gs *GossipSubRouter) connector() {
Expand Down

0 comments on commit 7da9c75

Please sign in to comment.