github.com/koko1123/flow-go-1@v0.29.6/network/p2p/p2pbuilder/utils.go (about)

     1  package p2pbuilder
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/libp2p/go-libp2p/core/peer"
     7  
     8  	"github.com/koko1123/flow-go-1/module"
     9  	"github.com/koko1123/flow-go-1/network/p2p"
    10  )
    11  
    12  // notEjectedPeerFilter returns a PeerFilter that will return an error if the peer is unknown or ejected.
    13  func notEjectedPeerFilter(idProvider module.IdentityProvider) p2p.PeerFilter {
    14  	return func(p peer.ID) error {
    15  		if id, found := idProvider.ByPeerID(p); !found {
    16  			return fmt.Errorf("failed to get identity of unknown peer with peer id %s", p.String())
    17  		} else if id.Ejected {
    18  			return fmt.Errorf("peer %s with node id %s is ejected", p.String(), id.NodeID.String())
    19  		}
    20  
    21  		return nil
    22  	}
    23  }