ip-v8/rust-ipv8

View on GitHub
rust_ipv8/tests/testpyipv8packets.rs

Summary

Maintainability
Test Coverage
use rust_ipv8::networking::address::Address;
use rust_ipv8::payloads::connectiontype::ConnectionType;
use rust_ipv8::payloads::introductionrequestpayload::IntroductionRequestPayload;
use rust_ipv8::payloads::introductionresponsepayload::IntroductionResponsePayload;
use rust_ipv8::payloads::puncturerequestpayload::PunctureRequestPayload;
use rust_ipv8::payloads::timedistributionpayload::TimeDistributionPayload;
use rust_ipv8::serialization::header::Header;
use rust_ipv8::serialization::rawend::RawEnd;
use rust_ipv8::serialization::Packet;
use std::net::{Ipv4Addr, SocketAddr, IpAddr};

#[test]
fn test_packet_1() {
    // packet #1 in testpackets
    // header + BinMemberAuthenticationPayload + GlobalTimeDistributionPayload + IntroductionResponsePayload:
    let data = Packet(vec![
        0x00, 0x02, 0xba, 0xf3, 0x0e, 0xd9, 0x19, 0x2b, 0xa3, 0x54, 0xcd, 0xd7, 0xb1, 0x73, 0xe0,
        0xef, 0x2c, 0x32, 0x80, 0x27, 0xf1, 0xd3, 0xf5, 0x00, 0x4a, 0x4c, 0x69, 0x62, 0x4e, 0x61,
        0x43, 0x4c, 0x50, 0x4b, 0x3a, 0x51, 0xe7, 0x12, 0xc4, 0xeb, 0x8a, 0xc2, 0x5a, 0xe3, 0xa5,
        0x68, 0x24, 0x08, 0xb2, 0xad, 0xbd, 0x6b, 0x78, 0xa4, 0x25, 0x54, 0x7f, 0x26, 0x85, 0xcf,
        0xdf, 0x1e, 0xe9, 0x27, 0x0c, 0xbe, 0x7e, 0xc3, 0x36, 0xc4, 0x16, 0x0f, 0xf5, 0x72, 0x05,
        0x4c, 0x87, 0x78, 0x42, 0xbe, 0x37, 0x73, 0x50, 0x45, 0xa9, 0x3b, 0xc4, 0xe2, 0x04, 0x15,
        0x31, 0x6f, 0xdb, 0x14, 0x71, 0x61, 0xa2, 0xd7, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x01, 0x51, 0xab, 0x1b, 0xc2, 0x2b, 0x67, 0xc0, 0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0xc0,
        0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0xd2, 0x0e, 0x00, 0x00, 0x00, 0x00, 0xce, 0xe9, 0x32, 0x6b, 0x9d, 0xd4,
        0xbb, 0x8a, 0xaf, 0x8d, 0xc0, 0x39, 0x28, 0x8e, 0xbf, 0xc2, 0x4a, 0x10, 0xad, 0xc3, 0x7a,
        0xf1, 0xd9, 0xc8, 0x04, 0x17, 0x72, 0x5d, 0x2d, 0x3e, 0x5e, 0x07, 0x52, 0x4d, 0xab, 0x6e,
        0xa7, 0x1b, 0x17, 0x5a, 0x77, 0x5d, 0xb5, 0xd8, 0x91, 0x0c, 0x2b, 0x4b, 0xc8, 0xbb, 0x03,
        0xd3, 0x55, 0xed, 0x10, 0x26, 0xdd, 0xbb, 0xd8, 0xb2, 0x3b, 0xfd, 0xfc, 0x01,
    ]);
    let mut deserializer = data.start_deserialize();

    let header: Header = deserializer.pop_header().unwrap();
    assert_eq!(
        header,
        Header::py_ipv8_header(
            [
                186, 243, 14, 217, 25, 43, 163, 84, 205, 215, 177, 115, 224, 239, 44, 50, 128, 39,
                241, 211
            ],
            245,
        )
    );

    assert!(deserializer.verify());

    let time: TimeDistributionPayload = deserializer.next_payload().unwrap();
    assert_eq!(time, TimeDistributionPayload { global_time: 1 });

    let intro: IntroductionResponsePayload = deserializer.next_payload().unwrap();
    assert_eq!(
        intro,
        IntroductionResponsePayload {
            destination_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(81, 171, 27, 194)),
                11111
            )),
            source_lan_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            source_wan_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            lan_introduction_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
                0
            )),
            wan_introduction_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
                0
            )),
            tunnel: false,
            connection_type: ConnectionType::UNKNOWN,
            identifier: 53774,
            extra_bytes: RawEnd(vec![0, 0, 0, 0])
        }
    )
}

