Skip to content

Commit 67fc3da

Browse files
committed
make code-climate happier
License: MIT Signed-off-by: Steven Allen <[email protected]>
1 parent 0d12a97 commit 67fc3da

File tree

13 files changed

+56
-16
lines changed

13 files changed

+56
-16
lines changed

blockservice/blockservice.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ var log = logging.Logger("blockservice")
2222

2323
var ErrNotFound = errors.New("blockservice: key not found")
2424

25+
// BlockGetter is the common interface shared between blockservice sessions and
26+
// the blockservice.
2527
type BlockGetter interface {
2628
// GetBlock gets the requested block.
2729
GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, error)
@@ -95,12 +97,14 @@ func NewWriteThrough(bs blockstore.Blockstore, rem exchange.Interface) BlockServ
9597
}
9698
}
9799

98-
func (bs *blockService) Blockstore() blockstore.Blockstore {
99-
return bs.blockstore
100+
// Blockstore returns the blockstore behind this blockservice.
101+
func (s *blockService) Blockstore() blockstore.Blockstore {
102+
return s.blockstore
100103
}
101104

102-
func (bs *blockService) Exchange() exchange.Interface {
103-
return bs.exchange
105+
// Exchange returns the exchange behind this blockservice.
106+
func (s *blockService) Exchange() exchange.Interface {
107+
return s.exchange
104108
}
105109

106110
// NewSession creates a bitswap session that allows for controlled exchange of
@@ -286,3 +290,5 @@ func (s *Session) GetBlock(ctx context.Context, c *cid.Cid) (blocks.Block, error
286290
func (s *Session) GetBlocks(ctx context.Context, ks []*cid.Cid) <-chan blocks.Block {
287291
return getBlocks(ctx, ks, s.bs, s.ses)
288292
}
293+
294+
var _ BlockGetter = (*Session)(nil)

importer/helpers/helpers.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ func (n *UnixfsNode) SetPrefix(prefix *cid.Prefix) {
6565
n.node.SetPrefix(prefix)
6666
}
6767

68+
// NumChildren returns the number of children referenced by this UnixfsNode.
6869
func (n *UnixfsNode) NumChildren() int {
6970
return n.ufmt.NumChildren()
7071
}
7172

73+
// Set replaces this UnixfsNode with another UnixfsNode
7274
func (n *UnixfsNode) Set(other *UnixfsNode) {
7375
n.node = other.node
7476
n.raw = other.raw
@@ -78,6 +80,7 @@ func (n *UnixfsNode) Set(other *UnixfsNode) {
7880
}
7981
}
8082

83+
// GetChild gets the ith child of this node from the given DAGService.
8184
func (n *UnixfsNode) GetChild(ctx context.Context, i int, ds node.DAGService) (*UnixfsNode, error) {
8285
nd, err := n.node.Links()[i].GetNode(ctx, ds)
8386
if err != nil {
@@ -92,8 +95,8 @@ func (n *UnixfsNode) GetChild(ctx context.Context, i int, ds node.DAGService) (*
9295
return NewUnixfsNodeFromDag(pbn)
9396
}
9497

95-
// addChild will add the given UnixfsNode as a child of the receiver.
96-
// the passed in DagBuilderHelper is used to store the child node an
98+
// AddChild adds the given UnixfsNode as a child of the receiver.
99+
// The passed in DagBuilderHelper is used to store the child node an
97100
// pin it locally so it doesnt get lost
98101
func (n *UnixfsNode) AddChild(child *UnixfsNode, db *DagBuilderHelper) error {
99102
n.ufmt.AddBlockSize(child.FileSize())
@@ -115,7 +118,7 @@ func (n *UnixfsNode) AddChild(child *UnixfsNode, db *DagBuilderHelper) error {
115118
return err
116119
}
117120

118-
// Removes the child node at the given index
121+
// RemoveChild removes the child node at the given index
119122
func (n *UnixfsNode) RemoveChild(index int, dbh *DagBuilderHelper) {
120123
n.ufmt.RemoveBlockSize(index)
121124
n.node.SetLinks(append(n.node.Links()[:index], n.node.Links()[index+1:]...))
@@ -140,7 +143,7 @@ func (n *UnixfsNode) SetPosInfo(offset uint64, fullPath string, stat os.FileInfo
140143
}
141144
}
142145

143-
// getDagNode fills out the proper formatting for the unixfs node
146+
// GetDagNode fills out the proper formatting for the unixfs node
144147
// inside of a DAG node and returns the dag node
145148
func (n *UnixfsNode) GetDagNode() (node.Node, error) {
146149
nd, err := n.getBaseDagNode()

importer/importer.go

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// package importer implements utilities used to create IPFS DAGs from files
2-
// and readers
1+
// Package importer implements utilities used to create IPFS DAGs from files
2+
// and readers.
33
package importer
44

55
import (
@@ -15,8 +15,8 @@ import (
1515
node "gx/ipfs/Qme5bWv7wtjUNGsK2BNGVUFPKiuxWrsqrtvYwCLRw8YFES/go-ipld-format"
1616
)
1717

18-
// Builds a DAG from the given file, writing created blocks to disk as they are
19-
// created
18+
// BuildDagFromFile builds a DAG from the given file, writing created blocks to
19+
// disk as they are created
2020
func BuildDagFromFile(fpath string, ds node.DAGService) (node.Node, error) {
2121
stat, err := os.Lstat(fpath)
2222
if err != nil {
@@ -36,6 +36,8 @@ func BuildDagFromFile(fpath string, ds node.DAGService) (node.Node, error) {
3636
return BuildDagFromReader(ds, chunk.DefaultSplitter(f))
3737
}
3838

39+
// BuildDagFromReader builds a DAG from the chunks returned by the given chunk
40+
// splitter.
3941
func BuildDagFromReader(ds node.DAGService, spl chunk.Splitter) (node.Node, error) {
4042
dbp := h.DagBuilderParams{
4143
Dagserv: ds,
@@ -45,6 +47,7 @@ func BuildDagFromReader(ds node.DAGService, spl chunk.Splitter) (node.Node, erro
4547
return bal.BalancedLayout(dbp.New(spl))
4648
}
4749

50+
// BuildTrickleDagFromReader is similar to BuildDagFromReader but uses the trickle layout.
4851
func BuildTrickleDagFromReader(ds node.DAGService, spl chunk.Splitter) (node.Node, error) {
4952
dbp := h.DagBuilderParams{
5053
Dagserv: ds,

merkledag/node.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (n *ProtoNode) AddRawLink(name string, l *node.Link) error {
124124
return nil
125125
}
126126

127-
// Remove a link on this node by the given name
127+
// RemoveNodeLink removes a link on this node by the given name.
128128
func (n *ProtoNode) RemoveNodeLink(name string) error {
129129
n.encoded = nil
130130
good := make([]*node.Link, 0, len(n.links))
@@ -146,7 +146,7 @@ func (n *ProtoNode) RemoveNodeLink(name string) error {
146146
return nil
147147
}
148148

149-
// Return a copy of the link with given name
149+
// GetNodeLink returns a copy of the link with the given name.
150150
func (n *ProtoNode) GetNodeLink(name string) (*node.Link, error) {
151151
for _, l := range n.links {
152152
if l.Name == name {
@@ -160,6 +160,7 @@ func (n *ProtoNode) GetNodeLink(name string) (*node.Link, error) {
160160
return nil, ErrLinkNotFound
161161
}
162162

163+
// GetLinkedProtoNode returns a copy of the ProtoNode with the given name.
163164
func (n *ProtoNode) GetLinkedProtoNode(ctx context.Context, ds node.DAGService, name string) (*ProtoNode, error) {
164165
nd, err := n.GetLinkedNode(ctx, ds, name)
165166
if err != nil {
@@ -174,6 +175,7 @@ func (n *ProtoNode) GetLinkedProtoNode(ctx context.Context, ds node.DAGService,
174175
return pbnd, nil
175176
}
176177

178+
// GetLinkedNode returns a copy of the IPLD Node with the given name.
177179
func (n *ProtoNode) GetLinkedNode(ctx context.Context, ds node.DAGService, name string) (node.Node, error) {
178180
lnk, err := n.GetNodeLink(name)
179181
if err != nil {

merkledag/utils/diff.go

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (c *Change) String() string {
3737
}
3838
}
3939

40+
// ApplyChange applies the requested changes to the given node in the given dag.
4041
func ApplyChange(ctx context.Context, ds node.DAGService, nd *dag.ProtoNode, cs []*Change) (*dag.ProtoNode, error) {
4142
e := NewDagEditor(nd, ds)
4243
for _, c := range cs {

merkledag/utils/utils.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ type Editor struct {
2727
src node.DAGService
2828
}
2929

30+
// NewMemoryDagService returns a new, thread-safe in-memory DAGService.
3031
func NewMemoryDagService() node.DAGService {
3132
// build mem-datastore for editor's intermediary nodes
3233
bs := bstore.NewBlockstore(syncds.MutexWrap(ds.NewMapDatastore()))
3334
bsrv := bserv.New(bs, offline.Exchange(bs))
3435
return dag.NewDAGService(bsrv)
3536
}
3637

37-
// root is the node to be modified, source is the dagstore to pull nodes from (optional)
38+
// NewDagEditor returns an ProtoNode editor.
39+
//
40+
// * root is the node to be modified
41+
// * source is the dagstore to pull nodes from (optional)
3842
func NewDagEditor(root *dag.ProtoNode, source node.DAGService) *Editor {
3943
return &Editor{
4044
root: root,
@@ -43,17 +47,19 @@ func NewDagEditor(root *dag.ProtoNode, source node.DAGService) *Editor {
4347
}
4448
}
4549

50+
// GetNode returns the a copy of the root node being edited.
4651
func (e *Editor) GetNode() *dag.ProtoNode {
4752
return e.root.Copy().(*dag.ProtoNode)
4853
}
4954

55+
// GetDagService returns the DAGService used by this editor.
5056
func (e *Editor) GetDagService() node.DAGService {
5157
return e.tmp
5258
}
5359

5460
func addLink(ctx context.Context, ds node.DAGService, root *dag.ProtoNode, childname string, childnd node.Node) (*dag.ProtoNode, error) {
5561
if childname == "" {
56-
return nil, errors.New("cannot create link with no name!")
62+
return nil, errors.New("cannot create link with no name")
5763
}
5864

5965
// ensure that the node we are adding is in the dagservice
@@ -188,6 +194,8 @@ func (e *Editor) rmLink(ctx context.Context, root *dag.ProtoNode, path []string)
188194
return root, nil
189195
}
190196

197+
// Finalize writes the new DAG to the given DAGService and returns the modified
198+
// root node.
191199
func (e *Editor) Finalize(ctx context.Context, ds node.DAGService) (*dag.ProtoNode, error) {
192200
nd := e.GetNode()
193201
err := copyDag(ctx, nd, e.tmp, ds)

mfs/dir.go

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ type Directory struct {
4040
name string
4141
}
4242

43+
// NewDirectory constructs a new MFS directory.
44+
//
45+
// You probably don't want to call this directly. Instead, construct a new root
46+
// using NewRoot.
4347
func NewDirectory(ctx context.Context, name string, node node.Node, parent childCloser, dserv node.DAGService) (*Directory, error) {
4448
db, err := uio.NewDirectoryFromNode(dserv, node)
4549
if err != nil {

path/resolver.go

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ type Resolver struct {
4040
ResolveOnce func(ctx context.Context, ds node.DAGService, nd node.Node, names []string) (*node.Link, []string, error)
4141
}
4242

43+
// NewBasicResolver constructs a new basic resolver.
4344
func NewBasicResolver(ds node.DAGService) *Resolver {
4445
return &Resolver{
4546
DAG: ds,

tar/format.go

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ func marshalHeader(h *tar.Header) ([]byte, error) {
3434
return buf.Bytes(), nil
3535
}
3636

37+
// ImportTar imports a tar file into the given DAGService and returns the root
38+
// node.
3739
func ImportTar(ctx context.Context, r io.Reader, ds node.DAGService) (*dag.ProtoNode, error) {
3840
tr := tar.NewReader(r)
3941

unixfs/hamt/hamt.go

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type child interface {
6666
Label() string
6767
}
6868

69+
// NewHamtShard creates a new, empty HAMT shard with the given size.
6970
func NewHamtShard(dserv node.DAGService, size int) (*HamtShard, error) {
7071
ds, err := makeHamtShard(dserv, size)
7172
if err != nil {
@@ -93,6 +94,7 @@ func makeHamtShard(ds node.DAGService, size int) (*HamtShard, error) {
9394
}, nil
9495
}
9596

97+
// NewHamtFromDag creates new a HAMT shard from the given DAG.
9698
func NewHamtFromDag(dserv node.DAGService, nd node.Node) (*HamtShard, error) {
9799
pbnd, ok := nd.(*dag.ProtoNode)
98100
if !ok {

unixfs/io/dirbuilder.go

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func NewDirectory(dserv node.DAGService) *Directory {
5151
// ErrNotADir implies that the given node was not a unixfs directory
5252
var ErrNotADir = fmt.Errorf("merkledag node was not a directory or shard")
5353

54+
// NewDirectoryFromNode loads a unixfs directory from the given IPLD node and
55+
// DAGService.
5456
func NewDirectoryFromNode(dserv node.DAGService, nd node.Node) (*Directory, error) {
5557
pbnd, ok := nd.(*mdag.ProtoNode)
5658
if !ok {

unixfs/io/pbdagreader.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ type pbDagReader struct {
5050

5151
var _ DagReader = (*pbDagReader)(nil)
5252

53+
// NewPBFileReader constructs a new PBFileReader.
5354
func NewPBFileReader(ctx context.Context, n *mdag.ProtoNode, pb *ftpb.Data, serv node.DAGService) *pbDagReader {
5455
fctx, cancel := context.WithCancel(ctx)
5556
curLinks := getLinkCids(n)

unixfs/test/utils.go

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ func SizeSplitterGen(size int64) chunk.SplitterGen {
2727
}
2828
}
2929

30+
// GetDAGServ returns a mock DAGService.
3031
func GetDAGServ() node.DAGService {
3132
return mdagmock.Mock()
3233
}
@@ -51,6 +52,7 @@ func init() {
5152
UseBlake2b256.Prefix.MhLength = -1
5253
}
5354

55+
// GetNode returns a unixfs file node with the specified data.
5456
func GetNode(t testing.TB, dserv node.DAGService, data []byte, opts NodeOpts) node.Node {
5557
in := bytes.NewReader(data)
5658

@@ -69,10 +71,12 @@ func GetNode(t testing.TB, dserv node.DAGService, data []byte, opts NodeOpts) no
6971
return node
7072
}
7173

74+
// GetEmptyNode returns an empty unixfs file node.
7275
func GetEmptyNode(t testing.TB, dserv node.DAGService, opts NodeOpts) node.Node {
7376
return GetNode(t, dserv, []byte{}, opts)
7477
}
7578

79+
// GetRandomNode returns a random unixfs file node.
7680
func GetRandomNode(t testing.TB, dserv node.DAGService, size int64, opts NodeOpts) ([]byte, node.Node) {
7781
in := io.LimitReader(u.NewTimeSeededRand(), size)
7882
buf, err := ioutil.ReadAll(in)
@@ -96,6 +100,7 @@ func ArrComp(a, b []byte) error {
96100
return nil
97101
}
98102

103+
// PrintDag pretty-prints the given dag to stdout.
99104
func PrintDag(nd *mdag.ProtoNode, ds node.DAGService, indent int) {
100105
pbd, err := ft.FromBytes(nd.Data())
101106
if err != nil {

0 commit comments

Comments
 (0)