]> git.rkrishnan.org Git - tahoe-lafs/tahoe-lafs.git/blob - docs/frontends/webapi.txt
76d1ca2b245a4074ff8ade3dd3f2bfeb7e08940c
[tahoe-lafs/tahoe-lafs.git] / docs / frontends / webapi.txt
1
2 = The Tahoe REST-ful Web API =
3
4 1. Enabling the web-API port
5 2. Basic Concepts: GET, PUT, DELETE, POST
6 3. URLs, Machine-Oriented Interfaces
7 4. Browser Operations: Human-Oriented Interfaces
8 5. Welcome / Debug / Status pages
9 6. Static Files in /public_html
10 7. Safety and security issues -- names vs. URIs
11 8. Concurrency Issues
12
13
14 == Enabling the web-API port ==
15
16 Every Tahoe node is capable of running a built-in HTTP server. To enable
17 this, just write a port number into the "[node]web.port" line of your node's
18 tahoe.cfg file. For example, writing "web.port = 3456" into the "[node]"
19 section of $NODEDIR/tahoe.cfg will cause the node to run a webserver on port
20 3456.
21
22 This string is actually a Twisted "strports" specification, meaning you can
23 get more control over the interface to which the server binds by supplying
24 additional arguments. For more details, see the documentation on
25 twisted.application.strports:
26 http://twistedmatrix.com/documents/current/api/twisted.application.strports.html
27
28 Writing "tcp:3456:interface=127.0.0.1" into the web.port line does the same
29 but binds to the loopback interface, ensuring that only the programs on the
30 local host can connect. Using
31 "ssl:3456:privateKey=mykey.pem:certKey=cert.pem" runs an SSL server.
32
33 This webport can be set when the node is created by passing a --webport
34 option to the 'tahoe create-node' command. By default, the node listens on
35 port 3456, on the loopback (127.0.0.1) interface.
36
37 == Basic Concepts ==
38
39 As described in architecture.txt, each file and directory in a Tahoe virtual
40 filesystem is referenced by an identifier that combines the designation of
41 the object with the authority to do something with it (such as read or modify
42 the contents). This identifier is called a "read-cap" or "write-cap",
43 depending upon whether it enables read-only or read-write access. These
44 "caps" are also referred to as URIs.
45
46 The Tahoe web-based API is "REST-ful", meaning it implements the concepts of
47 "REpresentational State Transfer": the original scheme by which the World
48 Wide Web was intended to work. Each object (file or directory) is referenced
49 by a URL that includes the read- or write- cap. HTTP methods (GET, PUT, and
50 DELETE) are used to manipulate these objects. You can think of the URL as a
51 noun, and the method as a verb.
52
53 In REST, the GET method is used to retrieve information about an object, or
54 to retrieve some representation of the object itself. When the object is a
55 file, the basic GET method will simply return the contents of that file.
56 Other variations (generally implemented by adding query parameters to the
57 URL) will return information about the object, such as metadata. GET
58 operations are required to have no side-effects.
59
60 PUT is used to upload new objects into the filesystem, or to replace an
61 existing object. DELETE it used to delete objects from the filesystem. Both
62 PUT and DELETE are required to be idempotent: performing the same operation
63 multiple times must have the same side-effects as only performing it once.
64
65 POST is used for more complicated actions that cannot be expressed as a GET,
66 PUT, or DELETE. POST operations can be thought of as a method call: sending
67 some message to the object referenced by the URL. In Tahoe, POST is also used
68 for operations that must be triggered by an HTML form (including upload and
69 delete), because otherwise a regular web browser has no way to accomplish
70 these tasks. In general, everything that can be done with a PUT or DELETE can
71 also be done with a POST.
72
73 Tahoe's web API is designed for two different kinds of consumer. The first is
74 a program that needs to manipulate the virtual file system. Such programs are
75 expected to use the RESTful interface described above. The second is a human
76 using a standard web browser to work with the filesystem. This user is given
77 a series of HTML pages with links to download files, and forms that use POST
78 actions to upload, rename, and delete files.
79
80 When an error occurs, the HTTP response code will be set to an appropriate
81 400-series code (like 404 Not Found for an unknown childname, or 400 Bad Request
82 when the parameters to a webapi operation are invalid), and the HTTP response
83 body will usually contain a few lines of explanation as to the cause of the
84 error and possible responses. Unusual exceptions may result in a
85 500 Internal Server Error as a catch-all, with a default response body containing
86 a Nevow-generated HTML-ized representation of the Python exception stack trace
87 that caused the problem. CLI programs which want to copy the response body to
88 stderr should provide an "Accept: text/plain" header to their requests to get
89 a plain text stack trace instead. If the Accept header contains */*, or
90 text/*, or text/html (or if there is no Accept header), HTML tracebacks will
91 be generated.
92
93 == URLs ==
94
95 Tahoe uses a variety of read- and write- caps to identify files and
96 directories. The most common of these is the "immutable file read-cap", which
97 is used for most uploaded files. These read-caps look like the following:
98
99  URI:CHK:ime6pvkaxuetdfah2p2f35pe54:4btz54xk3tew6nd4y2ojpxj4m6wxjqqlwnztgre6gnjgtucd5r4a:3:10:202
100
101 The next most common is a "directory write-cap", which provides both read and
102 write access to a directory, and look like this:
103
104  URI:DIR2:djrdkfawoqihigoett4g6auz6a:jx5mplfpwexnoqff7y5e4zjus4lidm76dcuarpct7cckorh2dpgq
105
106 There are also "directory read-caps", which start with "URI:DIR2-RO:", and
107 give read-only access to a directory. Finally there are also mutable file
108 read- and write- caps, which start with "URI:SSK", and give access to mutable
109 files.
110
111 (Later versions of Tahoe will make these strings shorter, and will remove the
112 unfortunate colons, which must be escaped when these caps are embedded in
113 URLs.)
114
115 To refer to any Tahoe object through the web API, you simply need to combine
116 a prefix (which indicates the HTTP server to use) with the cap (which
117 indicates which object inside that server to access). Since the default Tahoe
118 webport is 3456, the most common prefix is one that will use a local node
119 listening on this port:
120
121  http://127.0.0.1:3456/uri/ + $CAP
122
123 So, to access the directory named above (which happens to be the
124 publically-writeable sample directory on the Tahoe test grid, described at
125 http://allmydata.org/trac/tahoe/wiki/TestGrid), the URL would be:
126
127  http://127.0.0.1:3456/uri/URI%3ADIR2%3Adjrdkfawoqihigoett4g6auz6a%3Ajx5mplfpwexnoqff7y5e4zjus4lidm76dcuarpct7cckorh2dpgq/
128
129 (note that the colons in the directory-cap are url-encoded into "%3A"
130 sequences).
131
132 Likewise, to access the file named above, use:
133
134  http://127.0.0.1:3456/uri/URI%3ACHK%3Aime6pvkaxuetdfah2p2f35pe54%3A4btz54xk3tew6nd4y2ojpxj4m6wxjqqlwnztgre6gnjgtucd5r4a%3A3%3A10%3A202
135
136 In the rest of this document, we'll use "$DIRCAP" as shorthand for a read-cap
137 or write-cap that refers to a directory, and "$FILECAP" to abbreviate a cap
138 that refers to a file (whether mutable or immutable). So those URLs above can
139 be abbreviated as:
140
141  http://127.0.0.1:3456/uri/$DIRCAP/
142  http://127.0.0.1:3456/uri/$FILECAP
143
144 The operation summaries below will abbreviate these further, by eliding the
145 server prefix. They will be displayed like this:
146
147  /uri/$DIRCAP/
148  /uri/$FILECAP
149
150
151 === Child Lookup ===
152
153 Tahoe directories contain named child entries, just like directories in a regular
154 local filesystem. These child entries, called "dirnodes", consist of a name,
155 metadata, a write slot, and a read slot. The write and read slots normally contain
156 a write-cap and read-cap referring to the same object, which can be either a file
157 or a subdirectory. The write slot may be empty (actually, both may be empty,
158 but that is unusual).
159
160 If you have a Tahoe URL that refers to a directory, and want to reference a
161 named child inside it, just append the child name to the URL. For example, if
162 our sample directory contains a file named "welcome.txt", we can refer to
163 that file with:
164
165  http://127.0.0.1:3456/uri/$DIRCAP/welcome.txt
166
167 (or http://127.0.0.1:3456/uri/URI%3ADIR2%3Adjrdkfawoqihigoett4g6auz6a%3Ajx5mplfpwexnoqff7y5e4zjus4lidm76dcuarpct7cckorh2dpgq/welcome.txt)
168
169 Multiple levels of subdirectories can be handled this way:
170
171  http://127.0.0.1:3456/uri/$DIRCAP/tahoe-source/docs/webapi.txt
172
173 In this document, when we need to refer to a URL that references a file using
174 this child-of-some-directory format, we'll use the following string:
175
176  /uri/$DIRCAP/[SUBDIRS../]FILENAME
177
178 The "[SUBDIRS../]" part means that there are zero or more (optional)
179 subdirectory names in the middle of the URL. The "FILENAME" at the end means
180 that this whole URL refers to a file of some sort, rather than to a
181 directory.
182
183 When we need to refer specifically to a directory in this way, we'll write:
184
185  /uri/$DIRCAP/[SUBDIRS../]SUBDIR
186
187
188 Note that all components of pathnames in URLs are required to be UTF-8
189 encoded, so "resume.doc" (with an acute accent on both E's) would be accessed
190 with:
191
192  http://127.0.0.1:3456/uri/$DIRCAP/r%C3%A9sum%C3%A9.doc
193
194 Also note that the filenames inside upload POST forms are interpreted using
195 whatever character set was provided in the conventional '_charset' field, and
196 defaults to UTF-8 if not otherwise specified. The JSON representation of each
197 directory contains native unicode strings. Tahoe directories are specified to
198 contain unicode filenames, and cannot contain binary strings that are not
199 representable as such.
200
201 All Tahoe operations that refer to existing files or directories must include
202 a suitable read- or write- cap in the URL: the webapi server won't add one
203 for you. If you don't know the cap, you can't access the file. This allows
204 the security properties of Tahoe caps to be extended across the webapi
205 interface.
206
207 == Slow Operations, Progress, and Cancelling ==
208
209 Certain operations can be expected to take a long time. The "t=deep-check",
210 described below, will recursively visit every file and directory reachable
211 from a given starting point, which can take minutes or even hours for
212 extremely large directory structures. A single long-running HTTP request is a
213 fragile thing: proxies, NAT boxes, browsers, and users may all grow impatient
214 with waiting and give up on the connection.
215
216 For this reason, long-running operations have an "operation handle", which
217 can be used to poll for status/progress messages while the operation
218 proceeds. This handle can also be used to cancel the operation. These handles
219 are created by the client, and passed in as a an "ophandle=" query argument
220 to the POST or PUT request which starts the operation. The following
221 operations can then be used to retrieve status:
222
223 GET /operations/$HANDLE?output=HTML   (with or without t=status)
224 GET /operations/$HANDLE?output=JSON   (same)
225
226  These two retrieve the current status of the given operation. Each operation
227  presents a different sort of information, but in general the page retrieved
228  will indicate:
229
230   * whether the operation is complete, or if it is still running
231   * how much of the operation is complete, and how much is left, if possible
232
233  Note that the final status output can be quite large: a deep-manifest of a
234  directory structure with 300k directories and 200k unique files is about
235  275MB of JSON, and might take two minutes to generate. For this reason, the
236  full status is not provided until the operation has completed.
237
238  The HTML form will include a meta-refresh tag, which will cause a regular
239  web browser to reload the status page about 60 seconds later. This tag will
240  be removed once the operation has completed.
241
242  There may be more status information available under
243  /operations/$HANDLE/$ETC : i.e., the handle forms the root of a URL space.
244
245 POST /operations/$HANDLE?t=cancel
246
247  This terminates the operation, and returns an HTML page explaining what was
248  cancelled. If the operation handle has already expired (see below), this
249  POST will return a 404, which indicates that the operation is no longer
250  running (either it was completed or terminated). The response body will be
251  the same as a GET /operations/$HANDLE on this operation handle, and the
252  handle will be expired immediately afterwards.
253
254 The operation handle will eventually expire, to avoid consuming an unbounded
255 amount of memory. The handle's time-to-live can be reset at any time, by
256 passing a retain-for= argument (with a count of seconds) to either the
257 initial POST that starts the operation, or the subsequent GET request which
258 asks about the operation. For example, if a 'GET
259 /operations/$HANDLE?output=JSON&retain-for=600' query is performed, the
260 handle will remain active for 600 seconds (10 minutes) after the GET was
261 received.
262
263 In addition, if the GET includes a release-after-complete=True argument, and
264 the operation has completed, the operation handle will be released
265 immediately.
266
267 If a retain-for= argument is not used, the default handle lifetimes are:
268
269  * handles will remain valid at least until their operation finishes
270  * uncollected handles for finished operations (i.e. handles for operations
271    which have finished but for which the GET page has not been accessed since
272    completion) will remain valid for one hour, or for the total time consumed
273    by the operation, whichever is greater.
274  * collected handles (i.e. the GET page has been retrieved at least once
275    since the operation completed) will remain valid for ten minutes.
276
277 Many "slow" operations can begin to use unacceptable amounts of memory when
278 operating on large directory structures. The memory usage increases when the
279 ophandle is polled, as the results must be copied into a JSON string, sent
280 over the wire, then parsed by a client. So, as an alternative, many "slow"
281 operations have streaming equivalents. These equivalents do not use operation
282 handles. Instead, they emit line-oriented status results immediately. Client
283 code can cancel the operation by simply closing the HTTP connection.
284
285 == Programmatic Operations ==
286
287 Now that we know how to build URLs that refer to files and directories in a
288 Tahoe virtual filesystem, what sorts of operations can we do with those URLs?
289 This section contains a catalog of GET, PUT, DELETE, and POST operations that
290 can be performed on these URLs. This set of operations are aimed at programs
291 that use HTTP to communicate with a Tahoe node. A later section describes
292 operations that are intended for web browsers.
293
294 === Reading A File ===
295
296 GET /uri/$FILECAP
297 GET /uri/$DIRCAP/[SUBDIRS../]FILENAME
298
299  This will retrieve the contents of the given file. The HTTP response body
300  will contain the sequence of bytes that make up the file.
301
302  To view files in a web browser, you may want more control over the
303  Content-Type and Content-Disposition headers. Please see the next section
304  "Browser Operations", for details on how to modify these URLs for that
305  purpose.
306
307 === Writing/Uploading A File ===
308
309 PUT /uri/$FILECAP
310 PUT /uri/$DIRCAP/[SUBDIRS../]FILENAME
311
312  Upload a file, using the data from the HTTP request body, and add whatever
313  child links and subdirectories are necessary to make the file available at
314  the given location. Once this operation succeeds, a GET on the same URL will
315  retrieve the same contents that were just uploaded. This will create any
316  necessary intermediate subdirectories.
317
318  To use the /uri/$FILECAP form, $FILECAP must be a write-cap for a mutable file.
319
320  In the /uri/$DIRCAP/[SUBDIRS../]FILENAME form, if the target file is a
321  writeable mutable file, that file's contents will be overwritten in-place. If
322  it is a read-cap for a mutable file, an error will occur. If it is an
323  immutable file, the old file will be discarded, and a new one will be put in
324  its place.
325
326  When creating a new file, if "mutable=true" is in the query arguments, the
327  operation will create a mutable file instead of an immutable one.
328
329  This returns the file-cap of the resulting file. If a new file was created
330  by this method, the HTTP response code (as dictated by rfc2616) will be set
331  to 201 CREATED. If an existing file was replaced or modified, the response
332  code will be 200 OK.
333
334  Note that the 'curl -T localfile http://127.0.0.1:3456/uri/$DIRCAP/foo.txt'
335  command can be used to invoke this operation.
336
337 PUT /uri
338
339  This uploads a file, and produces a file-cap for the contents, but does not
340  attach the file into the filesystem. No directories will be modified by
341  this operation. The file-cap is returned as the body of the HTTP response.
342
343  If "mutable=true" is in the query arguments, the operation will create a
344  mutable file, and return its write-cap in the HTTP respose. The default is
345  to create an immutable file, returning the read-cap as a response.
346
347 === Creating A New Directory ===
348
349 POST /uri?t=mkdir
350 PUT /uri?t=mkdir
351
352  Create a new empty directory and return its write-cap as the HTTP response
353  body. This does not make the newly created directory visible from the
354  filesystem. The "PUT" operation is provided for backwards compatibility:
355  new code should use POST.
356
357 POST /uri?t=mkdir-with-children
358
359  Create a new directory, populated with a set of child nodes, and return its
360  write-cap as the HTTP response body. The new directory is not attached to
361  any other directory: the returned write-cap is the only reference to it.
362
363  Initial children are provided as the body of the POST form (this is more
364  efficient than doing separate mkdir and set_children operations). If the
365  body is empty, the new directory will be empty. If not empty, the body will
366  be interpreted as a UTF-8 JSON-encoded dictionary of children with which the
367  new directory should be populated, using the same format as would be
368  returned in the 'children' value of the t=json GET request, described below.
369  Each dictionary key should be a child name, and each value should be a list
370  of [TYPE, PROPDICT], where PROPDICT contains "rw_uri", "ro_uri", and
371  "metadata" keys (all others are ignored). For example, the PUT request body
372  could be:
373
374   {
375     "Fran\u00e7ais": [ "filenode", {
376         "ro_uri": "URI:CHK:...",
377         "size": bytes,
378         "metadata": {
379           "ctime": 1202777696.7564139,
380           "mtime": 1202777696.7564139,
381           "tahoe": {
382             "linkcrtime": 1202777696.7564139,
383             "linkmotime": 1202777696.7564139
384             } } } ],
385     "subdir":  [ "dirnode", {
386         "rw_uri": "URI:DIR2:...",
387         "ro_uri": "URI:DIR2-RO:...",
388         "metadata": {
389           "ctime": 1202778102.7589991,
390           "mtime": 1202778111.2160511,
391           "tahoe": {
392             "linkcrtime": 1202777696.7564139,
393             "linkmotime": 1202777696.7564139
394           } } } ]
395   }
396
397  For forward-compatibility, a mutable directory can also contain caps in
398  a format that is unknown to the webapi server. When such caps are retrieved
399  from a mutable directory in a "ro_uri" field, they will be prefixed with
400  the string "ro.", indicating that they must not be decoded without
401  checking that they are read-only. The "ro." prefix must not be stripped
402  off without performing this check. (Future versions of the webapi server
403  will perform it where necessary.)
404
405  If both the "rw_uri" and "ro_uri" fields are present in a given PROPDICT,
406  and the webapi server recognizes the rw_uri as a write cap, then it will
407  reset the ro_uri to the corresponding read cap and discard the original
408  contents of ro_uri (in order to ensure that the two caps correspond to the
409  same object and that the ro_uri is in fact read-only). However this may not
410  happen for caps in a format unknown to the webapi server. Therefore, when
411  writing a directory the webapi client should ensure that the contents
412  of "rw_uri" and "ro_uri" for a given PROPDICT are a consistent
413  (write cap, read cap) pair if possible. If the webapi client only has
414  one cap and does not know whether it is a write cap or read cap, then
415  it is acceptable to set "rw_uri" to that cap and omit "ro_uri". The
416  client must not put a write cap into a "ro_uri" field.
417  
418  Note that the webapi-using client application must not provide the
419  "Content-Type: multipart/form-data" header that usually accompanies HTML
420  form submissions, since the body is not formatted this way. Doing so will
421  cause a server error as the lower-level code misparses the request body.
422
423  Child file names should each be expressed as a unicode string, then used as
424  keys of the dictionary. The dictionary should then be converted into JSON,
425  and the resulting string encoded into UTF-8. This UTF-8 bytestring should
426  then be used as the POST body.
427
428 POST /uri?t=mkdir-immutable
429
430  Like t=mkdir-with-children above, but the new directory will be
431  deep-immutable. This means that the directory itself is immutable, and that
432  it can only contain objects that are treated as being deep-immutable, like
433  immutable files, literal files, and deep-immutable directories.
434
435  For forward-compatibility, a deep-immutable directory can also contain caps
436  in a format that is unknown to the webapi server. When such caps are retrieved
437  from a deep-immutable directory in a "ro_uri" field, they will be prefixed
438  with the string "imm.", indicating that they must not be decoded without
439  checking that they are immutable. The "imm." prefix must not be stripped
440  off without performing this check. (Future versions of the webapi server
441  will perform it where necessary.)
442  
443  The cap for each child may be given either in the "rw_uri" or "ro_uri"
444  field of the PROPDICT (not both). If a cap is given in the "rw_uri" field,
445  then the webapi server will check that it is an immutable read-cap of a
446  *known* format, and give an error if it is not. If a cap is given in the
447  "ro_uri" field, then the webapi server will still check whether known
448  caps are immutable, but for unknown caps it will simply assume that the
449  cap can be stored, as described above. Note that an attacker would be
450  able to store any cap in an immutable directory, so this check when
451  creating the directory is only to help non-malicious clients to avoid
452  accidentally giving away more authority than intended.
453
454  A non-empty request body is mandatory, since after the directory is created,
455  it will not be possible to add more children to it.
456
457 POST /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=mkdir
458 PUT /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=mkdir
459
460  Create new directories as necessary to make sure that the named target
461  ($DIRCAP/SUBDIRS../SUBDIR) is a directory. This will create additional
462  intermediate mutable directories as necessary. If the named target directory
463  already exists, this will make no changes to it.
464
465  If the final directory is created, it will be empty.
466
467  This operation will return an error if a blocking file is present at any of
468  the parent names, preventing the server from creating the necessary parent
469  directory; or if it would require changing an immutable directory.
470
471  The write-cap of the new directory will be returned as the HTTP response
472  body.
473
474 POST /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=mkdir-with-children
475
476  Like /uri?t=mkdir-with-children, but the final directory is created as a
477  child of an existing mutable directory. This will create additional
478  intermediate mutable directories as necessary. If the final directory is
479  created, it will be populated with initial children from the POST request
480  body, as described above.
481  
482  This operation will return an error if a blocking file is present at any of
483  the parent names, preventing the server from creating the necessary parent
484  directory; or if it would require changing an immutable directory; or if
485  the immediate parent directory already has a a child named SUBDIR.
486
487 POST /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=mkdir-immutable
488
489  Like /uri?t=mkdir-immutable, but the final directory is created as a child
490  of an existing mutable directory. The final directory will be deep-immutable,
491  and will be populated with the children specified as a JSON dictionary in
492  the POST request body.
493
494  In Tahoe 1.6 this operation creates intermediate mutable directories if
495  necessary, but that behaviour should not be relied on; see ticket #920.
496
497  This operation will return an error if the parent directory is immutable,
498  or already has a child named SUBDIR.
499
500 POST /uri/$DIRCAP/[SUBDIRS../]?t=mkdir&name=NAME
501
502  Create a new empty mutable directory and attach it to the given existing
503  directory. This will create additional intermediate directories as necessary.
504
505  This operation will return an error if a blocking file is present at any of
506  the parent names, preventing the server from creating the necessary parent
507  directory, or if it would require changing any immutable directory.
508
509  The URL of this operation points to the parent of the bottommost new directory,
510  whereas the /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=mkdir operation above has a URL
511  that points directly to the bottommost new directory.
512
513 POST /uri/$DIRCAP/[SUBDIRS../]?t=mkdir-with-children&name=NAME
514
515  Like /uri/$DIRCAP/[SUBDIRS../]?t=mkdir&name=NAME, but the new directory will
516  be populated with initial children via the POST request body. This command
517  will create additional intermediate mutable directories as necessary.
518  
519  This operation will return an error if a blocking file is present at any of
520  the parent names, preventing the server from creating the necessary parent
521  directory; or if it would require changing an immutable directory; or if
522  the immediate parent directory already has a a child named NAME.
523
524  Note that the name= argument must be passed as a queryarg, because the POST
525  request body is used for the initial children JSON. 
526
527 POST /uri/$DIRCAP/[SUBDIRS../]?t=mkdir-immutable&name=NAME
528
529  Like /uri/$DIRCAP/[SUBDIRS../]?t=mkdir-with-children&name=NAME, but the
530  final directory will be deep-immutable. The children are specified as a
531  JSON dictionary in the POST request body. Again, the name= argument must be
532  passed as a queryarg.
533
534  In Tahoe 1.6 this operation creates intermediate mutable directories if
535  necessary, but that behaviour should not be relied on; see ticket #920.
536
537  This operation will return an error if the parent directory is immutable,
538  or already has a child named NAME.
539
540 === Get Information About A File Or Directory (as JSON) ===
541
542 GET /uri/$FILECAP?t=json
543 GET /uri/$DIRCAP?t=json
544 GET /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=json
545 GET /uri/$DIRCAP/[SUBDIRS../]FILENAME?t=json
546
547   This returns a machine-parseable JSON-encoded description of the given
548   object. The JSON always contains a list, and the first element of the list is
549   always a flag that indicates whether the referenced object is a file or a
550   directory. If it is a capability to a file, then the information includes
551   file size and URI, like this:
552
553    GET /uri/$FILECAP?t=json :
554
555     [ "filenode", {
556       "ro_uri": file_uri,
557       "verify_uri": verify_uri,
558       "size": bytes,
559       "mutable": false
560       } ]
561
562   If it is a capability to a directory followed by a path from that directory
563   to a file, then the information also includes metadata from the link to the
564   file in the parent directory, like this:
565
566    GET /uri/$DIRCAP/[SUBDIRS../]FILENAME?t=json :
567
568     [ "filenode", {
569       "ro_uri": file_uri,
570       "verify_uri": verify_uri,
571       "size": bytes,
572       "mutable": false,
573       "metadata": {
574         "ctime": 1202777696.7564139,
575         "mtime": 1202777696.7564139,
576         "tahoe": {
577           "linkcrtime": 1202777696.7564139,
578           "linkmotime": 1202777696.7564139
579           } } } ]
580
581   If it is a directory, then it includes information about the children of
582   this directory, as a mapping from child name to a set of data about the
583   child (the same data that would appear in a corresponding GET?t=json of the
584   child itself). The child entries also include metadata about each child,
585   including link-creation- and link-change- timestamps. The output looks like
586   this:
587
588    GET /uri/$DIRCAP?t=json :
589    GET /uri/$DIRCAP/[SUBDIRS../]SUBDIR?t=json :
590
591     [ "dirnode", {
592       "rw_uri": read_write_uri,
593       "ro_uri": read_only_uri,
594       "verify_uri": verify_uri,
595       "mutable": true,
596       "children": {
597         "foo.txt": [ "filenode", {
598             "ro_uri": uri,
599             "size": bytes,
600             "metadata": {
601               "ctime": 1202777696.7564139,
602               "mtime": 1202777696.7564139,
603               "tahoe": {
604                 "linkcrtime": 1202777696.7564139,
605                 "linkmotime": 1202777696.7564139
606                 } } } ],
607         "subdir":  [ "dirnode", {
608             "rw_uri": rwuri,
609             "ro_uri": rouri,
610             "metadata": {
611               "ctime": 1202778102.7589991,
612               "mtime": 1202778111.2160511,
613               "tahoe": {
614                 "linkcrtime": 1202777696.7564139,
615                 "linkmotime": 1202777696.7564139
616               } } } ]
617       } } ]
618
619   In the above example, note how 'children' is a dictionary in which the keys
620   are child names and the values depend upon whether the child is a file or a
621   directory. The value is mostly the same as the JSON representation of the
622   child object (except that directories do not recurse -- the "children"
623   entry of the child is omitted, and the directory view includes the metadata
624   that is stored on the directory edge).
625
626   The rw_uri field will be present in the information about a directory
627   if and only if you have read-write access to that directory. The verify_uri
628   field will be present if and only if the object has a verify-cap
629   (non-distributed LIT files do not have verify-caps).
630   
631   If the cap is of an unknown format, then the file size and verify_uri will
632   not be available:
633
634    GET /uri/$UNKNOWNCAP?t=json :
635
636     [ "unknown", {
637       "ro_uri": unknown_read_uri
638       } ]
639
640    GET /uri/$DIRCAP/[SUBDIRS../]UNKNOWNCHILDNAME?t=json :
641
642     [ "unknown", {
643       "rw_uri": unknown_write_uri,
644       "ro_uri": unknown_read_uri,
645       "mutable": true,
646       "metadata": {
647         "ctime": 1202777696.7564139,
648         "mtime": 1202777696.7564139,
649         "tahoe": {
650           "linkcrtime": 1202777696.7564139,
651           "linkmotime": 1202777696.7564139
652           } } } ]
653
654   As in the case of file nodes, the metadata will only be present when the
655   capability is to a directory followed by a path. The "mutable" field is also
656   not always present; when it is absent, the mutability of the object is not
657   known.
658
659 ==== About the metadata ====
660
661   The value of the 'mtime' key and of the 'tahoe':'linkmotime' is updated
662   whenever a link to a child is set. The value of the 'ctime' key and of the
663   'tahoe':'linkcrtime' key is updated whenever a link to a child is created --
664   i.e. when there was not previously a link under that name.
665
666   In Tahoe earlier than v1.4.0, only the 'mtime'/'ctime' keys were populated.
667   Starting in Tahoe v1.4.0, the 'linkmotime'/'linkcrtime' keys in the 'tahoe'
668   sub-dict are also populated.
669
670   The reason we added the new values in Tahoe v1.4.0 is that there is a
671   "set_children" API (described below) which you can use to overwrite the
672   values of the 'mtime'/'ctime' pair, and this API is used by the "tahoe
673   backup" command (both in Tahoe v1.3.0 and in Tahoe v1.4.0) to set the
674   'mtime' and 'ctime' values when backing up files from a local filesystem
675   into the Tahoe filesystem. As of Tahoe v1.4.0, the set_children API cannot
676   be used to set anything under the 'tahoe' key of the metadata dict -- if
677   you include 'tahoe' keys in your 'metadata' arguments then it will silently
678   ignore those keys.
679
680   Therefore, if the 'tahoe' sub-dict is present, you can rely on the
681   'linkcrtime' and 'linkmotime' values therein to have the semantics described
682   above. (This is assuming that only official Tahoe clients have been used to
683   write those links, and that their system clocks were set to what you expected
684   -- there is nothing preventing someone from editing their Tahoe client or
685   writing their own Tahoe client which would overwrite those values however
686   they like, and there is nothing to constrain their system clock from taking
687   any value.)
688
689   The meaning of the 'ctime'/'mtime' fields are slightly more complex.
690
691   The meaning of the 'mtime' field is: whenever the edge is updated (by an HTTP
692   PUT or POST, as is done by the "tahoe cp" command), then the mtime is set to
693   the current time on the clock of the updating client. Whenever the edge is
694   updated by "tahoe backup" then the mtime is instead set to the value which
695   the updating client read from its local filesystem for the "mtime" of the
696   local file in question, which means the last time the contents of that file
697   were changed. Note however, that if the edge in the Tahoe filesystem points
698   to a mutable file and the contents of that mutable file is changed then the
699   "mtime" value on that edge will *not* be updated, since the edge itself
700   wasn't updated -- only the mutable file was.
701
702   The meaning of the 'ctime' field is even more complex. Whenever a new edge is
703   created (by an HTTP PUT or POST, as is done by "tahoe cp") then the ctime is
704   set to the current time on the clock of the updating client. Whenever the
705   edge is created *or updated* by "tahoe backup" then the ctime is instead set
706   to the value which the updating client read from its local filesystem. On
707   Windows, it reads the timestamp of when the local file was created and puts
708   that into the "ctime", and on other platforms it reads the timestamp of the
709   most recent time that either the contents or the metadata of the local file
710   was changed and puts that into the ctime. Again, if the edge points to a
711   mutable file and the content of that mutable file is changed then the ctime
712   will not be updated in any case.
713
714   Therefore there are several ways that the 'ctime' field could be confusing: 
715
716   1. You might be confused about whether it reflects the time of the creation
717   of a link in the Tahoe filesystem or a timestamp copied in from a local
718   filesystem.
719
720   2. You might be confused about whether it is a copy of the file creation time
721   (if "tahoe backup" was run on a Windows system) or of the last
722   contents-or-metadata change (if "tahoe backup" was run on a different
723   operating system).
724
725   3. You might be confused by the fact that changing the contents of a mutable
726   file in Tahoe don't have any effect on any links pointing at that file in any
727   directories, although "tahoe backup" sets the link 'ctime'/'mtime' to reflect
728   timestamps about the local file corresponding to the Tahoe file to which the
729   link points.
730
731   4. Also, quite apart from Tahoe, you might be confused about the meaning of
732   the 'ctime' in UNIX local filesystems, which people sometimes think means
733   file creation time, but which actually means, in UNIX local filesystems, the
734   most recent time that the file contents or the file metadata (such as owner,
735   permission bits, extended attributes, etc.) has changed. Note that although
736   'ctime' does not mean file creation time in UNIX, it does mean link creation
737   time in Tahoe, unless the "tahoe backup" command has been used on that link,
738   in which case it means something about the local filesystem file which
739   corresponds to the Tahoe file which is pointed at by the link. It means
740   either file creation time of the local file (if "tahoe backup" was run on
741   Windows) or file-contents-or-metadata-update-time of the local file (if
742   "tahoe backup" was run on a different operating system).
743
744 === Attaching an existing File or Directory by its read- or write- cap ===
745
746 PUT /uri/$DIRCAP/[SUBDIRS../]CHILDNAME?t=uri
747
748   This attaches a child object (either a file or directory) to a specified
749   location in the virtual filesystem. The child object is referenced by its
750   read- or write- cap, as provided in the HTTP request body. This will create
751   intermediate directories as necessary.
752
753   This is similar to a UNIX hardlink: by referencing a previously-uploaded file
754   (or previously-created directory) instead of uploading/creating a new one,
755   you can create two references to the same object.
756
757   The read- or write- cap of the child is provided in the body of the HTTP
758   request, and this same cap is returned in the response body.
759
760   The default behavior is to overwrite any existing object at the same
761   location. To prevent this (and make the operation return an error instead
762   of overwriting), add a "replace=false" argument, as "?t=uri&replace=false".
763   With replace=false, this operation will return an HTTP 409 "Conflict" error
764   if there is already an object at the given location, rather than
765   overwriting the existing object. To allow the operation to overwrite a
766   file, but return an error when trying to overwrite a directory, use
767   "replace=only-files" (this behavior is closer to the traditional UNIX "mv"
768   command). Note that "true", "t", and "1" are all synonyms for "True", and
769   "false", "f", and "0" are synonyms for "False", and the parameter is
770   case-insensitive.
771   
772   Note that this operation does not take its child cap in the form of
773   separate "rw_uri" and "ro_uri" fields. Therefore, it cannot accept a
774   child cap in a format unknown to the webapi server, unless its URI
775   starts with "ro." or "imm.". This restriction is necessary because the
776   server is not able to attenuate an unknown write cap to a read cap.
777   Unknown URIs starting with "ro." or "imm.", on the other hand, are
778   assumed to represent read caps. The client should not prefix a write
779   cap with "ro." or "imm." and pass it to this operation, since that
780   would result in granting the cap's write authority to holders of the
781   directory read cap.
782
783 === Adding multiple files or directories to a parent directory at once ===
784
785 POST /uri/$DIRCAP/[SUBDIRS..]?t=set_children
786 POST /uri/$DIRCAP/[SUBDIRS..]?t=set-children    (Tahoe >= v1.6)
787
788   This command adds multiple children to a directory in a single operation.
789   It reads the request body and interprets it as a JSON-encoded description
790   of the child names and read/write-caps that should be added.
791
792   The body should be a JSON-encoded dictionary, in the same format as the
793   "children" value returned by the "GET /uri/$DIRCAP?t=json" operation
794   described above. In this format, each key is a child names, and the
795   corresponding value is a tuple of (type, childinfo). "type" is ignored, and
796   "childinfo" is a dictionary that contains "rw_uri", "ro_uri", and
797   "metadata" keys. You can take the output of "GET /uri/$DIRCAP1?t=json" and
798   use it as the input to "POST /uri/$DIRCAP2?t=set_children" to make DIR2
799   look very much like DIR1 (except for any existing children of DIR2 that
800   were not overwritten, and any existing "tahoe" metadata keys as described
801   below).
802
803   When the set_children request contains a child name that already exists in
804   the target directory, this command defaults to overwriting that child with
805   the new value (both child cap and metadata, but if the JSON data does not
806   contain a "metadata" key, the old child's metadata is preserved). The
807   command takes a boolean "overwrite=" query argument to control this
808   behavior. If you use "?t=set_children&overwrite=false", then an attempt to
809   replace an existing child will instead cause an error.
810
811   Any "tahoe" key in the new child's "metadata" value is ignored. Any
812   existing "tahoe" metadata is preserved. The metadata["tahoe"] value is
813   reserved for metadata generated by the tahoe node itself. The only two keys
814   currently placed here are "linkcrtime" and "linkmotime". For details, see
815   the section above entitled "Get Information About A File Or Directory (as
816   JSON)", in the "About the metadata" subsection.
817   
818   Note that this command was introduced with the name "set_children", which
819   uses an underscore rather than a hyphen as other multi-word command names
820   do. The variant with a hyphen is now accepted, but clients that desire
821   backward compatibility should continue to use "set_children".
822
823
824 === Deleting a File or Directory ===
825
826 DELETE /uri/$DIRCAP/[SUBDIRS../]CHILDNAME
827
828   This removes the given name from its parent directory. CHILDNAME is the
829   name to be removed, and $DIRCAP/SUBDIRS.. indicates the directory that will
830   be modified.
831
832   Note that this does not actually delete the file or directory that the name
833   points to from the tahoe grid -- it only removes the named reference from
834   this directory. If there are other names in this directory or in other
835   directories that point to the resource, then it will remain accessible
836   through those paths. Even if all names pointing to this object are removed
837   from their parent directories, then someone with possession of its read-cap
838   can continue to access the object through that cap.
839
840   The object will only become completely unreachable once 1: there are no
841   reachable directories that reference it, and 2: nobody is holding a read-
842   or write- cap to the object. (This behavior is very similar to the way
843   hardlinks and anonymous files work in traditional UNIX filesystems).
844
845   This operation will not modify more than a single directory. Intermediate
846   directories which were implicitly created by PUT or POST methods will *not*
847   be automatically removed by DELETE.
848
849   This method returns the file- or directory- cap of the object that was just
850   removed.
851
852 == Browser Operations ==
853
854 This section describes the HTTP operations that provide support for humans
855 running a web browser. Most of these operations use HTML forms that use POST
856 to drive the Tahoe node. This section is intended for HTML authors who want
857 to write web pages that contain forms and buttons which manipulate the Tahoe
858 filesystem.
859
860 Note that for all POST operations, the arguments listed can be provided
861 either as URL query arguments or as form body fields. URL query arguments are
862 separated from the main URL by "?", and from each other by "&". For example,
863 "POST /uri/$DIRCAP?t=upload&mutable=true". Form body fields are usually
864 specified by using <input type="hidden"> elements. For clarity, the
865 descriptions below display the most significant arguments as URL query args.
866
867 === Viewing A Directory (as HTML) ===
868
869 GET /uri/$DIRCAP/[SUBDIRS../]
870
871  This returns an HTML page, intended to be displayed to a human by a web
872  browser, which contains HREF links to all files and directories reachable
873  from this directory. These HREF links do not have a t= argument, meaning
874  that a human who follows them will get pages also meant for a human. It also
875  contains forms to upload new files, and to delete files and directories.
876  Those forms use POST methods to do their job.
877
878 === Viewing/Downloading a File ===
879
880 GET /uri/$FILECAP
881 GET /uri/$DIRCAP/[SUBDIRS../]FILENAME
882
883  This will retrieve the contents of the given file. The HTTP response body
884  will contain the sequence of bytes that make up the file.
885
886  If you want the HTTP response to include a useful Content-Type header,
887  either use the second form (which starts with a $DIRCAP), or add a
888  "filename=foo" query argument, like "GET /uri/$FILECAP?filename=foo.jpg".
889  The bare "GET /uri/$FILECAP" does not give the Tahoe node enough information
890  to determine a Content-Type (since Tahoe immutable files are merely
891  sequences of bytes, not typed+named file objects).
892
893  If the URL has both filename= and "save=true" in the query arguments, then
894  the server to add a "Content-Disposition: attachment" header, along with a
895  filename= parameter. When a user clicks on such a link, most browsers will
896  offer to let the user save the file instead of displaying it inline (indeed,
897  most browsers will refuse to display it inline). "true", "t", "1", and other
898  case-insensitive equivalents are all treated the same.
899
900  Character-set handling in URLs and HTTP headers is a dubious art[1]. For
901  maximum compatibility, Tahoe simply copies the bytes from the filename=
902  argument into the Content-Disposition header's filename= parameter, without
903  trying to interpret them in any particular way.
904
905
906 GET /named/$FILECAP/FILENAME
907
908  This is an alternate download form which makes it easier to get the correct
909  filename. The Tahoe server will provide the contents of the given file, with
910  a Content-Type header derived from the given filename. This form is used to
911  get browsers to use the "Save Link As" feature correctly, and also helps
912  command-line tools like "wget" and "curl" use the right filename. Note that
913  this form can *only* be used with file caps; it is an error to use a
914  directory cap after the /named/ prefix.
915
916 === Get Information About A File Or Directory (as HTML) ===
917
918 GET /uri/$FILECAP?t=info
919 GET /uri/$DIRCAP/?t=info
920 GET /uri/$DIRCAP/[SUBDIRS../]SUBDIR/?t=info
921 GET /uri/$DIRCAP/[SUBDIRS../]FILENAME?t=info
922
923   This returns a human-oriented HTML page with more detail about the selected
924   file or directory object. This page contains the following items:
925
926    object size
927    storage index
928    JSON representation
929    raw contents (text/plain)
930    access caps (URIs): verify-cap, read-cap, write-cap (for mutable objects)
931    check/verify/repair form
932    deep-check/deep-size/deep-stats/manifest (for directories)
933    replace-conents form (for mutable files)
934
935 === Creating a Directory ===
936
937 POST /uri?t=mkdir
938
939  This creates a new empty directory, but does not attach it to the virtual
940  filesystem.
941
942  If a "redirect_to_result=true" argument is provided, then the HTTP response
943  will cause the web browser to be redirected to a /uri/$DIRCAP page that
944  gives access to the newly-created directory. If you bookmark this page,
945  you'll be able to get back to the directory again in the future. This is the
946  recommended way to start working with a Tahoe server: create a new unlinked
947  directory (using redirect_to_result=true), then bookmark the resulting
948  /uri/$DIRCAP page. There is a "create directory" button on the Welcome page
949  to invoke this action.
950
951  If "redirect_to_result=true" is not provided (or is given a value of
952  "false"), then the HTTP response body will simply be the write-cap of the
953  new directory.
954
955 POST /uri/$DIRCAP/[SUBDIRS../]?t=mkdir&name=CHILDNAME
956
957  This creates a new empty directory as a child of the designated SUBDIR. This
958  will create additional intermediate directories as necessary.
959
960  If a "when_done=URL" argument is provided, the HTTP response will cause the
961  web browser to redirect to the given URL. This provides a convenient way to
962  return the browser to the directory that was just modified. Without a
963  when_done= argument, the HTTP response will simply contain the write-cap of
964  the directory that was just created.
965
966
967 === Uploading a File ===
968
969 POST /uri?t=upload
970
971  This uploads a file, and produces a file-cap for the contents, but does not
972  attach the file into the filesystem. No directories will be modified by
973  this operation.
974
975  The file must be provided as the "file" field of an HTML encoded form body,
976  produced in response to an HTML form like this:
977   <form action="/uri" method="POST" enctype="multipart/form-data">
978    <input type="hidden" name="t" value="upload" />
979    <input type="file" name="file" />
980    <input type="submit" value="Upload Unlinked" />
981   </form>
982
983  If a "when_done=URL" argument is provided, the response body will cause the
984  browser to redirect to the given URL. If the when_done= URL has the string
985  "%(uri)s" in it, that string will be replaced by a URL-escaped form of the
986  newly created file-cap. (Note that without this substitution, there is no
987  way to access the file that was just uploaded).
988
989  The default (in the absence of when_done=) is to return an HTML page that
990  describes the results of the upload. This page will contain information
991  about which storage servers were used for the upload, how long each
992  operation took, etc.
993
994  If a "mutable=true" argument is provided, the operation will create a
995  mutable file, and the response body will contain the write-cap instead of
996  the upload results page. The default is to create an immutable file,
997  returning the upload results page as a response.
998
999
1000 POST /uri/$DIRCAP/[SUBDIRS../]?t=upload
1001
1002  This uploads a file, and attaches it as a new child of the given directory,
1003  which must be mutable. The file must be provided as the "file" field of an
1004  HTML-encoded form body, produced in response to an HTML form like this:
1005   <form action="." method="POST" enctype="multipart/form-data">
1006    <input type="hidden" name="t" value="upload" />
1007    <input type="file" name="file" />
1008    <input type="submit" value="Upload" />
1009   </form>
1010
1011  A "name=" argument can be provided to specify the new child's name,
1012  otherwise it will be taken from the "filename" field of the upload form
1013  (most web browsers will copy the last component of the original file's
1014  pathname into this field). To avoid confusion, name= is not allowed to
1015  contain a slash.
1016
1017  If there is already a child with that name, and it is a mutable file, then
1018  its contents are replaced with the data being uploaded. If it is not a
1019  mutable file, the default behavior is to remove the existing child before
1020  creating a new one. To prevent this (and make the operation return an error
1021  instead of overwriting the old child), add a "replace=false" argument, as
1022  "?t=upload&replace=false". With replace=false, this operation will return an
1023  HTTP 409 "Conflict" error if there is already an object at the given
1024  location, rather than overwriting the existing object. Note that "true",
1025  "t", and "1" are all synonyms for "True", and "false", "f", and "0" are
1026  synonyms for "False". the parameter is case-insensitive.
1027
1028  This will create additional intermediate directories as necessary, although
1029  since it is expected to be triggered by a form that was retrieved by "GET
1030  /uri/$DIRCAP/[SUBDIRS../]", it is likely that the parent directory will
1031  already exist.
1032
1033  If a "mutable=true" argument is provided, any new file that is created will
1034  be a mutable file instead of an immutable one. <input type="checkbox"
1035  name="mutable" /> will give the user a way to set this option.
1036
1037  If a "when_done=URL" argument is provided, the HTTP response will cause the
1038  web browser to redirect to the given URL. This provides a convenient way to
1039  return the browser to the directory that was just modified. Without a
1040  when_done= argument, the HTTP response will simply contain the file-cap of
1041  the file that was just uploaded (a write-cap for mutable files, or a
1042  read-cap for immutable files).
1043
1044 POST /uri/$DIRCAP/[SUBDIRS../]FILENAME?t=upload
1045
1046  This also uploads a file and attaches it as a new child of the given
1047  directory, which must be mutable. It is a slight variant of the previous
1048  operation, as the URL refers to the target file rather than the parent
1049  directory. It is otherwise identical: this accepts mutable= and when_done=
1050  arguments too.
1051
1052 POST /uri/$FILECAP?t=upload
1053
1054  This modifies the contents of an existing mutable file in-place. An error is
1055  signalled if $FILECAP does not refer to a mutable file. It behaves just like
1056  the "PUT /uri/$FILECAP" form, but uses a POST for the benefit of HTML forms
1057  in a web browser.
1058
1059 === Attaching An Existing File Or Directory (by URI) ===
1060
1061 POST /uri/$DIRCAP/[SUBDIRS../]?t=uri&name=CHILDNAME&uri=CHILDCAP
1062
1063  This attaches a given read- or write- cap "CHILDCAP" to the designated
1064  directory, with a specified child name. This behaves much like the PUT t=uri
1065  operation, and is a lot like a UNIX hardlink. It is subject to the same
1066  restrictions as that operation on the use of cap formats unknown to the
1067  webapi server.
1068
1069  This will create additional intermediate directories as necessary, although
1070  since it is expected to be triggered by a form that was retrieved by "GET
1071  /uri/$DIRCAP/[SUBDIRS../]", it is likely that the parent directory will
1072  already exist.
1073
1074  This accepts the same replace= argument as POST t=upload.
1075
1076 === Deleting A Child ===
1077
1078 POST /uri/$DIRCAP/[SUBDIRS../]?t=delete&name=CHILDNAME
1079
1080  This instructs the node to remove a child object (file or subdirectory) from
1081  the given directory, which must be mutable. Note that the entire subtree is
1082  unlinked from the parent. Unlike deleting a subdirectory in a UNIX local
1083  filesystem, the subtree need not be empty; if it isn't, then other references
1084  into the subtree will see that the child subdirectories are not modified by
1085  this operation. Only the link from the given directory to its child is severed.
1086
1087 === Renaming A Child ===
1088
1089 POST /uri/$DIRCAP/[SUBDIRS../]?t=rename&from_name=OLD&to_name=NEW
1090
1091  This instructs the node to rename a child of the given directory, which must
1092  be mutable. This has a similar effect to removing the child, then adding the
1093  same child-cap under the new name, except that it preserves metadata. This
1094  operation cannot move the child to a different directory.
1095
1096  This operation will replace any existing child of the new name, making it
1097  behave like the UNIX "mv -f" command.
1098
1099 === Other Utilities ===
1100
1101 GET /uri?uri=$CAP
1102
1103   This causes a redirect to /uri/$CAP, and retains any additional query
1104   arguments (like filename= or save=). This is for the convenience of web
1105   forms which allow the user to paste in a read- or write- cap (obtained
1106   through some out-of-band channel, like IM or email).
1107
1108   Note that this form merely redirects to the specific file or directory
1109   indicated by the $CAP: unlike the GET /uri/$DIRCAP form, you cannot
1110   traverse to children by appending additional path segments to the URL.
1111
1112 GET /uri/$DIRCAP/[SUBDIRS../]?t=rename-form&name=$CHILDNAME
1113
1114   This provides a useful facility to browser-based user interfaces. It
1115   returns a page containing a form targetting the "POST $DIRCAP t=rename"
1116   functionality described above, with the provided $CHILDNAME present in the
1117   'from_name' field of that form. I.e. this presents a form offering to
1118   rename $CHILDNAME, requesting the new name, and submitting POST rename.
1119
1120 GET /uri/$DIRCAP/[SUBDIRS../]CHILDNAME?t=uri
1121
1122  This returns the file- or directory- cap for the specified object.
1123
1124 GET /uri/$DIRCAP/[SUBDIRS../]CHILDNAME?t=readonly-uri
1125
1126  This returns a read-only file- or directory- cap for the specified object.
1127  If the object is an immutable file, this will return the same value as
1128  t=uri.
1129
1130 === Debugging and Testing Features ===
1131
1132 These URLs are less-likely to be helpful to the casual Tahoe user, and are
1133 mainly intended for developers.
1134
1135 POST $URL?t=check
1136
1137   This triggers the FileChecker to determine the current "health" of the
1138   given file or directory, by counting how many shares are available. The
1139   page that is returned will display the results. This can be used as a "show
1140   me detailed information about this file" page.
1141
1142   If a verify=true argument is provided, the node will perform a more
1143   intensive check, downloading and verifying every single bit of every share.
1144
1145   If an add-lease=true argument is provided, the node will also add (or
1146   renew) a lease to every share it encounters. Each lease will keep the share
1147   alive for a certain period of time (one month by default). Once the last
1148   lease expires or is explicitly cancelled, the storage server is allowed to
1149   delete the share.
1150
1151   If an output=JSON argument is provided, the response will be
1152   machine-readable JSON instead of human-oriented HTML. The data is a
1153   dictionary with the following keys:
1154
1155    storage-index: a base32-encoded string with the objects's storage index,
1156                   or an empty string for LIT files
1157    summary: a string, with a one-line summary of the stats of the file
1158    results: a dictionary that describes the state of the file. For LIT files,
1159             this dictionary has only the 'healthy' key, which will always be
1160             True. For distributed files, this dictionary has the following
1161             keys:
1162      count-shares-good: the number of good shares that were found
1163      count-shares-needed: 'k', the number of shares required for recovery
1164      count-shares-expected: 'N', the number of total shares generated
1165      count-good-share-hosts: the number of distinct storage servers with
1166                              good shares. If this number is less than
1167                              count-shares-good, then some shares are doubled
1168                              up, increasing the correlation of failures. This
1169                              indicates that one or more shares should be
1170                              moved to an otherwise unused server, if one is
1171                              available.
1172      count-wrong-shares: for mutable files, the number of shares for
1173                          versions other than the 'best' one (highest
1174                          sequence number, highest roothash). These are
1175                          either old ...
1176      count-recoverable-versions: for mutable files, the number of
1177                                  recoverable versions of the file. For
1178                                  a healthy file, this will equal 1.
1179      count-unrecoverable-versions: for mutable files, the number of
1180                                    unrecoverable versions of the file.
1181                                    For a healthy file, this will be 0.
1182      count-corrupt-shares: the number of shares with integrity failures
1183      list-corrupt-shares: a list of "share locators", one for each share
1184                           that was found to be corrupt. Each share locator
1185                           is a list of (serverid, storage_index, sharenum).
1186      needs-rebalancing: (bool) True if there are multiple shares on a single
1187                         storage server, indicating a reduction in reliability
1188                         that could be resolved by moving shares to new
1189                         servers.
1190      servers-responding: list of base32-encoded storage server identifiers,
1191                          one for each server which responded to the share
1192                          query.
1193      healthy: (bool) True if the file is completely healthy, False otherwise.
1194               Healthy files have at least N good shares. Overlapping shares
1195               (indicated by count-good-share-hosts < count-shares-good) do not
1196               currently cause a file to be marked unhealthy. If there are at
1197               least N good shares, then corrupt shares do not cause the file to
1198               be marked unhealthy, although the corrupt shares will be listed
1199               in the results (list-corrupt-shares) and should be manually
1200               removed to wasting time in subsequent downloads (as the
1201               downloader rediscovers the corruption and uses alternate shares).
1202      sharemap: dict mapping share identifier to list of serverids
1203                (base32-encoded strings). This indicates which servers are
1204                holding which shares. For immutable files, the shareid is
1205                an integer (the share number, from 0 to N-1). For
1206                immutable files, it is a string of the form
1207                'seq%d-%s-sh%d', containing the sequence number, the
1208                roothash, and the share number.
1209
1210 POST $URL?t=start-deep-check    (must add &ophandle=XYZ)
1211
1212   This initiates a recursive walk of all files and directories reachable from
1213   the target, performing a check on each one just like t=check. The result
1214   page will contain a summary of the results, including details on any
1215   file/directory that was not fully healthy.
1216
1217   t=start-deep-check can only be invoked on a directory. An error (400
1218   BAD_REQUEST) will be signalled if it is invoked on a file. The recursive
1219   walker will deal with loops safely.
1220
1221   This accepts the same verify= and add-lease= arguments as t=check.
1222
1223   Since this operation can take a long time (perhaps a second per object),
1224   the ophandle= argument is required (see "Slow Operations, Progress, and
1225   Cancelling" above). The response to this POST will be a redirect to the
1226   corresponding /operations/$HANDLE page (with output=HTML or output=JSON to
1227   match the output= argument given to the POST). The deep-check operation
1228   will continue to run in the background, and the /operations page should be
1229   used to find out when the operation is done.
1230
1231   Detailed check results for non-healthy files and directories will be
1232   available under /operations/$HANDLE/$STORAGEINDEX, and the HTML status will
1233   contain links to these detailed results.
1234
1235   The HTML /operations/$HANDLE page for incomplete operations will contain a
1236   meta-refresh tag, set to 60 seconds, so that a browser which uses
1237   deep-check will automatically poll until the operation has completed.
1238
1239   The JSON page (/options/$HANDLE?output=JSON) will contain a
1240   machine-readable JSON dictionary with the following keys:
1241
1242    finished: a boolean, True if the operation is complete, else False. Some
1243              of the remaining keys may not be present until the operation
1244              is complete.
1245    root-storage-index: a base32-encoded string with the storage index of the
1246                        starting point of the deep-check operation
1247    count-objects-checked: count of how many objects were checked. Note that
1248                           non-distributed objects (i.e. small immutable LIT
1249                           files) are not checked, since for these objects,
1250                           the data is contained entirely in the URI.
1251    count-objects-healthy: how many of those objects were completely healthy
1252    count-objects-unhealthy: how many were damaged in some way
1253    count-corrupt-shares: how many shares were found to have corruption,
1254                          summed over all objects examined
1255    list-corrupt-shares: a list of "share identifiers", one for each share
1256                         that was found to be corrupt. Each share identifier
1257                         is a list of (serverid, storage_index, sharenum).
1258    list-unhealthy-files: a list of (pathname, check-results) tuples, for
1259                          each file that was not fully healthy. 'pathname' is
1260                          a list of strings (which can be joined by "/"
1261                          characters to turn it into a single string),
1262                          relative to the directory on which deep-check was
1263                          invoked. The 'check-results' field is the same as
1264                          that returned by t=check&output=JSON, described
1265                          above.
1266    stats: a dictionary with the same keys as the t=start-deep-stats command
1267           (described below)
1268
1269 POST $URL?t=stream-deep-check
1270
1271  This initiates a recursive walk of all files and directories reachable from
1272  the target, performing a check on each one just like t=check. For each
1273  unique object (duplicates are skipped), a single line of JSON is emitted to
1274  the HTTP response channel (or an error indication, see below). When the walk
1275  is complete, a final line of JSON is emitted which contains the accumulated
1276  file-size/count "deep-stats" data.
1277
1278  This command takes the same arguments as t=start-deep-check.
1279
1280  A CLI tool can split the response stream on newlines into "response units",
1281  and parse each response unit as JSON. Each such parsed unit will be a
1282  dictionary, and will contain at least the "type" key: a string, one of
1283  "file", "directory", or "stats".
1284
1285  For all units that have a type of "file" or "directory", the dictionary will
1286  contain the following keys:
1287
1288   "path": a list of strings, with the path that is traversed to reach the
1289           object
1290   "cap": a write-cap URI for the file or directory, if available, else a
1291          read-cap URI
1292   "verifycap": a verify-cap URI for the file or directory
1293   "repaircap": an URI for the weakest cap that can still be used to repair
1294                the object
1295   "storage-index": a base32 storage index for the object
1296   "check-results": a copy of the dictionary which would be returned by
1297                    t=check&output=json, with three top-level keys:
1298                    "storage-index", "summary", and "results", and a variety
1299                    of counts and sharemaps in the "results" value.
1300
1301  Note that non-distributed files (i.e. LIT files) will have values of None
1302  for verifycap, repaircap, and storage-index, since these files can neither
1303  be verified nor repaired, and are not stored on the storage servers.
1304  Likewise the check-results dictionary will be limited: an empty string for
1305  storage-index, and a results dictionary with only the "healthy" key.
1306
1307  The last unit in the stream will have a type of "stats", and will contain
1308  the keys described in the "start-deep-stats" operation, below.
1309
1310  If any errors occur during the traversal (specifically if a directory is
1311  unrecoverable, such that further traversal is not possible), an error
1312  indication is written to the response body, instead of the usual line of
1313  JSON. This error indication line will begin with the string "ERROR:" (in all
1314  caps), and contain a summary of the error on the rest of the line. The
1315  remaining lines of the response body will be a python exception. The client
1316  application should look for the ERROR: and stop processing JSON as soon as
1317  it is seen. Note that neither a file being unrecoverable nor a directory
1318  merely being unhealthy will cause traversal to stop. The line just before
1319  the ERROR: will describe the directory that was untraversable, since the
1320  unit is emitted to the HTTP response body before the child is traversed.
1321
1322
1323 POST $URL?t=check&repair=true
1324
1325   This performs a health check of the given file or directory, and if the
1326   checker determines that the object is not healthy (some shares are missing
1327   or corrupted), it will perform a "repair". During repair, any missing
1328   shares will be regenerated and uploaded to new servers.
1329
1330   This accepts the same verify=true and add-lease= arguments as t=check. When
1331   an output=JSON argument is provided, the machine-readable JSON response
1332   will contain the following keys:
1333
1334    storage-index: a base32-encoded string with the objects's storage index,
1335                   or an empty string for LIT files
1336    repair-attempted: (bool) True if repair was attempted
1337    repair-successful: (bool) True if repair was attempted and the file was
1338                       fully healthy afterwards. False if no repair was
1339                       attempted, or if a repair attempt failed.
1340    pre-repair-results: a dictionary that describes the state of the file
1341                        before any repair was performed. This contains exactly
1342                        the same keys as the 'results' value of the t=check
1343                        response, described above.
1344    post-repair-results: a dictionary that describes the state of the file
1345                         after any repair was performed. If no repair was
1346                         performed, post-repair-results and pre-repair-results
1347                         will be the same. This contains exactly the same keys
1348                         as the 'results' value of the t=check response,
1349                         described above.
1350
1351 POST $URL?t=start-deep-check&repair=true    (must add &ophandle=XYZ)
1352
1353   This triggers a recursive walk of all files and directories, performing a
1354   t=check&repair=true on each one.
1355
1356   Like t=start-deep-check without the repair= argument, this can only be
1357   invoked on a directory. An error (400 BAD_REQUEST) will be signalled if it
1358   is invoked on a file. The recursive walker will deal with loops safely.
1359
1360   This accepts the same verify= and add-lease= arguments as
1361   t=start-deep-check. It uses the same ophandle= mechanism as
1362   start-deep-check. When an output=JSON argument is provided, the response
1363   will contain the following keys:
1364
1365    finished: (bool) True if the operation has completed, else False
1366    root-storage-index: a base32-encoded string with the storage index of the
1367                        starting point of the deep-check operation
1368    count-objects-checked: count of how many objects were checked
1369
1370    count-objects-healthy-pre-repair: how many of those objects were completely
1371                                      healthy, before any repair
1372    count-objects-unhealthy-pre-repair: how many were damaged in some way
1373    count-objects-healthy-post-repair: how many of those objects were completely
1374                                        healthy, after any repair
1375    count-objects-unhealthy-post-repair: how many were damaged in some way
1376
1377    count-repairs-attempted: repairs were attempted on this many objects.
1378    count-repairs-successful: how many repairs resulted in healthy objects
1379    count-repairs-unsuccessful: how many repairs resulted did not results in
1380                                completely healthy objects
1381    count-corrupt-shares-pre-repair: how many shares were found to have
1382                                     corruption, summed over all objects
1383                                     examined, before any repair
1384    count-corrupt-shares-post-repair: how many shares were found to have
1385                                      corruption, summed over all objects
1386                                      examined, after any repair
1387    list-corrupt-shares: a list of "share identifiers", one for each share
1388                         that was found to be corrupt (before any repair).
1389                         Each share identifier is a list of (serverid,
1390                         storage_index, sharenum).
1391    list-remaining-corrupt-shares: like list-corrupt-shares, but mutable shares
1392                                   that were successfully repaired are not
1393                                   included. These are shares that need
1394                                   manual processing. Since immutable shares
1395                                   cannot be modified by clients, all corruption
1396                                   in immutable shares will be listed here.
1397    list-unhealthy-files: a list of (pathname, check-results) tuples, for
1398                          each file that was not fully healthy. 'pathname' is
1399                          relative to the directory on which deep-check was
1400                          invoked. The 'check-results' field is the same as
1401                          that returned by t=check&repair=true&output=JSON,
1402                          described above.
1403    stats: a dictionary with the same keys as the t=start-deep-stats command
1404           (described below)
1405
1406 POST $URL?t=stream-deep-check&repair=true
1407
1408  This triggers a recursive walk of all files and directories, performing a
1409  t=check&repair=true on each one. For each unique object (duplicates are
1410  skipped), a single line of JSON is emitted to the HTTP response channel (or
1411  an error indication). When the walk is complete, a final line of JSON is
1412  emitted which contains the accumulated file-size/count "deep-stats" data.
1413
1414  This emits the same data as t=stream-deep-check (without the repair=true),
1415  except that the "check-results" field is replaced with a
1416  "check-and-repair-results" field, which contains the keys returned by
1417  t=check&repair=true&output=json (i.e. repair-attempted, repair-successful,
1418  pre-repair-results, and post-repair-results). The output does not contain
1419  the summary dictionary that is provied by t=start-deep-check&repair=true
1420  (the one with count-objects-checked and list-unhealthy-files), since the
1421  receiving client is expected to calculate those values itself from the
1422  stream of per-object check-and-repair-results.
1423
1424  Note that the "ERROR:" indication will only be emitted if traversal stops,
1425  which will only occur if an unrecoverable directory is encountered. If a
1426  file or directory repair fails, the traversal will continue, and the repair
1427  failure will be indicated in the JSON data (in the "repair-successful" key).
1428
1429 POST $DIRURL?t=start-manifest    (must add &ophandle=XYZ)
1430
1431   This operation generates a "manfest" of the given directory tree, mostly
1432   for debugging. This is a table of (path, filecap/dircap), for every object
1433   reachable from the starting directory. The path will be slash-joined, and
1434   the filecap/dircap will contain a link to the object in question. This page
1435   gives immediate access to every object in the virtual filesystem subtree.
1436
1437   This operation uses the same ophandle= mechanism as deep-check. The
1438   corresponding /operations/$HANDLE page has three different forms. The
1439   default is output=HTML.
1440
1441   If output=text is added to the query args, the results will be a text/plain
1442   list. The first line is special: it is either "finished: yes" or "finished:
1443   no"; if the operation is not finished, you must periodically reload the
1444   page until it completes. The rest of the results are a plaintext list, with
1445   one file/dir per line, slash-separated, with the filecap/dircap separated
1446   by a space.
1447
1448   If output=JSON is added to the queryargs, then the results will be a
1449   JSON-formatted dictionary with six keys. Note that because large directory
1450   structures can result in very large JSON results, the full results will not
1451   be available until the operation is complete (i.e. until output["finished"]
1452   is True):
1453
1454    finished (bool): if False then you must reload the page until True
1455    origin_si (base32 str): the storage index of the starting point
1456    manifest: list of (path, cap) tuples, where path is a list of strings.
1457    verifycaps: list of (printable) verify cap strings
1458    storage-index: list of (base32) storage index strings
1459    stats: a dictionary with the same keys as the t=start-deep-stats command
1460           (described below)
1461
1462 POST $DIRURL?t=start-deep-size    (must add &ophandle=XYZ)
1463
1464   This operation generates a number (in bytes) containing the sum of the
1465   filesize of all directories and immutable files reachable from the given
1466   directory. This is a rough lower bound of the total space consumed by this
1467   subtree. It does not include space consumed by mutable files, nor does it
1468   take expansion or encoding overhead into account. Later versions of the
1469   code may improve this estimate upwards.
1470
1471   The /operations/$HANDLE status output consists of two lines of text:
1472
1473    finished: yes
1474    size: 1234
1475
1476 POST $DIRURL?t=start-deep-stats    (must add &ophandle=XYZ)
1477
1478   This operation performs a recursive walk of all files and directories
1479   reachable from the given directory, and generates a collection of
1480   statistics about those objects.
1481
1482   The result (obtained from the /operations/$OPHANDLE page) is a
1483   JSON-serialized dictionary with the following keys (note that some of these
1484   keys may be missing until 'finished' is True):
1485
1486    finished: (bool) True if the operation has finished, else False
1487    count-immutable-files: count of how many CHK files are in the set
1488    count-mutable-files: same, for mutable files (does not include directories)
1489    count-literal-files: same, for LIT files (data contained inside the URI)
1490    count-files: sum of the above three
1491    count-directories: count of directories
1492    count-unknown: count of unrecognized objects (perhaps from the future)
1493    size-immutable-files: total bytes for all CHK files in the set, =deep-size
1494    size-mutable-files (TODO): same, for current version of all mutable files
1495    size-literal-files: same, for LIT files
1496    size-directories: size of directories (includes size-literal-files)
1497    size-files-histogram: list of (minsize, maxsize, count) buckets,
1498                          with a histogram of filesizes, 5dB/bucket,
1499                          for both literal and immutable files
1500    largest-directory: number of children in the largest directory
1501    largest-immutable-file: number of bytes in the largest CHK file
1502
1503   size-mutable-files is not implemented, because it would require extra
1504   queries to each mutable file to get their size. This may be implemented in
1505   the future.
1506
1507   Assuming no sharing, the basic space consumed by a single root directory is
1508   the sum of size-immutable-files, size-mutable-files, and size-directories.
1509   The actual disk space used by the shares is larger, because of the
1510   following sources of overhead:
1511
1512    integrity data
1513    expansion due to erasure coding
1514    share management data (leases)
1515    backend (ext3) minimum block size
1516
1517 POST $URL?t=stream-manifest
1518
1519  This operation performs a recursive walk of all files and directories
1520  reachable from the given starting point. For each such unique object
1521  (duplicates are skipped), a single line of JSON is emitted to the HTTP
1522  response channel (or an error indication, see below). When the walk is
1523  complete, a final line of JSON is emitted which contains the accumulated
1524  file-size/count "deep-stats" data.
1525
1526  A CLI tool can split the response stream on newlines into "response units",
1527  and parse each response unit as JSON. Each such parsed unit will be a
1528  dictionary, and will contain at least the "type" key: a string, one of
1529  "file", "directory", or "stats".
1530
1531  For all units that have a type of "file" or "directory", the dictionary will
1532  contain the following keys:
1533
1534   "path": a list of strings, with the path that is traversed to reach the
1535           object
1536   "cap": a write-cap URI for the file or directory, if available, else a
1537          read-cap URI
1538   "verifycap": a verify-cap URI for the file or directory
1539   "repaircap": an URI for the weakest cap that can still be used to repair
1540                the object
1541   "storage-index": a base32 storage index for the object
1542
1543  Note that non-distributed files (i.e. LIT files) will have values of None
1544  for verifycap, repaircap, and storage-index, since these files can neither
1545  be verified nor repaired, and are not stored on the storage servers.
1546
1547  The last unit in the stream will have a type of "stats", and will contain
1548  the keys described in the "start-deep-stats" operation, below.
1549
1550  If any errors occur during the traversal (specifically if a directory is
1551  unrecoverable, such that further traversal is not possible), an error
1552  indication is written to the response body, instead of the usual line of
1553  JSON. This error indication line will begin with the string "ERROR:" (in all
1554  caps), and contain a summary of the error on the rest of the line. The
1555  remaining lines of the response body will be a python exception. The client
1556  application should look for the ERROR: and stop processing JSON as soon as
1557  it is seen. The line just before the ERROR: will describe the directory that
1558  was untraversable, since the manifest entry is emitted to the HTTP response
1559  body before the child is traversed.
1560
1561 == Other Useful Pages ==
1562
1563 The portion of the web namespace that begins with "/uri" (and "/named") is
1564 dedicated to giving users (both humans and programs) access to the Tahoe
1565 virtual filesystem. The rest of the namespace provides status information
1566 about the state of the Tahoe node.
1567
1568 GET /   (the root page)
1569
1570 This is the "Welcome Page", and contains a few distinct sections:
1571
1572  Node information: library versions, local nodeid, services being provided.
1573
1574  Filesystem Access Forms: create a new directory, view a file/directory by
1575                           URI, upload a file (unlinked), download a file by
1576                           URI.
1577
1578  Grid Status: introducer information, helper information, connected storage
1579               servers.
1580
1581 GET /status/
1582
1583  This page lists all active uploads and downloads, and contains a short list
1584  of recent upload/download operations. Each operation has a link to a page
1585  that describes file sizes, servers that were involved, and the time consumed
1586  in each phase of the operation.
1587
1588  A GET of /status/?t=json will contain a machine-readable subset of the same
1589  data. It returns a JSON-encoded dictionary. The only key defined at this
1590  time is "active", with a value that is a list of operation dictionaries, one
1591  for each active operation. Once an operation is completed, it will no longer
1592  appear in data["active"] .
1593
1594  Each op-dict contains a "type" key, one of "upload", "download",
1595  "mapupdate", "publish", or "retrieve" (the first two are for immutable
1596  files, while the latter three are for mutable files and directories).
1597
1598  The "upload" op-dict will contain the following keys:
1599
1600    type (string): "upload"
1601    storage-index-string (string): a base32-encoded storage index
1602    total-size (int): total size of the file
1603    status (string): current status of the operation
1604    progress-hash (float): 1.0 when the file has been hashed
1605    progress-ciphertext (float): 1.0 when the file has been encrypted.
1606    progress-encode-push (float): 1.0 when the file has been encoded and
1607                                  pushed to the storage servers. For helper
1608                                  uploads, the ciphertext value climbs to 1.0
1609                                  first, then encoding starts. For unassisted
1610                                  uploads, ciphertext and encode-push progress
1611                                  will climb at the same pace.
1612
1613  The "download" op-dict will contain the following keys:
1614
1615    type (string): "download"
1616    storage-index-string (string): a base32-encoded storage index
1617    total-size (int): total size of the file
1618    status (string): current status of the operation
1619    progress (float): 1.0 when the file has been fully downloaded
1620
1621  Front-ends which want to report progress information are advised to simply
1622  average together all the progress-* indicators. A slightly more accurate
1623  value can be found by ignoring the progress-hash value (since the current
1624  implementation hashes synchronously, so clients will probably never see
1625  progress-hash!=1.0).
1626
1627 GET /provisioning/
1628
1629  This page provides a basic tool to predict the likely storage and bandwidth
1630  requirements of a large Tahoe grid. It provides forms to input things like
1631  total number of users, number of files per user, average file size, number
1632  of servers, expansion ratio, hard drive failure rate, etc. It then provides
1633  numbers like how many disks per server will be needed, how many read
1634  operations per second should be expected, and the likely MTBF for files in
1635  the grid. This information is very preliminary, and the model upon which it
1636  is based still needs a lot of work.
1637
1638 GET /helper_status/
1639
1640  If the node is running a helper (i.e. if [helper]enabled is set to True in
1641  tahoe.cfg), then this page will provide a list of all the helper operations
1642  currently in progress. If "?t=json" is added to the URL, it will return a
1643  JSON-formatted list of helper statistics, which can then be used to produce
1644  graphs to indicate how busy the helper is.
1645
1646 GET /statistics/
1647
1648  This page provides "node statistics", which are collected from a variety of
1649  sources.
1650
1651    load_monitor: every second, the node schedules a timer for one second in
1652                  the future, then measures how late the subsequent callback
1653                  is. The "load_average" is this tardiness, measured in
1654                  seconds, averaged over the last minute. It is an indication
1655                  of a busy node, one which is doing more work than can be
1656                  completed in a timely fashion. The "max_load" value is the
1657                  highest value that has been seen in the last 60 seconds.
1658
1659    cpu_monitor: every minute, the node uses time.clock() to measure how much
1660                 CPU time it has used, and it uses this value to produce
1661                 1min/5min/15min moving averages. These values range from 0%
1662                 (0.0) to 100% (1.0), and indicate what fraction of the CPU
1663                 has been used by the Tahoe node. Not all operating systems
1664                 provide meaningful data to time.clock(): they may report 100%
1665                 CPU usage at all times.
1666
1667    uploader: this counts how many immutable files (and bytes) have been
1668              uploaded since the node was started
1669
1670    downloader: this counts how many immutable files have been downloaded
1671                since the node was started
1672
1673    publishes: this counts how many mutable files (including directories) have
1674               been modified since the node was started
1675
1676    retrieves: this counts how many mutable files (including directories) have
1677               been read since the node was started
1678
1679  There are other statistics that are tracked by the node. The "raw stats"
1680  section shows a formatted dump of all of them.
1681
1682  By adding "?t=json" to the URL, the node will return a JSON-formatted
1683  dictionary of stats values, which can be used by other tools to produce
1684  graphs of node behavior. The misc/munin/ directory in the source
1685  distribution provides some tools to produce these graphs.
1686
1687 GET /   (introducer status)
1688
1689  For Introducer nodes, the welcome page displays information about both
1690  clients and servers which are connected to the introducer. Servers make
1691  "service announcements", and these are listed in a table. Clients will
1692  subscribe to hear about service announcements, and these subscriptions are
1693  listed in a separate table. Both tables contain information about what
1694  version of Tahoe is being run by the remote node, their advertised and
1695  outbound IP addresses, their nodeid and nickname, and how long they have
1696  been available.
1697
1698  By adding "?t=json" to the URL, the node will return a JSON-formatted
1699  dictionary of stats values, which can be used to produce graphs of connected
1700  clients over time. This dictionary has the following keys:
1701
1702   ["subscription_summary"] : a dictionary mapping service name (like
1703                              "storage") to an integer with the number of
1704                              clients that have subscribed to hear about that
1705                              service
1706   ["announcement_summary"] : a dictionary mapping service name to an integer
1707                              with the number of servers which are announcing
1708                              that service
1709   ["announcement_distinct_hosts"] : a dictionary mapping service name to an
1710                                     integer which represents the number of
1711                                     distinct hosts that are providing that
1712                                     service. If two servers have announced
1713                                     FURLs which use the same hostnames (but
1714                                     different ports and tubids), they are
1715                                     considered to be on the same host.
1716
1717
1718 == Static Files in /public_html ==
1719
1720 The webapi server will take any request for a URL that starts with /static
1721 and serve it from a configurable directory which defaults to
1722 $BASEDIR/public_html . This is configured by setting the "[node]web.static"
1723 value in $BASEDIR/tahoe.cfg . If this is left at the default value of
1724 "public_html", then http://localhost:3456/static/subdir/foo.html will be
1725 served with the contents of the file $BASEDIR/public_html/subdir/foo.html .
1726
1727 This can be useful to serve a javascript application which provides a
1728 prettier front-end to the rest of the Tahoe webapi.
1729
1730
1731 == Safety and security issues -- names vs. URIs ==
1732
1733 Summary: use explicit file- and dir- caps whenever possible, to reduce the
1734 potential for surprises when the filesystem structure is changed.
1735
1736 Tahoe provides a mutable filesystem, but the ways that the filesystem can
1737 change are limited. The only thing that can change is that the mapping from
1738 child names to child objects that each directory contains can be changed by
1739 adding a new child name pointing to an object, removing an existing child name,
1740 or changing an existing child name to point to a different object.
1741
1742 Obviously if you query Tahoe for information about the filesystem and then act
1743 to change the filesystem (such as by getting a listing of the contents of a
1744 directory and then adding a file to the directory), then the filesystem might
1745 have been changed after you queried it and before you acted upon it.  However,
1746 if you use the URI instead of the pathname of an object when you act upon the
1747 object, then the only change that can happen is if the object is a directory
1748 then the set of child names it has might be different. If, on the other hand,
1749 you act upon the object using its pathname, then a different object might be in
1750 that place, which can result in more kinds of surprises.
1751
1752 For example, suppose you are writing code which recursively downloads the
1753 contents of a directory. The first thing your code does is fetch the listing
1754 of the contents of the directory. For each child that it fetched, if that
1755 child is a file then it downloads the file, and if that child is a directory
1756 then it recurses into that directory. Now, if the download and the recurse
1757 actions are performed using the child's name, then the results might be
1758 wrong, because for example a child name that pointed to a sub-directory when
1759 you listed the directory might have been changed to point to a file (in which
1760 case your attempt to recurse into it would result in an error and the file
1761 would be skipped), or a child name that pointed to a file when you listed the
1762 directory might now point to a sub-directory (in which case your attempt to
1763 download the child would result in a file containing HTML text describing the
1764 sub-directory!).
1765
1766 If your recursive algorithm uses the uri of the child instead of the name of
1767 the child, then those kinds of mistakes just can't happen. Note that both the
1768 child's name and the child's URI are included in the results of listing the
1769 parent directory, so it isn't any harder to use the URI for this purpose.
1770
1771 The read and write caps in a given directory node are separate URIs, and
1772 can't be assumed to point to the same object even if they were retrieved in
1773 the same operation (although the webapi server attempts to ensure this
1774 in most cases). If you need to rely on that property, you should explicitly
1775 verify it. More generally, you should not make assumptions about the
1776 internal consistency of the contents of mutable directories. As a result
1777 of the signatures on mutable object versions, it is guaranteed that a given
1778 version was written in a single update, but -- as in the case of a file --
1779 the contents may have been chosen by a malicious writer in a way that is
1780 designed to confuse applications that rely on their consistency.
1781
1782 In general, use names if you want "whatever object (whether file or
1783 directory) is found by following this name (or sequence of names) when my
1784 request reaches the server". Use URIs if you want "this particular object".
1785
1786 == Concurrency Issues ==
1787
1788 Tahoe uses both mutable and immutable files. Mutable files can be created
1789 explicitly by doing an upload with ?mutable=true added, or implicitly by
1790 creating a new directory (since a directory is just a special way to
1791 interpret a given mutable file).
1792
1793 Mutable files suffer from the same consistency-vs-availability tradeoff that
1794 all distributed data storage systems face. It is not possible to
1795 simultaneously achieve perfect consistency and perfect availability in the
1796 face of network partitions (servers being unreachable or faulty).
1797
1798 Tahoe tries to achieve a reasonable compromise, but there is a basic rule in
1799 place, known as the Prime Coordination Directive: "Don't Do That". What this
1800 means is that if write-access to a mutable file is available to several
1801 parties, then those parties are responsible for coordinating their activities
1802 to avoid multiple simultaneous updates. This could be achieved by having
1803 these parties talk to each other and using some sort of locking mechanism, or
1804 by serializing all changes through a single writer.
1805
1806 The consequences of performing uncoordinated writes can vary. Some of the
1807 writers may lose their changes, as somebody else wins the race condition. In
1808 many cases the file will be left in an "unhealthy" state, meaning that there
1809 are not as many redundant shares as we would like (reducing the reliability
1810 of the file against server failures). In the worst case, the file can be left
1811 in such an unhealthy state that no version is recoverable, even the old ones.
1812 It is this small possibility of data loss that prompts us to issue the Prime
1813 Coordination Directive.
1814
1815 Tahoe nodes implement internal serialization to make sure that a single Tahoe
1816 node cannot conflict with itself. For example, it is safe to issue two
1817 directory modification requests to a single tahoe node's webapi server at the
1818 same time, because the Tahoe node will internally delay one of them until
1819 after the other has finished being applied. (This feature was introduced in
1820 Tahoe-1.1; back with Tahoe-1.0 the web client was responsible for serializing
1821 web requests themselves).
1822
1823 For more details, please see the "Consistency vs Availability" and "The Prime
1824 Coordination Directive" sections of mutable.txt, in the same directory as
1825 this file.
1826
1827
1828 [1]: URLs and HTTP and UTF-8, Oh My
1829
1830  HTTP does not provide a mechanism to specify the character set used to
1831  encode non-ascii names in URLs (rfc2396#2.1). We prefer the convention that
1832  the filename= argument shall be a URL-encoded UTF-8 encoded unicode object.
1833  For example, suppose we want to provoke the server into using a filename of
1834  "f i a n c e-acute e" (i.e. F I A N C U+00E9 E). The UTF-8 encoding of this
1835  is 0x66 0x69 0x61 0x6e 0x63 0xc3 0xa9 0x65 (or "fianc\xC3\xA9e", as python's
1836  repr() function would show). To encode this into a URL, the non-printable
1837  characters must be escaped with the urlencode '%XX' mechansim, giving us
1838  "fianc%C3%A9e". Thus, the first line of the HTTP request will be "GET
1839  /uri/CAP...?save=true&filename=fianc%C3%A9e HTTP/1.1". Not all browsers
1840  provide this: IE7 uses the Latin-1 encoding, which is fianc%E9e.
1841
1842  The response header will need to indicate a non-ASCII filename. The actual
1843  mechanism to do this is not clear. For ASCII filenames, the response header
1844  would look like:
1845
1846   Content-Disposition: attachment; filename="english.txt"
1847
1848  If Tahoe were to enforce the utf-8 convention, it would need to decode the
1849  URL argument into a unicode string, and then encode it back into a sequence
1850  of bytes when creating the response header. One possibility would be to use
1851  unencoded utf-8. Developers suggest that IE7 might accept this:
1852
1853   #1: Content-Disposition: attachment; filename="fianc\xC3\xA9e"
1854     (note, the last four bytes of that line, not including the newline, are
1855     0xC3 0xA9 0x65 0x22)
1856
1857  RFC2231#4 (dated 1997): suggests that the following might work, and some
1858  developers (http://markmail.org/message/dsjyokgl7hv64ig3) have reported that
1859  it is supported by firefox (but not IE7):
1860
1861   #2: Content-Disposition: attachment; filename*=utf-8''fianc%C3%A9e
1862
1863  My reading of RFC2616#19.5.1 (which defines Content-Disposition) says that
1864  the filename= parameter is defined to be wrapped in quotes (presumeably to
1865  allow spaces without breaking the parsing of subsequent parameters), which
1866  would give us:
1867
1868   #3: Content-Disposition: attachment; filename*=utf-8''"fianc%C3%A9e"
1869
1870  However this is contrary to the examples in the email thread listed above.
1871
1872  Developers report that IE7 (when it is configured for UTF-8 URL encoding,
1873  which is not the default in asian countries), will accept:
1874
1875   #4: Content-Disposition: attachment; filename=fianc%C3%A9e
1876
1877  However, for maximum compatibility, Tahoe simply copies bytes from the URL
1878  into the response header, rather than enforcing the utf-8 convention. This
1879  means it does not try to decode the filename from the URL argument, nor does
1880  it encode the filename into the response header.