Removing spec quotation from LN_MAX_MSG_LEN definition
[rust-lightning] / lightning / src / ln / wire.rs
index 15a218060e6ffc52b4843272c3d6fa64113408b2..43a8cd5ddac6c79ad5d7190df617c73f33719da0 100644 (file)
 use ln::msgs;
 use util::ser::{Readable, Writeable, Writer};
 
+/// Maximum Lightning message data length according to
+/// [BOLT-8](https://github.com/lightningnetwork/lightning-rfc/blob/v1.0/08-transport.md#lightning-message-specification)
+/// and [BOLT-1](https://github.com/lightningnetwork/lightning-rfc/blob/master/01-messaging.md#lightning-message-format):
+pub const LN_MAX_MSG_LEN: usize = std::u16::MAX as usize; // Must be equal to 65535
+
 /// A Lightning message returned by [`read`] when decoding bytes received over the wire. Each
 /// variant contains a message from [`ln::msgs`] or otherwise the message type if unknown.
 ///
@@ -311,6 +316,12 @@ mod tests {
        // Big-endian wire encoding of Pong message (type = 19, byteslen = 2).
        const ENCODED_PONG: [u8; 6] = [0u8, 19u8, 0u8, 2u8, 0u8, 0u8];
 
+       #[test]
+       fn max_msg_len() {
+               assert_eq!(LN_MAX_MSG_LEN, 65535);
+               assert_eq!(LN_MAX_MSG_LEN, std::u16::MAX as usize);
+       }
+
        #[test]
        fn read_empty_buffer() {
                let buffer = [];