Message Framing, Part 4

Past entries that you should have read by now:

After the message encoding is communicated, the framing protocol starts to diverge based on the mode record that was provided.

In the modes used by TCP, which are all duplex and half-duplex communication modes, there is now an opportunity for the two sides to negotiate additional framing options. This is also the first time that the communication backchannel has data to exchange. In the modes used by MSMQ, which are all one-way communication modes, there is no negotiation capability so these described records are not present.

Optionally, the initiator of the connection sends an upgrade request record to negotiate additional framing options. An upgrade request record starts with the byte 9 followed by the size of the upgrade string and followed by the upgrade string itself. An upgrade string is an opaque blob that uniquely identifies the upgrade. The size is encoded in the usual way. We happen to use MIME content types to name our upgrades because the upgrades we've implemented so far are all preexisting standards.

The receiver indicates its acceptance of an upgrade by sending an upgrade response record. An upgrade response record is the byte 10. When we get to talking about errors, I'll explain what happens if the receiver doesn't accept the upgrade.

After an upgrade is accepted, the upgraded stream wraps all of the protocol transmissions. For example, if the upgrade was to negotiate an additional framing option of SSL communication, at this point an SSL handshake would be exchanged. All future transmissions would be over the SSL connection. Due to the way that upgrades wrap the underlying byte stream to add new protocol options, these are called stream upgrades.

Once the initiator is done sending upgrade requests, the next record is a preamble end record. A preamble end record is the byte 12. We know that the receiver and initiator are synchronized on all of the data that has been transmitted so far when the initiator receives back a preamble acknowledgment record. A preamble acknowledgment record is the byte 11.