~whereswaldon/sprout-go

f66714d4fe0c2d313dc505dd3d1cd7bf1ef30d72 — Chris Waldon 6 months ago 49319bf grove-child-cache
feat: worker: announce all local leaf nodes when syncing tree
3 files changed, 25 insertions(+), 3 deletions(-)

M go.mod
M go.sum
M worker.go
M go.mod => go.mod +1 -0
@@ 5,4 5,5 @@ go 1.13
require (
	git.sr.ht/~whereswaldon/forest-go v0.0.0-20200123003050-cfe3d417aa37
	github.com/fsnotify/fsnotify v1.4.7
	golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 // indirect
)

M go.sum => go.sum +2 -2
@@ 1,5 1,3 @@
git.sr.ht/~whereswaldon/forest-go v0.0.0-20200122034404-23fc212466a7 h1:T3+jC7d9jJWQPwEnuO3J2hkjXRP1CPrLaC/VjQvJBdU=
git.sr.ht/~whereswaldon/forest-go v0.0.0-20200122034404-23fc212466a7/go.mod h1:LV1LNV6Mg4ajBo2fOTk16RIaC9Oh8pB+SpgXev6kAoU=
git.sr.ht/~whereswaldon/forest-go v0.0.0-20200123003050-cfe3d417aa37 h1:B3gXGgiB1y2rTFejLyoDAY5wCxTcVwWg/vNjIz06HPU=
git.sr.ht/~whereswaldon/forest-go v0.0.0-20200123003050-cfe3d417aa37/go.mod h1:LV1LNV6Mg4ajBo2fOTk16RIaC9Oh8pB+SpgXev6kAoU=
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=


@@ 11,4 9,6 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756 h1:9nuHUbU8dRnRRfj9KjWUVrJeoexdbeMjttk6Oh1rD10=
golang.org/x/sys v0.0.0-20190626150813-e07cf5db2756/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=

M worker.go => worker.go +22 -1
@@ 9,6 9,7 @@ import (
	"time"

	"git.sr.ht/~whereswaldon/forest-go"
	"git.sr.ht/~whereswaldon/forest-go/archive"
	"git.sr.ht/~whereswaldon/forest-go/fields"
)



@@ 381,8 382,27 @@ func (c *Worker) BootstrapLocalStore(maxCommunities int) {
func (c *Worker) synchronizeFullTree(root forest.Node, maxNodes int, perRequestTimeout time.Duration) error {
	leafList, err := c.SendLeavesOf(root.ID(), maxNodes, makeTicker(perRequestTimeout))
	if err != nil {
		return fmt.Errorf("couldn't fetch leaves of node %s: %v", root.ID().String(), err)
		return fmt.Errorf("couldn't fetch leaves of node %s: %w", root.ID(), err)
	}
	c.Printf("Fetched leaves of %s", root.ID())
	archive := archive.New(c.SubscribableStore)
	localLeaves, err := archive.LeavesOf(root.ID())
	if err != nil {
		return fmt.Errorf("couldn't list local leaves of node %s: %w", root.ID(), err)
	}
	localLeafNodes := make([]forest.Node, 0, len(localLeaves))
	for i := range localLeafNodes {
		node, inStore, err := archive.Get(localLeaves[i])
		if err != nil {
			return fmt.Errorf("couldn't get local node %s: %w", localLeaves[i], err)
		} else if inStore {
			localLeafNodes = append(localLeafNodes, node)
		}
	}
	if err := c.SendAnnounce(localLeafNodes, makeTicker(perRequestTimeout)); err != nil {
		return fmt.Errorf("failed announcing available local nodes: %w", err)
	}
	c.Printf("Announced local leaves of %s to peer", root.ID())
	for _, leaf := range leafList.Nodes {
		if _, alreadyInStore, err := c.Get(leaf.ID()); err != nil {
			return fmt.Errorf("failed checking if we already have leaf node %s: %w", leaf.ID().String(), err)


@@ 409,6 429,7 @@ func (c *Worker) synchronizeFullTree(root forest.Node, maxNodes int, perRequestT
			}
		}
	}
	c.Printf("Finished synchronizing tree rooted at %s with peer", root.ID())
	return nil
}