Skip to content

Commit 9634e2a

Browse files
committed
Merge commit 'cdd5285f16af665e5fd5d3592f53b2134281e76a' into HEAD
* commit 'cdd5285f16af665e5fd5d3592f53b2134281e76a': add cmd: clean up default logic of --progress option add cmd: use .Default(true) for pin option. Revert "Merge pull request ipfs#2657 from ipfs/feature/add-defaults-to-add" bitswap: add wantlist fullness to protobuf messages Enable parallel builds on CircleCI Fix PHONY name in Makefile Run coveralls if COVERALLS_TOKEN is set Switch unixfs.Metadata.MimeType to optional Fix bad formatting introduced by e855047 blockstore.AllKeyChan: fix/cleanup error handling blockstore.AllKeyChan: avoid channels by using the new NextSync method ulimit: handle freebsd ulimit code separately from the rest of the unixes Add test for flags. bitswap: increase wantlist resend delay to one minute ds-help: avoid unnecessary allocs when posssible and make use of RawKey fix formatting on error call "block rm": make channel large enough to avoid blocking # Conflicts: # Makefile # core/commands/add.go
2 parents a6b8abe + cdd5285 commit 9634e2a

File tree

23 files changed

+178
-105
lines changed

23 files changed

+178
-105
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*.swp
66
.ipfsconfig
77
*.out
8+
*.coverprofile
89
*.test
910
*.orig
1011
*~

Makefile

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,19 @@ IPFS_MIN_GO_VERSION = 1.7
33
IPFS_MIN_GX_VERSION = 0.6
44
IPFS_MIN_GX_GO_VERSION = 1.1
55

6-
ifeq ($(TEST_NO_FUSE),1)
7-
go_test=IPFS_REUSEPORT=false go test -tags nofuse
6+
7+
export IPFS_REUSEPORT=false
8+
9+
ifneq ($(COVERALLS_TOKEN), )
10+
covertools_rule = covertools
11+
GOT = overalls -project=github.com/ipfs/go-ipfs -covermode atomic -ignore=.git,Godeps,thirdparty,test -- $(GOTFLAGS)
812
else
9-
go_test=IPFS_REUSEPORT=false go test
13+
covertools_rule = $()
14+
GOT = go test $(GOTFLAGS) ./...
15+
endif
16+
17+
ifeq ($(TEST_NO_FUSE),1)
18+
GOTFLAGS += -tags nofuse
1019
endif
1120

1221
ifeq ($(OS),Windows_NT)
@@ -48,9 +57,14 @@ gx_check: ${gx_bin} ${gx-go_bin}
4857
path_check:
4958
@bin/check_go_path $(realpath $(shell pwd)) $(realpath $(addsuffix /src/github.com/ipfs/go-ipfs,$(subst $(GOPATH_DELIMITER), ,$(GOPATH))))
5059

51-
deps: go_check gx_check path_check
60+
deps: go_check gx_check path_check $(covertools_rule)
5261
${gx_bin} --verbose install --global
5362

63+
covertools:
64+
go get -u github.com/mattn/goveralls
65+
go get -u golang.org/x/tools/cmd/cover
66+
go get -u github.com/Kubuxu/overalls
67+
5468
# saves/vendors third-party dependencies to Godeps/_workspace
5569
# -r flag rewrites import paths to use the vendored path
5670
# ./... performs operation on all packages in tree
@@ -67,7 +81,7 @@ clean:
6781
uninstall:
6882
$(MAKE) -C cmd/ipfs uninstall
6983

70-
PHONY += all help godep gx_check
84+
PHONY += all help godep gx_check covertools
7185
PHONY += go_check deps vendor ipfs_lib install build nofuse clean uninstall
7286

7387
##############################################################
@@ -85,14 +99,14 @@ test_3node:
8599
test_go_fmt:
86100
bin/test-go-fmt
87101

88-
test_go_short:
89-
$(go_test) -test.short ./...
90102

91-
test_go_expensive:
92-
$(go_test) ./...
93-
94-
test_go_race:
95-
$(go_test) ./... -race
103+
test_go_short: GOTFLAGS += -test.short
104+
test_go_race: GOTFLAGS += -race
105+
test_go_expensive test_go_short test_go_race:
106+
$(GOT)
107+
ifneq ($(COVERALLS_TOKEN), )
108+
goveralls -coverprofile=overalls.coverprofile -service $(SERVICE)
109+
endif
96110