#[test]
fn test_packet_2() {
    // packet 2 in testpackets
    // header + BinMemberAuthenticationPayload + GlobalTimeDistributionPayload + PunctureRequestPayload
    let data = Packet(vec![
        0x00, 0x02, 0xb9, 0x5f, 0xa1, 0xdd, 0xcf, 0xab, 0xbf, 0xbb, 0xa1, 0x60, 0xf0, 0x3c, 0x44,
        0x19, 0xad, 0x49, 0xab, 0x14, 0xe3, 0x8f, 0xf9, 0x00, 0x4a, 0x4c, 0x69, 0x62, 0x4e, 0x61,
        0x43, 0x4c, 0x50, 0x4b, 0x3a, 0x51, 0xe7, 0x12, 0xc4, 0xeb, 0x8a, 0xc2, 0x5a, 0xe3, 0xa5,
        0x68, 0x24, 0x08, 0xb2, 0xad, 0xbd, 0x6b, 0x78, 0xa4, 0x25, 0x54, 0x7f, 0x26, 0x85, 0xcf,
        0xdf, 0x1e, 0xe9, 0x27, 0x0c, 0xbe, 0x7e, 0xc3, 0x36, 0xc4, 0x16, 0x0f, 0xf5, 0x72, 0x05,
        0x4c, 0x87, 0x78, 0x42, 0xbe, 0x37, 0x73, 0x50, 0x45, 0xa9, 0x3b, 0xc4, 0xe2, 0x04, 0x15,
        0x31, 0x6f, 0xdb, 0x14, 0x71, 0x61, 0xa2, 0xd7, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x03, 0xc0, 0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0x51, 0xab, 0x1b, 0xc2, 0x3d, 0xf7, 0xd1,
        0x5a, 0xd2, 0xc2, 0xcf, 0x7a, 0x79, 0x45, 0x44, 0x73, 0x15, 0x90, 0xc6, 0xe0, 0x01, 0x66,
        0x48, 0xe5, 0xbc, 0xa1, 0xe2, 0xb2, 0x47, 0xa9, 0x93, 0x9d, 0xbf, 0xc7, 0xa2, 0x96, 0xd3,
        0x42, 0xda, 0xd0, 0xd4, 0x4a, 0x25, 0xb8, 0xa8, 0x9c, 0xc3, 0xe1, 0x2d, 0x46, 0x7d, 0x49,
        0x95, 0x38, 0xea, 0xca, 0xec, 0x06, 0xf2, 0x03, 0x0b, 0xff, 0xa8, 0xf8, 0x06, 0x65, 0xd4,
        0x74, 0x3b, 0x32, 0xb0, 0x00,
    ]);
    let mut deserializer = data.start_deserialize();

    let header: Header = deserializer.pop_header().unwrap();
    assert_eq!(
        header,
        Header::py_ipv8_header(
            [
                185, 95, 161, 221, 207, 171, 191, 187, 161, 96, 240, 60, 68, 25, 173, 73, 171, 20,
                227, 143
            ],
            249,
        )
    );

    assert!(deserializer.verify());

    let time: TimeDistributionPayload = deserializer.next_payload().unwrap();
    assert_eq!(time, TimeDistributionPayload { global_time: 3 });

    let puncture: PunctureRequestPayload = deserializer.next_payload().unwrap();
    assert_eq!(
        puncture,
        PunctureRequestPayload {
            lan_walker_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            wan_walker_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(81, 171, 27, 194)),
                15863
            )),
            identifier: 53594
        }
    )
}

