github.com/filecoin-project/lassie@v0.23.0/pkg/events/events.go (about) 1 package events 2 3 import ( 4 "github.com/filecoin-project/lassie/pkg/types" 5 "github.com/libp2p/go-libp2p/core/peer" 6 "github.com/multiformats/go-multicodec" 7 ) 8 9 // Identifier returns the peer ID of the storage provider if this retrieval was 10 // requested via peer ID, or the string "Bitswap" if this retrieval was 11 // requested via the Bitswap protocol 12 func Identifier(evt types.RetrievalEvent) string { 13 spEvent, spOk := evt.(EventWithProviderID) 14 if spOk && spEvent.ProviderId() != peer.ID("") { 15 return spEvent.ProviderId().String() 16 } 17 // we only want to return "Bitswap" if this is an event with a storage provider id using the bitswap protocol 18 protocolEvent, pOk := evt.(EventWithProtocol) 19 if spOk && pOk && protocolEvent.Protocol() == multicodec.TransportBitswap { 20 return types.BitswapIndentifier 21 } 22 return "" 23 } 24 25 func collectProtocols(candidates []types.RetrievalCandidate) []multicodec.Code { 26 allProtocols := make(map[multicodec.Code]struct{}) 27 for _, candidate := range candidates { 28 for _, protocol := range candidate.Metadata.Protocols() { 29 allProtocols[protocol] = struct{}{} 30 } 31 } 32 allProtocolsArr := make([]multicodec.Code, 0, len(allProtocols)) 33 for protocol := range allProtocols { 34 allProtocolsArr = append(allProtocolsArr, protocol) 35 } 36 return allProtocolsArr 37 }