asterism 0.13.0 → 0.14.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.
data/README.md CHANGED
@@ -7,16 +7,16 @@ repository holds the pure Ruby layers, written once for every Ruby:
7
7
 
8
8
  | Path | What |
9
9
  |---|---|
10
- | `mrblib/` | The layers: remote objects (`Asterism`), `Asterism::CDR`, `Asterism::ROS`. The source of truth for both forms below |
10
+ | `mrblib/` | The layers: remote objects (`Asterism::Connection`), `Asterism::CDR`, `Asterism::ROS`. The source of truth for both forms below |
11
11
  | `mrbgem.rake` | The mrbgem `picoruby-asterism` (mruby / PicoRuby): compiles `mrblib/` |
12
12
  | `asterism.gemspec`, `lib/` | The CRuby gem `asterism`: `lib/asterism.rb` loads `mrblib/` as it is, `lib/asterism/cruby.rb` adds what CRuby needs, `lib/asterism/cruby/` the CRuby API (CRuby only) |
13
13
  | `data/icon.png` | CRuby's default profile icon (32x32 PNG; [Profiles](#profiles)) |
14
14
  | `data/msgs/` | ROS 2 message types generated from ROS 2 Jazzy's definitions (Apache-2.0; tf2_msgs BSD-3-Clause; see NOTICE) |
15
15
  | `tools/` | The type generator `asterism_msggen.rb`, the Jazzy definitions it reads, `ros2_types.rb` (refreshes them from a ROS 2 image) |