#[test]
fn test_packet_3() {
    // #3 header + GlobalTimeDistributionPayload + PunctureRequestPayload:
    let data = Packet(vec![
        0x00, 0x02, 0xb9, 0x5f, 0xa1, 0xdd, 0xcf, 0xab, 0xbf, 0xbb, 0xa1, 0x60, 0xf0, 0x3c, 0x44,
        0x19, 0xad, 0x49, 0xab, 0x14, 0xe3, 0x8f, 0xf9, 0x00, 0x4a, 0x4c, 0x69, 0x62, 0x4e, 0x61,
        0x43, 0x4c, 0x50, 0x4b, 0x3a, 0x51, 0xe7, 0x12, 0xc4, 0xeb, 0x8a, 0xc2, 0x5a, 0xe3, 0xa5,
        0x68, 0x24, 0x08, 0xb2, 0xad, 0xbd, 0x6b, 0x78, 0xa4, 0x25, 0x54, 0x7f, 0x26, 0x85, 0xcf,
        0xdf, 0x1e, 0xe9, 0x27, 0x0c, 0xbe, 0x7e, 0xc3, 0x36, 0xc4, 0x16, 0x0f, 0xf5, 0x72, 0x05,
        0x4c, 0x87, 0x78, 0x42, 0xbe, 0x37, 0x73, 0x50, 0x45, 0xa9, 0x3b, 0xc4, 0xe2, 0x04, 0x15,
        0x31, 0x6f, 0xdb, 0x14, 0x71, 0x61, 0xa2, 0xd7, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x04, 0xc0, 0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0x51, 0xab, 0x1b, 0xc2, 0x3d, 0xf7, 0x4c,
        0x34, 0x87, 0x99, 0x1d, 0xa5, 0x6b, 0x09, 0xa5, 0x58, 0xca, 0xab, 0x28, 0x26, 0x04, 0x9d,
        0x5c, 0xe3, 0xc5, 0xb6, 0xcf, 0xdd, 0xae, 0x0c, 0x12, 0x72, 0xa5, 0x1f, 0x63, 0x20, 0x3d,
        0x74, 0x11, 0xe3, 0x92, 0xb9, 0x4e, 0xd2, 0x83, 0xbb, 0x0d, 0x59, 0x6f, 0xe2, 0xde, 0xb2,
        0x06, 0x61, 0x88, 0xd1, 0xb6, 0xa3, 0x5c, 0x92, 0xaf, 0x14, 0xb1, 0x37, 0x41, 0xc6, 0x17,
        0x3f, 0x1e, 0x7c, 0xc7, 0x02,
    ]);
    let mut deserializer = data.start_deserialize();

    let header: Header = deserializer.pop_header().unwrap();
    assert_eq!(
        header,
        Header::py_ipv8_header(
            [
                185, 95, 161, 221, 207, 171, 191, 187, 161, 96, 240, 60, 68, 25, 173, 73, 171, 20,
                227, 143
            ],
            249,
        )
    );

    assert!(deserializer.verify());

    let time: TimeDistributionPayload = deserializer.next_payload().unwrap();
    assert_eq!(time, TimeDistributionPayload { global_time: 4 });

    let puncture: PunctureRequestPayload = deserializer.next_payload().unwrap();
    assert_eq!(
        puncture,
        PunctureRequestPayload {
            lan_walker_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            wan_walker_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(81, 171, 27, 194)),
                15863
            )),
            identifier: 19508
        }
    )
}

#[test]
fn test_packet_4() {
    // packet 7 in testpackets
    // header + BinMemberAuthenticationPayload + GlobalTimeDistributionPayload + IntroductionRequestPayload
    let data = Packet(vec![
        0x00, 0x02, 0xb9, 0x5f, 0xa1, 0xdd, 0xcf, 0xab, 0xbf, 0xbb, 0xa1, 0x60, 0xf0, 0x3c, 0x44,
        0x19, 0xad, 0x49, 0xab, 0x14, 0xe3, 0x8f, 0xf9, 0x00, 0x4a, 0x4c, 0x69, 0x62, 0x4e, 0x61,
        0x43, 0x4c, 0x50, 0x4b, 0x3a, 0x51, 0xe7, 0x12, 0xc4, 0xeb, 0x8a, 0xc2, 0x5a, 0xe3, 0xa5,
        0x68, 0x24, 0x08, 0xb2, 0xad, 0xbd, 0x6b, 0x78, 0xa4, 0x25, 0x54, 0x7f, 0x26, 0x85, 0xcf,
        0xdf, 0x1e, 0xe9, 0x27, 0x0c, 0xbe, 0x7e, 0xc3, 0x36, 0xc4, 0x16, 0x0f, 0xf5, 0x72, 0x05,
        0x4c, 0x87, 0x78, 0x42, 0xbe, 0x37, 0x73, 0x50, 0x45, 0xa9, 0x3b, 0xc4, 0xe2, 0x04, 0x15,
        0x31, 0x6f, 0xdb, 0x14, 0x71, 0x61, 0xa2, 0xd7, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x07, 0xc0, 0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0x51, 0xab, 0x1b, 0xc2, 0x3d, 0xf7, 0xa5,
        0x72, 0x9c, 0x5b, 0xed, 0x8c, 0x60, 0xf6, 0x2b, 0x3f, 0x17, 0xe7, 0xa7, 0x96, 0xb5, 0xc2,
        0xd5, 0x2b, 0xc5, 0xb0, 0x11, 0x86, 0x23, 0xcf, 0x32, 0xe3, 0x91, 0x00, 0xa5, 0x3b, 0xc3,
        0xfd, 0x40, 0x8c, 0x14, 0xe7, 0x36, 0x90, 0x23, 0xfe, 0xca, 0x07, 0xb5, 0xde, 0xff, 0xf8,
        0x00, 0xb1, 0x20, 0x5d, 0x3d, 0xf9, 0xc0, 0x2d, 0x75, 0xcf, 0x4c, 0x31, 0xbb, 0x41, 0x84,
        0x2f, 0xcf, 0x6a, 0xdc, 0x05,
    ]);
    let mut deserializer = data.start_deserialize();

    let header: Header = deserializer.pop_header().unwrap();
    assert_eq!(
        header,
        Header::py_ipv8_header(
            [
                185, 95, 161, 221, 207, 171, 191, 187, 161, 96, 240, 60, 68, 25, 173, 73, 171, 20,
                227, 143
            ],
            249,
        )
    );

    assert!(deserializer.verify());

    let time: TimeDistributionPayload = deserializer.next_payload().unwrap();
    assert_eq!(time, TimeDistributionPayload { global_time: 7 });

    let puncture: PunctureRequestPayload = deserializer.next_payload().unwrap();
    assert_eq!(
        puncture,
        PunctureRequestPayload {
            lan_walker_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            wan_walker_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(81, 171, 27, 194)),
                15863
            )),
            identifier: 42354
        }
    )
}

