Skip to content

Commit 7c8cc68

Browse files
committed
allow p2p meshThreadInner called for relays with GossipFanout=0
1 parent 6f4e8e8 commit 7c8cc68

File tree

4 files changed

+14
-10
lines changed

4 files changed

+14
-10
lines changed

network/hybridNetwork.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@ func (n *HybridP2PNetwork) RegisterHTTPHandlerFunc(path string, handlerFunc func
188188
}
189189

190190
// RequestConnectOutgoing implements GossipNode
191-
func (n *HybridP2PNetwork) RequestConnectOutgoing(replace bool, quit <-chan struct{}) {}
191+
func (n *HybridP2PNetwork) RequestConnectOutgoing(replace bool, quit <-chan struct{}) {
192+
_ = n.runParallel(func(net GossipNode) error {
193+
net.RequestConnectOutgoing(replace, quit)
194+
return nil
195+
})
196+
}
192197

193198
// GetPeers implements GossipNode
194199
func (n *HybridP2PNetwork) GetPeers(options ...PeerOption) []Peer {

network/mesh.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,9 @@ func (c hybridRelayMeshCreator) create(opts ...meshOption) (mesher, error) {
244244
wsConnections := cfg.wsnet.meshThreadInner(targetConnCount)
245245

246246
var p2pConnections int
247-
if wsConnections < targetConnCount {
247+
if wsConnections <= targetConnCount {
248+
// note "less or equal". Even if p2pTarget is zero it makes sense to call
249+
// p2p meshThreadInner to fetch DHT peers
248250
p2pTarget := targetConnCount - wsConnections
249251
p2pConnections = cfg.p2pnet.meshThreadInner(p2pTarget)
250252

@@ -325,9 +327,6 @@ func (c noopMeshPubSubFilteredCreator) create(opts ...meshOption) (mesher, error
325327
}
326328
func (c noopMeshPubSubFilteredCreator) makeConfig(wsnet *WebsocketNetwork, p2pnet *P2PNetwork) networkConfig {
327329
return networkConfig{
328-
pubsubOpts: []p2p.PubSubOption{
329-
// p2p.DisablePubSubPeerExchange(),
330-
p2p.SetPubSubPeerFilter(p2pnet.p2pRelayPeerFilter, p2pnet.pstore),
331-
},
330+
pubsubOpts: []p2p.PubSubOption{},
332331
}
333332
}

network/p2pNetwork.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,6 @@ func (n *P2PNetwork) setup() error {
380380
return nil
381381
}
382382

383-
func (n *P2PNetwork) p2pRelayPeerFilter(checker peerstore.RoleChecker, pid peer.ID) bool {
384-
return !checker.HasRole(pid, phonebook.RelayRole)
385-
}
386-
387383
// PeerID returns this node's peer ID.
388384
func (n *P2PNetwork) PeerID() p2p.PeerID {
389385
return p2p.PeerID(n.service.ID())

node/node_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,6 +1020,10 @@ func TestNodeHybridTopology(t *testing.T) {
10201020
return node0Conn && node1Conn && node2Conn
10211021
}, 60*time.Second, 500*time.Millisecond)
10221022

1023+
// node 0 has GossipFanout=0 but we still want to run all the machinery to update phonebooks
1024+
// (it this particular case to update peerstore with DHT nodes)
1025+
nodes[0].net.RequestConnectOutgoing(false, nil)
1026+
10231027
initialRound := nodes[0].ledger.NextRound()
10241028
targetRound := initialRound + 10
10251029

0 commit comments

Comments
 (0)