-
Notifications
You must be signed in to change notification settings - Fork 217
/
Copy pathfetcher.go
89 lines (73 loc) · 2.65 KB
/
fetcher.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package system
import (
"context"
"github.com/spacemeshos/go-spacemesh/common/types"
"github.com/spacemeshos/go-spacemesh/p2p"
)
//go:generate mockgen -typed -package=mocks -destination=./mocks/fetcher.go -source=./fetcher.go
// Fetcher is a general interface that defines a component capable of fetching data from remote peers.
type Fetcher interface {
AtxFetcher
BlockFetcher
PoetProofFetcher
BallotFetcher
ActiveSetFetcher
ProposalFetcher
TxFetcher
PeerTracker
}
// BlockFetcher defines an interface for fetching blocks from remote peers.
type BlockFetcher interface {
GetBlocks(context.Context, []types.BlockID) error
}
type GetAtxOpts struct {
LimitingOff bool
Callback func(types.ATXID, error)
}
type GetAtxOpt func(*GetAtxOpts)
// WithoutLimiting disables rate limiting when downloading ATXs.
func WithoutLimiting() GetAtxOpt {
return func(opts *GetAtxOpts) {
opts.LimitingOff = true
}
}
// WithATXCallback sets a callback function to be called after each ATX is downloaded,
// found locally or failed to download.
// The callback is guaranteed to be called exactly once for each ATX ID passed to GetAtxs.
// The callback is guaranteed not to be invoked after GetAtxs returns.
// The callback may be called concurrently from multiple goroutines.
// A non-nil error is passed in case the ATX cannot be found locally and failed to download.
func WithATXCallback(callback func(types.ATXID, error)) GetAtxOpt {
return func(opts *GetAtxOpts) {
opts.Callback = callback
}
}
// AtxFetcher defines an interface for fetching ATXs from remote peers.
type AtxFetcher interface {
GetAtxs(context.Context, []types.ATXID, ...GetAtxOpt) error
}
// TxFetcher defines an interface for fetching transactions from remote peers.
type TxFetcher interface {
GetBlockTxs(context.Context, []types.TransactionID) error
GetProposalTxs(context.Context, []types.TransactionID) error
}
// PoetProofFetcher defines an interface for fetching PoET proofs from remote peers.
type PoetProofFetcher interface {
GetPoetProof(context.Context, types.Hash32) error
}
// BallotFetcher defines an interface for fetching Ballot from remote peers.
type BallotFetcher interface {
GetBallots(context.Context, []types.BallotID) error
}
// ProposalFetcher defines an interface for fetching Proposal from remote peers.
type ProposalFetcher interface {
GetProposals(context.Context, []types.ProposalID) error
}
// ActiveSetFetcher defines an interface downloading active set.
type ActiveSetFetcher interface {
GetActiveSet(context.Context, types.Hash32) error
}
// PeerTracker defines an interface to track peer hashes.
type PeerTracker interface {
RegisterPeerHashes(peer p2p.Peer, hashes []types.Hash32)
}