#[test]
fn test_packet_5() {
    // packet 7 in testpackets
    // header + BinMemberAuthenticationPayload + GlobalTimeDistributionPayload + IntroductionRequestPayload
    let data = Packet(vec![
        0x00, 0x02, 0xb9, 0x5f, 0xa1, 0xdd, 0xcf, 0xab, 0xbf, 0xbb, 0xa1, 0x60, 0xf0, 0x3c, 0x44,
        0x19, 0xad, 0x49, 0xab, 0x14, 0xe3, 0x8f, 0xf9, 0x00, 0x4a, 0x4c, 0x69, 0x62, 0x4e, 0x61,
        0x43, 0x4c, 0x50, 0x4b, 0x3a, 0x51, 0xe7, 0x12, 0xc4, 0xeb, 0x8a, 0xc2, 0x5a, 0xe3, 0xa5,
        0x68, 0x24, 0x08, 0xb2, 0xad, 0xbd, 0x6b, 0x78, 0xa4, 0x25, 0x54, 0x7f, 0x26, 0x85, 0xcf,
        0xdf, 0x1e, 0xe9, 0x27, 0x0c, 0xbe, 0x7e, 0xc3, 0x36, 0xc4, 0x16, 0x0f, 0xf5, 0x72, 0x05,
        0x4c, 0x87, 0x78, 0x42, 0xbe, 0x37, 0x73, 0x50, 0x45, 0xa9, 0x3b, 0xc4, 0xe2, 0x04, 0x15,
        0x31, 0x6f, 0xdb, 0x14, 0x71, 0x61, 0xa2, 0xd7, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x08, 0xc0, 0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0x51, 0xab, 0x1b, 0xc2, 0xc2, 0xcb, 0xf0,
        0xe1, 0xc2, 0xe9, 0x01, 0x82, 0x3e, 0xd4, 0xcc, 0x0c, 0x83, 0xe6, 0x23, 0xc2, 0x29, 0x86,
        0x97, 0x80, 0x18, 0xad, 0x5b, 0xa9, 0x67, 0x9e, 0x64, 0x60, 0x3a, 0xe8, 0x02, 0x2b, 0x2d,
        0x78, 0x25, 0xd3, 0x73, 0xc9, 0xef, 0xe7, 0xa2, 0xce, 0x17, 0xe2, 0x28, 0x6a, 0x38, 0x40,
        0x2a, 0xdd, 0xa5, 0xf7, 0xe0, 0x8c, 0x72, 0xa3, 0xb4, 0x98, 0xa4, 0x82, 0x6c, 0x8a, 0x4f,
        0xc3, 0xfc, 0x91, 0xc7, 0x03,
    ]);
    let mut deserializer = data.start_deserialize();

    let header: Header = deserializer.pop_header().unwrap();
    assert_eq!(
        header,
        Header::py_ipv8_header(
            [
                185, 95, 161, 221, 207, 171, 191, 187, 161, 96, 240, 60, 68, 25, 173, 73, 171, 20,
                227, 143
            ],
            249,
        )
    );

    assert!(deserializer.verify());

    let time: TimeDistributionPayload = deserializer.next_payload().unwrap();
    assert_eq!(time, TimeDistributionPayload { global_time: 8 });

    let puncture: PunctureRequestPayload = deserializer.next_payload().unwrap();
    assert_eq!(
        puncture,
        PunctureRequestPayload {
            lan_walker_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            wan_walker_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(81, 171, 27, 194)),
                49867
            )),
            identifier: 61665
        }
    )
}

