Skip to content

Commit

Permalink
wksp: repo notify
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Mar 2, 2025
1 parent a42f0a7 commit 7794fe1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion ndn/app/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"syscall/js"
"time"

spec_repo "github.com/named-data/ndnd/repo/tlv"
enc "github.com/named-data/ndnd/std/encoding"
"github.com/named-data/ndnd/std/log"
"github.com/named-data/ndnd/std/ndn"
Expand All @@ -20,6 +21,10 @@ import (
"github.com/pulsejet/ownly/ndn/app/tlv"
)

const SnapshotThreshold = 100

var repoName, _ = enc.NameFromStr("/ndnd/ucla/repo")

// CreateWorkspace creates a new workspace with the given name.
func (a *App) CreateWorkspace(nameStr string) (nameStrFinal string, err error) {
name, err := enc.NameFromStr(nameStr)
Expand Down Expand Up @@ -165,7 +170,7 @@ func (a *App) GetWorkspace(groupStr string) (api js.Value, err error) {

Snapshot: &ndn_sync.SnapshotNodeHistory{
Client: client,
Threshold: 100,
Threshold: SnapshotThreshold,
Compress: CompressSnapshotYjs,
},
})
Expand Down Expand Up @@ -208,6 +213,7 @@ func (a *App) SvsAloJs(client ndn.Client, alo *ndn_sync.SvsALO, persistState js.

// start(): Promise<void>;
"start": jsutil.AsyncFunc(func(this js.Value, p []js.Value) (any, error) {
// Announce prefixes to the network
for _, route := range routes {
client.AnnouncePrefix(ndn.Announcement{
Name: route,
Expand All @@ -218,6 +224,9 @@ func (a *App) SvsAloJs(client ndn.Client, alo *ndn_sync.SvsALO, persistState js.
})
}

// Notify repo to start
a.NotifyRepo(client, alo.GroupPrefix())

if err := alo.Start(); err != nil {
return nil, err
}
Expand Down Expand Up @@ -362,3 +371,36 @@ func (a *App) AwarenessJs(awareness *Awareness) (api js.Value) {
}
return js.ValueOf(awarenessJs)
}

func (a *App) NotifyRepo(client ndn.Client, group enc.Name) {
// If the face is not running, wait for it to come up
if !a.face.IsRunning() {
var cancel func()
cancel = a.face.OnUp(func() {
go a.NotifyRepo(client, group)
cancel()
})
return
}

// Notify repo to join SVS group
repoCmd := spec_repo.RepoCmd{
SyncJoin: &spec_repo.SyncJoin{
Protocol: spec_repo.SyncProtocolSvsV3,
Group: group,
HistorySnapshot: &spec_repo.HistorySnapshotConfig{
Threshold: SnapshotThreshold,
},
},
}
client.ExpressCommand(
repoName.Append(enc.NewKeywordComponent("cmd")),
repoCmd.Encode(),
func(w enc.Wire, err error) {
if err != nil {
log.Warn(nil, "Repo sync join command failed", "group", group, "err", err)
} else {
log.Info(nil, "Repo joined SVS group", "group", group)
}
})
}
Binary file modified public/main.wasm
Binary file not shown.

0 comments on commit 7794fe1

Please sign in to comment.