A value over buscalls.ChunkBytes is put by mesh/objects.put-chunk (written into the module's store as each chunk is taken, sealed on the last, dropped at its bound or a disorder) and got by mesh/objects.get-chunk after a chunked answer, for a state's object and a sent object alike; the 8 MiB BundleObjectMost cap is gone with the stateobjects constant. Builds: design 47 G §518, §345, §457, §490, §620, §622, A-21, A-25 Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
61 lines
2.7 KiB
Go
61 lines
2.7 KiB
Go
package bus
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
|
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
|
"git.novox.be/novox/mesh-sdk/go/stateobjects"
|
|
"github.com/nats-io/nats.go/jetstream"
|
|
)
|
|
|
|
// SentGet reads one object of a sender's store of sent objects by the reference that carried it (ADR 0666 §16): the
|
|
// store is the sender's `<module>_sent-objects`, and no other — a state's objects are reached through their owner's
|
|
// bindings alone. It reads as this connection's account, which the bus lets read a sender's sent store only where the
|
|
// grants part granted it (a bundle is held to what its runtime channel carries by the runtime call, not here), from the manifests' callers and consumers; a refusal says the store.
|
|
func (c *Conn) SentGet(r buscalls.ObjectsSentGetRequest) (*buscalls.ObjectData, error) {
|
|
ctx, cancel := context.WithTimeout(context.Background(), StateTimeout)
|
|
defer cancel()
|
|
obs, err := c.sentStore(ctx, r)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
info, err := obs.GetInfo(ctx, r.Object)
|
|
if errors.Is(err, jetstream.ErrObjectNotFound) {
|
|
return nil, fmt.Errorf("the sent object %s is not in %s: it is kept 7 days, then expires", r.Object, r.Store)
|
|
}
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the sent object %s of %s: %w", r.Object, r.Store, err)
|
|
}
|
|
data, err := obs.GetBytes(ctx, r.Object)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the sent object %s of %s: %w", r.Object, r.Store, err)
|
|
}
|
|
return &buscalls.ObjectData{Info: objectInfoOf(info), Data: data}, nil
|
|
}
|
|
|
|
// sentStore checks the reference r and opens the sender's sent store it names.
|
|
func (c *Conn) sentStore(ctx context.Context, r buscalls.ObjectsSentGetRequest) (jetstream.ObjectStore, error) {
|
|
ref := stateobjects.Ref{Store: r.Store, Object: r.Object, Size: r.Size, Digest: r.Digest, Form: stateobjects.FormVersion}
|
|
if _, ok := stateobjects.ReadRef(stateobjects.Wrap(ref)); !ok {
|
|
return nil, errors.New("a sent object is named by the reference's store, object, size and sha256, as the reply or event carried them")
|
|
}
|
|
if !strings.HasSuffix(r.Store, catalogue.BusNameSeparator+catalogue.SentObjectsLocal) {
|
|
return nil, fmt.Errorf("%s is no sent store (a module's is `<module>%s%s`): only a sent object is read by its reference",
|
|
r.Store, catalogue.BusNameSeparator, catalogue.SentObjectsLocal)
|
|
}
|
|
js, err := c.JetStream()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
obs, err := js.ObjectStore(ctx, r.Store)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("the sent store %s cannot be read as %s: it is not on the bus, or the bus grants this account no "+
|
|
"read of it (the manifests' callers and consumers are granted): %w", r.Store, c.cred.Module, err)
|
|
}
|
|
return obs, nil
|
|
}
|