97111
test_sharness_short:
98112
$(MAKE) -j1 -C test/sharness/

blocks/blockstore/blockstore.go

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -181,44 +181,27 @@ func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan *cid.Cid, error)
181181
return nil, err
182182
}
183183

184-
// this function is here to compartmentalize
185-
get := func() (*cid.Cid, bool) {
186-
select {
187-
case <-ctx.Done():
188-
return nil, false
189-
case e, more := <-res.Next():
190-
if !more {
191-
return nil, false
192-
}
193-
if e.Error != nil {
194-
log.Debug("blockstore.AllKeysChan got err:", e.Error)
195-
return nil, false
196-
}
197-
198-
// need to convert to key.Key using key.KeyFromDsKey.
199-
c, err := dshelp.DsKeyStringToCid(e.Key)
200-
if err != nil {
201-
log.Warningf("error parsing key from DsKey: ", err)
202-
return nil, true
203-
}
204-
205-
return c, true
206-
}
207-
}
208-
209184
output := make(chan *cid.Cid, dsq.KeysOnlyBufSize)
210185
go func() {
211186
defer func() {
212-
res.Process().Close() // ensure exit (signals early exit, too)
187+
res.Close() // ensure exit (signals early exit, too)
213188
close(output)
214189
}()
215190

216191
for {
217-
k, ok := get()
192+
e, ok := res.NextSync()
218193
if !ok {
219194
return
220195
}
221-
if k == nil {
196+
if e.Error != nil {
197+
log.Errorf("blockstore.AllKeysChan got err:", e.Error)
198+
return
199+
}
200+
201+
// need to convert to key.Key using key.KeyFromDsKey.
202+
k, err := dshelp.DsKeyToCid(ds.RawKey(e.Key))
203+
if err != nil {
204+
log.Warningf("error parsing key from DsKey: ", err)
222205
continue
223206
}
224207

blocks/blockstore/util/remove.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ type RmBlocksOpts struct {
2727
Force bool
2828
}
2929

30-
func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid, opts RmBlocksOpts) error {
30+
func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, cids []*cid.Cid, opts RmBlocksOpts) (<-chan interface{}, error) {
31+
// make the channel large enough to hold any result to avoid
32+
// blocking while holding the GCLock
33+
out := make(chan interface{}, len(cids))
3134
go func() {
3235
defer close(out)
3336

@@ -47,7 +50,7 @@ func RmBlocks(blocks bs.GCBlockstore, pins pin.Pinner, out chan<- interface{}, c
4750
}
4851
}
4952
}()
50-
return nil
53+
return out, nil
5154
}
5255

5356
func FilterPinned(pins pin.Pinner, out chan<- interface{}, cids []*cid.Cid) []*cid.Cid {

circle.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ machine:
77
CIRCLE: 1
88
IMPORT_PATH: "github.com/ipfs/go-ipfs"
99
GOPATH: "$HOME/.go_workspace"
10+
GOBIN: "$GOPATH/bin"
11+
SERVICE: "circle-ci"
1012

1113
post:
1214
- sudo rm -rf /usr/local/go
@@ -35,5 +37,7 @@ test:
3537
override:
3638
- make test_go_expensive:
3739
pwd: "../.go_workspace/src/$IMPORT_PATH"
40+
parallel: true
3841
- make test_sharness_expensive:
3942
pwd: "../.go_workspace/src/$IMPORT_PATH"
43+
parallel: true

cmd/ipfs/ulimit.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"strconv"
6+
)
7+
8+
var ipfsFileDescNum = uint64(1024)
9+
10+
func init() {
11+
if val := os.Getenv("IPFS_FD_MAX"); val != "" {
12+
n, err := strconv.Atoi(val)
13+
if err != nil {
14+
log.Errorf("bad value for IPFS_FD_MAX: %s", err)
15+
} else {
16+
ipfsFileDescNum = uint64(n)
17+
}
18+
}
19+
}

cmd/ipfs/ulimit_freebsd.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// +build freebsd
2+
3+
package main
4+
5+
import (
6+
"fmt"
7+
"syscall"
8+
)
9+
10+
func init() {
11+
fileDescriptorCheck = checkAndSetUlimit
12+
}
13+
14+
func checkAndSetUlimit() error {
15+
var rLimit syscall.Rlimit
16+
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rLimit)
17+
if err != nil {
18+
return fmt.Errorf("error getting rlimit: %s", err)
19+
}
20+
21+
ipfsFileDescNum := int64(ipfsFileDescNum)
22+
23+
var setting bool
24+
if rLimit.Cur < ipfsFileDescNum {
25+
if rLimit.Max < ipfsFileDescNum {
26+
log.Error("adjusting max")
27+
rLimit.Max = ipfsFileDescNum
28+
}
29+
fmt.Printf("Adjusting current ulimit to %d...\n", ipfsFileDescNum)
30+
rLimit.Cur = ipfsFileDescNum
31+
setting = true
32+
}
33+
34+
err = syscall.Setrlimit(syscall.RLIMIT_NOFILE, &rLimit)
35+
if err != nil {
36+
return fmt.Errorf("error setting ulimit: %s", err)
37+
}
38+
39+
if setting {
40+
fmt.Printf("Successfully raised file descriptor limit to %d.\n", ipfsFileDescNum)
41+
}
42+
43+
return nil
44+
}

