on master help sign in
add foreign requests doc
eed6a2btinnus-napbus
arvo/clay/_index.md+4
@@ -46,3 +46,7 @@ How to merge desks programmatically.
46[Permissions](@/docs/arvo/clay/permissions.md)
46[Permissions](@/docs/arvo/clay/permissions.md)
47
47
48How to manage file permissions in clay.
48How to manage file permissions in clay.
49+
50+[Foreign Ships](@/docs/arvo/clay/foreign-requests.md)
51+
52+How to make requests to foreign ships.
arvo/clay/clay.md+4
@@ -75,3 +75,7 @@ How to merge desks programmatically.
75[Permissions](@/docs/arvo/clay/permissions.md)
75[Permissions](@/docs/arvo/clay/permissions.md)
76
76
77How to manage file permissions in clay.
77How to manage file permissions in clay.
78+
79+[Foreign Ships](@/docs/arvo/clay/foreign-requests.md)
80+
81+How to make requests to foreign ships.
arvo/clay/foreign-requests.mdnew file+146
@@ -0,0 +1,146 @@
1++++
2+title = "Foreign Ships"
3+weight = 11
4+template = "doc.html"
5++++
6+
7+Here we'll looking at making `clay` requests to a foreign ship.
8+
9+As it currently stands, it's not possible to write to a foreign desk. Additionally, remote scries are not implemented. That leaves requests to read files (`%warp`) and merge desks (`%merg`).
10+
11+## Contents
12+
13+- [%warp](#warp) - Read files and directories.
14+- [%merg](#merg) - Merge a foreign desk into a local one.
15+
16+## %warp
17+
18+To read files on a foreign desk, you just send clay a `%warp` `task:clay` (as you would for a local read) and specify the target ship in the `wer` field. For details on making such requests, see the [Read and Subscribe](@/docs/arvo/clay/read.md) document.
19+
20+Clay only allows a subset of cares to be used remotely. They are:
21+
22+- `%u` - Check for existence of file.
23+- `%v` - Get entire `dome:clay` state of a desk.
24+- `%w` - Get revision number.
25+- `%x` - Get data of file.
26+- `%y` - Get `arch` of file or directory.
27+- `%z` - Get content hash of file or directory.
28+
29+Any other `care` will crash with a `%clay-bad-foreign-request-care` error.
30+
31+The foreign ship will respond only if correct permissions have been set. See the [Permissions](@/docs/arvo/clay/permissions.md) document for details.
32+
33+Note that if you're reading a whole desk or directory, all subfolders and files must also permit reading. If even a single file does not permit you reading it, the foreign ship will not respond to the request.
34+
35+Example:
36+
37+We'll use a fake ~nes as the the foreign ship and a fake ~zod as the local ship.
38+
39+First we'll set permissions on the foreign ship. Here's a simple thread that just sends a task to clay:
40+
41+**`send-clay-task.hoon`**
42+
43+```hoon
44+/- spider
45+/+ strandio
46+=, strand=strand:spider
47+^- thread:spider
48+|= arg=vase
49+=/ m (strand ,vase)
50+^- form:m
51+=/ uarg !< (unit task:clay) arg
52+?~ uarg
53+ (strand-fail:strand %no-arg ~)
54+=/ =task:clay u.uarg
55+=/ =card:agent:gall [%pass /foo %arvo %c task]
56+;< ~ bind:m (send-raw-card:strandio card)
57+(pure:m !>(~))
58+```
59+
60+Create a file called `foo.txt` in the `%home` of ~nes. Save the above thread to `ted/send-clay/task.hoon`, `|commit %home`, and then send a `%perm` request to allow ~zod to read and write the file:
61+
62+```hoon
63+> -send-clay-task [%perm %home /foo/txt %rw `[%white (sy [%.y ~zod]~)] `[%white (sy [%.y ~zod]~)]]
64+```
65+
66+If we scry the file for its permissions with a `%p` care, we'll see ~zod is now whitelisted:
67+
68+```hoon
69+> .^([r=dict:clay w=dict:clay] %cp /===/foo/txt)
70+[r=[src=/foo/txt rul=[mod=%white who=[p={~zod} q={}]]] w=[src=/foo/txt rul=[mod=%white who=[p={~zod} q={}]]]]
71+```
72+
73+Next, save the following thread to `ted/send-task-take-gift.hoon` on ~zod:
74+
75+**`send-task-take-gift.hoon`**
76+
77+```hoon
78+/- spider
79+/+ strandio
80+=, strand=strand:spider
81+^- thread:spider
82+|= arg=vase
83+=/ m (strand ,vase)
84+^- form:m
85+=/ uarg !< (unit task:clay) arg
86+?~ uarg
87+ (strand-fail:strand %no-arg ~)
88+=/ =task:clay u.uarg
89+=/ =card:agent:gall [%pass /foo %arvo %c task]
90+;< ~ bind:m (send-raw-card:strandio card)
91+;< res=[wire sign-arvo] bind:m take-sign-arvo:strandio
92+~& +>:res
93+(pure:m !>(~))
94+```
95+
96+`|commit %home`, and send a `%x` read request for `/foo/txt` on ~nes like:
97+
98+```hoon
99+> -send-task-take-gift [%warp ~nes %home ~ %sing %x da+now /foo/txt]
100+[ %writ
101+ p
102+ [ ~
103+ [ p=[p=%x q=[%da p=~2021.5.3..08.24.22..9ce7] r=%home]
104+ q=/foo/txt
105+ r=[p=%txt q=[#t/txt=*'' q=[7.303.014 0]]]
106+ ]
107+ ]
108+]
109+```
110+
111+As you can see, we've received a `%writ` containing the requested data just as we would with a local request. Let's try a `%u`:
112+
113+```hoon
114+> -send-task-take-gift [%warp ~nes %home ~ %sing %u da+now /foo/txt]
115+[ %writ
116+ p
117+ [ ~
118+ [ p=[p=%u q=[%da p=~2021.5.3..08.26.32..88cf] r=%home]
119+ q=/foo/txt
120+ r=[p=%flag q=[#t/?(%.y %.n) q=0]]
121+ ]
122+ ]
123+]
124+```
125+
126+If we send a `%d` request however, it will crash:
127+
128+```hoon
129+> -send-receive-task [%warp ~nes %home ~ %sing %d da+now /foo/txt]
130+call: failed
131+/sys/vane/clay/hoon:<[4.085 3].[4.314 5]>
132+...
133+/sys/vane/clay/hoon:<[1.365 7].[1.365 51]>
134+[ %clay-bad-foreign-request-care
135+ [%sing mood=[care=%d case=[%da p=~2021.5.3..20.04.57..1092] path=/foo/txt]]
136+]
137+/sys/vane/clay/hoon:<[1.365 48].[1.365 50]>
138+```
139+
140+## %merg
141+
142+To merge a foreign desk into a local one, you just send clay a `%merg` `task:clay` (as you would for a local merge) and specify the foreign ship in the `her` field. For details on making such requests, see the [Merge Desks](@/docs/arvo/clay/merge.md) document.
143+
144+The foreign ship will respond only if correct permissions have been set. See the [Permissions](@/docs/arvo/clay/permissions.md) document for details. By default, a ship's `%kids` desk is set to be publicly readable, so unless permissions have been manually modified, you should be able to merge from any `%kids` desk.
145+
146+Note that all subfolders and individual files within the desk must permit your reading in order for the merge to succeed. If even one file does not permit you reading it, the remote ship will not respond to the request at all.