From d734e64a44b0a4cbc3f39783719356f7009f7d35 Mon Sep 17 00:00:00 2001 From: akwizgran Date: Tue, 24 Mar 2015 10:01:35 +0000 Subject: [PATCH] akwizgran created page: BSP --- BSP.markdown | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/BSP.markdown b/BSP.markdown index e6dde95..001686e 100644 --- a/BSP.markdown +++ b/BSP.markdown @@ -14,8 +14,14 @@ Each channel has a unique identifier hash_len bytes long. This identifier is sup ### Message format -Each message consists of one or more blocks, each of which is block_len bytes long, except the last block, which may be shorter. The blocks form the leaves of a binary hash tree. Each parent node consists of the concatenated hashes of its children. If the number of blocks is not a power of two, some parent nodes will only have one child. +Each message consists of one or more blocks, each block_len bytes long, except the last, which may be shorter. The blocks form the leaves of a binary hash tree. Each parent node consists of the concatenated hashes of its children. If the number of blocks is not a power of two, some parent nodes will only have one child. -The message's unique identifier is calculated by hashing a message header concatenated with the root node of the hash tree. The message header consists of the channel identifier, a timestamp, the message type, and the depth of the tree excluding leaves. +The message's unique identifier is calculated by hashing a message header concatenated with the root hash of the tree. The message header consists of the channel identifier, a timestamp, the message length and the message type. -The timestamp is a 64-bit big-endian integer representing the time at which the message was created, in seconds since the Unix epoch. The message type is a single byte that is supplied by the application and not interpreted by BSP. The depth of the tree is an 8-bit integer. The total length of the message header is hash_len + 10 bytes. +The timestamp is a 64-bit integer representing seconds since the Unix epoch. (All integers in BSP are big-endian and signed.) The message length is a 64-bit integer representing the length of the message in bytes. The message type is a single byte that is supplied by the application and not interpreted by BSP. The length of the message header is hash_len + 17 bytes. + +Each block also has a unique identifier, which is calculated by hashing the message header concatenated with a block header and the hash of the block itself. The block header consists of the block number and a list of hashes called the path. + +The block number is a 64-bit integer starting from zero for the first block of the file. The path contains the hashes of the block's ancestors' siblings in the hash tree. If the number of blocks is not a power of two, some ancestors may not have siblings. The positions of any nonexistent siblings can be calculated from the message length and the block number. + +Given the message header, block header and block, it is possible to check that the message header, block header and block are consistent, and to calculate the message identifier. Any blocks that produce the same message identifier must have consistent message and block headers. This makes it possible to synchronise messages a block at a time by including the message header and block header with each block.