mirror of
https://github.com/logos-messaging/logos-messaging-go.git
synced 2026-01-04 06:53:06 +00:00
fix: use simple protocol and pubsubTopic based selection for peerExchange (#1295)
This commit is contained in:
parent
06c9af60f3
commit
84a4b1be7a
@ -96,6 +96,7 @@ type PeerSelection int
|
|||||||
const (
|
const (
|
||||||
Automatic PeerSelection = iota
|
Automatic PeerSelection = iota
|
||||||
LowestRTT
|
LowestRTT
|
||||||
|
ProtoPubSubTopicOnly //This is added to address an issue with peerExchange where on-demand discovery cannot be used.
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxFailedAttempts = 5
|
const maxFailedAttempts = 5
|
||||||
|
|||||||
@ -204,6 +204,12 @@ func (pm *PeerManager) SelectPeers(criteria PeerSelectionCriteria) (peer.IDSlice
|
|||||||
}
|
}
|
||||||
//TODO: Update this once peer Ping cache PR is merged into this code.
|
//TODO: Update this once peer Ping cache PR is merged into this code.
|
||||||
return []peer.ID{peerID}, nil
|
return []peer.ID{peerID}, nil
|
||||||
|
case ProtoPubSubTopicOnly:
|
||||||
|
peers, err := pm.SelectPeersByProto(criteria.Proto, criteria.SpecificPeers, criteria.PubsubTopics)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return peers, nil
|
||||||
default:
|
default:
|
||||||
return nil, errors.New("unknown peer selection type specified")
|
return nil, errors.New("unknown peer selection type specified")
|
||||||
}
|
}
|
||||||
@ -257,3 +263,16 @@ func (pm *PeerManager) FilterPeersByProto(specificPeers peer.IDSlice, excludePee
|
|||||||
}
|
}
|
||||||
return peers, nil
|
return peers, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (pm *PeerManager) SelectPeersByProto(protocol protocol.ID, specificPeers peer.IDSlice, pubsubTopics []string) (peer.IDSlice, error) {
|
||||||
|
var selectedPeers peer.IDSlice
|
||||||
|
selectedPeers, err := pm.FilterPeersByProto(specificPeers, nil, protocol)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
selectedPeers = pm.host.Peerstore().(wps.WakuPeerstore).PeersByPubSubTopics(pubsubTopics, selectedPeers...)
|
||||||
|
if len(selectedPeers) == 0 {
|
||||||
|
return nil, utils.ErrNoPeersAvailable
|
||||||
|
}
|
||||||
|
return selectedPeers, nil
|
||||||
|
}
|
||||||
|
|||||||
@ -53,7 +53,7 @@ func (wakuPX *WakuPeerExchange) Request(ctx context.Context, numPeers int, opts
|
|||||||
}
|
}
|
||||||
selectedPeers, err := wakuPX.pm.SelectPeers(
|
selectedPeers, err := wakuPX.pm.SelectPeers(
|
||||||
peermanager.PeerSelectionCriteria{
|
peermanager.PeerSelectionCriteria{
|
||||||
SelectionType: params.peerSelectionType,
|
SelectionType: peermanager.ProtoPubSubTopicOnly, //Overriding selection type, this is hacky but to avoid refactor
|
||||||
Proto: PeerExchangeID_v20alpha1,
|
Proto: PeerExchangeID_v20alpha1,
|
||||||
PubsubTopics: pubsubTopics,
|
PubsubTopics: pubsubTopics,
|
||||||
SpecificPeers: params.preferredPeers,
|
SpecificPeers: params.preferredPeers,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user