| | @@ -1,20 +1,16 @@ |
| 1 | 1 | <title>The Fossil Sync Protocol</title> |
| 2 | 2 | |
| 3 | | -<p>Fossil supports commands <b>push</b>, <b>pull</b>, and <b>sync</b> |
| 4 | | -for transferring information from one repository to another. The |
| 5 | | -command is run on the client repository. A URL for the server repository |
| 6 | | -is specified as part of the command. This document describes what happens |
| 7 | | -behind the scenes in order to synchronize the information on the two |
| 8 | | -repositories.</p> |
| 3 | +<p>This document describes the wire protocol used to synchronize |
| 4 | +content between two Fossil repositories.</p> |
| 9 | 5 | |
| 10 | 6 | <h2>1.0 Overview</h2> |
| 11 | 7 | |
| 12 | 8 | <p>The global state of a fossil repository consists of an unordered |
| 13 | 9 | collection of artifacts. Each artifact is identified by its SHA1 hash |
| 14 | 10 | expressed as a 40-character lower-case hexadecimal string. |
| 15 | | -Synchronization is simply the process of sharing artifacts between |
| 11 | +Synchronization is the process of sharing artifacts between |
| 16 | 12 | servers so that all servers have copies of all artifacts. Because |
| 17 | 13 | artifacts are unordered, the order in which artifacts are received |
| 18 | 14 | at a server is inconsequential. It is assumed that the SHA1 hashes |
| 19 | 15 | of artifacts are unique - that every artifact has a different SHA1 hash. |
| 20 | 16 | To a first approximation, synchronization proceeds by sharing lists |
| | @@ -26,15 +22,16 @@ |
| 26 | 22 | shared to a few hundred.</p> |
| 27 | 23 | |
| 28 | 24 | <p>Each repository also has local state. The local state determines |
| 29 | 25 | the web-page formatting preferences, authorized users, ticket formats, |
| 30 | 26 | and similar information that varies from one repository to another. |
| 31 | | -The local state is not transferred by the <b>push</b>, <b>pull</b>, |
| 32 | | -and <b>sync</b> command, though some local state is transferred during |
| 33 | | -a <b>clone</b> in order to initialize the local state of the new |
| 34 | | -repository. The <b>configuration push</b> and <b>configuration pull</b> |
| 35 | | -commands can be used to send or receive local state.</p> |
| 27 | +The local state is not using transferred during a sync. Except, |
| 28 | +some local state is transferred during a [/help?cmd=clone|clone] |
| 29 | +in order to initialize the local state of the new repository. And |
| 30 | +the [/help?cmd=configuration|config push] and |
| 31 | +[/help?cmd=configuration|config pull] |
| 32 | +commands can be an administrator to sync local state.</p> |
| 36 | 33 | |
| 37 | 34 | |
| 38 | 35 | <h2>2.0 Transport</h2> |
| 39 | 36 | |
| 40 | 37 | <p>All communication between client and server is via HTTP requests. |
| | @@ -43,20 +40,31 @@ |
| 43 | 40 | request.</p> |
| 44 | 41 | |
| 45 | 42 | <p>The server might be running as an independent server |
| 46 | 43 | using the <b>server</b> command, or it might be launched from |
| 47 | 44 | inetd or xinetd using the <b>http</b> command. Or the server might |
| 48 | | -be launched from CGI. The details of how the server is configured |
| 49 | | -to "listen" for incoming HTTP requests is immaterial. The important |
| 50 | | -point is that the server is listening for requests and the client |
| 51 | | -is the issuer of the requests.</p> |
| 45 | +be launched from CGI. |
| 46 | +(See "[./server.wiki|How To Configure A Fossil Server]" for details.) |
| 47 | +The specifics of how the server listens |
| 48 | +for incoming HTTP requests is immaterial to this protocol. |
| 49 | +The important point is that the server is listening for requests and |
| 50 | +the client is the issuer of the requests.</p> |
| 52 | 51 | |
| 53 | 52 | <p>A single push, pull, or sync might involve multiple HTTP requests. |
| 54 | 53 | The client maintains state between all requests. But on the server |
| 55 | 54 | side, each request is independent. The server does not preserve |
| 56 | 55 | any information about the client from one request to the next.</p> |
| 57 | 56 | |
| 57 | +<h4>2.0.1 Encrypted Transport</h4> |
| 58 | + |
| 59 | +<p>In the current implementation of Fossil, the server only |
| 60 | +understands HTTP requests. The client can send either |
| 61 | +clear-text HTTP requested or or encrypted HTTPS requests. But when |
| 62 | +HTTPS requests are sent, they first must be decrypted by a webserver |
| 63 | +or proxy before being passed to the Fossil server. This limitation |
| 64 | +may be relaxed in a future release.</p> |
| 65 | + |
| 58 | 66 | <h3>2.1 Server Identification</h3> |
| 59 | 67 | |
| 60 | 68 | <p>The server is identified by a URL argument that accompanies the |
| 61 | 69 | push, pull, or sync command on the client. (As a convenience to |
| 62 | 70 | users, the URL can be omitted on the client command and the same URL |
| | @@ -233,10 +241,26 @@ |
| 233 | 241 | delta artifact.</p> |
| 234 | 242 | |
| 235 | 243 | <p>Unlike file cards, cfile cards are only sent in one direction during a |
| 236 | 244 | clone from server to client for clone protocol version "3" or greater.</p> |
| 237 | 245 | |
| 246 | +<h4>3.3.3 Private artifacts</h4> |
| 247 | + |
| 248 | +<p>"Private" content consist of artifacts that are not normally synced. |
| 249 | +However, private content will be synced when the |
| 250 | +the [/help?cmd=sync|fossil sync] command includes the "--private" option. |
| 251 | +</p> |
| 252 | + |
| 253 | +<p>Private content is marked by a "private" card: |
| 254 | + |
| 255 | +<blockquote> |
| 256 | +<b>private</b> |
| 257 | +</blockquote> |
| 258 | + |
| 259 | +<p>The private card has no arguments and must directly precede a |
| 260 | +file card that contains the private content.</p> |
| 261 | + |
| 238 | 262 | <h3>3.4 Push and Pull Cards</h3> |
| 239 | 263 | |
| 240 | 264 | <p>Among the first cards in a client-to-server message are |
| 241 | 265 | the push and pull cards. The push card tells the server that |
| 242 | 266 | the client is pushing content. The pull card tells the server |
| | @@ -255,10 +279,12 @@ |
| 255 | 279 | for the transaction to proceed.</p> |
| 256 | 280 | |
| 257 | 281 | <p>The server will also send a push card back to the client |
| 258 | 282 | during a clone. This is how the client determines what project |
| 259 | 283 | code to put in the new repository it is constructing.</p> |
| 284 | + |
| 285 | +<p>The <i>servercode</i> argument is currently unused. |
| 260 | 286 | |
| 261 | 287 | <h3>3.5 Clone Cards</h3> |
| 262 | 288 | |
| 263 | 289 | <p>A clone card works like a pull card in that it is sent from |
| 264 | 290 | client to server in order to tell the server that the client |
| | @@ -320,19 +346,23 @@ |
| 320 | 346 | <p>An igot card can be sent from either client to server or from |
| 321 | 347 | server to client in order to indicate that the sender holds a copy |
| 322 | 348 | of a particular artifact. The format is:</p> |
| 323 | 349 | |
| 324 | 350 | <blockquote> |
| 325 | | -<b>igot</b> <i>artifact-id</i> |
| 351 | +<b>igot</b> <i>artifact-id</i> ?<i>flag</i>? |
| 326 | 352 | </blockquote> |
| 327 | 353 | |
| 328 | | -<p>The argument of the igot card is the ID of the artifact that |
| 354 | +<p>The first argument of the igot card is the ID of the artifact that |
| 329 | 355 | the sender possesses. |
| 330 | 356 | The receiver of an igot card will typically check to see if |
| 331 | 357 | it also holds the same artifact and if not it will request the artifact |
| 332 | 358 | using a gimme card in either the reply or in the next message.</p> |
| 333 | 359 | |
| 360 | +<p>If the second argument exists and is "1", then the artifact |
| 361 | +identified by the first argument is private on the sender and should |
| 362 | +be ignored unless a "--private" [/help?cmd=sync|sync] is occurring. |
| 363 | + |
| 334 | 364 | <h3>3.7 Gimme Cards</h3> |
| 335 | 365 | |
| 336 | 366 | <p>A gimme card is sent from either client to server or from server |
| 337 | 367 | to client. The gimme card asks the receiver to send a particular |
| 338 | 368 | artifact back to the sender. The format of a gimme card is this:</p> |
| | @@ -477,11 +507,50 @@ |
| 477 | 507 | it had sent a corresponding reqconfig card in its request. |
| 478 | 508 | |
| 479 | 509 | <p>The content of the configuration item is used to overwrite the |
| 480 | 510 | corresponding configuration data in the receiver. |
| 481 | 511 | |
| 482 | | -<h3>3.11 Error Cards</h3> |
| 512 | +<h3>3.11 Pragma Cards</h3> |
| 513 | + |
| 514 | +<p>The client may try to influence the behavior of the server by |
| 515 | +issuing a pragma card: |
| 516 | + |
| 517 | +<blockquote> |
| 518 | +<b>pragma</i> <i>name value...</i> |
| 519 | +</blockquote> |
| 520 | + |
| 521 | +<p>The "pragma" card has at least one argument which is the pragma name. |
| 522 | +The pragma name defines what the pragma does. |
| 523 | +A pragma might have zero or more "value" arguments |
| 524 | +depending on the pragma name. |
| 525 | + |
| 526 | +<p>New pragma names may be added to the protocol from time to time |
| 527 | +in order to enhance the capabilities of Fossil. |
| 528 | +Unknown pragmas are silently ignored, for backwards compatibility. |
| 529 | + |
| 530 | +<p>The following are the known pragma names as of 2016-08-03: |
| 531 | + |
| 532 | +<ol> |
| 533 | +<li><p><b>send-private</b> |
| 534 | +<p>The send-private pragma instructs the server to send all of its |
| 535 | +private artifacts to the client. The server will only obey this |
| 536 | +request if the user has the "x" or "Private" privilege. |
| 537 | + |
| 538 | +<li><p><b>send-catalog</b> |
| 539 | +<p>The send-catalog pragma instructs the server to transmit igot |
| 540 | +cards for every known artifact. This can help the client and server |
| 541 | +to get back in synchronization after a prior protocol error. The |
| 542 | +"--verily" option to the [/help?cmd=sync|fossil sync] command causes |
| 543 | +the send-catalog pragma to be transmitted.</p> |
| 544 | +</ol> |
| 545 | + |
| 546 | +<h3>3.12 Comment Cards</h3> |
| 547 | + |
| 548 | +<p>Any card that begins with "#" (ASCII 0x23) is a comment card and |
| 549 | +is silently ignored.</p> |
| 550 | + |
| 551 | +<h3>3.13 Error Cards</h3> |
| 483 | 552 | |
| 484 | 553 | <p>If the server discovers anything wrong with a request, it generates |
| 485 | 554 | an error card in its reply. When the client sees the error card, |
| 486 | 555 | it displays an error message to the user and aborts the sync |
| 487 | 556 | operation. An error card looks like this:</p> |
| | @@ -497,16 +566,11 @@ |
| 497 | 566 | (ASCII 0x5C) is represented as two backslashes "\\". Apart from |
| 498 | 567 | space and newline, no other whitespace characters nor any |
| 499 | 568 | unprintable characters are allowed in |
| 500 | 569 | the error message.</p> |
| 501 | 570 | |
| 502 | | -<h3>3.12 Comment Cards</h3> |
| 503 | | - |
| 504 | | -<p>Any card that begins with "#" (ASCII 0x23) is a comment card and |
| 505 | | -is silently ignored.</p> |
| 506 | | - |
| 507 | | -<h3>3.13 Unknown Cards</h3> |
| 571 | +<h3>3.14 Unknown Cards</h3> |
| 508 | 572 | |
| 509 | 573 | <p>If either the client or the server sees a card that is not |
| 510 | 574 | described above, then it generates an error and aborts.</p> |
| 511 | 575 | |
| 512 | 576 | <h2>4.0 Phantoms And Clusters</h2> |
| | @@ -665,23 +729,28 @@ |
| 665 | 729 | <ul> |
| 666 | 730 | <li> <b>login</b> <i>userid nonce signature</i> |
| 667 | 731 | <li> <b>push</b> <i>servercode projectcode</i> |
| 668 | 732 | <li> <b>pull</b> <i>servercode projectcode</i> |
| 669 | 733 | <li> <b>clone</b> |
| 734 | + <li> <b>clone_seqno</b> <i>sequence-number</i> |
| 670 | 735 | <li> <b>file</b> <i>artifact-id size</i> <b>\n</b> <i>content</i> |
| 671 | 736 | <li> <b>file</b> <i>artifact-id delta-artifact-id size</i> <b>\n</b> <i>content</i> |
| 672 | | - <li> <b>igot</b> <i>artifact-id</i> |
| 737 | + <li> <b>cfile</b> <i>artifact-id size</i> <b>\n</b> <i>content</i> |
| 738 | + <li> <b>cfile</b> <i>artifact-id delta-artifact-id size</i> <b>\n</b> <i>content</i> |
| 739 | + <li> <b>private</b> |
| 740 | + <li> <b>igot</b> <i>artifact-id</i> ?<i>flag</i>? |
| 673 | 741 | <li> <b>gimme</b> <i>artifact-id</i> |
| 674 | 742 | <li> <b>cookie</b> <i>cookie-text</i> |
| 675 | 743 | <li> <b>reqconfig</b> <i>parameter-name</i> |
| 676 | 744 | <li> <b>config</b> <i>parameter-name size</i> <b>\n</b> <i>content</i> |
| 677 | | - <li> <b>#</b> <i>arbitrary-text...</i> |
| 745 | + <li> <b>pragma</b> <i>name</i> <i>value...</i> |
| 678 | 746 | <li> <b>error</b> <i>error-message</i> |
| 747 | + <li> <b>#</b> <i>arbitrary-text...</i> |
| 679 | 748 | </ul> |
| 680 | 749 | <li>Phantoms are artifacts that a repository knows exist but does not possess. |
| 681 | 750 | <li>Clusters are artifacts that contain IDs of other artifacts. |
| 682 | 751 | <li>Clusters are created automatically on the server during a pull. |
| 683 | 752 | <li>Repositories keep track of all artifacts that are not named in any |
| 684 | 753 | cluster and send igot messages for those artifacts. |
| 685 | 754 | <li>Repositories keep track of all the phantoms they hold and send |
| 686 | 755 | gimme messages for those artifacts. |
| 687 | 756 | </ol> |
| 688 | 757 | |