a few more comments
Jeromy committed
Nov 3, 2014 at 03:53 UTC
c3d04570c091366a0b75a32df96daa9d923c309c
5 files changed
+23
-4
blocks/blocks.go
+3
@@ -19,6 +19,9 @@ func NewBlock(data []byte) *Block {
19
return &Block{Data: data, Multihash: u.Hash(data)}
20
}
21
22
+// NewBlockWithHash creates a new block when the hash of the data
23
+// is already known, this is used to save time in situations where
24
+// we are able to be confident that the data is correct
25
func NewBlockWithHash(data []byte, h mh.Multihash) (*Block, error) {
26
if u.Debug {
27
chk := u.Hash(data)
merkledag/merkledag.go
+7
@@ -48,6 +48,7 @@ type Link struct {
48
Node *Node
49
}
50
51
+// MakeLink creates a link to the given node
52
func MakeLink(n *Node) (*Link, error) {
53
s, err := n.Size()
54
if err != nil {
@@ -64,6 +65,7 @@ func MakeLink(n *Node) (*Link, error) {
65
}, nil
66
}
67
68
+// GetNode returns the MDAG Node that this link points to
69
func (l *Link) GetNode(serv DAGService) (*Node, error) {
70
if l.Node != nil {
71
return l.Node, nil
@@ -98,6 +100,7 @@ func (n *Node) AddNodeLinkClean(name string, that *Node) error {
100
return nil
101
}
102
103
+// Remove a link on this node by the given name
104
func (n *Node) RemoveNodeLink(name string) error {
105
for i, l := range n.Links {
106
if l.Name == name {
@@ -196,6 +199,7 @@ func (n *dagService) Add(nd *Node) (u.Key, error) {
199
return n.Blocks.AddBlock(b)
200
}
201
202
+// AddRecursive adds the given node and all child nodes to the BlockService
203
func (n *dagService) AddRecursive(nd *Node) error {
204
_, err := n.Add(nd)
205
if err != nil {
@@ -230,6 +234,7 @@ func (n *dagService) Get(k u.Key) (*Node, error) {
234
return Decoded(b.Data)
235
}
236
237
+// Remove deletes the given node and all of its children from the BlockService
238
func (n *dagService) Remove(nd *Node) error {
239
for _, l := range nd.Links {
240
if l.Node != nil {
@@ -243,6 +248,8 @@ func (n *dagService) Remove(nd *Node) error {
248
return n.Blocks.DeleteBlock(k)
249
}
250
251
+// FetchGraph asynchronously fetches all nodes that are children of the given
252
+// node, and returns a channel that may be waited upon for the fetch to complete
253
func FetchGraph(ctx context.Context, root *Node, serv DAGService) chan struct{} {
254
var wg sync.WaitGroup
255
done := make(chan struct{})
namesys/publisher.go
+1
@@ -26,6 +26,7 @@ func NewRoutingPublisher(route routing.IpfsRouting) Publisher {
26
}
27
28
// Publish implements Publisher. Accepts a keypair and a value,
29
+// and publishes it out to the routing system
30
func (p *ipnsPublisher) Publish(k ci.PrivKey, value string) error {
31
log.Debugf("namesys: Publish %s", value)
32
peer/peer.go
+1
@@ -274,6 +274,7 @@ func (p *peer) VerifyAndSetPubKey(pk ic.PubKey) error {
274
panic("invariant violated: unexpected key mismatch")
275
}
276
277
+// Updates this peer with information from another peer instance
278
func (p *peer) Update(other Peer) error {
279
if !p.ID().Equal(other.ID()) {
280
return errors.New("peer ids do not match")
pin/pin.go
+11
-4
@@ -1,9 +1,6 @@
1
package pin
2
3
import (
4
-
5
- //ds "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/datastore.go"
6
-
4
"encoding/json"
5
"errors"
6
"sync"
@@ -36,12 +33,14 @@ type Pinner interface {
33
}
34
35
// ManualPinner is for manually editing the pin structure
39
-// Use with care
36
+// Use with care! If used improperly, garbage collection
37
+// may not be successful
38
type ManualPinner interface {
39
PinWithMode(util.Key, PinMode)
40
Pinner
41
}
42
43
+// pinner implements the Pinner interface
44
type pinner struct {
45
lock sync.RWMutex
46
recursePin set.BlockSet
@@ -51,6 +50,7 @@ type pinner struct {
50
dstore ds.Datastore
51
}
52
53
+// NewPinner creates a new pinner using the given datastore as a backend
54
func NewPinner(dstore ds.Datastore, serv mdag.DAGService) Pinner {
55
56
// Load set from given datastore...
@@ -70,6 +70,7 @@ func NewPinner(dstore ds.Datastore, serv mdag.DAGService) Pinner {
70
}
71
}
72
73
+// Pin the given node, optionally recursive
74
func (p *pinner) Pin(node *mdag.Node, recurse bool) error {
75
p.lock.Lock()
76
defer p.lock.Unlock()
@@ -95,6 +96,7 @@ func (p *pinner) Pin(node *mdag.Node, recurse bool) error {
96
return nil
97
}
98
99
+// Unpin a given key with optional recursive unpinning
100
func (p *pinner) Unpin(k util.Key, recurse bool) error {
101
p.lock.Lock()
102
defer p.lock.Unlock()
@@ -158,6 +160,7 @@ func (p *pinner) pinLinks(node *mdag.Node) error {
160
return nil
161
}
162
163
+// IsPinned returns whether or not the given key is pinned
164
func (p *pinner) IsPinned(key util.Key) bool {
165
p.lock.RLock()
166
defer p.lock.RUnlock()
@@ -166,6 +169,7 @@ func (p *pinner) IsPinned(key util.Key) bool {
169
p.indirPin.HasKey(key)
170
}
171
172
+// LoadPinner loads a pinner and its keysets from the given datastore
173
func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) {
174
p := new(pinner)
175
@@ -200,6 +204,7 @@ func LoadPinner(d ds.Datastore, dserv mdag.DAGService) (Pinner, error) {
204
return p, nil
205
}
206
207
+// Flush encodes and writes pinner keysets to the datastore
208
func (p *pinner) Flush() error {
209
p.lock.RLock()
210
defer p.lock.RUnlock()
@@ -244,6 +249,8 @@ func loadSet(d ds.Datastore, k ds.Key, val interface{}) error {
249
return json.Unmarshal(bf, val)
250
}
251
252
+// PinWithMode is a method on ManualPinners, allowing the user to have fine
253
+// grained control over pin counts
254
func (p *pinner) PinWithMode(k util.Key, mode PinMode) {
255
switch mode {
256
case Recursive: