G C-2, C-3: a value larger than one chunk is put and got by session through the tool runner
buscalls.ChunkBytes (512 KiB), mesh/objects.put-chunk and get-chunk with the store named in each chunk, the digest and size of a get checked, the capability word put-sessions required, and a bundle's refusal of a value over 8 MiB gone. Builds: design 47 G §518, §345, §490, §620, A-21 Claude-Session: https://claude.ai/code/session_01JG73KEq4zoDfM9WtYpcQgZ
This commit is contained in:
@@ -50,12 +50,9 @@ func (b BundleKV) Keys() ([]string, error) { return b.State.Keys() }
|
||||
// BundleObjects is an object store as a bundle reaches it.
|
||||
type BundleObjects struct{ Store busstate.Objects }
|
||||
|
||||
// BundleObjectMost is the largest object a bundle puts in one call: the runtime's channel carries a message of 16 MiB, and
|
||||
// the bytes travel in it as base64.
|
||||
const BundleObjectMost = 8 << 20
|
||||
|
||||
// MostBytes is BundleObjectMost: a larger value is refused, loudly, until the design decides how a bundle keeps one.
|
||||
func (BundleObjects) MostBytes() int { return BundleObjectMost }
|
||||
// MostBytes is zero: a bundle's value of any size is put by a session of chunks, bounded by its store's cap, which the tool
|
||||
// runner refuses at the chunk that passes it (design 47 G §518).
|
||||
func (BundleObjects) MostBytes() int { return 0 }
|
||||
|
||||
func (b BundleObjects) Put(name string, data []byte) error {
|
||||
_, err := b.Store.Put(name, data, "a value kept beside its key")
|
||||
|
||||
@@ -2,6 +2,8 @@ package stateobjects
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -25,6 +27,7 @@ type memory struct {
|
||||
failPuts bool
|
||||
modified map[string]time.Time
|
||||
most int
|
||||
puts map[string][]byte // a put session's chunks so far, by call
|
||||
}
|
||||
|
||||
func newMemory() *memory { return &memory{keys: map[string]Entry{}, objects: map[string][]byte{}} }
|
||||
@@ -216,14 +219,47 @@ func (m *memory) serve(method string, raw json.RawMessage) (any, error) {
|
||||
return buscalls.Done{}, m.Delete(p.Key)
|
||||
case "mesh/state.keys":
|
||||
return m.Keys()
|
||||
case stdio.CapabilitiesCall:
|
||||
return map[string]any{"words": []string{stdio.CapPutSessions}}, nil
|
||||
case buscalls.ObjectsPut:
|
||||
return buscalls.ObjectInfo{Name: p.Name, Size: uint64(len(p.Data))}, m.Put(p.Name, p.Data)
|
||||
case buscalls.ObjectsGet:
|
||||
d, err := m.Object(p.Name)
|
||||
return buscalls.ObjectData{Info: buscalls.ObjectInfo{Name: p.Name}, Data: d}, err
|
||||
case buscalls.ObjectsSentGet:
|
||||
d, err := m.Object(p.Object)
|
||||
return buscalls.ObjectData{Info: buscalls.ObjectInfo{Name: p.Object}, Data: d}, err
|
||||
case buscalls.ObjectsPutChunk:
|
||||
// a put session (design 47 G §518): the chunks are kept by call and the object is put on the last
|
||||
var c buscalls.ObjectsPutChunkRequest
|
||||
_ = json.Unmarshal(raw, &c)
|
||||
m.mu.Lock()
|
||||
if m.puts == nil {
|
||||
m.puts = map[string][]byte{}
|
||||
}
|
||||
m.puts[c.Call] = append(m.puts[c.Call], c.Data...)
|
||||
whole := m.puts[c.Call]
|
||||
if c.Last {
|
||||
delete(m.puts, c.Call)
|
||||
}
|
||||
m.mu.Unlock()
|
||||
if !c.Last {
|
||||
return buscalls.ObjectsChunkTaken{Seq: c.Seq}, nil
|
||||
}
|
||||
return buscalls.ObjectInfo{Name: c.Name, Size: uint64(len(whole))}, m.Put(c.Name, whole)
|
||||
case buscalls.ObjectsGet, buscalls.ObjectsSentGet:
|
||||
name := p.Name
|
||||
if method == buscalls.ObjectsSentGet {
|
||||
name = p.Object
|
||||
}
|
||||
d, err := m.Object(name)
|
||||
if err == nil && len(d) > buscalls.ChunkBytes {
|
||||
sum := sha256.Sum256(d)
|
||||
return map[string]any{"chunked": (len(d) + buscalls.ChunkBytes - 1) / buscalls.ChunkBytes, "size": len(d),
|
||||
"digest": "sha256:" + hex.EncodeToString(sum[:]), "call": name}, nil
|
||||
}
|
||||
return buscalls.ObjectData{Info: buscalls.ObjectInfo{Name: name}, Data: d}, err
|
||||
case buscalls.ObjectsGetChunk:
|
||||
var c buscalls.ObjectsGetChunkRequest
|
||||
_ = json.Unmarshal(raw, &c)
|
||||
d, err := m.Object(c.Call)
|
||||
at := int(c.Seq-1) * buscalls.ChunkBytes
|
||||
end := min(at+buscalls.ChunkBytes, len(d))
|
||||
return buscalls.ObjectsChunk{Seq: c.Seq, Last: end == len(d), Data: d[at:end]}, err
|
||||
case buscalls.ObjectsDelete:
|
||||
return buscalls.Done{}, memObjects{m}.Delete(p.Name)
|
||||
case buscalls.ObjectsList:
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/buscalls"
|
||||
"git.novox.be/novox/mesh-sdk/go/busstate"
|
||||
)
|
||||
|
||||
// MessageLimit is the most a message of the bus carries when the sender does not know its connection's own
|
||||
@@ -148,11 +149,8 @@ func BundleFetch(ref Ref) ([]byte, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var d buscalls.ObjectData
|
||||
if err := json.Unmarshal(raw, &d); err != nil {
|
||||
return nil, fmt.Errorf("the runtime's answer to %s: %w", buscalls.ObjectsSentGet, err)
|
||||
}
|
||||
return d.Data, nil
|
||||
d, err := busstate.ReadObject(ref.Object, raw)
|
||||
return d.Data, err
|
||||
}
|
||||
|
||||
// ProcessFetch reads a sent object through the reader's own object store.
|
||||
|
||||
@@ -41,10 +41,9 @@ func TestABodyOverTheMessageLimitIsSentAsAReference(t *testing.T) {
|
||||
if _, err := Receive(sent, fetch); err == nil {
|
||||
t.Fatal("a tampered object was accepted")
|
||||
}
|
||||
// a bundle's store takes at most what one runtime message carries
|
||||
bundle := Sender{Objects: BundleObjects{}, Store: "m_sent-objects"}
|
||||
if _, err := bundle.Send("reply.huge", make([]byte, BundleObjectMost+1)); err == nil {
|
||||
t.Fatal("a bundle sent a body its runtime cannot carry")
|
||||
// a bundle's store is bounded by its cap alone, and the tool runner refuses at the chunk that passes it (design 47 G §518)
|
||||
if (BundleObjects{}).MostBytes() != 0 {
|
||||
t.Fatal("a bundle's value is refused by a number of its own")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ func TestValuesOfAnySizeThroughTheRuntime(t *testing.T) {
|
||||
m := newMemory()
|
||||
out := runtimeOf(t, m, func() (any, error) {
|
||||
v := ForState("views")
|
||||
valueRows(t, v, 1, 10) // a bundle puts at most 8 MiB in an object: 100x is a process's
|
||||
valueRows(t, v, 1, 10, 100) // a bundle puts a value of any size by session (design 47 G §518)
|
||||
return "done", nil
|
||||
})
|
||||
if !strings.Contains(out.(string), "done") {
|
||||
|
||||
Reference in New Issue
Block a user