F-parts: distribution and gitea bind mesh-sdk's idle key and binding cap instead of their own copies
Both holders carried the same idle bound and the same read of incoming's cap; the second instance of the kind moved into mesh-sdk's Receiver (Arm, Expired, Bound, with BusArm, BusCap and FollowIdle). Each holder now hands its idle state and its objects to those, and keeps its rows. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
@@ -10,11 +10,9 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/busstate"
|
||||
"git.novox.be/novox/mesh-sdk/go/parts"
|
||||
|
||||
"gitea/internal/packageseats"
|
||||
)
|
||||
@@ -53,53 +51,19 @@ func incomingTool(typ, seat string, holder func() (*packageseats.Holder, error))
|
||||
}
|
||||
}
|
||||
|
||||
// incomingCap reads incoming's cap from its binding (the bus's bound of the object store), once it answers one.
|
||||
func incomingCap() func() (uint64, error) {
|
||||
var known atomic.Uint64
|
||||
return func() (uint64, error) {
|
||||
if c := known.Load(); c > 0 {
|
||||
return c, nil
|
||||
}
|
||||
f, err := busstate.ObjectsOf(packageseats.IncomingObjects).Fill()
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("incoming's cap cannot be read from its binding: %w", err)
|
||||
}
|
||||
if f.MaxBytes == 0 {
|
||||
return 0, errors.New("incoming's binding carries no cap")
|
||||
}
|
||||
known.Store(f.MaxBytes)
|
||||
return f.MaxBytes, nil
|
||||
}
|
||||
}
|
||||
|
||||
// armIdle writes a transfer's idle key with its own time to live; one already there is the same bound, kept.
|
||||
func armIdle(key string, ttl time.Duration) error {
|
||||
if _, err := stdio.State(packageseats.IdleState).CreateTTL(key, map[string]any{"transfer": key}, ttl); err != nil && !errors.Is(err, stdio.ErrChanged) {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// followIdle drops a transfer when its idle key ends (packageseats.Holder.Expired): the bus's marker is the event.
|
||||
func followIdle(holder func() (*packageseats.Holder, error)) {
|
||||
<-stdio.Served()
|
||||
stdio.State(packageseats.IdleState).Follow("", func(ch stdio.StateChange) error {
|
||||
if ch.Op != stdio.OpExpire {
|
||||
return nil
|
||||
}
|
||||
parts.FollowIdle(packageseats.IdleState, func(id string) (bool, error) {
|
||||
h, err := holder()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "transfer %s's idle bound ended, but the holder cannot be made: %v\n", ch.Key, err)
|
||||
return err
|
||||
return false, fmt.Errorf("transfer %s's idle bound ended, but the holder cannot be made: %w", id, err)
|
||||
}
|
||||
dropped, err := h.Expired(ch.Key)
|
||||
return h.Expired(id)
|
||||
}, func(id string, dropped bool, err error) {
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
return err
|
||||
return
|
||||
}
|
||||
if dropped {
|
||||
fmt.Fprintf(os.Stderr, "transfer %s had no chunk for %s: dropped with its chunks\n", ch.Key, packageseats.TransferIdle)
|
||||
}
|
||||
return nil
|
||||
fmt.Fprintf(os.Stderr, "transfer %s had no chunk for %s: dropped with its chunks\n", id, packageseats.TransferIdle)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ func finding(kind, subject, words string, raised bool) {
|
||||
}
|
||||
|
||||
// boundCap is incoming's cap from its binding, read once per bundle.
|
||||
var boundCap = incomingCap()
|
||||
var boundCap = parts.BusCap(packageseats.IncomingObjects)
|
||||
|
||||
// busHolder is the holder over the runtime's bus state, the builder's numbering and the forge.
|
||||
func busHolder(forge func() (*Forge, error)) (*packageseats.Holder, error) {
|
||||
@@ -275,7 +275,7 @@ func busHolder(forge func() (*Forge, error)) (*packageseats.Holder, error) {
|
||||
return &packageseats.Holder{Callers: callers, Objects: parts.BusObjects(packageseats.IncomingObjects),
|
||||
Transfers: parts.BusTransfers[packageseats.Opening](packageseats.TransfersState),
|
||||
Builder: delivery.BuilderVersions{Ask: stdio.Ask}, Store: seatStore{forge}, Say: say, Finding: finding,
|
||||
Cap: boundCap, Idle: armIdle}, nil
|
||||
Cap: boundCap, Idle: parts.BusArm(packageseats.IdleState)}, nil
|
||||
}
|
||||
|
||||
// SeatTools are both seats' verbs as tools <seat>.<verb>.
|
||||
|
||||
Reference in New Issue
Block a user