forked from harmony-one/harmony
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
39 lines (34 loc) · 1.11 KB
/
options.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
package requestmanager
import sttypes "github.com/harmony-one/harmony/p2p/stream/types"
// RequestOption is the additional instruction for requests.
// Currently, two options are supported:
// 1. WithHighPriority
// 2. WithBlacklist
// 3. WithWhitelist
type RequestOption func(*request)
// WithHighPriority is the request option to do request with higher priority.
// High priority requests are done first.
func WithHighPriority() RequestOption {
return func(req *request) {
req.priority = reqPriorityHigh
}
}
// WithBlacklist is the request option not to assign the request to the blacklisted
// stream ID.
func WithBlacklist(blacklist []sttypes.StreamID) RequestOption {
return func(req *request) {
for _, stid := range blacklist {
req.addBlacklistedStream(stid)
}
}
}
// WithWhitelist is the request option to restrict the request to be assigned to the
// given stream IDs.
// If a request is not with this option, all streams will be allowed.
func WithWhitelist(whitelist []sttypes.StreamID) RequestOption {
return func(req *request) {
for _, stid := range whitelist {
req.addWhiteListStream(stid)
}
}
}