forked from ipfs/go-bitswap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
79 lines (61 loc) · 1.97 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
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
package bitswap
import (
"time"
"github.com/ipfs/go-bitswap/client"
"github.com/ipfs/go-bitswap/server"
"github.com/ipfs/go-bitswap/tracer"
delay "github.com/ipfs/go-ipfs-delay"
)
type option func(*Bitswap)
// Option is interface{} of server.Option or client.Option or func(*Bitswap)
// wrapped in a struct to gain strong type checking.
type Option struct {
v interface{}
}
func EngineBlockstoreWorkerCount(count int) Option {
return Option{server.EngineBlockstoreWorkerCount(count)}
}
func EngineTaskWorkerCount(count int) Option {
return Option{server.EngineTaskWorkerCount(count)}
}
func MaxOutstandingBytesPerPeer(count int) Option {
return Option{server.MaxOutstandingBytesPerPeer(count)}
}
func TaskWorkerCount(count int) Option {
return Option{server.TaskWorkerCount(count)}
}
func ProvideEnabled(enabled bool) Option {
return Option{server.ProvideEnabled(enabled)}
}
func SetSendDontHaves(send bool) Option {
return Option{server.SetSendDontHaves(send)}
}
func WithPeerBlockRequestFilter(pbrf server.PeerBlockRequestFilter) Option {
return Option{server.WithPeerBlockRequestFilter(pbrf)}
}
func WithScoreLedger(scoreLedger server.ScoreLedger) Option {
return Option{server.WithScoreLedger(scoreLedger)}
}
func WithTargetMessageSize(tms int) Option {
return Option{server.WithTargetMessageSize(tms)}
}
func WithTaskComparator(comparator server.TaskComparator) Option {
return Option{server.WithTaskComparator(comparator)}
}
func ProviderSearchDelay(newProvSearchDelay time.Duration) Option {
return Option{client.ProviderSearchDelay(newProvSearchDelay)}
}
func RebroadcastDelay(newRebroadcastDelay delay.D) Option {
return Option{client.RebroadcastDelay(newRebroadcastDelay)}
}
func SetSimulateDontHavesOnTimeout(send bool) Option {
return Option{client.SetSimulateDontHavesOnTimeout(send)}
}
func WithTracer(tap tracer.Tracer) Option {
// Only trace the server, both receive the same messages anyway
return Option{
func(bs *Bitswap) {
bs.tracer = tap
},
}
}