16
16
  | `exe/asterism`, `lib/asterism/cli*` | The command line: look at a network, call an object, an MCP server ([The command line](#the-command-line); CRuby only) |
17
- | `test/` | `test/msgs` (types, CDR; CRuby only), `test_asterism.rb` (objects and ROS between CRuby sessions), `test_profile.rb` (node profiles), `test_status.rb` (application statuses), `test_meta_apps.rb` (the meta's args / doc, on_app_join / on_app_leave), `test_cli.rb` (the command line), `test_session.rb` (`Asterism.session`, `on_join` / `on_leave`), `test_api_*.rb` (the CRuby API), `bench_poll.rb` (`rake bench:poll`) |
17
+ | `test/` | `test/msgs` (types, CDR; CRuby only), `test_asterism.rb` (objects and ROS between CRuby sessions), `test_profile.rb` (node profiles), `test_status.rb` (application statuses), `test_meta_apps.rb` (the meta's args / doc, on_app_join / on_app_leave), `test_cli.rb` (the command line), `test_session.rb` (`Connection#session`, `on_join` / `on_leave`), `test_connections.rb` (several connections in one program), `test_api_*.rb` (the CRuby API), `bench_poll.rb` (`rake bench:poll`) |
18
18
  | `test/protocol/` | the conformance samples of the wire protocol (`samples.json`), the driver that checks an implementation against them, and the Ruby node it checks (`rake test:protocol`, `rake test:protocol_mruby`; [docs/protocol.md](docs/protocol.md)) |
19
- | `host_test/` | `rake test:mruby`: the shared layer on mruby (profiles between two mruby processes; `Asterism.session`, `on_join` / `on_leave` and the time of a poll against `peer.rb`) |
19
+ | `host_test/` | `rake test:mruby`: the shared layer on mruby (profiles between two mruby processes; `Connection#session`, `on_join` / `on_leave` and the time of a poll against `peer.rb`); with `rake test:cross`, topics with a CRuby node and several connections in one mruby program |
20
20
  | `examples/` | CRuby: `node.rb` (objects with a board), `node_polled.rb` (the same with the portable API of the boards), `ros2_talker.rb` (topics, a timer, services with ROS 2), `ros2_rover.rb` (drive a ROS 2 robot: `/cmd_vel`, `/odom`, `/imu`), `zenoh.rb` (plain Zenoh), `mujoco/` (MuJoCo run from CRuby through Fiddle, its robot exposed as Asterism objects; see its README) |
21
21
 
22
22
  The Zenoh binding underneath is a separate gem with the same Ruby API on
@@ -41,15 +41,18 @@ asterism-zenoh too). What changed in each version is in
41
41
  ([docs/api_review.md](docs/api_review.md)) and only adds and deprecates
42
42
  (see [Deprecations and 1.0](#deprecations-and-10)); 0.5.0 adds node
43
43
  profiles ([Profiles](#profiles): what a node runs on, where, a name and an
44
- icon); 0.6.0 adds `Asterism.session`
45
- ([One connection](#one-connection-asterismsession): the object layer's
46
- session for plain Zenoh and ROS 2 too) and makes `Asterism.poll` cheap when
47
- nothing changed. **0.7.0 speaks wire protocol 1 only**
44
+ icon); 0.6.0 adds the object layer's session
45
+ ([The connection's session](#the-connections-session-netsession): for plain
46
+ Zenoh and ROS 2 too) and makes polling cheap when nothing changed. **0.7.0 speaks wire protocol 1 only**
48
47
  ([docs/protocol.md](docs/protocol.md)): it does not talk to the object
49
48
  layer of earlier versions, so every node of a network moves to 0.7.0
50
- together. It adds who called (`Asterism.current_call`, `expose(...,
49
+ together. It adds who called (`current_call`, `expose(...,
51
50
  caller: :from)`; [Who called](#who-called)), the kind of a remote error
52
- (`RemoteError#remote_kind`) and `proxy.asterism_call`.
51
+ (`RemoteError#remote_kind`) and `proxy.asterism_call`. Protocol 2 adds
52
+ topics, types and an application's own profile ([Topics](#topics)), and
53
+ the connection becomes an object: `Asterism.connect` returns an
54
+ `Asterism::Connection`, whose methods are the whole API, and a program may
55
+ hold several ([Several connections](#several-connections)).
53
56
 
54
57
  A mechanism-by-mechanism comparison with dRuby and Rinda is in
55
58
  [docs/comparison.md](docs/comparison.md).
@@ -61,7 +64,7 @@ the boards have the first one only.
61
64
 
62
65
  | You write for | Use | Why |
63
66
  |---|---|---|
64
- | A board, or code that must run on both | the **portable API** ([below](#the-portable-api): `Asterism.poll`, `node.poll`, `each_pending`) | the only one on the boards; nothing runs behind your back |
67
+ | A board, or code that must run on both | the **portable API** ([below](#the-portable-api): `net.poll`, `node.poll`, `each_pending`) | the only one on the boards; nothing runs behind your back |
65
68
  | CRuby only (tools, servers, scripts) | the **CRuby API** ([The CRuby API](#the-cruby-api): `Asterism.connect { }`, `Asterism::Zenoh.open { }`, `Asterism::ROS.connect { }`) | blocks, a receiving thread, Enumerators, `Data` values |
66
69
  | CRuby, but you own the loop (a game loop, a test) | the portable API | same as the boards |
67
70
 
@@ -71,8 +74,8 @@ Entry points and what they give:
71
74
  |---|---|---|
72
75
  | `Asterism::Zenoh::Session.open` | a `Session` (portable) | zenoh-c / zenoh-pico |
73
76
  | `Asterism::Zenoh.open` | a `Zenoh::Connection` (CRuby) | `c.session` is the `Session` |
74
- | `Asterism.connect` | `Asterism` itself (portable; one connection per process or VM), or a `Net` to the block (CRuby) | a `Session` of its own |
75
- | `Asterism.session` | that `Session` (portable), for put, subscribe and a ROS 2 node on the same connection; `net.session` is it as a `Zenoh::Connection` (CRuby) | the object layer's (Asterism closes it) |
77
+ | `Asterism.connect` | an `Asterism::Connection` (portable: one application; a program may open several), also to the block (CRuby) | a `Session` of its own |
78
+ | `net.session` | that `Session` (portable), for put, subscribe and a ROS 2 node on the same connection; `net.zenoh` is it as a `Zenoh::Connection` (CRuby) | the connection's (its `close` closes it) |
76
79
  | `Asterism::ROS::Node.new(session, ...)` | a `Node` (portable) | the `Session` given |
77
80
  | `Asterism::ROS.connect` | a `ROS::Connection` (CRuby) | `ros.zenoh` is the `Zenoh::Connection` |
78
81
 
@@ -112,11 +115,11 @@ ruby -I lib -I ../asterism-zenoh/lib your_script.rb # after `rake compile` in
112
115
 
113
116
  `Asterism::ROS::TYPE_PATH` is `data/msgs` there; add your own directories.
114
117
  MessagePack sends a binary (ASCII-8BIT) String as bin and any other String
115
- as str (protocol 1; [Values](#values)).
118
+ as str (the wire protocol; [Values](#values)).
116
119
 
117
120
  mruby / PicoRuby: add this repository and picoruby-asterism-zenoh as gems
118
121
  (`conf.gem "path/to/asterism"`; a `MessagePack` module with `pack` /
119
- `unpack` is needed too: for protocol 1 it must write a binary String
122
+ `unpack` is needed too: for the wire protocol it must write a binary String
120
123
  (`String#b`) as bin and read a bin as one, and refuse ext types, integers
121
124
  outside int64 and bytes after the value), and put `data/msgs` on the device's file system at
122
125
  `/usr/share/asterism/msgs` (or add the place to
@@ -129,14 +132,15 @@ these repositories.
129
132
  rake # every suite
130
133
  rake test:msgs # generator, type hashes, CDR, bundled types (CRuby only; no Zenoh, no docker)
131
134
  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
132
- rake test:objects # objects and Asterism::ROS between CRuby sessions over a local peer link
135
+ rake test:objects # objects, profiles, statuses, topics, several connections in one program and Asterism::ROS between CRuby sessions
133
136
  rake test:api # the CRuby API (blocks, receiving threads, Enumerators)
134
137
  rake test:cli # the command line (exe/asterism), its Tab completion and its MCP bridge (the mcp gem's client; skipped without it)
135
138
  ASTERISM_TEST_ROUTER=tcp/127.0.0.1:7447 rake test:objects test:api # the same through a zenohd router
136
139
  rake test:mruby # the shared layer on mruby (builds mruby; not part of `rake`)
140
+ rake test:cross # topics between an mruby node and a CRuby one, and several connections in one mruby program through a router (builds mruby; not part of `rake`)
137
141
  rake test:protocol # the wire protocol's conformance samples and driver against CRuby (docs/protocol.md)
138
142
  rake test:protocol_mruby # the same driver against mruby (builds mruby; not part of `rake`)
139
- rake bench:poll # the time and allocations of one Asterism.poll by nodes and objects (prints a table)
143
+ rake bench:poll # the time and allocations of one Connection#poll by nodes and objects (prints a table)
140
144
  ```
141
145
 
142
146
  `test:mruby` builds mruby with picoruby-asterism-zenoh and this gem
@@ -265,17 +269,17 @@ end
265
269
 
266
270
  | Call | Notes |
267
271
  |---|---|
268
- | `Asterism.connect(...) { \|net\| }` | yields an `Asterism::Net`, `Asterism.close` when the block ends; returns the block's value. Without a block, as before |
269
- | `Asterism.net` | the `Net` of the connection made without a block (nil when not connected) |
270
- | `net.expose` / `unexpose` / `exposed` | as `Asterism.expose` (also `caller: :from`). The methods run on the receiving thread, in `run`, or in whatever polls |
271
- | `net.current_call` | `Asterism.current_call`: the call being answered on this thread (the receiving thread while it answers), or nil |
272
- | `net[path, timeout: 2.0]` | a proxy (`timeout` in seconds, or `timeout_ms:`) |
273
- | `net.each(pattern = "**")` | the proxies alive now; an Enumerator without a block. With a block it returns their number (1.0: `self`, as Ruby's `each` does; `net.count` is the number) |
274
- | `net.on_join { \|node\| }` / `net.on_leave { \|node\| }` | `Asterism.on_join` / `on_leave` of the portable API (the same blocks, told from `Asterism.poll`), here on the receiving thread; what they raise goes to `on_error`. `net.off_join(proc)` / `off_leave(proc)` remove one |
275
- | `net.start` / `stop` / `run` / `running?` / `on_error` | as for Zenoh. A method of an exposed object that raises is answered to its caller as a `RemoteError`, as before; `on_error` gets what `on_join` / `on_leave` raise |
276
- | `net.profile(**fields)` / `net.profile_of(node, icon: true, timeout: 2.0)` | `Asterism.profile` / `profile_of` ([Profiles](#profiles)); `profile_of` waits for the receiving thread's ticks while it runs |
277
- | `net.session` | `Asterism.session` as a `Zenoh::Connection` (`subscribe { }`, `put`, `publisher`, ...) on this receiving thread: its blocks run there, between the calls answered. `shared?` is true; its `close` does nothing and `start` / `stop` / `run` are the `Net`'s. A ROS 2 node on it: `Asterism::ROS::Connection.new(net.session).node("name")`. See [One connection](#one-connection-asterismsession) |
278
- | `net.nodes`, `node_id`, `app`, `connected?`, `lost_reason`, `poll`, `close` | |
272
+ The connection (`Asterism::Connection`) is the portable API's (the same
273
+ object and methods on a board); CRuby adds to it:
274
+
275
+ | Call | Notes |
276
+ |---|---|
277
+ | `Asterism.connect(...) { \|net\| }` | yields the `Asterism::Connection`, `net.close` when the block ends; returns the block's value. Without a block, returns the connection (as on a board) |
278
+ | `net.start` / `stop` / `run` / `running?` / `on_error` | the connection's receiving thread, as for Zenoh. The exposed objects' methods, the `on_join` / `on_leave` / `on_app_*` blocks and the `subscribe` blocks run there (or in `run`, or in whatever polls). A method of an exposed object that raises is answered to its caller as a `RemoteError`; `on_error` gets what the blocks raise |
279
+ | `net.zenoh` | `net.session` as a `Zenoh::Connection` (`subscribe { }`, `put`, `publisher`, ...) on this receiving thread: its blocks run there, between the calls answered. `shared?` is true; its `close` does nothing and `start` / `stop` / `run` are the connection's. A ROS 2 node on it: `Asterism::ROS::Connection.new(net.zenoh).node("name")`. See [The connection's session](#the-connections-session-netsession) |
280
+ | `net.on_status(pattern = "*/*") { \|node, app, status\| }` | the statuses put by the applications matching, on the receiving thread ([Status](#status)) |
281
+ | `net.each(pattern)` | as on the boards (an Array without a block); the connection is `Enumerable` over `each("**")` (`net.map(&:asterism_path)`, `net.count`) |
282
+ | Waiting calls (`net[path].method`, `status_of`, `profile_of`, ...) | from another thread while the receiving thread runs, they wait for its ticks; on that thread, or while nothing receives, they poll as on the boards |
279
283
 
280
284
  ### Over TLS (a router on the internet)
281
285
 
@@ -359,7 +363,7 @@ end
359
363
  | `node.call(name, type, request = nil, request:, timeout: 2.0, **fields)` | waits for the response. Here `timeout:` is always the time limit (see [Reserved keywords](#reserved-keywords)) |
360
364
  | `ros.spin` (`run`) / `start` / `stop` / `running?` / `on_error` / `close` | |
361
365
  | `ros.zenoh` | the `Asterism::Zenoh::Connection` underneath (same receiving thread) |
362
- | `Asterism::ROS::Connection.new(net.session, domain: 0)` | nodes on the object layer's session (the same Zenoh ID as the objects), spun by the `Net`'s receiving thread. Its `close` withdraws its nodes only |
366
+ | `Asterism::ROS::Connection.new(net.zenoh, domain: 0)` | nodes on an Asterism connection's session (the same Zenoh ID as its objects), spun by that connection's receiving thread. Its `close` withdraws its nodes only |
363
367
 
364
368
  `type` is a generated type or its name (`"geometry_msgs/msg/Twist"`).
365
369
  Messages and `Attachment` take part in pattern matching (`deconstruct_keys`,
@@ -380,10 +384,10 @@ that is not bundled: generate it with `tools/asterism_msggen.rb -o DIR`
380
384
  - zenoh-c never calls Ruby: it fills the queues, and the receiving thread
381
385
  empties them every 2 ms (`interval:`) with the portable API.
382
386
  - A tick of the receiving thread holds the connection's lock (a `Monitor`;
383
- for the object layer, which is one connection per process,
384
- `Asterism::LOCK`). The application's calls into the same layer take it
385
- too, so the layers written for one thread are never entered by two at
386
- once.
387
+ for the object layer one for all its connections, `Asterism::LOCK`: a
388
+ call waiting on one connection answers the calls of the others). The
389
+ application's calls into the same layer take it too, so the layers
390
+ written for one thread are never entered by two at once.
387
391
  - A call that waits for an answer (`proxy.method`, `node.call`) from another
388
392
  thread while the receiving thread runs does not poll by itself: it waits
389
393
  until a tick brings the answer. On the receiving thread itself (a block
@@ -404,7 +408,7 @@ What may be shared between threads:
404
408
  | `Asterism::Zenoh::Session` and its subscribers, queryables, gets, publishers, queriers (CRuby) | yes; each queued entry goes to exactly one taker |
405
409
  | `Zenoh::Connection` | yes; its blocks run one at a time on the receiving thread |
406
410
  | An Enumerator (`Subscription#each`, `Watch#each`, `get`, `topic`) | one thread per iteration |
407
- | The object layer (`Asterism.*`, `Net`, proxies, `Future`) | yes; serialized by `Asterism::LOCK` (one connection per process) |
411
+ | The object layer (`Asterism::Connection`, proxies, `Future`) | yes; serialized by `Asterism::LOCK` (one for all the connections of the process) |
408
412
  | `ROS::Connection` and the nodes it makes | yes (its runner's lock) |
409
413
  | A `ROS::Node` made with `Node.new` (portable API) on CRuby | **no**: one thread, as on the boards |
410
414
  | A session opened before `fork` | not in the child: its calls raise `Zenoh::ClosedError`; connect after fork |
@@ -424,12 +428,15 @@ them):
424
428
  asterism node list --router tcp/192.0.2.2:7447 # the nodes, a name a line
425
429
  asterism node info games # one node: profile, apps, statuses, objects
426
430
  asterism app list # node/app, a line each
427
- asterism app info games/games # its status and its objects
431
+ asterism app info games/games # its status, topics, types and objects
428
432
  asterism object list 'games/games/*' # node/app/object, a line each
429
433
  asterism object info games/games/othello1 # its description and its methods
430
434
  asterism object find join # the objects that have join (* as a wildcard)
431
435
  asterism object get games/games/othello1 state # the next value the application puts there
432
436
  asterism object echo games/games/othello1 state # the values as they come (what changed)
437
+ asterism object echo '*/@shared/spectate' '*/state' # a shared place's values, each with its sender
438
+ asterism topic list 'games/*' # node/app/name of each topic, with its type
439
+ asterism topic info games/games/board1/strokes # its declaration, and its type's definition
433
440
  asterism status get games/games # the status now
434
441
  asterism status echo games/games # the status, then each change (--once: now, once)
435
442
  asterism status hz games/games # how often it changes
@@ -556,9 +563,16 @@ $ asterism watch
556
563
  only what changed: `a.b 0→1`, `+a.c=…` (a key came), `-a.d` (a key
557
564
  went). `--timeout` (2.0 s) is each get's and call's limit, `--settle`
558
565
  (1.5 s) how long it waits for the tokens after connecting.
566
+ - **topic list / info** read what the applications declare
567
+ (`@profile?pubs;types`, docs/protocol.md 10, 11): each topic's type (a
568
+ built-in one by its name, `vector3`, or an application's own), its
569
+ encoding (none: MessagePack), unit and text, and the definition of an
570
+ application's own type (`topic info`, and `app info`, which lists the
571
+ types the application defines). `tree`, `nodes`, `node info` and
572
+ `app info` list an application's topics under its status.
559
573
  - **object get / echo PATH [KEY]** read what an application puts on its
560
- own keys, `asterism/<node>/<app>/<object>/<more>` (docs/protocol.md 2.2;
561
- a game table puts its state on `<table>/state`). `PATH` is
574
+ topics, `asterism/<node>/<app>/<name>` (docs/protocol.md 9; a game
575
+ table puts its state on `<table>/state`). `PATH` is
562
576
  `node/app/object` (`*` for a part), `KEY` the rest (`*` and `**` as whole
563
577
  parts; `**` by default). A put is kept nowhere and a get has no answer
564
578
  for it, so both wait for puts: `object get` prints the next one and ends
@@ -566,9 +580,21 @@ $ asterism watch
566
580
  one gives nothing), `object echo` prints them as they come: a key's
567
581
  value whole the first time, then only what changed in it, as
568
582
  `status echo` does (`--raw`: each value whole; `--once`: the first put;
569
- `--duration`). The value is MessagePack (Asterism's own) or JSON as it
570
- is, other text as a string, bytes as their count; `-o json` gives each
571
- put as `{"key", "t", "bytes", "format", "value"}`. When nothing comes
583
+ `--duration`). The value is MessagePack (Asterism's own, no encoding) as
584
+ it is; a value with an encoding as JSON or text for those encodings, as
585
+ its encoding and size otherwise (`image/jpeg`); from a sender that does
586
+ not follow the protocol, JSON or text as they are, bytes as their count.
587
+ `-o json` gives each put as `{"key", "t", "bytes", "format", "value"}`
588
+ (`format`: `msgpack` or the encoding) with `seq`, `run_id` (the sender's
589
+ connection) and `sent` (the sender's time) from its attachment, and
590
+ `lost` (values missed before it) or `restarted` (the sender connected
591
+ again, or its numbers went back); the text says those
592
+ on a line of their own (`(2 lost)`). **The shared places** (17):
593
+ `PATH` is `node/@shared/name...` (`*` for the node) or `@shared/name...`
594
+ (`asterism object get games/@shared/spectate/mahjong1/state`); `*` and
595
+ `**` never match `@shared` itself (as in Zenoh), so a pattern names it.
596
+ Each value shows its sender (`... from games/room01`; `from` in
597
+ `-o json`), and its numbers are counted per sender. When nothing comes
572
598
  they say so: the router does not let this node read the key (a role
573
599
  needs `read` on it), or nothing changed.
574
600
  - **status hz** counts the changes of the status (a put of the same status
@@ -612,12 +638,12 @@ commands on a page) runs the same commands on its own connection:
612
638
 
613
639
  ```ruby
614
640
  require "asterism/cli"
615
- cli = Asterism::CLI.new(out: io, err: io, env: {}, net: Asterism.net,
641
+ cli = Asterism::CLI.new(out: io, err: io, env: {}, net: conn,
616
642
  stop: -> { asked_to_stop }, permit: ->(plan) { nil })
617
643
  cli.run(%w[node list]) # the exit code; the text went to io
618
644
  ```
619
645
 
620
- - `net:` the `Asterism::Net` to run on. It is neither started nor closed:
646
+ - `net:` the `Asterism::Connection` to run on. It is neither started nor closed:
621
647
  what a command subscribes to or hooks onto it (watch, echo, hz, get) is
622
648
  released when the command ends. Its own application is left out of the
623
649
  listings, as the command line's own is.
@@ -656,7 +682,8 @@ claude mcp add asterism -- asterism mcp --credentials admin.tar --allow 'games/o
656
682
  | `asterism_nodes` | the nodes, their profiles, applications (with their statuses) and objects |
657
683
  | `asterism_objects` | the objects and their methods (meta); `callable_as` names the tool for an allowed method |
658
684
  | `asterism_status` | the applications' statuses (`node` / `app` narrow it) |
659
- | `asterism_values` | the latest value of each key the applications put on (`asterism/<node>/<app>/<object>/<more>`, e.g. a game table's state), as this server received them since it started; `pattern` (`node/app/object/more`, `*` and `**`; default `**`) and `wait` (seconds, at most 30) |
685
+ | `asterism_topics` | the topics the applications declare, with their types, encodings, units and texts, and the definitions of their own types (`node` / `app` narrow it) |
686
+ | `asterism_values` | the latest value of each topic the applications put on (`asterism/<node>/<app>/<name>`, e.g. a game table's state) and in the shared places (`<node>/@shared/<name>`, `@shared/<name>`: each sender's, with `from`), as this server received them since it started, with its encoding and sequence numbers; `pattern` (`node/app/name` or a shared place's key, `*` and `**`; default `**`, the applications' keys), `wait` (seconds, at most 30) and `images` (true: pictures as MCP images, at most 4) |
660
687
  | `<node>.<app>.<object>.<method>` | one per method an `--allow` pattern names, made from the meta: the arguments' names it tells are the inputs and its doc the description (with the object's doc after it); without names, arity n gives the inputs `arg1` .. `argN` (any JSON value), arity -1 an array `args`; `kwargs` is an object of keyword arguments. The answer is `{"value": ...}`, or an error with its kind |
661
688
 
662
689
  - `--allow PATTERN` (repeatable): `[node/][app/]object.method`, `*` within
@@ -673,12 +700,18 @@ claude mcp add asterism -- asterism mcp --credentials admin.tar --allow 'games/o
673
700
  MCP client started with `--app game` come and go).
674
701
  - **asterism_values**: from its start the server subscribes to
675
702
  `asterism/**` (the applications' own keys; `@profile` and `@status` are
676
- not under it) and keeps the last value of each key with the time it
677
- came. A put comes only when a value changes and is kept nowhere else, so
703
+ not under it) and to the shared places (`asterism/*/@shared/**`,
704
+ `asterism/@shared/**`, 17), and keeps the last value of each key (of
705
+ each sender on a shared key, with `from`: its sender) with the time it
706
+ came. `**` is the applications' keys; a shared place is named in the
707
+ pattern (`*/@shared/spectate/**`, `@shared/**`). A put comes only when a value changes and is kept nowhere else, so
678
708
  a key that has not been put since the server started is not there:
679
709
  `wait` waits (at most 30 s) for the first put that matches when none has
680
710
  come yet. Each value has `key`, `value`, `t`, `age_s` (seconds since it
681
- came), `bytes`, `format` and `app`: `alive`, `gone` (the application is
711
+ came), `bytes`, `format` (`msgpack`, or the encoding it came with:
712
+ `image/jpeg` shows as its size), `seq`, `run_id` and `sent` (the
713
+ sender's time) from its attachment, `lost` (values of the key missed since the start)
714
+ and `app`: `alive`, `gone` (the application is
682
715
  not on the network now; the value is its last one, not the present) or
683
716
  `restarted` (it left and came back after this value). A value whose JSON
684
717
  is longer than 8192 bytes is cut (`truncated: true`, the value the start
@@ -738,52 +771,73 @@ and the short pauses while waiting; otherwise `Time` and `sleep`. Besides
738
771
 
739
772
  ```ruby
740
773
  # on the machine that has the object
741
- Asterism.connect("tcp/192.0.2.2:7447", node: "fmruby-bbbbbb", app: "demo")
742
- Asterism.expose("apu", apu, methods: [:play, :stop])
743
- loop { Asterism.poll; ... } # in the update loop
774
+ net = Asterism.connect("tcp/192.0.2.2:7447", node: "fmruby-bbbbbb", app: "demo")
775
+ net.expose("apu", apu, methods: [:play, :stop])
776
+ loop { net.poll; ... } # in the update loop
744
777
 
745
778
  # on another machine
746
- Asterism.connect("tcp/192.0.2.2:7447", node: "linux", app: "demo")
747
- apu = Asterism["fmruby-bbbbbb/demo/apu"] # <node>/<app>/<object>
779
+ net = Asterism.connect("tcp/192.0.2.2:7447", node: "linux", app: "demo")
780
+ apu = net["fmruby-bbbbbb/demo/apu"] # <node>/<app>/<object>
748
781
  apu.play("t120 o4 cdefg") # runs there, returns its value
749
782
  apu.respond_to?(:play) # => true (from the exposed list)
750
783
  f = apu.async.play("cde") # does not wait
751
784
  f.done?; f.value
752
- Asterism["fmruby-bbbbbb/demo/apu", timeout: 5.0].play("c") # a longer time limit
753
- Asterism.each("*/*/apu") { |a| a.stop } # every apu alive now
754
- Asterism.nodes # => ["linux", "fmruby-bbbbbb"]
785
+ net["fmruby-bbbbbb/demo/apu", timeout: 5.0].play("c") # a longer time limit
786
+ net.each("*/*/apu") { |a| a.stop } # every apu alive now
787
+ net.nodes # => ["linux", "fmruby-bbbbbb"]
755
788
  ```
756
789
 
790
+ `Asterism.connect` returns the connection (an `Asterism::Connection`): one
791
+ application on the network, with everything of it (its session, its
792
+ token, its objects, its status, topics and types). Everything below is a
793
+ method of it (`net.` in the tables); the module keeps only
794
+ `Asterism.connect`, `Asterism.connections`, `Asterism.poll_all` and
795
+ `Asterism.profile_defaults`, and the stateless helpers (`Asterism::Codec`,
796
+ `Asterism::Profile`, `Asterism::Status`, `Asterism::Types`,
797
+ `Asterism::Pubs`).
798
+
757
799
  ## API
758
800
 
759
801
  | Call | Returns | Raises / notes |
760
802
  |---|---|---|
761
- | `Asterism.connect(locator = nil, node: nil, app:, mode: nil, listen: nil, config: nil, connect_timeout: nil, check_timeout: 1.5, credentials: nil)` (`credentials:` see [Over TLS](#over-tls-a-router-on-the-internet)) | `Asterism` | `locator`, `mode:`, `listen:` (and `config:` / `connect_timeout:` when given: TLS and the rest of zenoh's configuration on CRuby; the boards take the TLS keys of `config:` only and raise `ArgumentError` for the rest) go to `Asterism::Zenoh::Session.open` (client of a router by default; `mode: :peer` with or without `listen:` without one). `node:` is this machine's ID, `app:` the application's name (one key chunk each: no `/ * $ ? #`, not starting with `@`; else `ArgumentError`). `Disconnected` when it cannot connect; `Error` when objects of the same `<node>/<app>` are already alive (a second copy of the application), or when already connected. Waits up to `check_timeout:` seconds for that check (a router answers at once; give more over a slow relay). Returns the module itself: on a board the module is the connection (one per application). The default is plain text without authentication; see [Over TLS](#over-tls-a-router-on-the-internet). |
762
- | `Asterism.expose(name, obj, methods:, caller: nil, doc: nil)` | `"<node>/<app>/<name>"` | `methods:` is an Array of names, or a Hash `name => number of arguments` (checked before the call; `-1` or the Array form: any) or `name => { args: [names], doc: "text" }` ([Describing the methods](#describing-the-methods)); `doc:` the object's own text. `ArgumentError` when `obj` has no such public method. Exposing a name again replaces it. `caller: :from` passes the calling node's ID to every method as the keyword `from:` and refuses a call that brings `from:` itself ([Who called](#who-called)). |
763
- | `Asterism.current_call` | `Asterism::CurrentCall` or nil | While an exposed method runs for a call: `from` (the calling node's ID), `verified` (`:claimed`, or `:local` for a call from this application), `object`, `method`. nil outside a call ([Who called](#who-called)). |
764
- | `Asterism.unexpose(name)` | true / false | |
765
- | `Asterism.poll` | true / false | Call from the update loop: polls Zenoh, answers the calls that came in, follows who is alive and calls the `on_join` / `on_leave` blocks. `false` once the connection is closed or lost. Cheap when nothing came (0.6.0): each queue is looked at by its count, and the list of nodes is made again only after a liveliness change. |
766
- | `Asterism.on_app_join { \|node, app\| }` / `Asterism.on_app_leave { \|node, app\| }` | `Asterism` | An application of another node appeared (its token `asterism/<node>/<app>`) / is gone. A node may run several: each comes and goes on its own while the node stays. Told like `on_join` (from `Asterism.poll`; at connect for those there; all leave when the connection is lost); `off_app_join(proc)` / `off_app_leave(proc)`; CRuby `net.on_app_join` / `net.on_app_leave` |
767
- | `Asterism.on_join { \|node\| }` / `Asterism.on_leave { \|node\| }` | `Asterism` | Another node appeared (one of its applications or objects) / is gone (no application and no object left). The nodes there already join on the first polls after connecting; when the connection is lost, every node known until then leaves (on the next `Asterism.poll`). The blocks run from `Asterism.poll` only, never from the polling inside a waiting call; what they raise comes out of `Asterism.poll`. Each call adds a block; `Asterism.off_join(proc)` / `off_leave(proc)` remove one; `Asterism.close` forgets them (a lost connection does not). |
768
- | `Asterism[path, timeout: 2.0]` | `Proxy` | `path` is `<node>/<app>/<object>` without wildcards (`ArgumentError`). `timeout:` (seconds) or `timeout_ms:` is the time limit of its calls. Nothing is sent until a method is called. |
803
+ | `Asterism.connect(locator = nil, node: nil, app:, mode: nil, listen: nil, config: nil, connect_timeout: nil, check_timeout: 1.5, credentials: nil)` (`credentials:` see [Over TLS](#over-tls-a-router-on-the-internet)) | `Asterism::Connection` | `locator`, `mode:`, `listen:` (and `config:` / `connect_timeout:` when given: TLS and the rest of zenoh's configuration on CRuby; the boards take the TLS keys of `config:` only and raise `ArgumentError` for the rest) go to `Asterism::Zenoh::Session.open` (client of a router by default; `mode: :peer` with or without `listen:` without one). `node:` is this machine's ID, `app:` the application's name (one key chunk each: no `/ * $ ? #`, not starting with `@`; else `ArgumentError`). `Disconnected` when it cannot connect; `Error` when the same `<node>/<app>` is already there: open in this program, or its token or objects alive on the network (a second copy of the application). Waits up to `check_timeout:` seconds for that check (a router answers at once; give more over a slow relay). A program may connect several times, as several applications ([Several connections](#several-connections)). The default is plain text without authentication; see [Over TLS](#over-tls-a-router-on-the-internet). |
804
+ | `Asterism.connections` | `[Connection]` | The connections of this program that are open (or lost, until their `on_leave` blocks were told), in the order they were opened. |
805
+ | `Asterism.poll_all` | true / false | `poll` on each of them; true while one is connected. |
806
+ | `Asterism.profile_defaults(kind:, name:, host:, icon:)` / `Asterism.profile_defaults` | Hash | The profile every node of this program starts with (a board's firmware sets it before the application connects); see [Profiles](#profiles). |
807
+ | `net.expose(name, obj, methods:, caller: nil, doc: nil)` | `"<node>/<app>/<name>"` | `methods:` is an Array of names, or a Hash `name => number of arguments` (checked before the call; `-1` or the Array form: any) or `name => { args: [names], doc: "text" }` ([Describing the methods](#describing-the-methods)); `doc:` the object's own text. `ArgumentError` when `obj` has no such public method. Exposing a name again replaces it. `caller: :from` passes the calling node's ID to every method as the keyword `from:` and refuses a call that brings `from:` itself ([Who called](#who-called)). |
808
+ | `net.current_call` | `Asterism::CurrentCall` or nil | While an exposed method of this connection runs for a call: `from` (the calling node's ID), `verified` (`:claimed`, or `:local` for a call from this application), `object`, `method`. nil outside a call ([Who called](#who-called)). |
809
+ | `net.unexpose(name)` | true / false | |
810
+ | `net.poll` | true / false | Call from the update loop: polls Zenoh, answers the calls that came in, follows who is alive, calls the `on_join` / `on_leave` blocks and hands the values to the `subscribe` blocks. `false` once the connection is closed or lost. Cheap when nothing came (0.6.0): each queue is looked at by its count, and the list of nodes is made again only after a liveliness change. |
811
+ | `net.on_app_join { \|node, app\| }` / `net.on_app_leave { \|node, app\| }` | the connection | An application of another node appeared (its token `asterism/<node>/<app>/protocol/<n>`; also one of another protocol) / is gone. A node may run several (another connection of this program among them): each comes and goes on its own while the node stays. Told like `on_join` (from `poll`; at connect for those there; all leave when the connection is lost); `off_app_join(proc)` / `off_app_leave(proc)` |
812
+ | `net.on_join { \|node\| }` / `net.on_leave { \|node\| }` | the connection | Another node appeared (one of its applications or objects) / is gone (no application and no object left). The nodes there already join on the first polls after connecting; when the connection is lost, every node known until then leaves (on the next `poll`). The blocks run from `poll` only, never from the polling inside a waiting call; what they raise comes out of `poll`. Each call adds a block; `off_join(proc)` / `off_leave(proc)` remove one; `close` forgets them (a lost connection does not). |
813
+ | `net[path, timeout: 2.0]` | `Proxy` | `path` is `<node>/<app>/<object>` without wildcards (`ArgumentError`). `timeout:` (seconds) or `timeout_ms:` is the time limit of its calls, which go out on this connection. Nothing is sent until a method is called. |
769
814
  | `proxy.<method>(*args, **kw)` | the remote return value | Waits for the answer (the proxy's time limit). `RemoteError` when it raised there or could not be called (`remote_kind` says which: `raised`, or not exposed `not_exposed` (`NoMethodError`), wrong number of arguments `arguments` (`ArgumentError`), no such object `no_object` (`NameError`); [Errors](#errors)), `TimeoutError` when no answer came in time (also at once when nobody answers that key), `Disconnected`, `EncodeError` (before anything is sent) for a value MessagePack cannot carry. A block cannot be sent (`ArgumentError`). |
770
815
  | `proxy.asterism_call(name, *args, **kw)` | the remote return value | The same call by the method's name (a String or Symbol): for names a proxy cannot forward (those `Object` and `Kernel` have: `display`, `hash`, `class`, `fail`, ...) and names that are not Ruby identifiers. `proxy.async.asterism_call(...)` returns a `Future`. |
771
816
  | `proxy.async.<method>(...)` | `Future` | Sends and returns at once. `EncodeError` / `Disconnected` are raised here. |
772
- | `future.done?` | true / false | Never waits (`Asterism.poll` moves it on). True once the answer came, the time ran out or the connection closed. |
817
+ | `future.done?` | true / false | Never waits (`net.poll` moves it on). True once the answer came, the time ran out or the connection closed. |
773
818
  | `future.value` | the return value | Waits (polling) if not done; raises like a waiting call. `future.took` (seconds) / `took_ms`: time to the answer. |
774
819
  | `proxy.respond_to?(name)` / `proxy.remote_methods` | true / false, `[Symbol]` | From the object's meta (fetched once, `proxy.asterism_refresh` forgets it). `respond_to?` is false when the object does not answer; `remote_methods` raises then. (`proxy.methods` returns the same with a deprecation warning; from 1.0 it is `Object#methods`.) |
775
- | `proxy.asterism_meta` / `proxy.asterism_path` | Hash, String | `{"methods" => [{"name" => name, "arity" => n}, ...]}` |
776
- | `Asterism.each(pattern = "**") { \|proxy\| }` | count (Array without a block) | The exposed objects alive now (this application's own included) whose `<node>/<app>/<object>` matches; `*` is one chunk, `**` any number. 1.0 returns the proxies from the block form instead of their number (Ruby's `each` returns its receiver); write `Asterism.each(pattern).size` for the count. |
777
- | `Asterism.nodes` | `[String]` | Node IDs alive now, this one first. |
778
- | `Asterism.apps(pattern = "*/*")` | `[String]` | The applications alive now, `"<node>/<app>"` (from their liveliness tokens; this one first). |
779
- | `Asterism.connected?` / `node_id` / `app` / `exposed` / `lost_reason` | | |
780
- | `Asterism.reconnecting?` | true / false | True while the router is away and the binding opens the connection again ([When the connection is lost](#when-the-connection-is-lost)). |
781
- | `Asterism.session` | `Asterism::Zenoh::Session` | The connection's own session, for put / subscribe / a ROS 2 node on the same connection ([One connection](#one-connection-asterismsession)). The same object until the connection closes. `Disconnected` when not connected. Its `close` does nothing (warns once); `Asterism.close` closes it. |
782
- | `Asterism.close` | nil | Withdraws every exposed object. Idempotent. |
783
- | `Asterism.profile(kind:, name:, host:, icon:)` / `Asterism.profile` | Hash | This node's profile: sets the fields given and returns it; without arguments, returns it. See [Profiles](#profiles). |
784
- | `Asterism.profile_of(node, icon: true, timeout: 2.0)` | Hash or nil | Another node's profile, nil when it does not answer (an older version, a ROS 2 node). |
785
- | `Asterism.status(hash = nil, **fields)` / `Asterism.status` | Hash or nil | This application's status: a Hash is the whole status, keywords change those fields (nil removes one); put on the network when it changes. Without arguments, returns it. See [Status](#status). |
786
- | `Asterism.status_of(node, app, timeout: 2.0)` | Hash or nil | Another application's status, nil when it has none or does not answer. |
820
+ | `proxy.asterism_meta` / `proxy.asterism_path` / `proxy.asterism_connection` | Hash, String, `Connection` | `{"methods" => [{"name" => name, "arity" => n}, ...]}` |
821
+ | `net.each(pattern = "**") { \|proxy\| }` | count (Array without a block) | The exposed objects alive now (this application's own included) whose `<node>/<app>/<object>` matches; `*` is one chunk, `**` any number. 1.0 returns the connection from the block form instead of the number (Ruby's `each` returns its receiver); write `net.each(pattern).size` for the count. |
822
+ | `net.nodes` | `[String]` | Node IDs alive now, this one first. |
823
+ | `net.apps(pattern = "*/*")` | `[String]` | The applications alive now, `"<node>/<app>"` (from their liveliness tokens; this one first). |
824
+ | `net.node_id` / `app` / `path` / `connected?` / `exposed` / `lost_reason` | | `path` is `"<node>/<app>"` |
825
+ | `net.run_id` | Integer | This connection's run id: 16 random bits picked when it opened, sent with each value of its topics (a reader that sees another one knows it connected again). |
826
+ | `net.reconnecting?` | true / false | True while the router is away and the binding opens the connection again ([When the connection is lost](#when-the-connection-is-lost)). |
827
+ | `net.session` | `Asterism::Zenoh::Session` | The connection's own session, for put / subscribe / a ROS 2 node on the same connection ([The connection's session](#the-connections-session-netsession)). The same object until the connection closes. `Disconnected` when not connected. Its `close` does nothing (warns once); `net.close` closes it. |
828
+ | `net.close` | nil | Withdraws every exposed object, topic and subscription, and closes the session. Idempotent. A closed connection is not opened again: `Asterism.connect` makes a new one. |
829
+ | `net.profile(kind:, name:, host:, icon:)` / `net.profile` | Hash | This node's profile (the node of this connection): sets the fields given and returns it; without arguments, returns it. See [Profiles](#profiles). |
830
+ | `net.profile_of(node, icon: true, timeout: 2.0)` | Hash or nil | Another node's profile, nil when it does not answer (an older version, a ROS 2 node). |
831
+ | `net.protocol_of(node, timeout: 2.0)` / `net.protocol_of("node/app")` | Integer or nil | The protocol an application speaks, from its token (`asterism/<node>/<app>/protocol/2`; a token without the number is protocol 1), nil while it is not there. For a node: what its applications' tokens say (the lowest when they differ); for a node none of whose applications is known, its profile's `protocol` (0 when it says none, nil when it does not answer). Every connection says once (warning output on CRuby, the log on a board) about each application of another protocol; it is not refused, its values still flow, calls between them are refused with the error kind `protocol`. |
832
+ | `net.status(hash = nil, **fields)` / `net.status` | Hash or nil | This application's status: a Hash is the whole status, keywords change those fields (nil removes one); put on the network when it changes. Without arguments, returns it. See [Status](#status). |
833
+ | `net.status_of(node, app, timeout: 2.0)` | Hash or nil | Another application's status, nil when it has none or does not answer. |
834
+ | `net.publish(name, type:, unit:, desc:, ts:, encoding:, shared: nil)` | `Asterism::Topic` | Declares a topic of this application; `topic.put(value)` sends. `shared: :node` / `:global` puts it on a shared place instead. See [Topics](#topics) and [Shared places](#shared-places). |
835
+ | `net.subscribe(path, depth: nil) { \|v, info\| }` | `Asterism::Subscription` | The values on `<node>/<app>/<topic>` (wildcards allowed), or a shared place's `<node>/@shared/<name>` / `@shared/<name>`, from `net.poll`; `close` ends it. |
836
+ | `net.pubs_of(node, app)` / `net.types_of(node, app)` | Hash or nil | Another application's topics (shared ones under their entries) / types, `{}` when it has none, nil when it does not answer. |
837
+ | `net.publishers_of(path, timeout: 2.0)` | Hash | The applications that declare a shared key (`@shared/<name>`, `<node>/@shared/<name>`, `*` for the node): `{"<node>/<app>" => declaration}`. |
838
+ | `net.declaration_of(info)` / `net.type_of(info)` | Hash / Integer or `[name, definition]`, or nil | A received value's declaration / type, from its sender (`info.from`). Asked once, then kept for that sender until it puts its `@pubs` again or leaves: cheap to call for each value. |
839
+ | `net.define_type(name, fields, desc: nil)` | Hash | An application type, told by `@profile?types`. |
840
+ | `net.published` / `net.unpublish(topic or name)` / `net.unsubscribe(sub)` | | |
787
841
 
788
842
  ## Describing the methods
789
843
 
@@ -794,11 +848,11 @@ descriptions; `asterism objects` prints them). Give them at `expose`, next
794
848
  to the numbers:
795
849
 
796
850
  ```ruby
797
- Asterism.expose("othello1", table, caller: :from, doc: "An othello table. Call view for the board.",
798
- methods: { join: 1, # a number, as before
799
- "move" => { args: %w[token n square],
800
- doc: "Plays square (\"d3\") on the board version n of view." },
801
- view: { args: [:token], doc: "The board as this member sees it." } })
851
+ net.expose("othello1", table, caller: :from, doc: "An othello table. Call view for the board.",
852
+ methods: { join: 1, # a number, as before
853
+ "move" => { args: %w[token n square],
854
+ doc: "Plays square (\"d3\") on the board version n of view." },
855
+ view: { args: [:token], doc: "The board as this member sees it." } })
802
856
  ```
803
857
 
804
858
  - The names give the number of arguments checked (`args: %w[a b]` is 2);
@@ -815,34 +869,41 @@ A node tells what it is (0.5.0): what Ruby runs it, where, a display name
815
869
  and an icon. A console draws it with that; anyone can ask.
816
870
 
817
871
  ```ruby
818
- Asterism.profile(name: "Rover", icon: File.binread("rover.png")) # this node's (any time)
819
- Asterism.profile
820
- # => {"protocol" => 1, "kind" => "cruby", "name" => "Rover", "icon" => "\x89PNG...", "icon_hash" => "2a8c0626"}
821
- Asterism.profile_of("fmruby-aaaaaa")
822
- # => {"protocol" => 1, "kind" => "family_mruby", "host" => "atoms3r", "icon" => "\x89PNG...", "icon_hash" => "..."}
823
- Asterism.profile_of("fmruby-aaaaaa", icon: false) # the same without the icon bytes
824
- Asterism.profile_of("an-older-node") # => nil
872
+ net.profile(name: "Rover", icon: File.binread("rover.png")) # this node's (any time)
873
+ net.profile
874
+ # => {"protocol" => 2, "kind" => "cruby", "name" => "Rover", "icon" => "\x89PNG...", "icon_hash" => "2a8c0626"}
875
+ net.profile_of("fmruby-aaaaaa")
876
+ # => {"protocol" => 2, "kind" => "family_mruby", "host" => "atoms3r", "icon" => "\x89PNG...", "icon_hash" => "..."}
877
+ net.profile_of("fmruby-aaaaaa", icon: false) # the same without the icon bytes
878
+ net.profile_of("an-older-node") # => nil
879
+ Asterism.profile_defaults(kind: :family_mruby, host: "atoms3r") # what every node of the program starts with
825
880
  ```
826
881
 
827
882
  | Field | Value | Default |
828
883
  |---|---|---|
829
- | `protocol` | set by Asterism, never given: the wire protocol the node speaks (`Asterism::PROTOCOL`, 1). A node whose profile has none speaks protocol 0 (asterism before 0.7.0), which 0.7.0 does not talk to | |
884
+ | `protocol` | set by Asterism, never given: the wire protocol the node speaks (`Asterism::PROTOCOL`, 2). A node whose profile has none speaks protocol 0 (asterism before 0.7.0), which this version does not talk to | |
830
885
  | `kind` | what Ruby runs the node: `family_mruby`, `picoruby`, `cruby`, `console` (a lower-case word: `a-z`, `0-9`, `_`, up to 32 bytes; other words are allowed) | `cruby` on CRuby, `picoruby` on mruby / PicoRuby; Family mruby's firmware sets `family_mruby` |
831
886
  | `host` | where it runs, e.g. `atoms3r`, `tab5`, `p4nano`, `browser`, `sim` (up to 32 bytes) | none; Family mruby's firmware sets it from the board |
832
887
  | `name` | a display name (up to 64 bytes) | none |
833
888
  | `icon` | the bytes of a PNG (a binary String; sent as a MessagePack bin): at most 8 KB and 256x256 (32x32 is the size meant). PNG only: an SVG can carry scripts | the file at `Asterism.default_icon_path` when it is there: on CRuby the gem's `data/icon.png` (a ruby), on the boards `/usr/share/asterism/icon.png` |
834
889
  | `icon_hash` | set by Asterism, never given: the icon's summary (8 hex digits: the Adler-32 of the PNG's chunk CRCs, so a board computes it from a few bytes) | |
835
890
 
836
- - **Setting.** `Asterism.profile(**fields)` changes the fields given and keeps
891
+ - **Setting.** `net.profile(**fields)` changes the fields given and keeps
837
892
  the others; `nil` leaves `name` / `host` out, goes back to the default
838
893
  `kind`, and means no icon for `icon:`. It raises `ArgumentError` for a
839
894
  field it does not accept (an unknown name, a `kind` that is not a word, an
840
- icon that is not a PNG, larger than 8 KB or 256x256). It may be called
841
- before connecting and at any time after; the profile belongs to the
842
- process (the VM on a board) and survives `close`. A firmware can set its
843
- defaults with the same call before the application runs (Family mruby
844
- sets `kind`, `host` and, through `/usr/share/asterism/icon.png`, the icon).
845
- - **Reading.** `Asterism.profile_of(node)` asks `asterism/<node>/@profile`
895
+ icon that is not a PNG, larger than 8 KB or 256x256). The profile is the
896
+ node's, not the connection's: every connection of this program made as
897
+ that node has the same one (a change on one is the others' too), and it
898
+ outlives them (a connection made again as that node finds it).
899
+ - **The program's defaults.** `Asterism.profile_defaults(**fields)` takes the
900
+ same fields, before connecting or at any time: what every node of this
901
+ program has where its own connections set nothing (a firmware sets them
902
+ before the application runs: Family mruby sets `kind`, `host` and,
903
+ through `/usr/share/asterism/icon.png`, the icon). A node's own field
904
+ wins, also a `nil` (`net.profile(host: nil)` leaves the host out over a
905
+ default).
906
+ - **Reading.** `net.profile_of(node)` asks `asterism/<node>/@profile`
846
907
  and waits like a call (`timeout:` / `timeout_ms:`); this node's own comes
847
908
  without the network. The answer is cleaned (`Asterism::Profile.check`):
848
909
  only the fields above, each checked; an icon that is not an acceptable
@@ -854,10 +915,12 @@ Asterism.profile_of("an-older-node") # => nil
854
915
  subscribe to `asterism/*/@profile` to follow the changes (and fetch the
855
916
  icon again only when `icon_hash` changed). Older nodes neither answer nor
856
917
  put.
857
- - **Several applications of one node** (a board running two): each answers
858
- for the node, and `profile_of` takes the first answer. Give them the same
859
- profile (Family mruby's firmware defaults are the same in each), or set it
860
- in one and read the notices, where the last change wins.
918
+ - **Several applications of one node.** Each connection answers for the
919
+ node, and `profile_of` takes the first answer. In one program they answer
920
+ the same (above). Applications of one node in different programs (a board
921
+ running two, each in a VM of its own) each answer their own: give them
922
+ the same defaults (Family mruby's firmware sets the same in each), or set
923
+ it in one and read the notices, where the last change wins.
861
924
  - `Asterism::Profile.png_info(bytes)` gives `[width, height, icon_hash]` of
862
925
  an acceptable PNG (nil otherwise), for a tool that wants to check an icon
863
926
  first.
@@ -869,86 +932,244 @@ host has open and who sits at them, a battery level, a mode. The profile
869
932
  says once what a node is; the status is the application's and changes.
870
933
 
871
934
  ```ruby
872
- Asterism.status(tables: 3, humans: 2) # sets those fields, keeps the others
873
- Asterism.status(humans: nil) # nil removes a field
874
- Asterism.status({ "mahjong1" => { "st" => "play", "humans" => 1 } }) # a Hash: the whole status
875
- Asterism.status # => {"mahjong1" => {...}} (nil when none was set)
876
- Asterism.status_of("games", "games") # another application's, or nil
935
+ net.status(tables: 3, humans: 2) # sets those fields, keeps the others
936
+ net.status(humans: nil) # nil removes a field
937
+ net.status({ "mahjong1" => { "st" => "play", "humans" => 1 } }) # a Hash: the whole status
938
+ net.status # => {"mahjong1" => {...}} (nil when none was set)
939
+ net.status_of("games", "games") # another application's, or nil
877
940
  ```
878
941
 
879
- - **On the network.** `asterism/<node>/<app>/@status`
880
- ([docs/protocol.md](docs/protocol.md) 8): the application answers a get
881
- there with its status, and puts it there when it changes (setting the
882
- same status again puts nothing), at connect and after a lost connection
883
- comes back. An application that never set one answers nothing.
942
+ - **On the network.** The application's own profile,
943
+ `asterism/<node>/<app>/@profile` ([docs/protocol.md](docs/protocol.md)
944
+ 8), answers the status (`?status`; with no parameters the status and
945
+ the topics), and the status is put on `asterism/<node>/<app>/@status`
946
+ when it changes (setting the same status again puts nothing) and after
947
+ a lost connection comes back. An application that has neither
948
+ a status nor a topic nor a type answers nothing.
884
949
  - **The value.** A Hash with String (or Symbol) keys; the values are
885
950
  anything a call can carry, nested at most 4 levels below the Hash, and
886
951
  the whole packs into 1024 bytes at most. `ArgumentError` otherwise.
887
- Whoever may read `asterism/*/*/@status` reads it: counts and states, not
888
- secrets.
952
+ Whoever may read `asterism/*/*/@profile` or `asterism/*/*/@status` reads
953
+ it: counts and states, not secrets.
889
954
  - **Following.** Subscribe to `asterism/*/*/@status` and read each put with
890
955
  `Asterism::Status.parse(key, payload)` (`[node, app, status]` or nil); on
891
956
  CRuby, `net.on_status("*/*") { |node, app, status| }`. Only changes are
892
957
  put: ask `status_of` once for an application that appeared.
893
- - **Behind access control.** `@status` is a verbatim chunk: `asterism/**`
894
- does not match it. A router's rules need `asterism/*/*/@status` for a
895
- reader (query, subscription) and `asterism/<node>/*/@status` for the
896
- application (put, queryable, reply).
897
- - Kept across `connect` and `close`, like the profile (it belongs to the
898
- process, or the VM on a board).
958
+ - **Behind access control.** `@profile`, `@status` and `@pubs` are
959
+ verbatim chunks: `asterism/**` does not match them. A router's rules
960
+ need `asterism/*/*/@profile` (query) and `asterism/*/*/@status`,
961
+ `asterism/*/*/@pubs` (subscription) for a reader, and the same under
962
+ `asterism/<node>/*/` for the application (queryable and reply, put).
963
+ - The status is the connection's (each connection is one application). It
964
+ stays readable after `close` but goes nowhere; a new connection starts
965
+ without one.
966
+
967
+ ## Topics
968
+
969
+ An application streams values on topics it declares: the type, unit and
970
+ description are said once, and each value goes with only a sequence number
971
+ (and the sender's time, when asked for).
899
972
 
900
- ## One connection: `Asterism.session`
973
+ ```ruby
974
+ imu = net.publish("imu", type: :vector3, unit: "m/s2", desc: "acceleration", ts: true)
975
+ imu.put([0.1, 0.0, 9.8]) # MessagePack, no encoding
976
+ cam = net.publish("camera", type: :image, encoding: "image/jpeg")
977
+ cam.put(File.binread("frame.jpg")) # the bytes as they are
978
+ net.define_type("mygame/board.strokes", [["pts", "int[]"], ["color", "str"]], desc: "one stroke")
979
+ net.publish("board1/strokes", type: "mygame/board.strokes")
980
+
981
+ net.subscribe("*/demo/imu") do |v, info| # from net.poll
982
+ puts "#{info.node} #{v.inspect} seq=#{info.seq} lost=#{info.lost} at #{info.time}"
983
+ end
984
+ net.pubs_of("linux", "demo") # => {"imu" => {"t" => 2, "u" => "m/s2", ...}}
985
+ ```
986
+
987
+ - **Keys.** `asterism/<node>/<app>/<topic>` (a topic name may have several
988
+ chunks). The declarations are answered at `@profile?pubs` and put on
989
+ `asterism/<node>/<app>/@pubs` when they change; types at `@profile?types`
990
+ ([docs/protocol.md](docs/protocol.md) 9-12).
991
+ - **define_type** fields: a type by its name, never a number: a built-in
992
+ one (`"vector3"` or `:vector3`, an array `"vector3[]"`), a basic one
993
+ (`"int"`, `"str[]"`, `"any"` for a value of any shape) or another
994
+ application type's name; `[]` repeats for arrays of arrays (`"int[][]"`).
995
+ The values are maps keyed by the field names, which go with every value:
996
+ short names (one or two letters: `"p"`, `"c"`) keep them small.
997
+ - **type:** a built-in type (`:number`, `:vector3`, `:pose`, `:image`,
998
+ `:state`, `:log`, `:text`, or its number `Asterism::Types::VECTOR3`) or an
999
+ application type's name (a String). **encoding:** one of Zenoh's
1000
+ encodings with a number (`image/jpeg`, `image/png`, `text/plain`, ...):
1001
+ the values are then Strings, sent as they are.
1002
+ - **info** (`Asterism::SampleInfo`): `key`, `node`, `app`, `name`, `seq`,
1003
+ `time` (the sender's, ms since 1970, with `ts: true`), `encoding`
1004
+ (`"msgpack"` for a MessagePack value), `timestamp` (the router's, when it
1005
+ stamped the value), `lost` (values of this key missed since the last
1006
+ one) and `restarted?` (the sender started a new run: it connected again,
1007
+ its `run_id` changed, and nothing is counted lost; or its numbers went
1008
+ back), `run_id` (the sender's connection's), `path` (the
1009
+ key below `asterism/`), `from` (the sender, `"<node>/<app>"`) and
1010
+ `shared` (nil, or `:node` / `:global` on a shared place). A block that
1011
+ takes only `|v|` gets the value.
1012
+ - **Numbers.** Each topic's numbers are the connection's: publishing a name
1013
+ again on the same connection goes on from its last number; a new
1014
+ connection starts at 0 with another run id. When an application leaves
1015
+ (its token goes), a subscription forgets its numbers: its next value is
1016
+ a first one (`lost` 0).
1017
+ - **The present value.** Values that did not come are counted, not given
1018
+ back: a topic whose present value a reader needs is also answered by a
1019
+ method of an exposed object, which the reader calls at the start and
1020
+ again when `info.lost > 0` or `info.restarted?`
1021
+ ([docs/protocol.md](docs/protocol.md) 9.6).
1022
+ - Topics and subscriptions end with the connection; the types and the
1023
+ status are the connection's too. After a new `connect`, declare them on
1024
+ the new connection.
1025
+ - A topic that belongs to another application is declared by a
1026
+ connection that is that application
1027
+ ([Several connections](#several-connections)).
1028
+
1029
+ ### Shared places
1030
+
1031
+ Data with no single owner goes on a shared place: a node's
1032
+ `asterism/<node>/@shared/<name>` (what the node emits: its tables'
1033
+ spectators' view, fed by whichever of its programs runs a table) or the
1034
+ network's `asterism/@shared/<name>` (a meeting place for the network's
1035
+ trusted members). Each sender declares the key in its own `@pubs`, with its
1036
+ own types; several applications may put on one key, and each value says
1037
+ its sender.
1038
+
1039
+ ```ruby
1040
+ t = net.publish("spectate/t1/state", shared: :node, type: "mygame/table")
1041
+ t.put(state) # asterism/<node>/@shared/spectate/t1/state
1042
+ g = net.publish("lobby", shared: :global, type: :text)
1043
+
1044
+ net.subscribe("*/@shared/spectate/**") do |v, info|
1045
+ info.from # => "linux/room01" (the sender)
1046
+ info.lost # counted per sender
1047
+ net.type_of(info) # the sender's type: 7, or ["mygame/table", definition]
1048
+ end
1049
+ net.publishers_of("linux/@shared/spectate/t1/state") # => {"linux/games" => {"t" => "mygame/table"}, ...}
1050
+ net.pubs_of("linux", "games") # => {"linux/@shared/spectate/t1/state" => {...}}
1051
+ ```
901
1052
 
902
- An application that also puts, subscribes or runs a ROS 2 node uses the
903
- object layer's own session for it (0.6.0) instead of opening a second one:
1053
+ - **Entries.** A shared topic is declared under the key below `asterism/`:
1054
+ `<node>/@shared/<name>` or `@shared/<name>` (an application's own topic
1055
+ under its name). `net.published` lists entries; `net.unpublish(topic)` or
1056
+ `net.unpublish(name, shared: :node)`.
1057
+ - **Attachment.** `[seq, run id, ms or nil, "<node>/<app>"]`; the numbers
1058
+ are each sender's, and the reader counts `lost` per key and sender. On a
1059
+ node's place, a sender of another node counts as none.
1060
+ - **Types.** Two senders may define one type name differently: read a
1061
+ value's type from its sender (`net.type_of(info)`,
1062
+ `net.declaration_of(info)`), not from another sender of the key.
1063
+ - **Wildcards.** `@shared` is a verbatim chunk: `net.subscribe("**")` and
1064
+ `"<node>/**"` do not reach it; subscribe to `"*/@shared/**"` and
1065
+ `"@shared/**"`.
1066
+ - **Who may put there** is the router's: a node's place by its own node
1067
+ (`asterism/${node}/@shared/**`), the network's by the roles an
1068
+ administrator grants it to ([docs/protocol.md](docs/protocol.md) 17).
1069
+
1070
+ ## The connection's session: `net.session`
1071
+
1072
+ An application that also puts, subscribes or runs a ROS 2 node uses its
1073
+ connection's own session for it (0.6.0) instead of opening another:
904
1074
 
905
1075
  ```ruby
906
- Asterism.connect("tcp/192.0.2.2:7447", node: "fmruby-aaaaaa", app: "game")
907
- Asterism.expose("othello", game, methods: [:move, :state])
908
- s = Asterism.session # an Asterism::Zenoh::Session
909
- s.put("asterism/fmruby-aaaaaa/game/othello/state", MessagePack.pack(state))
910
- moves = s.subscribe("asterism/*/game/othello/state") # moves.each_pending in the update loop
1076
+ net = Asterism.connect("tcp/192.0.2.2:7447", node: "fmruby-aaaaaa", app: "game")
1077
+ net.expose("othello", game, methods: [:move, :state])
1078
+ s = net.session # an Asterism::Zenoh::Session
1079
+ s.put("asterism/fmruby-aaaaaa/game/othello/log", MessagePack.pack(line))
1080
+ moves = s.subscribe("asterism/*/game/othello/log") # moves.each_pending in the update loop
911
1081
  node = Asterism::ROS::Node.new(s, "brain") # a ROS 2 node with the same Zenoh ID
912
1082
  cmd = node.publisher("/cmd_vel", "geometry_msgs/msg/Twist")
913
- # update loop: Asterism.poll; node.poll
1083
+ # update loop: net.poll; node.poll
914
1084
  ```
915
1085
 
916
1086
  CRuby API:
917
1087
 
918
1088
  ```ruby
919
1089
  Asterism.connect(router, node: "mypc", app: "demo") do |net|
920
- net.session.subscribe("asterism/*/game/**") { |sample| p sample.key } # on the receiving thread
921
- ros = Asterism::ROS::Connection.new(net.session)
1090
+ net.zenoh.subscribe("asterism/*/game/**") { |sample| p sample.key } # on the receiving thread
1091
+ ros = Asterism::ROS::Connection.new(net.zenoh)
922
1092
  ros.node("brain").subscribe("/odom", "nav_msgs/msg/Odometry") { |odom| puts odom.pose.pose.position.x }
923
1093
  net.run
924
1094
  end
925
1095
  ```
926
1096
 
927
- - **Why one.** A router that lets each pass in once (a one-time password
928
- at a `wss://` door) lets only the first session in; and a ROS 2 node on
929
- the object layer's session has the node's Zenoh ID, so a console draws it
930
- inside the node.
931
- - **Who closes it.** The session is Asterism's. `Asterism.session.close`
932
- (and `net.session.close`) does nothing but warn once, so a library handed
933
- the session cannot break the connection. `Asterism.close`, the end of the
1097
+ - **Why the same.** A ROS 2 node on the application's session has the
1098
+ application's Zenoh ID, so a console draws it inside the node; every
1099
+ session costs a TLS link and a router seat on a board; and a router that
1100
+ lets each pass in once (a one-time password at a `wss://` door) lets only
1101
+ the first session in.
1102
+ - **Who closes it.** The session is the connection's. `net.session.close`
1103
+ (and `net.zenoh.close`) does nothing but warn once, so a library handed
1104
+ the session cannot break the connection. `net.close`, the end of the
934
1105
  connect block and a lost connection close it, and with it everything
935
1106
  declared on it: the application's subscribers, publishers, ROS 2 nodes.
936
1107
  Close those yourself when you are done with them earlier (`sub.close`,
937
1108
  `node.close`; on CRuby `ros.close` withdraws its nodes and leaves the
938
1109
  rest).
939
- - **After a lost connection** (`Asterism.poll` returned false), connect
940
- again, take `Asterism.session` again (a new object) and declare again
941
- what you had on the old one.
942
- - **Polling.** `Asterism.poll` polls the session; `node.poll` polls it too
1110
+ - **After a lost connection** (`net.poll` returned false), connect
1111
+ again, take the new connection's session and declare again what you had
1112
+ on the old one.
1113
+ - **Polling.** `net.poll` polls the session; `node.poll` polls it too
943
1114
  and only then serves the node. Each subscriber, queryable and node keeps
944
1115
  what came for it, so the order does not matter and nothing is taken from
945
1116
  another. Your own `put` does not come back to your own subscriber on the
946
1117
  same session.
947
1118
  - **Keys.** Keep your keys out of the object layer's: `asterism/<node>/<app>/**`
948
- is answered by its queryable (`get` there is a call), `asterism/<node>/<app>` and
949
- `asterism/<node>/<app>/<object>` are its liveliness tokens. Putting under
950
- `asterism/<node>/<app>/<object>/<anything>` (a state, a log) is fine:
951
- puts and subscriptions do not meet queryables or liveliness.
1119
+ is answered by its queryable (`get` there is a call), `asterism/<node>/<app>/protocol/2` and
1120
+ `asterism/<node>/<app>/<object>` are its liveliness tokens. Values of your
1121
+ own under `asterism/<node>/<app>/...` are best declared as topics
1122
+ ([Topics](#topics)); a plain put there is fine too: puts and
1123
+ subscriptions do not meet queryables or liveliness.
1124
+
1125
+ ## Several connections
1126
+
1127
+ A connection is one application: its liveliness token, its objects, its
1128
+ status, topics and types, its own profile (`asterism/<node>/<app>/@profile`).
1129
+ A program that is several applications opens a connection for each,
1130
+ as the same node or another:
1131
+
1132
+ ```ruby
1133
+ game = Asterism.connect(router, node: "host", app: "games")
1134
+ game.expose("lobby", lobby, methods: { tables: 0 })
1135
+ room = Asterism.connect(router, node: "host", app: "room01") # a room as its own application
1136
+ room.expose("table1", table, methods: { move: 2, view: 1 })
1137
+ room.publish("table1/state", type: "mygame/table.state").put(state)
1138
+ room.publish("spectate/table1/state", shared: :node, # what the spectators see,
1139
+ type: "mygame/table.state") # on the node's shared place
1140
+ loop do
1141
+ Asterism.poll_all # or game.poll; room.poll
1142
+ ...
1143
+ end
1144
+ room.close # game goes on
1145
+ ```
1146
+
1147
+ - **Each its own.** Objects, `status`, `publish`, `subscribe`,
1148
+ `define_type`, `on_join` and the rest are the connection's. The others
1149
+ see each connection as an application (`apps`, `on_app_join`), call its
1150
+ objects through the network (with the router's access control, as any
1151
+ other application) and get its values (a connection's own values do not
1152
+ come back to it, another connection's do).
1153
+ - **The node's one profile.** Every connection answers
1154
+ `asterism/<node>/@profile` for its node, all with the same profile
1155
+ ([Profiles](#profiles)).
1156
+ - **Waiting.** A call waiting on one connection keeps answering the calls
1157
+ of the program's other connections (one of them may be the one called),
1158
+ and the waits of all of them nest at most `MAX_NESTING` deep in all.
1159
+ Their `on_join` / `subscribe` blocks still run only from their own
1160
+ `poll`. On CRuby, one lock (`Asterism::LOCK`) serializes them, and each
1161
+ may have its own receiving thread.
1162
+ - **The same `<node>/<app>` twice** is refused: `Asterism.connect` raises
1163
+ `Error` when it is open in this program or alive on the network
1164
+ (docs/protocol.md 6.3).
1165
+ - **What each costs.** Every connection is a Zenoh session of its own: on
1166
+ a board a TCP or TLS link (the TLS one with its buffers), a seat at the
1167
+ router, the queryables of the object layer (calls, the node's profile,
1168
+ and the application's profile once it has a status, topic or type) and
1169
+ a liveliness watch. One connection is the usual on a board; open a
1170
+ second only for a second application. zenoh-pico sessions of one
1171
+ program reach each other through a router only (a session's opening
1172
+ waits for the other's poll, so they cannot be peers of each other).
952
1173
 
953
1174
  ## Errors
954
1175
 
@@ -983,7 +1204,7 @@ is closed (1.0: `Disconnected`, as the object layer).
983
1204
 
984
1205
  | What | Default | Changed by |
985
1206
  |---|---|---|
986
- | A proxy call | 2 s | `Asterism[path, timeout:]` / `timeout_ms:`; `DEFAULT_TIMEOUT` (s), `DEFAULT_TIMEOUT_MS` |
1207
+ | A proxy call | 2 s | `net[path, timeout:]` / `timeout_ms:`; `DEFAULT_TIMEOUT` (s), `DEFAULT_TIMEOUT_MS` |
987
1208
  | A service call | 2 s | `client.call(..., timeout:)` / `timeout_ms:`; `Client::DEFAULT_TIMEOUT` |
988
1209
  | `get`, `liveliness_get`, a querier | 2 s | `timeout:` / `timeout_ms:` |
989
1210
  | Connecting | 3 s | `connect_timeout:` (CRuby); `Zenoh::CONNECT_TIMEOUT_MS` (fixed at build time on the boards) |
@@ -994,7 +1215,7 @@ is closed (1.0: `Disconnected`, as the object layer).
994
1215
  | A full queue | drops the oldest (counted in `dropped`); the CRuby API warns once | `depth:` |
995
1216
  | Pause between polls of a waiting call | 2 ms | `WAIT_STEP_MS`, `Client::WAIT_STEP_MS` |
996
1217
  | Receiving interval of the CRuby API | 2 ms | `interval:` |
997
- | Calls waiting inside each other | 4 | `MAX_NESTING` |
1218
+ | Calls waiting inside each other | 4 (all the connections of a program together) | `MAX_NESTING` |
998
1219
  | Encoding depth of a value | 16 | `Codec::MAX_DEPTH` |
999
1220
  | A profile icon | 8 KB, 256x256, PNG only | `Asterism::Profile::ICON_MAX`, `ICON_SIDE_MAX` |
1000
1221
  | `get` consolidation | `:none` (every reply; zenoh's own default is `:auto`, but services and the object layer want every reply) | `consolidation:` |
@@ -1015,7 +1236,7 @@ watch or a subscription of the CRuby API whose depth was left at the
1015
1236
  default warns once (`asterism: get demo/**: 3 replies dropped, ...`) when
1016
1237
  something was dropped; with `depth:` given it stays quiet, and `dropped`
1017
1238
  tells. The object layer warns once when its own watch dropped changes
1018
- (then `Asterism.each` and `Asterism.nodes` may miss objects).
1239
+ (then `net.each` and `net.nodes` may miss objects).
1019
1240
  `Asterism.warn_once(obj, message)` is the helper.
1020
1241
 
1021
1242
  Every `each_*` of the portable API (`each_pending`, `each_reply`,
@@ -1034,8 +1255,8 @@ for CI; `:silent` turns them off.
1034
1255
 
1035
1256
  | Deprecated (0.4.0) | Use | In 1.0 |
1036
1257
  |---|---|---|
1037
- | `Asterism[path, 2000]` (the time as a positional argument) | `Asterism[path, timeout: 2.0]` or `timeout_ms: 2000` | removed |
1038
- | A Float there (`Asterism[path, 2.0]` waits 2 ms) | `timeout: 2.0` | removed (warns with its own message now) |
1258
+ | `net[path, 2000]` (the time as a positional argument) | `net[path, timeout: 2.0]` or `timeout_ms: 2000` | removed |
1259
+ | A Float there (`net[path, 2.0]` waits 2 ms) | `timeout: 2.0` | removed (warns with its own message now) |
1039
1260
  | `session.get(key, ms, params, payload)`, `session.liveliness_get(key, ms)` | `timeout:` / `timeout_ms:`, `params:`, `payload:` | removed (a positional depth stays) |
1040
1261
  | `session.peers`, `connection.peers` | `connection_count` | removed |
1041
1262
  | `Asterism::Timeout`, `Asterism::ROS::Timeout` | `TimeoutError` | kept as aliases through 1.x |
@@ -1044,8 +1265,8 @@ for CI; `:silent` turns them off.
1044
1265
  | `q.reply(payload)` where the query's key differs from the queryable's own plain key | `q.reply(key, payload)` | answers on the queryable's key (as the CRuby API does) |
1045
1266
  | `client.call(field: ...)` with a field named `timeout` / `timeout_ms` | `request: { ... }` (or a Hash) | the keyword is the time limit (`ArgumentError` when ambiguous) |
1046
1267
 
1047
- Also changing in 1.0, without a warning now: `Asterism.each { }` and
1048
- `net.each { }` return the proxies / `self` instead of a count; the ROS
1268
+ Also changing in 1.0, without a warning now: `net.each { }` returns the
1269
+ connection instead of a count; the ROS
1049
1270
  layer raises `Disconnected` when its session is closed; the internal
1050
1271
  methods (marked `@api private` in the source) are hidden.
1051
1272
 
@@ -1065,24 +1286,27 @@ A client of a router keeps its connection when the router goes away for a
1065
1286
  while (it restarts, the line drops): the Zenoh binding opens the connection
1066
1287
  again by itself (zenoh-c on CRuby; zenoh-pico built with reconnection on
1067
1288
  the boards) and declares again everything that was declared, so the
1068
- application token, the exposed objects, the liveliness watch and what the
1069
- application declared on `Asterism.session` are all back without the
1070
- application doing anything. Meanwhile `Asterism.reconnecting?` is true,
1289
+ application token, the exposed objects, the liveliness watch, the topics
1290
+ and what the application declared on `net.session` are all back without
1291
+ the application doing anything. Meanwhile `net.reconnecting?` is true,
1071
1292
  `connected?` stays true, the other nodes leave (`on_leave`) and join again
1072
1293
  after it (`on_join`), calls raise `Asterism::Disconnected` or time out, and
1073
- puts reach nobody. The profile is told again once it is back. Measured
1294
+ puts reach nobody. The profile, the status and the topics are told again
1295
+ once it is back. Measured
1074
1296
  with zenohd 1.10.1 restarted by `docker restart` (`rake test:reconnect`,
1075
1297
  CRuby and mruby): back about 1 s after the router.
1076
1298
 
1077
1299
  A peer connection (or a build without reconnection) is closed when the
1078
1300
  peer (or the router) goes away, and is not reopened by itself. From then on
1079
- `Asterism.poll` returns `false`, `connected?` is false, `lost_reason` says
1301
+ `net.poll` returns `false`, `connected?` is false, `lost_reason` says
1080
1302
  why, and calls raise `Asterism::Disconnected`. **`Asterism::Zenoh::Error`
1081
1303
  never comes out of Asterism; it is always wrapped in `Disconnected`** (the
1082
- message is kept). The exposed objects are gone with the connection: to go
1083
- on, the application calls `connect` and `expose` again, and declares again
1084
- what it had on `Asterism.session` (subscribers, ROS 2 nodes; the old
1085
- session is closed, its entities raise `Zenoh::ClosedError`).
1304
+ message is kept). Everything of the connection is gone with it (objects,
1305
+ status, topics, types, subscriptions): to go on, the application calls
1306
+ `Asterism.connect` again (a new connection) and sets them again on it, with
1307
+ what it had on the old `net.session` (subscribers, ROS 2 nodes; the old
1308
+ session is closed, its entities raise `Zenoh::ClosedError`). The node's
1309
+ profile stays (it is the node's).
1086
1310
 
1087
1311
  ## Values
1088
1312
 
@@ -1098,8 +1322,8 @@ arguments, or an Integer outside the signed 64-bit range, raises
1098
1322
 
1099
1323
  - Hash keys: use String (or Symbol) and Integer keys for anything another
1100
1324
  language reads (Python and JavaScript refuse others by default).
1101
- - Times: send an Integer of nanoseconds since the epoch (or name the unit:
1102
- `timeout_ms`); there is no time type.
1325
+ - Times: send an Integer of milliseconds since the epoch (or name the
1326
+ unit: `timeout_ms`); there is no time type.
1103
1327
  - A keyword given as `nil` and one left out differ: the callee's default
1104
1328
  applies only to the one left out.
1105
1329
  - A JavaScript caller's `1.0` arrives as the Integer `1`.
@@ -1111,8 +1335,10 @@ exposed method can read it:
1111
1335
 
1112
1336
  ```ruby
1113
1337
  class Rover
1338
+ def initialize(net) = @net = net
1339
+
1114
1340
  def stop
1115
- c = Asterism.current_call # nil outside a call
1341
+ c = @net.current_call # nil outside a call
1116
1342
  log("stop from #{c.from}") # c.verified: :claimed (:local from this app)
1117
1343
  end
1118
1344
 
@@ -1120,12 +1346,12 @@ class Rover
1120
1346
  log("drive from #{from}")
1121
1347
  end
1122
1348
  end
1123
- Asterism.expose("rover", Rover.new, methods: { stop: 0 })
1124
- Asterism.expose("wheels", Rover.new, methods: { drive: 2 }, caller: :from)
1349
+ net.expose("rover", Rover.new(net), methods: { stop: 0 })
1350
+ net.expose("wheels", Rover.new(net), methods: { drive: 2 }, caller: :from)
1125
1351
  ```
1126
1352
 
1127
- - `Asterism.current_call` is set only while a method runs for a call (per
1128
- thread on CRuby). Calls answered while that method waits for its own
1353
+ - `net.current_call` is set only while a method of that connection runs
1354
+ for a call (per thread on CRuby). Calls answered while that method waits for its own
1129
1355
  call come on top of it and go when they end.
1130
1356
  - With `caller: :from`, a call that passes `from:` itself is refused
1131
1357
  (`RemoteError`, `remote_kind` `arguments`): `from` is always the one
@@ -1138,7 +1364,7 @@ Asterism.expose("wheels", Rover.new, methods: { drive: 2 }, caller: :from)
1138
1364
 
1139
1365
  ## Keys and encoding
1140
1366
 
1141
- Wire protocol 1. The full description, for implementations in other
1367
+ Wire protocol 2. The full description, for implementations in other
1142
1368
  languages, is [docs/protocol.md](docs/protocol.md) (with the conformance
1143
1369
  tests); why it has this shape (the review of protocol 0's Ruby-shaped
1144
1370
  parts, and what was decided) is
@@ -1146,16 +1372,18 @@ parts, and what was decided) is
1146
1372
 
1147
1373
  | Key | Zenoh | Payload |
1148
1374
  |---|---|---|
1149
- | `asterism/<node>/<app>/<object>/call/<caller>` | get / queryable | query: `{"method" => name, "args" => [...], "kwargs" => {...}}` (args and kwargs left out when empty); reply: `{"value" => value}` or `{"error" => {"kind" => ..., "class" => ..., "message" => ...}}`. `<caller>` is the calling node's ID |
1375
+ | `asterism/<node>/<app>/<object>/call/<caller>` | get / queryable | query: `{"method" => name, "protocol" => 2, "args" => [...], "kwargs" => {...}}` (args and kwargs left out when empty; a callee refuses another `protocol`, or none, with the error kind `protocol`); reply: `{"value" => value}` or `{"error" => {"kind" => ..., "class" => ..., "message" => ...}}`. `<caller>` is the calling node's ID |
1150
1376
  | `asterism/<node>/<app>/<object>/meta` | get / queryable | reply: `{"methods" => [{"name" => name, "arity" => n}, ...]}` (arity `-1` when not declared). The object may be `*` in the query: one reply per object |
1151
- | `asterism/<node>/<app>` | liveliness | the application is connected (a node is there while any of its applications or objects is) |
1377
+ | `asterism/<node>/<app>/protocol/<n>` | liveliness | the application is connected and speaks protocol `<n>` (2) (a node is there while any of its applications or objects is) |
1152
1378
  | `asterism/<node>/<app>/<object>` | liveliness | the object is exposed |
1153
- | `asterism/<node>/@profile` | get / queryable, and put | query (parameter `icon=0` for no icon): reply the node's profile, a Hash (`kind`, `host`, `name`, `icon`, `icon_hash`; [Profiles](#profiles)). The node also puts the profile without the icon at connect and on each change. `@profile` is a verbatim chunk, so `asterism/**` does not match it: the object layer's wildcards never see it. An application's own profile would go at `asterism/<node>/<app>/@profile` (not yet) |
1379
+ | `asterism/<node>/@profile` | get / queryable, and put | query (parameter `icon=0` for no icon): reply the node's profile, a Hash (`kind`, `host`, `name`, `icon`, `icon_hash`; [Profiles](#profiles)). The node also puts the profile without the icon at connect and on each change. `@profile` is a verbatim chunk, so `asterism/**` does not match it: the object layer's wildcards never see it. Every connection of the node answers it |
1380
+ | `asterism/<node>/<app>/@profile`, `@status`, `@pubs`, `<topic>` | get / queryable, put | the application's own profile (its status, topics and types), the puts of its status and topics, the values of its topics ([Status](#status), [Topics](#topics)) |
1154
1381
 
1155
- One queryable per application (`asterism/<node>/<app>/**`), and one for the
1156
- profile (`asterism/<node>/@profile`). A call whose
1382
+ One queryable per application (`asterism/<node>/<app>/**`), one for the
1383
+ node's profile (`asterism/<node>/@profile`), and one for the application's
1384
+ own profile once it has a status, topic or type. A call whose
1157
1385
  node or app is a wildcard reaches every application that exposes that
1158
- object, each answering with its own key; `Asterism` itself only sends calls
1386
+ object, each answering with its own key; Asterism itself only sends calls
1159
1387
  to one object.
1160
1388
 
1161
1389
  ## How waiting works
@@ -1167,7 +1395,9 @@ not lock up. An answered call may itself call and wait; such waits nest at
1167
1395
  most `Asterism::MAX_NESTING` (4) deep, beyond that the call raises `Error`
1168
1396
  (the caller of the outer call gets it as `RemoteError`). While a call
1169
1397
  waits, the rest of that application (drawing, input) waits too; other
1170
- applications do not.
1398
+ applications do not. A program's other connections keep answering their
1399
+ calls meanwhile (their `poll` blocks wait), and the nesting counts the
1400
+ waits of all of them.
1171
1401
 
1172
1402
  Calls to an object of the same application (`<node>/<app>` is this one) do
1173
1403
  not go out (a Zenoh session does not see its own queryable): they are run
@@ -1185,8 +1415,8 @@ took zenoh replies through blocks and fetched the meta from inside
1185
1415
  `respond_to_missing?`, overflowed the stack there. Make waiting calls from
1186
1416
  the update loop, or use `async`.
1187
1417
 
1188
- The blocks the layers call (`Asterism.on_join` / `on_leave`, the ROS
1189
- `node.subscribe` and `node.every` blocks) run from `Asterism.poll` /
1418
+ The blocks the layers call (`net.on_join` / `on_leave`, `net.subscribe`,
1419
+ the ROS `node.subscribe` and `node.every` blocks) run from `net.poll` /
1190
1420
  `node.poll`, that is on the update loop's stack, one Ruby block call deeper.
1191
1421
  The layers walk their lists with `while` loops so that nothing else stands
1192
1422
  between the update loop and the block. **Do not wait inside these blocks**
@@ -1222,13 +1452,13 @@ class Inbox < Asterism::Transfer::Inbox
1222
1452
  end
1223
1453
  inbox = Inbox.new("tmp/") # the piece files and their notes go here
1224
1454
  inbox.resume_held # a file held when it last ended goes on
1225
- Asterism.expose("inbox", inbox, methods: Asterism::Transfer::Inbox::METHODS, caller: :from)
1455
+ net.expose("inbox", inbox, methods: Asterism::Transfer::Inbox::METHODS, caller: :from)
1226
1456
  # ... inbox.tick in the update loop
1227
1457
 
1228
1458
  # 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")
1459
+ s = Asterism::Transfer::Sender.new("node-b/app/inbox", "file", "photo.png", net: net, name: "photo")
1230
1460
  until s.done?
1231
- Asterism.poll
1461
+ net.poll
1232
1462
  s.step
1233
1463
  end
1234
1464
  s.ok? ? s.answer : s.reason
@@ -1238,8 +1468,10 @@ On CRuby, `Asterism::Transfer::FileInbox` is the receiver of the kind
1238
1468
  `file` (the rules of a Family mruby machine: the senders allowed, names
1239
1469
  that stay in its directory, `foo(1).txt` beside a name already there unless
1240
1470
  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:
1471
+ a second connection (`Asterism.connect(router, node: "mypc", app: "transfer")`)
1472
+ can expose it at `<node>/transfer/inbox`, where the machines send, beside
1473
+ the program's own application. `Asterism::Transfer::Endpoint` does the
1474
+ same on a plain Zenoh connection:
1243
1475
 
1244
1476
  ```ruby
1245
1477
  conn = Asterism::Zenoh.open("tcp/127.0.0.1:7447")
@@ -1260,9 +1492,10 @@ where the build has it, else plain Ruby (`data/transfer/sha256.rb`, slow).
1260
1492
 
1261
1493
  - Objects cannot be passed by reference (a return value is a copy), blocks
1262
1494
  cannot be sent, there are no events (later stages).
1263
- - The wire protocol is protocol 1 only: nodes of asterism before 0.7.0
1264
- (protocol 0) do not see 0.7.0's objects and a call between the two
1265
- fails (a protocol 0 call is refused with `remote_kind` `protocol`).
1495
+ - The wire protocol is protocol 2 only: every node of a network moves to
1496
+ it together (nodes of asterism before 0.7.0, protocol 0, do not see its
1497
+ objects, and a protocol 0 call is refused with `remote_kind`
1498
+ `protocol`).
1266
1499
  - No authentication by default (plain TCP): a trusted LAN is assumed, or
1267
1500
  TLS through a router (CRuby; [Over TLS](#over-tls-a-router-on-the-internet)).
1268
1501
  - One object-layer connection per process (per VM on the boards).