diff --git a/fuse/ipns/ipns_unix.go b/fuse/ipns/ipns_unix.go index b15ee11e9695bbc07849e26b5a3c07ba87f72d70..c5b31a13c705415eadec640299db19f46359827c 100644 --- a/fuse/ipns/ipns_unix.go +++ b/fuse/ipns/ipns_unix.go @@ -76,6 +76,9 @@ func CreateRoot(n *core.IpfsNode, keys []ci.PrivKey, ipfsroot string) (*Root, er nd := new(Node) nd.Ipfs = n nd.key = k + nd.repub = NewRepublisher(nd, time.Millisecond*10) + + go nd.repub.Run() pointsTo, err := n.Namesys.Resolve(name) if err != nil { @@ -185,6 +188,8 @@ func (r *Root) ReadDir(intr fs.Intr) ([]fuse.Dirent, fuse.Error) { type Node struct { nsRoot *Node + repub *Republisher + // Name really only for logging purposes name string @@ -316,16 +321,20 @@ func (n *Node) Flush(req *fuse.FlushRequest, intr fs.Intr) fuse.Error { return fuse.ENODATA } - err = n.updateTree() - if err != nil { - log.Error("updateTree failed: %s", err) - return fuse.ENODATA - } - + n.sendPublishSignal() } return nil } +func (n *Node) sendPublishSignal() { + root := n.nsRoot + if root == nil { + root = n + } + + root.repub.Publish <- struct{}{} +} + func (n *Node) updateTree() error { var root *Node if n.nsRoot != nil { @@ -387,7 +396,7 @@ func (n *Node) Mkdir(req *fuse.MkdirRequest, intr fs.Intr) (fs.Node, fuse.Error) } n.changed = true - n.updateTree() + n.sendPublishSignal() return child, nil } @@ -425,6 +434,8 @@ func (n *Node) Remove(req *fuse.RemoveRequest, intr fs.Intr) fuse.Error { log.Error("Remove: No such file.") return fuse.ENOENT } + n.changed = true + n.sendPublishSignal() return nil } @@ -471,7 +482,7 @@ func Mount(ipfs *core.IpfsNode, fpath string, ipfspath string) error { if err == nil { return } - time.Sleep(time.Millisecond * 10) + time.Sleep(time.Millisecond * 100) } ipfs.Network.Close() }() @@ -563,12 +574,13 @@ func NewRepublisher(n *Node, tout time.Duration) *Republisher { } func (np *Republisher) Run() { - for _ := range np.Publish { + for _ = range np.Publish { timer := time.After(np.Timeout) for { select { case <-timer: //Do the publish! + log.Info("Publishing Changes!") err := np.node.updateTree() if err != nil { log.Critical("updateTree error: %s", err) diff --git a/routing/dht/dht.go b/routing/dht/dht.go index 4e844ecd6f4a049e3b19af6a7df14a71e4c91a51..eccfd7e451e5d5723e81267156246314753e990f 100644 --- a/routing/dht/dht.go +++ b/routing/dht/dht.go @@ -177,8 +177,7 @@ func (dht *IpfsDHT) sendRequest(ctx context.Context, p *peer.Peer, pmes *Message start := time.Now() // Print out diagnostic - log.Debug("[peer: %s] Sent message type: '%s' [to = %s]\n", - dht.self.ID.Pretty(), + log.Debug("Sent message type: '%s' [to = %s]", Message_MessageType_name[int32(pmes.GetType())], p.ID.Pretty()) rmes, err := dht.sender.SendRequest(ctx, mes) @@ -281,7 +280,7 @@ func (dht *IpfsDHT) getValueOrPeers(ctx context.Context, p *peer.Peer, } if len(peers) > 0 { - u.DOut("getValueOrPeers: peers") + log.Debug("getValueOrPeers: peers") return nil, peers, nil } @@ -400,7 +399,7 @@ func (dht *IpfsDHT) addProviders(key u.Key, peers []*Message_Peer) []*peer.Peer for _, prov := range peers { p, err := dht.peerFromInfo(prov) if err != nil { - u.PErr("error getting peer from info: %v\n", err) + log.Error("error getting peer from info: %v", err) continue } diff --git a/routing/dht/routing.go b/routing/dht/routing.go index d1f50afb889c3ec0eb871ec67950c7f70780b418..4fa6c8c946626381dd33e5dc295545552f94fb2c 100644 --- a/routing/dht/routing.go +++ b/routing/dht/routing.go @@ -18,7 +18,7 @@ import ( // PutValue adds value corresponding to given Key. // This is the top level "Store" operation of the DHT func (dht *IpfsDHT) PutValue(ctx context.Context, key u.Key, value []byte) error { - log.Debug("PutValue %s %v", key.Pretty(), value) + log.Debug("PutValue %s", key.Pretty()) err := dht.putLocal(key, value) if err != nil { return err