-
Notifications
You must be signed in to change notification settings - Fork 0
/
input_cluster_add.go
52 lines (44 loc) · 1.19 KB
/
input_cluster_add.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
package main
import (
"fmt"
"net/url"
)
const (
MinBlockSize = 1024 * 256
MaxBlockSize = 1024 * 1024
)
type ClusterAddInput struct {
HttpParams
Range
FileBufferSize int
BlockSize int
Replica int
Pin bool
}
func (i ClusterAddInput) name() string {
return "cluster_add"
}
func (i ClusterAddInput) info() string {
return fmt.Sprintf("%s_%s_bs%d_replica%d_pin-%v_%s", i.HttpParams.info(), i.Range.info(), i.BlockSize, i.Replica, i.Pin, i.Tag)
}
func (i ClusterAddInput) check() bool {
return i.HttpParams.check() && i.Range.check() && fileBufferSize > 0 && i.BlockSize >= MinBlockSize && i.BlockSize <= MaxBlockSize && i.Replica > 0
}
func (i ClusterAddInput) paramsUrl() string {
chunker := fmt.Sprintf("size-%d", i.BlockSize)
noPin := fmt.Sprintf("%t", !i.Pin)
min := fmt.Sprintf("%d", i.Replica)
max := fmt.Sprintf("%d", i.Replica)
values := url.Values{
"chunker": {chunker},
"cid-version": {"0"},
"format": {"unixfs"},
"local": {"false"},
"mode": {"recursive"},
"no-pin": {noPin},
"replication-min": {min},
"replication-max": {max},
"stream-channels": {"false"},
}
return "?" + values.Encode()
}