-
Notifications
You must be signed in to change notification settings - Fork 18
/
candidatesfiltered.go
35 lines (29 loc) · 1.23 KB
/
candidatesfiltered.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package events
import (
"fmt"
"time"
"github.com/filecoin-project/lassie/pkg/types"
"github.com/ipfs/go-cid"
"github.com/multiformats/go-multicodec"
)
var (
_ types.RetrievalEvent = CandidatesFilteredEvent{}
_ EventWithCandidates = CandidatesFilteredEvent{}
_ EventWithProtocols = CandidatesFilteredEvent{}
)
type CandidatesFilteredEvent struct {
retrievalEvent
candidates []types.RetrievalCandidate
protocols []multicodec.Code
}
func (e CandidatesFilteredEvent) Code() types.EventCode { return types.CandidatesFilteredCode }
func (e CandidatesFilteredEvent) Candidates() []types.RetrievalCandidate { return e.candidates }
func (e CandidatesFilteredEvent) Protocols() []multicodec.Code { return e.protocols }
func (e CandidatesFilteredEvent) String() string {
return fmt.Sprintf("CandidatesFilteredEvent<%s, %s, %s, %d>", e.eventTime, e.retrievalId, e.rootCid, len(e.candidates))
}
func CandidatesFiltered(at time.Time, retrievalId types.RetrievalID, rootCid cid.Cid, candidates []types.RetrievalCandidate) CandidatesFilteredEvent {
c := make([]types.RetrievalCandidate, len(candidates))
copy(c, candidates)
return CandidatesFilteredEvent{retrievalEvent{at, retrievalId, rootCid}, c, collectProtocols(c)}
}