asterism 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -1
- data/README.md +91 -0
- data/data/transfer/sha256.rb +124 -0
- data/data/transfer/transfer.rb +1027 -0
- data/lib/asterism/cli/commands.rb +91 -0
- data/lib/asterism/cli/nouns.rb +23 -6
- data/lib/asterism/cli.rb +160 -68
- data/lib/asterism/transfer/endpoint.rb +129 -0
- data/lib/asterism/transfer/file_inbox.rb +159 -0
- data/lib/asterism/transfer.rb +32 -0
- data/lib/asterism/version.rb +1 -1
- metadata +7 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 695c668eb3f8c5f24247a577350e62593d3258c1ccba88a2addc5741768ba304
|
|
4
|
+
data.tar.gz: dbbb782677ae81639aba09ae984e370f3749ccdd24ae941deb391a5cb8647f2b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ad45f8c308b32cd1f079651e7a049624646c8c3369fcd1042821285cbf20967bba2c9750c7eb11b0de1418bea7fb281dc07f95f3ca704e04f0065394e1262f92
|
|
7
|
+
data.tar.gz: 917539dea244fa7a2312da0b0a16b3a1082290f386f46a8d03d99156fd245f20078a099e33d02ead8c17d1888dc0cafc6b0c7a5c546a37276cbb406c5460955c
|
data/CHANGELOG.md
CHANGED
|
@@ -6,7 +6,19 @@ the earlier ones are only in this repository. From 0.4.0 the two Zenoh
|
|
|
6
6
|
bindings (asterism-zenoh, picoruby-asterism-zenoh) carry the same minor
|
|
7
7
|
version (a patch release of one may come without the other).
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## 0.13.0
|
|
10
|
+
|
|
11
|
+
- The command line runs inside another program, on that program's connection (README "Inside another program"): `Asterism::CLI.new(net:, stop:, permit:)`. `net:` an `Asterism::Net` already connected (neither started nor closed; what a command subscribes to or hooks onto it is released when it ends), `stop:` ends a streaming command as Ctrl-C does, `permit:` is asked with an `Asterism::CLI::Plan` (the command, `:read` / `:call` / `:local`, the object and method of a call) and may refuse with a reason (`CLI#refused`). Such a command line takes no connection options, runs neither `mcp` nor `completion`, takes long options only in full, prints `--help` to its `out`, and its `__complete` keeps no cache and never exits the process.
|
|
12
|
+
- `lib/asterism/cli/commands.rb`: the command table (`NOUNS`, `COMMANDS`, `ALIASES`, `VALUE_OPTIONS`, `CONNECTION_OPTIONS`, `LOCAL`), `CLI.kind(key, call:)` (what a command does on the network: only `call` and `ping --call` call a method) and `CLI::Plan`, loadable without the Zenoh binding.
|
|
13
|
+
- The command line closes what a command subscribed to (and takes off its `on_join` / `on_leave` blocks) when the command ends, before the connection closes. The output is the same.
|
|
14
|
+
|
|
15
|
+
## 0.12.0
|
|
16
|
+
|
|
17
|
+
- `Asterism::Transfer` (`data/transfer/`, `require "asterism/transfer"` on CRuby): a file carried in pieces over calls, resent from the receiver's position after lost, repeated or reordered pieces, a dropped connection or a receiver started again, checked whole by SHA-256. Plain Ruby loaded at run time on the boards (not part of the mrbgem). `rake test:transfer`.
|
|
18
|
+
- `Asterism::Transfer`: the receiver's hooks `name_ok?(kind, name)` (the names a kind takes; `plain_name?` by default) and `room(kind, meta)` (was `room`); `Transfer.file_name?` (a file name that stays in the receiver's directory: no `/`, `\`, `..`, not hidden, up to 48 bytes), `Transfer.numbered` / `Transfer.free_name` (`foo(1).txt` beside a `foo.txt`); `Sender#cancel` (the receiver drops what it holds of the file) and `Sender#kind`.
|
|
19
|
+
|
|
20
|
+
- `Asterism::Transfer::FileInbox` (CRuby): the receiver of the kind `file` with the rules of a Family mruby machine's transfer app, under a directory the program gives: the senders allowed (patterns or a block), names that stay in the directory, a name already there kept (`foo(1).txt` beside it) unless the sender asks to overwrite, a limit for the directory in all (`max_bytes:`, refused at `begin`), the pieces hidden beside where the file goes, the notes in a directory of their own (`start` goes on with a held file and deletes stray pieces). The SD card's inbox (`"inbox" => "sd"`) is refused as on a machine without a card.
|
|
21
|
+
- `Asterism::Transfer::Endpoint` (CRuby): an inbox answering at `<node>/transfer/inbox` (where the machines send: `asend <node> <file>`) on a Zenoh connection of the program's, beside the application `Asterism.connect` made (the object layer is one application per process). Its application's and object's tokens, its calls and its meta in the object layer's encoding, the caller's node ID as `from:`.
|
|
10
22
|
|
|
11
23
|
## 0.11.0
|
|
12
24
|
|
data/README.md
CHANGED
|
@@ -128,6 +128,7 @@ these repositories.
|
|
|
128
128
|
```
|
|
129
129
|
rake # every suite
|
|
130
130
|
rake test:msgs # generator, type hashes, CDR, bundled types (CRuby only; no Zenoh, no docker)
|
|
131
|
+
rake test:transfer # files in pieces (Asterism::Transfer) over a stand-in for the calls: lost, repeated, swapped pieces, a connection down, a receiver started again
|
|
131
132
|
rake test:objects # objects and Asterism::ROS between CRuby sessions over a local peer link
|
|
132
133
|
rake test:api # the CRuby API (blocks, receiving threads, Enumerators)
|
|
133
134
|
rake test:cli # the command line (exe/asterism), its Tab completion and its MCP bridge (the mcp gem's client; skipped without it)
|
|
@@ -604,6 +605,41 @@ network named on the line (`--router`, `--credentials`, `--peer`) or in
|
|
|
604
605
|
- as one more node for a moment (a `cli-` node, or the certificate's name),
|
|
605
606
|
so `asterism watch` shows it come and go.
|
|
606
607
|
|
|
608
|
+
### Inside another program
|
|
609
|
+
|
|
610
|
+
A program that is connected already (a console's bridge, which shows the
|
|
611
|
+
commands on a page) runs the same commands on its own connection:
|
|
612
|
+
|
|
613
|
+
```ruby
|
|
614
|
+
require "asterism/cli"
|
|
615
|
+
cli = Asterism::CLI.new(out: io, err: io, env: {}, net: Asterism.net,
|
|
616
|
+
stop: -> { asked_to_stop }, permit: ->(plan) { nil })
|
|
617
|
+
cli.run(%w[node list]) # the exit code; the text went to io
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
- `net:` the `Asterism::Net` to run on. It is neither started nor closed:
|
|
621
|
+
what a command subscribes to or hooks onto it (watch, echo, hz, get) is
|
|
622
|
+
released when the command ends. Its own application is left out of the
|
|
623
|
+
listings, as the command line's own is.
|
|
624
|
+
- `stop:` asked while a command streams or waits; `true` ends it as
|
|
625
|
+
Ctrl-C does.
|
|
626
|
+
- `permit:` asked once the words are read, with an `Asterism::CLI::Plan`:
|
|
627
|
+
`key` ("node list", "call", ...), `kind` (`:read`; `:call` for `call`
|
|
628
|
+
and `ping --call`, with `path` and `method`; `:local` for `mcp` and
|
|
629
|
+
`completion`), `args`, `options`. It returns nil to go on, or the reason
|
|
630
|
+
the command may not run (printed; `CLI#refused` keeps it).
|
|
631
|
+
- Such a command line takes no `--router`, `--credentials`, `--peer`,
|
|
632
|
+
`--node` or `--app`, never runs `mcp` or `completion`, takes long
|
|
633
|
+
options only as written in full (`--cal` is not `--call`), and prints
|
|
634
|
+
`--help` to `out` (OptionParser's own `--help` / `--version` would print
|
|
635
|
+
to `$stdout` and exit the process). `__complete` asks the connection on
|
|
636
|
+
each Tab and keeps nothing.
|
|
637
|
+
- Colours and width: `out` that answers `tty?` true (and `winsize`) gets
|
|
638
|
+
them, as a terminal does.
|
|
639
|
+
- `require "asterism/cli/commands"` loads the command table alone (the
|
|
640
|
+
nouns, verbs, commands, `CLI.kind`, `CLI::Plan`), without the Zenoh
|
|
641
|
+
binding, for a program that only checks a command line.
|
|
642
|
+
|
|
607
643
|
### MCP: Asterism as tools of an AI assistant
|
|
608
644
|
|
|
609
645
|
`asterism mcp` is an MCP server on stdio (it needs the `mcp` gem, which
|
|
@@ -1165,6 +1201,61 @@ publishing from `node.every` and receiving through a `node.subscribe` block
|
|
|
1165
1201
|
keeps 6.9 KB free, the same as polling `each_pending` by hand. Loading a
|
|
1166
1202
|
nested type (`geometry_msgs/msg/Twist`) at start-up took 0.6 KB more.
|
|
1167
1203
|
|
|
1204
|
+
## Files in pieces: `Asterism::Transfer`
|
|
1205
|
+
|
|
1206
|
+
A file carried from one machine to another over calls, that comes through
|
|
1207
|
+
lost, repeated and reordered pieces, a connection that drops for a while
|
|
1208
|
+
and a receiver started again, and arrives whole (its SHA-256 checked) or
|
|
1209
|
+
not at all. The receiver's position is the truth: every answer says how
|
|
1210
|
+
many bytes it holds, and the sender goes on from there. Plain Ruby that is
|
|
1211
|
+
not compiled into the mrbgem (an mruby VM that carries no files pays
|
|
1212
|
+
nothing for it): `data/transfer/transfer.rb`, which the boards load at run
|
|
1213
|
+
time (`require "/usr/share/asterism/transfer/transfer"` on Family mruby)
|
|
1214
|
+
and CRuby with `require "asterism/transfer"`. Its head describes the calls
|
|
1215
|
+
(`begin` / `chunk` / `commit` / `cancel`).
|
|
1216
|
+
|
|
1217
|
+
```ruby
|
|
1218
|
+
# the receiver: what it takes and where a whole file goes
|
|
1219
|
+
class Inbox < Asterism::Transfer::Inbox
|
|
1220
|
+
def refused(kind, from, meta) = (kind == "file" ? nil : "takes no #{kind}")
|
|
1221
|
+
def received(t) = (File.rename(t["part"], "inbox/#{t['name']}"); { "status" => "placed" })
|
|
1222
|
+
end
|
|
1223
|
+
inbox = Inbox.new("tmp/") # the piece files and their notes go here
|
|
1224
|
+
inbox.resume_held # a file held when it last ended goes on
|
|
1225
|
+
Asterism.expose("inbox", inbox, methods: Asterism::Transfer::Inbox::METHODS, caller: :from)
|
|
1226
|
+
# ... inbox.tick in the update loop
|
|
1227
|
+
|
|
1228
|
+
# the sender: stepped from the update loop, never waiting in one go
|
|
1229
|
+
s = Asterism::Transfer::Sender.new("node-b/app/inbox", "file", "photo.png", name: "photo")
|
|
1230
|
+
until s.done?
|
|
1231
|
+
Asterism.poll
|
|
1232
|
+
s.step
|
|
1233
|
+
end
|
|
1234
|
+
s.ok? ? s.answer : s.reason
|
|
1235
|
+
```
|
|
1236
|
+
|
|
1237
|
+
On CRuby, `Asterism::Transfer::FileInbox` is the receiver of the kind
|
|
1238
|
+
`file` (the rules of a Family mruby machine: the senders allowed, names
|
|
1239
|
+
that stay in its directory, `foo(1).txt` beside a name already there unless
|
|
1240
|
+
the sender asks to overwrite, a limit for the directory), and
|
|
1241
|
+
`Asterism::Transfer::Endpoint` answers for it at `<node>/transfer/inbox`,
|
|
1242
|
+
where the machines send, beside the program's own application:
|
|
1243
|
+
|
|
1244
|
+
```ruby
|
|
1245
|
+
conn = Asterism::Zenoh.open("tcp/127.0.0.1:7447")
|
|
1246
|
+
inbox = Asterism::Transfer::FileInbox.new("inbox/", work: "work/", from: ["fmruby-*"],
|
|
1247
|
+
max_bytes: 1 << 30, label: "mypc").start
|
|
1248
|
+
ep = Asterism::Transfer::Endpoint.new(conn, inbox, node: "mypc").start
|
|
1249
|
+
conn.start
|
|
1250
|
+
loop { ep.tick; sleep 0.5 } # a file that stopped coming is deleted after a minute
|
|
1251
|
+
```
|
|
1252
|
+
|
|
1253
|
+
A piece is 3,072 bytes by default: one call carries about 4 KB in all on
|
|
1254
|
+
zenoh-pico (`Z_FRAG_MAX_SIZE` 4096; a String argument of 4,044 bytes still
|
|
1255
|
+
went through between two Family mruby programs, 4,048 did not and was not
|
|
1256
|
+
answered at all). SHA-256 is CRuby's Digest, mbedTLS (`MbedTLS::Digest`)
|
|
1257
|
+
where the build has it, else plain Ruby (`data/transfer/sha256.rb`, slow).
|
|
1258
|
+
|
|
1168
1259
|
## Limits
|
|
1169
1260
|
|
|
1170
1261
|
- Objects cannot be passed by reference (a return value is a copy), blocks
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# SHA-256 (FIPS 180-4) in plain Ruby, for the builds that have neither
|
|
2
|
+
# CRuby's Digest nor mbedTLS (the browser build of Family mruby). Slow: it
|
|
3
|
+
# is there so that every machine can check a whole file the same way.
|
|
4
|
+
# Needs 64-bit Integers (MRB_INT64 on mruby). Loaded by transfer.rb only
|
|
5
|
+
# when it is the one to use.
|
|
6
|
+
module Asterism
|
|
7
|
+
module Transfer
|
|
8
|
+
class PlainSHA256
|
|
9
|
+
K = [
|
|
10
|
+
0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
|
|
11
|
+
0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
|
|
12
|
+
0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
|
|
13
|
+
0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
|
|
14
|
+
0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
|
|
15
|
+
0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
|
|
16
|
+
0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
|
|
17
|
+
0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2
|
|
18
|
+
]
|
|
19
|
+
M = 0xffffffff
|
|
20
|
+
|
|
21
|
+
def initialize
|
|
22
|
+
@h = [0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab, 0x5be0cd19]
|
|
23
|
+
@buf = String.new
|
|
24
|
+
@len = 0
|
|
25
|
+
@w = Array.new(64, 0)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def update(bytes)
|
|
29
|
+
s = bytes.to_s
|
|
30
|
+
@len += s.bytesize
|
|
31
|
+
@buf << s
|
|
32
|
+
n = @buf.bytesize - (@buf.bytesize % 64)
|
|
33
|
+
off = 0
|
|
34
|
+
while off < n
|
|
35
|
+
block(@buf, off)
|
|
36
|
+
off += 64
|
|
37
|
+
end
|
|
38
|
+
@buf = String.new << @buf.byteslice(n, @buf.bytesize - n).to_s if n > 0
|
|
39
|
+
self
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def hexdigest
|
|
43
|
+
bits = @len * 8
|
|
44
|
+
tail = @buf.dup
|
|
45
|
+
tail << 0x80.chr
|
|
46
|
+
tail << 0.chr while tail.bytesize % 64 != 56
|
|
47
|
+
i = 7
|
|
48
|
+
while i >= 0
|
|
49
|
+
tail << ((bits >> (i * 8)) & 0xff).chr
|
|
50
|
+
i -= 1
|
|
51
|
+
end
|
|
52
|
+
h = @h.dup
|
|
53
|
+
saved = @h
|
|
54
|
+
@h = h
|
|
55
|
+
off = 0
|
|
56
|
+
while off < tail.bytesize
|
|
57
|
+
block(tail, off)
|
|
58
|
+
off += 64
|
|
59
|
+
end
|
|
60
|
+
out = ""
|
|
61
|
+
i = 0
|
|
62
|
+
while i < 8
|
|
63
|
+
out << format("%08x", @h[i])
|
|
64
|
+
i += 1
|
|
65
|
+
end
|
|
66
|
+
@h = saved
|
|
67
|
+
out
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def block(s, off)
|
|
71
|
+
w = @w
|
|
72
|
+
i = 0
|
|
73
|
+
while i < 16
|
|
74
|
+
j = off + i * 4
|
|
75
|
+
w[i] = (s.getbyte(j) << 24) | (s.getbyte(j + 1) << 16) | (s.getbyte(j + 2) << 8) | s.getbyte(j + 3)
|
|
76
|
+
i += 1
|
|
77
|
+
end
|
|
78
|
+
while i < 64
|
|
79
|
+
x = w[i - 15]
|
|
80
|
+
y = w[i - 2]
|
|
81
|
+
s0 = (((x >> 7) | (x << 25)) ^ ((x >> 18) | (x << 14)) ^ (x >> 3)) & M
|
|
82
|
+
s1 = (((y >> 17) | (y << 15)) ^ ((y >> 19) | (y << 13)) ^ (y >> 10)) & M
|
|
83
|
+
w[i] = (w[i - 16] + s0 + w[i - 7] + s1) & M
|
|
84
|
+
i += 1
|
|
85
|
+
end
|
|
86
|
+
h = @h
|
|
87
|
+
a = h[0]
|
|
88
|
+
b = h[1]
|
|
89
|
+
c = h[2]
|
|
90
|
+
d = h[3]
|
|
91
|
+
e = h[4]
|
|
92
|
+
f = h[5]
|
|
93
|
+
g = h[6]
|
|
94
|
+
hh = h[7]
|
|
95
|
+
i = 0
|
|
96
|
+
while i < 64
|
|
97
|
+
s1 = (((e >> 6) | (e << 26)) ^ ((e >> 11) | (e << 21)) ^ ((e >> 25) | (e << 7))) & M
|
|
98
|
+
ch = (e & f) ^ ((~e) & g)
|
|
99
|
+
t1 = (hh + s1 + ch + K[i] + w[i]) & M
|
|
100
|
+
s0 = (((a >> 2) | (a << 30)) ^ ((a >> 13) | (a << 19)) ^ ((a >> 22) | (a << 10))) & M
|
|
101
|
+
maj = (a & b) ^ (a & c) ^ (b & c)
|
|
102
|
+
t2 = (s0 + maj) & M
|
|
103
|
+
hh = g
|
|
104
|
+
g = f
|
|
105
|
+
f = e
|
|
106
|
+
e = (d + t1) & M
|
|
107
|
+
d = c
|
|
108
|
+
c = b
|
|
109
|
+
b = a
|
|
110
|
+
a = (t1 + t2) & M
|
|
111
|
+
i += 1
|
|
112
|
+
end
|
|
113
|
+
h[0] = (h[0] + a) & M
|
|
114
|
+
h[1] = (h[1] + b) & M
|
|
115
|
+
h[2] = (h[2] + c) & M
|
|
116
|
+
h[3] = (h[3] + d) & M
|
|
117
|
+
h[4] = (h[4] + e) & M
|
|
118
|
+
h[5] = (h[5] + f) & M
|
|
119
|
+
h[6] = (h[6] + g) & M
|
|
120
|
+
h[7] = (h[7] + hh) & M
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|