#[test]
fn test_packet_6() {
    // packet 7 in testpackets
    // header + BinMemberAuthenticationPayload + GlobalTimeDistributionPayload + IntroductionRequestPayload
    let data = Packet(vec![
        0x00, 0x02, 0xb4, 0x2c, 0x93, 0xd1, 0x67, 0xa0, 0xfc, 0x4a, 0x08, 0x43, 0xf9, 0x17, 0xd4,
        0xbf, 0x1e, 0x9e, 0xbb, 0x34, 0x0e, 0xc4, 0xf9, 0x00, 0x4a, 0x4c, 0x69, 0x62, 0x4e, 0x61,
        0x43, 0x4c, 0x50, 0x4b, 0x3a, 0x51, 0xe7, 0x12, 0xc4, 0xeb, 0x8a, 0xc2, 0x5a, 0xe3, 0xa5,
        0x68, 0x24, 0x08, 0xb2, 0xad, 0xbd, 0x6b, 0x78, 0xa4, 0x25, 0x54, 0x7f, 0x26, 0x85, 0xcf,
        0xdf, 0x1e, 0xe9, 0x27, 0x0c, 0xbe, 0x7e, 0xc3, 0x36, 0xc4, 0x16, 0x0f, 0xf5, 0x72, 0x05,
        0x4c, 0x87, 0x78, 0x42, 0xbe, 0x37, 0x73, 0x50, 0x45, 0xa9, 0x3b, 0xc4, 0xe2, 0x04, 0x15,
        0x31, 0x6f, 0xdb, 0x14, 0x71, 0x61, 0xa2, 0xd7, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x0e, 0xc0, 0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0x51, 0xab, 0x1b, 0xc2, 0x2b, 0x67, 0xd2,
        0x17, 0xb8, 0x27, 0xf6, 0x75, 0x83, 0x7f, 0x4e, 0xce, 0xa0, 0x2a, 0x96, 0x07, 0xde, 0x98,
        0x02, 0x94, 0x0b, 0x0e, 0x6f, 0x95, 0x6b, 0xa5, 0xd6, 0xe1, 0x15, 0x32, 0x7a, 0xd1, 0x20,
        0x40, 0x83, 0xdf, 0xa7, 0xf5, 0xc9, 0xf4, 0x99, 0x18, 0x81, 0x83, 0x0b, 0x07, 0xc0, 0x12,
        0x20, 0x85, 0x6d, 0x3d, 0x67, 0x7f, 0x52, 0x93, 0xed, 0xe1, 0x03, 0x8d, 0x31, 0x34, 0xab,
        0xe0, 0x50, 0xaa, 0xef, 0x07,
    ]);
    let mut deserializer = data.start_deserialize();

    let header: Header = deserializer.pop_header().unwrap();
    assert_eq!(
        header,
        Header::py_ipv8_header(
            [
                180, 44, 147, 209, 103, 160, 252, 74, 8, 67, 249, 23, 212, 191, 30, 158, 187, 52,
                14, 196
            ],
            249,
        )
    );

    assert!(deserializer.verify());

    let time: TimeDistributionPayload = deserializer.next_payload().unwrap();
    assert_eq!(time, TimeDistributionPayload { global_time: 14 });

    let puncture: PunctureRequestPayload = deserializer.next_payload().unwrap();
    assert_eq!(
        puncture,
        PunctureRequestPayload {
            lan_walker_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            wan_walker_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(81, 171, 27, 194)),
                11111
            )),
            identifier: 53783
        }
    )
}

