467 ordered sends and receives is required. That is, each peer has one pipe |
467 ordered sends and receives is required. That is, each peer has one pipe |
468 for sending data and another for receiving. |
468 for sending data and another for receiving. |
469 |
469 |
470 The protocol is request-response based: the client issues requests to |
470 The protocol is request-response based: the client issues requests to |
471 the server, which issues replies to those requests. Server-initiated |
471 the server, which issues replies to those requests. Server-initiated |
472 messaging is not supported. |
472 messaging is not currently supported, but this specification carves |
|
473 out room to implement it. |
473 |
474 |
474 All data is read and written in atomic units called *frames*. These |
475 All data is read and written in atomic units called *frames*. These |
475 are conceptually similar to TCP packets. Higher-level functionality |
476 are conceptually similar to TCP packets. Higher-level functionality |
476 is built on the exchange and processing of frames. |
477 is built on the exchange and processing of frames. |
477 |
478 |
478 Frames begin with a 4 octet header followed by a variable length |
479 All frames are associated with a numbered request. Frames can thus |
|
480 be logically grouped by their request ID. |
|
481 |
|
482 Frames begin with a 6 octet header followed by a variable length |
479 payload:: |
483 payload:: |
480 |
484 |
481 +-----------------------------------------------+ |
485 +-----------------------------------------------+ |
482 | Length (24) | |
486 | Length (24) | |
483 +-----------+-----------------------------------+ |
487 +---------------------------------+-------------+ |
484 | Type (4) | |
488 | Request ID (16) | |
485 +-----------+ |
489 +----------+-----------+----------+ |
486 | Flags (4) | |
490 | Type (4) | Flags (4) | |
487 +===========+===================================================| |
491 +==========+===========+========================================| |
488 | Frame Payload (0...) ... |
492 | Frame Payload (0...) ... |
489 +---------------------------------------------------------------+ |
493 +---------------------------------------------------------------+ |
490 |
494 |
491 The length of the frame payload is expressed as an unsigned 24 bit |
495 The length of the frame payload is expressed as an unsigned 24 bit |
492 little endian integer. Values larger than 65535 MUST NOT be used unless |
496 little endian integer. Values larger than 65535 MUST NOT be used unless |
493 given permission by the server as part of the negotiated capabilities |
497 given permission by the server as part of the negotiated capabilities |
494 during the handshake. The frame header is not part of the advertised |
498 during the handshake. The frame header is not part of the advertised |
495 frame length. |
499 frame length. |
|
500 |
|
501 The 16-bit ``Request ID`` field denotes the integer request identifier, |
|
502 stored as an unsigned little endian integer. Odd numbered requests are |
|
503 client-initiated. Even numbered requests are server-initiated. This |
|
504 refers to where the *request* was initiated - not where the *frame* was |
|
505 initiated, so servers will send frames with odd ``Request ID`` in |
|
506 response to client-initiated requests. Implementations are advised to |
|
507 start ordering request identifiers at ``1`` and ``0``, increment by |
|
508 ``2``, and wrap around if all available numbers have been exhausted. |
496 |
509 |
497 The 4-bit ``Type`` field denotes the type of message being sent. |
510 The 4-bit ``Type`` field denotes the type of message being sent. |
498 |
511 |
499 The 4-bit ``Flags`` field defines special, per-type attributes for |
512 The 4-bit ``Flags`` field defines special, per-type attributes for |
500 the frame. |
513 the frame. |
630 |
643 |
631 A client can request that a remote run a command by sending it |
644 A client can request that a remote run a command by sending it |
632 frames defining that command. This logical stream is composed of |
645 frames defining that command. This logical stream is composed of |
633 1 ``Command Request`` frame, 0 or more ``Command Argument`` frames, |
646 1 ``Command Request`` frame, 0 or more ``Command Argument`` frames, |
634 and 0 or more ``Command Data`` frames. |
647 and 0 or more ``Command Data`` frames. |
|
648 |
|
649 All frames composing a single command request MUST be associated with |
|
650 the same ``Request ID``. |
|
651 |
|
652 Clients MAY send additional command requests without waiting on the |
|
653 response to a previous command request. If they do so, they MUST ensure |
|
654 that the ``Request ID`` field of outbound frames does not conflict |
|
655 with that of an active ``Request ID`` whose response has not yet been |
|
656 fully received. |
|
657 |
|
658 Servers MAY respond to commands in a different order than they were |
|
659 sent over the wire. Clients MUST be prepared to deal with this. Servers |
|
660 also MAY start executing commands in a different order than they were |
|
661 received, or MAY execute multiple commands concurrently. |
|
662 |
|
663 If there is a dependency between commands or a race condition between |
|
664 commands executing (e.g. a read-only command that depends on the results |
|
665 of a command that mutates the repository), then clients MUST NOT send |
|
666 frames issuing a command until a response to all dependent commands has |
|
667 been received. |
|
668 TODO think about whether we should express dependencies between commands |
|
669 to avoid roundtrip latency. |
635 |
670 |
636 Argument frames are the recommended mechanism for transferring fixed |
671 Argument frames are the recommended mechanism for transferring fixed |
637 sets of parameters to a command. Data frames are appropriate for |
672 sets of parameters to a command. Data frames are appropriate for |
638 transferring variable data. A similar comparison would be to HTTP: |
673 transferring variable data. A similar comparison would be to HTTP: |
639 argument frames are headers and the message body is data frames. |
674 argument frames are headers and the message body is data frames. |