Serve a bundle its own bound objects, streams and work queues on its pipe (issue 1966 T1)

This commit is contained in:
2026-11-03 13:34:32 +01:00
parent b8e42cf54c
commit d6c516ab44
8 changed files with 666 additions and 2 deletions
+45
View File
@@ -19,6 +19,7 @@ import (
"syscall"
"time"
"git.novox.be/novox/mesh-sdk/go/buscalls"
"golang.org/x/sys/unix"
"github.com/novox/mesh-tools/node-tools/internal/wire"
@@ -91,8 +92,26 @@ type Bus interface {
// (novox/hq ADR 0349 §14, ADR 0370 §4): its config, and its bindings' values that are not secret.
Provision(verb string, params json.RawMessage) (json.RawMessage, error)
ProvisionWatch(params json.RawMessage, deliver func(change json.RawMessage) error) (stop func(), err error)
// BusState answers a bundle's calls on its module's bus state in the new form (mesh-sdk buscalls; novox/hq ADR 0595
// §9, design 25 § 12.5): its objects, a stream's read-back and fill, a work queue's size and dead letters, and its
// ledgers, by the method the bundle asked, from its own module's bindings alone.
BusState(method string, params json.RawMessage) (json.RawMessage, error)
// BusStateWatch hands deliver each change of an objects or a ledger watch, the current ones first.
BusStateWatch(method string, params json.RawMessage, deliver func(change json.RawMessage) error) (stop func(), err error)
}
// busStateCalls are the methods of mesh-sdk buscalls a bundle asks and BusState answers.
var busStateCalls = map[string]bool{
buscalls.ObjectsPut: true, buscalls.ObjectsGet: true, buscalls.ObjectsList: true, buscalls.ObjectsDelete: true,
buscalls.ObjectsInfo: true, buscalls.StreamRead: true, buscalls.StreamFill: true, buscalls.WorkQueueSize: true,
buscalls.WorkQueueDead: true, buscalls.LedgerApply: true, buscalls.LedgerGet: true, buscalls.LedgerHistory: true,
buscalls.LedgerQuery: true, buscalls.LedgerRebuild: true, buscalls.LedgerReindex: true, buscalls.LedgerSnapshot: true,
buscalls.LedgerLag: true,
}
// busStateWatches are the watches of mesh-sdk buscalls, each with the method its changes are handed to the bundle by.
var busStateWatches = map[string]string{buscalls.ObjectsWatch: buscalls.ObjectsWatched, buscalls.LedgerWatch: buscalls.LedgerWatched}
// EventTimeout bounds how long a bundle has to handle one event before it is offered again.
var EventTimeout = 2 * time.Minute
@@ -399,7 +418,33 @@ func Start(module, entry string, env []string, mesh Bus, logf func(string, ...an
c.mu.Unlock()
}
}
case buscalls.ObjectsWatch, buscalls.LedgerWatch:
// As a state's watch: each change asked of this child in order, by the method of its
// family; the change names the watch by the id the bundle gave in its request.
var stop func()
told := busStateWatches[m.Method]
stop, err = mesh.BusStateWatch(m.Method, m.Params, func(change json.RawMessage) error {
_, err := c.ask(module, told, change, EventTimeout)
return err
})
if err == nil {
c.mu.Lock()
if c.why != nil {
c.mu.Unlock()
stop()
} else {
c.watches = append(c.watches, stop)
c.mu.Unlock()
}
}
default:
if busStateCalls[m.Method] {
var answered json.RawMessage
if answered, err = mesh.BusState(m.Method, m.Params); err == nil {
result = answered
}
break
}
if len(m.ID) > 0 {
_ = c.write(map[string]any{"jsonrpc": "2.0", "id": m.ID,
"error": map[string]any{"code": -32601, "message": "the runtime answers no " + m.Method + " from a bundle"}})