Example #1
0
func (d *gossipDiscoveryImpl) InitiateSync(peerNum int) {
	if d.toDie() {
		return
	}
	var peers2SendTo []*NetworkMember
	memReq := d.createMembershipRequest()

	d.lock.RLock()

	n := len(d.cachedMembership.Alive)
	k := peerNum
	if k > n {
		k = n
	}

	for _, i := range util.GetRandomIndices(k, n-1) {
		pulledPeer := d.cachedMembership.Alive[i].Membership
		netMember := &NetworkMember{
			Endpoint: pulledPeer.Endpoint,
			Metadata: pulledPeer.Metadata,
			PKIid:    pulledPeer.PkiID,
		}
		peers2SendTo = append(peers2SendTo, netMember)
	}

	d.lock.RUnlock()

	for _, netMember := range peers2SendTo {
		d.comm.SendToPeer(netMember, memReq)
	}
}
Example #2
0
func SelectEndpoints(k int, peerPool []discovery.NetworkMember) []*comm.RemotePeer {
	if len(peerPool) < k {
		k = len(peerPool)
	}

	indices := util.GetRandomIndices(k, len(peerPool)-1)
	endpoints := make([]*comm.RemotePeer, len(indices))
	for i, j := range indices {
		endpoints[i] = &comm.RemotePeer{Endpoint: peerPool[j].Endpoint, PKIID: peerPool[j].PKIid}
	}
	return endpoints
}