Beispiel #1
0
    def __init__(self,
                 sntp_servers: Iterable[IPv6Address],
                 always_send: bool = False):
        option = SNTPServersOption(sntp_servers=sntp_servers)
        option.validate()

        super().__init__(option, always_send=always_send)
Beispiel #2
0
 def setUp(self):
     self.option_bytes = bytes.fromhex('001f0020'
                                       '20010db8000000000000000000000001'
                                       '20010db8000000000000000000000002')
     self.option_object = SNTPServersOption(sntp_servers=[IPv6Address('2001:db8::1'),
                                                          IPv6Address('2001:db8::2')])
     self.parse_option()
Beispiel #3
0
    def test_bad_option_length(self):
        with self.assertRaisesRegex(ValueError, 'length must be a multiple of 16'):
            SNTPServersOption.parse(bytes.fromhex('001f000f20010db8000000000000000000000001'))

        with self.assertRaisesRegex(ValueError, 'longer than the available buffer'):
            SNTPServersOption.parse(bytes.fromhex('001f001120010db8000000000000000000000001'))

        with self.assertRaisesRegex(ValueError, 'length must be a multiple of 16'):
            SNTPServersOption.parse(bytes.fromhex('001f001120010db800000000000000000000000100'))
Beispiel #4
0
    def test_bad_option_length(self):
        with self.assertRaisesRegex(ValueError, 'length must be a multiple of 16'):
            SNTPServersOption.parse(bytes.fromhex('001f000f20010db8000000000000000000000001'))

        with self.assertRaisesRegex(ValueError, 'longer than the available buffer'):
            SNTPServersOption.parse(bytes.fromhex('001f001120010db8000000000000000000000001'))

        with self.assertRaisesRegex(ValueError, 'length must be a multiple of 16'):
            SNTPServersOption.parse(bytes.fromhex('001f001120010db800000000000000000000000100'))
Beispiel #5
0
    def combine(
            self, existing_options: Iterable[SNTPServersOption]
    ) -> SNTPServersOption:
        """
        Combine multiple options into one.

        :param existing_options: The existing options to include NTP servers from
        :return: The combined option
        """
        sntp_servers = []

        # Add from existing options first
        for option in existing_options:
            for sntp_server in option.sntp_servers:
                if sntp_server not in sntp_servers:
                    sntp_servers.append(sntp_server)

        # Then add our own
        for sntp_server in self.option.sntp_servers:
            if sntp_server not in sntp_servers:
                sntp_servers.append(sntp_server)

        # And return a new option with the combined addresses
        return SNTPServersOption(sntp_servers=sntp_servers)
Beispiel #6
0
    def __init__(self, sntp_servers: Iterable[IPv6Address], always_send: bool = False):
        option = SNTPServersOption(sntp_servers=sntp_servers)
        option.validate()

        super().__init__(option, always_send=always_send)
Beispiel #7
0
    def __init__(self, sntp_servers: [IPv6Address]):
        option = SNTPServersOption(sntp_servers=sntp_servers)
        option.validate()

        super().__init__(option)