cmd/ipfs/ulimit_unix.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
1-
// +build darwin freebsd linux netbsd openbsd
1+
// +build darwin linux netbsd openbsd
22

33
package main
44

55
import (
66
"fmt"
7-
"os"
8-
"strconv"
97
"syscall"
108
)
119

12-
var ipfsFileDescNum = uint64(1024)
13-
1410
func init() {
15-
if val := os.Getenv("IPFS_FD_MAX"); val != "" {
16-
n, err := strconv.Atoi(val)
17-
if err != nil {
18-
log.Errorf("bad value for IPFS_FD_MAX: %s", err)
19-
} else {
20-
ipfsFileDescNum = uint64(n)
21-
}
22-
}
2311
fileDescriptorCheck = checkAndSetUlimit
2412
}
2513

core/commands/add.go

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@ const (
4343

4444
var AddCmd = &cmds.Command{
4545
Helptext: cmds.HelpText{
46-
Tagline: "Add a file to ipfs.",
46+
Tagline: "Add a file or directory to ipfs.",
4747
ShortDescription: `
48-
Adds contents of <path> to ipfs. Use -r to add directories.
49-
Note that directories are added recursively, to form the ipfs
50-
MerkleDAG.
48+
Adds contents of <path> to ipfs. Use -r to add directories (recursively).
5149
`,
5250
LongDescription: `
5351
Adds contents of <path> to ipfs. Use -r to add directories.
@@ -76,23 +74,27 @@ You can now refer to the added file in a gateway, like so:
7674
},
7775
Options: []cmds.Option{
7876
cmds.OptionRecursivePath, // a builtin option that allows recursive paths (-r, --recursive)
79-
cmds.BoolOption(quietOptionName, "q", "Write minimal output.").Default(false),
80-
cmds.BoolOption(silentOptionName, "Write no output.").Default(false),
77+
cmds.BoolOption(quietOptionName, "q", "Write minimal output."),
78+
cmds.BoolOption(silentOptionName, "Write no output."),
8179
cmds.BoolOption(progressOptionName, "p", "Stream progress data."),
82-
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation.").Default(false),
83-
cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk.").Default(false),
84-
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object.").Default(false),
85-
cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add.").Default(false),
80+
cmds.BoolOption(trickleOptionName, "t", "Use trickle-dag format for dag generation."),
81+
cmds.BoolOption(onlyHashOptionName, "n", "Only chunk and hash - do not write to disk."),
82+
cmds.BoolOption(wrapOptionName, "w", "Wrap files with a directory object."),
83+
cmds.BoolOption(hiddenOptionName, "H", "Include files that are hidden. Only takes effect on recursive add."),
8684
cmds.StringOption(chunkerOptionName, "s", "Chunking algorithm to use."),
8785
cmds.BoolOption(pinOptionName, "Pin this object when adding.").Default(true),
8886
cmds.BoolOption(rawLeavesOptionName, "Use raw blocks for leaf nodes. (experimental)"),
8987
cmds.BoolOption(islibOptionName, "Is for lib").Default(false),
9088
},
9189
PreRun: func(req cmds.Request) error {
92-
if quiet, _, _ := req.Option(quietOptionName).Bool(); quiet {
90+
quiet, _, _ := req.Option(quietOptionName).Bool()
91+
silent, _, _ := req.Option(silentOptionName).Bool()
92+
93+
if quiet || silent {
9394
return nil
9495
}
9596

97+
// ipfs cli progress bar defaults to true unless quiet or silent is used
9698
_, found, _ := req.Option(progressOptionName).Bool()
9799
if !found {
98100
req.SetOption(progressOptionName, true)
@@ -280,22 +282,12 @@ You can now refer to the added file in a gateway, like so:
280282
return
281283
}
282284

283-
silent, _, err := req.Option(silentOptionName).Bool()
284-
if err != nil {
285-
res.SetError(u.ErrCast(), cmds.ErrNormal)
286-
return
287-
}
288-
289285
islib, _, err := req.Option(islibOptionName).Bool()
290286
if err != nil {
291287
res.SetError(u.ErrCast(), cmds.ErrNormal)
292288
return
293289
}
294290

295-
if !quiet && !silent {
296-
progress = true
297-
}
298-
299291
var bar *pb.ProgressBar
300292
if progress {
301293
bar = pb.New64(0).SetUnits(pb.U_BYTES)

core/commands/block.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,15 @@ It takes a list of base58 encoded multihashs to remove.
254254

255255
cids = append(cids, c)
256256
}
257-
outChan := make(chan interface{})
258-
err = util.RmBlocks(n.Blockstore, n.Pinning, outChan, cids, util.RmBlocksOpts{
257+
ch, err := util.RmBlocks(n.Blockstore, n.Pinning, cids, util.RmBlocksOpts{
259258
Quiet: quiet,
260259
Force: force,
261260
})
262261
if err != nil {
263262
res.SetError(err, cmds.ErrNormal)
264263
return
265264
}
266-
res.SetOutput((<-chan interface{})(outChan))
265+
res.SetOutput(ch)
267266
},
268267
PostRun: func(req cmds.Request, res cmds.Response) {
269268
if res.Error() != nil {

exchange/bitswap/bitswap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func init() {
5757
}
5858
}
5959

60-
var rebroadcastDelay = delay.Fixed(time.Second * 10)
60+
var rebroadcastDelay = delay.Fixed(time.Minute)
6161

6262
// New initializes a BitSwap instance that communicates over the provided
6363
// BitSwapNetwork. This function registers the returned instance as the network

exchange/bitswap/message/message.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ func (m *impl) ToProtoV0() *pb.Message {
189189
Cancel: proto.Bool(e.Cancel),
190190
})
191191
}
192+
pbm.Wantlist.Full = proto.Bool(m.full)
192193
for _, b := range m.Blocks() {
193194
pbm.Blocks = append(pbm.Blocks, b.RawData())
194195
}
@@ -205,6 +206,7 @@ func (m *impl) ToProtoV1() *pb.Message {
205206
Cancel: proto.Bool(e.Cancel),
206207
})
207208
}
209+
pbm.Wantlist.Full = proto.Bool(m.full)
208210
for _, b := range m.Blocks() {
209211
blk := &pb.Message_Block{
210212
Data: b.RawData(),

exchange/bitswap/message/message_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ func TestToNetFromNetPreservesWantList(t *testing.T) {
118118
t.Fatal(err)
119119
}
120120

121+
if !copied.Full() {
122+
t.Fatal("fullness attribute got dropped on marshal")
123+
}
124+
121125
keys := make(map[string]bool)
122126
for _, k := range copied.Wantlist() {
123127
keys[k.Cid.KeyString()] = true

exchange/bitswap/wantmanager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ func (mq *msgQueue) doWork(ctx context.Context) {
227227

228228
err = mq.openSender(ctx)
229229
if err != nil {
230-
log.Error("couldnt open sender again after SendMsg(%s) failed: %s", mq.p, err)
230+
log.Errorf("couldnt open sender again after SendMsg(%s) failed: %s", mq.p, err)
231231
// TODO(why): what do we do now?
232232
// I think the *right* answer is to probably put the message we're
233233
// trying to send back, and then return to waiting for new work or

0 commit comments

Comments
 (0)