#[test]
fn test_packet_7() {
    // packet 7 in testpackets
    // header + BinMemberAuthenticationPayload + GlobalTimeDistributionPayload + IntroductionRequestPayload
    let data = Packet(vec![
        0x00, 0x02, 0xb9, 0x5f, 0xa1, 0xdd, 0xcf, 0xab, 0xbf, 0xbb, 0xa1, 0x60, 0xf0, 0x3c, 0x44,
        0x19, 0xad, 0x49, 0xab, 0x14, 0xe3, 0x8f, 0xf9, 0x00, 0x4a, 0x4c, 0x69, 0x62, 0x4e, 0x61,
        0x43, 0x4c, 0x50, 0x4b, 0x3a, 0x51, 0xe7, 0x12, 0xc4, 0xeb, 0x8a, 0xc2, 0x5a, 0xe3, 0xa5,
        0x68, 0x24, 0x08, 0xb2, 0xad, 0xbd, 0x6b, 0x78, 0xa4, 0x25, 0x54, 0x7f, 0x26, 0x85, 0xcf,
        0xdf, 0x1e, 0xe9, 0x27, 0x0c, 0xbe, 0x7e, 0xc3, 0x36, 0xc4, 0x16, 0x0f, 0xf5, 0x72, 0x05,
        0x4c, 0x87, 0x78, 0x42, 0xbe, 0x37, 0x73, 0x50, 0x45, 0xa9, 0x3b, 0xc4, 0xe2, 0x04, 0x15,
        0x31, 0x6f, 0xdb, 0x14, 0x71, 0x61, 0xa2, 0xd7, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x0f, 0xc0, 0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0x49, 0x91, 0x8a, 0xe9, 0x1e, 0x4f, 0xff,
        0xa6, 0x68, 0x80, 0xe7, 0x74, 0xcf, 0x85, 0x76, 0xe6, 0xff, 0x59, 0x7b, 0xf0, 0xec, 0x81,
        0x40, 0x43, 0x63, 0x34, 0x5e, 0xff, 0x58, 0x53, 0x70, 0x65, 0xa0, 0xdd, 0x3e, 0x34, 0xdf,
        0x72, 0x84, 0xff, 0x82, 0x12, 0x2d, 0x5b, 0x86, 0xa0, 0xfb, 0xa6, 0xf9, 0x08, 0x65, 0x6e,
        0x72, 0x7c, 0x1e, 0xae, 0x1c, 0x1f, 0xf5, 0x57, 0x0d, 0x04, 0x5e, 0xfc, 0x4f, 0xe3, 0x1e,
        0xa9, 0x13, 0x98, 0x08, 0x0b,
    ]);
    let mut deserializer = data.start_deserialize();

    let header: Header = deserializer.pop_header().unwrap();
    assert_eq!(
        header,
        Header::py_ipv8_header(
            [
                185, 95, 161, 221, 207, 171, 191, 187, 161, 96, 240, 60, 68, 25, 173, 73, 171, 20,
                227, 143
            ],
            249,
        )
    );

    assert!(deserializer.verify());

    let time: TimeDistributionPayload = deserializer.next_payload().unwrap();
    assert_eq!(time, TimeDistributionPayload { global_time: 15 });

    let puncture: PunctureRequestPayload = deserializer.next_payload().unwrap();
    assert_eq!(
        puncture,
        PunctureRequestPayload {
            lan_walker_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            wan_walker_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(73, 145, 138, 233)),
                7759
            )),
            identifier: 65446
        }
    )
}

#[test]
fn test_packet_8() {
    // packet 8 in testpackets
    // header + BinMemberAuthenticationPayload + GlobalTimeDistributionPayload + IntroductionResponsePayload:
    let data = Packet(vec![
        0x00, 0x02, 0xb9, 0x5f, 0xa1, 0xdd, 0xcf, 0xab, 0xbf, 0xbb, 0xa1, 0x60, 0xf0, 0x3c, 0x44,
        0x19, 0xad, 0x49, 0xab, 0x14, 0xe3, 0x8f, 0xf5, 0x00, 0x4a, 0x4c, 0x69, 0x62, 0x4e, 0x61,
        0x43, 0x4c, 0x50, 0x4b, 0x3a, 0x51, 0xe7, 0x12, 0xc4, 0xeb, 0x8a, 0xc2, 0x5a, 0xe3, 0xa5,
        0x68, 0x24, 0x08, 0xb2, 0xad, 0xbd, 0x6b, 0x78, 0xa4, 0x25, 0x54, 0x7f, 0x26, 0x85, 0xcf,
        0xdf, 0x1e, 0xe9, 0x27, 0x0c, 0xbe, 0x7e, 0xc3, 0x36, 0xc4, 0x16, 0x0f, 0xf5, 0x72, 0x05,
        0x4c, 0x87, 0x78, 0x42, 0xbe, 0x37, 0x73, 0x50, 0x45, 0xa9, 0x3b, 0xc4, 0xe2, 0x04, 0x15,
        0x31, 0x6f, 0xdb, 0x14, 0x71, 0x61, 0xa2, 0xd7, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x0b, 0xc0, 0xa8, 0x01, 0x4b, 0x1e, 0x4f, 0xc0, 0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0xc0,
        0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x15, 0xbd, 0x4f, 0xe9, 0x55, 0x3a, 0x2b, 0x79, 0x98, 0x4c, 0xc0, 0xd4,
        0xee, 0x6e, 0x8e, 0xad, 0x9d, 0xfe, 0x20, 0xd5, 0xbd, 0xee, 0x28, 0x07, 0xe5, 0x2f, 0x83,
        0x9b, 0x4a, 0xbb, 0xb0, 0x1e, 0xb3, 0xa5, 0x38, 0x18, 0xce, 0xba, 0x28, 0x0f, 0xa6, 0x6b,
        0xa3, 0x01, 0x59, 0xf5, 0x96, 0x6d, 0x4b, 0xa8, 0xd7, 0x94, 0x86, 0x78, 0x4a, 0x4f, 0xb0,
        0xc1, 0xb3, 0x53, 0x92, 0x1f, 0x58, 0xb6, 0x81, 0x0d,
    ]);
    let mut deserializer = data.start_deserialize();
    let header: Header = deserializer.pop_header().unwrap();

    assert_eq!(
        header,
        Header::py_ipv8_header(
            [
                185, 95, 161, 221, 207, 171, 191, 187, 161, 96, 240, 60, 68, 25, 173, 73, 171, 20,
                227, 143,
            ],
            245,
        )
    );

    assert!(deserializer.verify());

    let time: TimeDistributionPayload = deserializer.next_payload().unwrap();
    assert_eq!(time, TimeDistributionPayload { global_time: 11 });

    let intro: IntroductionResponsePayload = deserializer.next_payload().unwrap();

    assert_eq!(
        intro,
        IntroductionResponsePayload {
            destination_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                7759
            )),
            source_lan_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            source_wan_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            lan_introduction_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
                0
            )),
            wan_introduction_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)),
                0
            )),
            tunnel: false,
            connection_type: ConnectionType::UNKNOWN,
            identifier: 5565,
            extra_bytes: RawEnd(vec![])
        }
    )
}

