Stream DEFINITIONS AUTOMATIC TAGS ::= BEGIN

IMPORTS UInt8, UInt96, UInt128, VarUInt, VarBytes FROM GenericTypes

Address
FROM InterledgerTypes

Receipt
FROM StreamReceipt

;

StreamEncryptionEnvelope ::= SEQUENCE { -- Random nonce initializationVector UInt96,

-- Authentication tag (output of AES-GCM encryption)
authenticationTag UInt128,

-- Encrypted STREAM Packet
-- Note: This is NOT encoded as a variable length (length-prefixed)
-- octet string. The size is constrained by the length of the data
-- field in the InterledgerPrepare, InterledgerFulfill, or InterledgerReject
-- packet containing this StreamEncryptionEnvelope
cipherText OCTET STRING (SIZE (0..32739))

}

StreamPacket ::= SEQUENCE { -- Always 1 for now version UInt8,

-- ILP Packet type this STREAM packet must be carried upon ilpPacketType UInt8,

-- Packet ID sequence VarUInt,

-- If attached to a Prepare packet, minimum amount that the receiver should accept -- If attached to a Fulfill or Reject packet, amount that arrived at the receiver prepareAmount VarUInt,

-- Array of Frames frames SEQUENCE OF StreamFrame }

FRAME ::= CLASS { &typeId UInt8 UNIQUE, &Type } WITH SYNTAX {&typeId &Type}

FrameSet FRAME ::= { {1 ConnectionError} | {2 ConnectionNewAddress} | {3 ConnectionMaxData} | {4 ConnectionDataBlocked} | {5 ConnectionMaxStreamId} | {6 ConnectionStreamIdBlocked} |

{16 StreamClose} | {17 StreamMoney} | {18 StreamMaxMoney} | {19 StreamMoneyBlocked} | {20 StreamData} | {21 StreamMaxData} | {22 StreamDataBlocked} | {23 StreamReceipt} }

StreamFrame ::= SEQUENCE { type FRAME.&typeId ({FrameSet}), data FRAME.&Type ({FrameSet}{@type}) }

ConnectionError ::= SEQUENCE { -- Numeric error code code UInt8,

-- Human-readable error message message UTF8String }

ConnectionNewAddress ::= SEQUENCE { -- ILP Address of the party that sends the frame address Address }

ConnectionMaxData ::= SEQUENCE { maxOffset VarUInt }

ConnectionDataBlocked ::= SEQUENCE { maxOffset VarUInt }

ConnectionMaxStreamId ::= SEQUENCE { maxStreamId VarUInt }

ConnectionStreamIdBlocked ::= SEQUENCE { maxStreamId VarUInt }

StreamClose ::= SEQUENCE { -- Identifier of the stream streamId VarUInt,

-- Numeric error code code UInt8,

-- Human-readable error message message UTF8String }

StreamMoney ::= SEQUENCE { -- Identifier of the stream streamId VarUInt,

-- The proportion of the Prepare amount that should go to this stream -- i.e. the amount for a given stream = prepare amount * shares / (sum of shares from all StreamMoney frames in the packet) shares VarUInt }

StreamMaxMoney ::= SEQUENCE { -- Identifier of the stream streamId VarUInt,

-- Maximum amount the stream can receive receiveMax VarUInt,

-- Total amount the stream has received so far totalReceived VarUInt }

StreamMoneyBlocked ::= SEQUENCE { -- Identifier of the stream streamId VarUInt,

-- Maximum amount the stream can send sendMax VarUInt,

-- Total amount the stream has sent so far totalSent VarUInt }

StreamData ::= SEQUENCE { -- Identifier of the DataStream streamId VarUInt,

-- Byte number of the first byte in this frame within the whole DataStream -- (the first StreamData frame sent for a given DataStream will have an offset of 0) offset VarUInt,

-- Application data data VarBytes }

StreamMaxData ::= SEQUENCE { -- Identifier of the stream streamId VarUInt,

-- Maximum number of bytes the endpoint is willing to receive on this stream maxOffset VarUInt }

StreamDataBlocked ::= SEQUENCE { -- Identifier of the stream streamId VarUInt,

-- Maximum number of bytes the endpoint wants to send on this stream maxOffset VarUInt }

StreamReceipt ::= SEQUENCE { -- Identifier of the stream streamId VarUInt,

-- Length-prefixed Receipt for verifying the total amount received on this stream -- The sender is not expected to decode the Receipt fields but must be able to decode the -- receipt string in the frame, even if it represents an unsupported Receipt version receipt Receipt }

END