#[test]
fn test_packet_9() {
    // packet 7 in testpackets
    // header + BinMemberAuthenticationPayload + GlobalTimeDistributionPayload + IntroductionResponsePayload
    let data = Packet(vec![
        0x00, 0x02, 0xb9, 0x5f, 0xa1, 0xdd, 0xcf, 0xab, 0xbf, 0xbb, 0xa1, 0x60, 0xf0, 0x3c, 0x44,
        0x19, 0xad, 0x49, 0xab, 0x14, 0xe3, 0x8f, 0xf5, 0x00, 0x4a, 0x4c, 0x69, 0x62, 0x4e, 0x61,
        0x43, 0x4c, 0x50, 0x4b, 0x3a, 0x51, 0xe7, 0x12, 0xc4, 0xeb, 0x8a, 0xc2, 0x5a, 0xe3, 0xa5,
        0x68, 0x24, 0x08, 0xb2, 0xad, 0xbd, 0x6b, 0x78, 0xa4, 0x25, 0x54, 0x7f, 0x26, 0x85, 0xcf,
        0xdf, 0x1e, 0xe9, 0x27, 0x0c, 0xbe, 0x7e, 0xc3, 0x36, 0xc4, 0x16, 0x0f, 0xf5, 0x72, 0x05,
        0x4c, 0x87, 0x78, 0x42, 0xbe, 0x37, 0x73, 0x50, 0x45, 0xa9, 0x3b, 0xc4, 0xe2, 0x04, 0x15,
        0x31, 0x6f, 0xdb, 0x14, 0x71, 0x61, 0xa2, 0xd7, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x0c, 0x51, 0xab, 0x1b, 0xc2, 0x3d, 0xf7, 0xc0, 0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0xc0,
        0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0xc0, 0xa8, 0x01, 0x4b, 0x1e, 0x4f, 0xc0, 0xa8, 0x01, 0x4b,
        0x1e, 0x4f, 0x00, 0xc4, 0x22, 0x26, 0xda, 0x61, 0x3e, 0xc2, 0x3a, 0xe6, 0x43, 0xd1, 0xa4,
        0xe7, 0x0a, 0x92, 0x74, 0x46, 0x5d, 0x02, 0x9a, 0x4c, 0xb5, 0x1f, 0x32, 0x5e, 0x40, 0x9a,
        0x3b, 0x1b, 0x59, 0x32, 0xc8, 0x3f, 0x42, 0x46, 0x5e, 0x91, 0x9f, 0x56, 0x34, 0x5a, 0xb2,
        0x9c, 0x32, 0xa1, 0x32, 0xce, 0x5b, 0x95, 0x93, 0x16, 0x16, 0xda, 0xb8, 0x03, 0x0d, 0x3d,
        0xe7, 0x6f, 0xea, 0x90, 0x43, 0xfd, 0x5f, 0x93, 0x04,
    ]);
    let mut deserializer = data.start_deserialize();
    let header: Header = deserializer.pop_header().unwrap();

    assert_eq!(
        header,
        Header::py_ipv8_header(
            [
                185, 95, 161, 221, 207, 171, 191, 187, 161, 96, 240, 60, 68, 25, 173, 73, 171, 20,
                227, 143,
            ],
            245,
        )
    );

    assert!(deserializer.verify());

    let time: TimeDistributionPayload = deserializer.next_payload().unwrap();
    assert_eq!(time, TimeDistributionPayload { global_time: 12 });

    let intro: IntroductionResponsePayload = deserializer.next_payload().unwrap();

    assert_eq!(
        intro,
        IntroductionResponsePayload {
            destination_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(81, 171, 27, 194)),
                15863
            )),
            source_lan_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            source_wan_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            lan_introduction_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                7759
            )),
            wan_introduction_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                7759
            )),
            tunnel: false,
            connection_type: ConnectionType::UNKNOWN,
            identifier: 50210,
            extra_bytes: RawEnd(vec![])
        }
    )
}

#[test]
fn test_packet_10() {
    // packet 15 in testpackets
    // header + BinMemberAuthenticationPayload + GlobalTimeDistributionPayload + IntroductionRequestPayload
    let data = Packet(vec![
        0x00, 0x02, 0xba, 0xf3, 0x0e, 0xd9, 0x19, 0x2b, 0xa3, 0x54, 0xcd, 0xd7, 0xb1, 0x73, 0xe0,
        0xef, 0x2c, 0x32, 0x80, 0x27, 0xf1, 0xd3, 0xf6, 0x00, 0x4a, 0x4c, 0x69, 0x62, 0x4e, 0x61,
        0x43, 0x4c, 0x50, 0x4b, 0x3a, 0x51, 0xe7, 0x12, 0xc4, 0xeb, 0x8a, 0xc2, 0x5a, 0xe3, 0xa5,
        0x68, 0x24, 0x08, 0xb2, 0xad, 0xbd, 0x6b, 0x78, 0xa4, 0x25, 0x54, 0x7f, 0x26, 0x85, 0xcf,
        0xdf, 0x1e, 0xe9, 0x27, 0x0c, 0xbe, 0x7e, 0xc3, 0x36, 0xc4, 0x16, 0x0f, 0xf5, 0x72, 0x05,
        0x4c, 0x87, 0x78, 0x42, 0xbe, 0x37, 0x73, 0x50, 0x45, 0xa9, 0x3b, 0xc4, 0xe2, 0x04, 0x15,
        0x31, 0x6f, 0xdb, 0x14, 0x71, 0x61, 0xa2, 0xd7, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x00, 0x97, 0x51, 0xab, 0x1b, 0xc2, 0x2b, 0x67, 0xc0, 0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0xc0,
        0xa8, 0x01, 0x4b, 0x1f, 0x9a, 0x01, 0x00, 0x97, 0x00, 0x00, 0x00, 0x00, 0x03, 0xa5, 0xdb,
        0xf5, 0xcc, 0x02, 0x1a, 0x21, 0xe9, 0x70, 0x2d, 0x8a, 0xf2, 0x91, 0xb4, 0x62, 0x49, 0x91,
        0xb2, 0x41, 0x08, 0x89, 0xe3, 0x45, 0xa1, 0x9c, 0x2f, 0xf9, 0x0b, 0x60, 0x26, 0xc9, 0x70,
        0x68, 0x2a, 0xbc, 0xd1, 0x03, 0x47, 0x2d, 0xfd, 0xee, 0x19, 0xd8, 0xf9, 0x48, 0x6e, 0xbf,
        0x2b, 0xfd, 0xe7, 0x0c, 0x86, 0xd7, 0xbc, 0x00, 0xa6, 0x21, 0xfe, 0x26, 0x22, 0x89, 0xda,
        0x0b,
    ]);
    let mut deserializer = data.start_deserialize();
    let header: Header = deserializer.pop_header().unwrap();

    assert!(deserializer.verify());

    assert_eq!(
        header,
        Header::py_ipv8_header(
            [
                186, 243, 14, 217, 25, 43, 163, 84, 205, 215, 177, 115, 224, 239, 44, 50, 128, 39,
                241, 211,
            ],
            246
        )
    );

    let time: TimeDistributionPayload = deserializer.next_payload().unwrap();

    assert_eq!(time, TimeDistributionPayload { global_time: 151 });

    let intro: IntroductionRequestPayload = deserializer.next_payload().unwrap();

    assert_eq!(
        intro,
        IntroductionRequestPayload {
            destination_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(81, 171, 27, 194)),
                11111
            )),
            source_lan_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            source_wan_address: Address(SocketAddr::new(
                IpAddr::V4(Ipv4Addr::new(192, 168, 1, 75)),
                8090
            )),
            advice: false,
            connection_type: ConnectionType::PUBLIC,
            identifier: 151,
            extra_bytes: RawEnd(vec![0, 0, 0, 0])
        }
    )
}