Ejemplo n.º 1
0
    def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size >= 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        pos = bisect.bisect_left(self.data_size_list, buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list))
        # 假设random均匀分布,则越长的原始数据长度越容易if false
        if final_pos < len(self.data_size_list):
            return self.data_size_list[final_pos] - buf_size - self.server_info.overhead

        # 上面if false后选择2号补全数组,此处有更精细的长度分段
        pos = bisect.bisect_left(self.data_size_list2, buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list2))
        if final_pos < len(self.data_size_list2):
            return self.data_size_list2[final_pos] - buf_size - self.server_info.overhead
        # final_pos 总是分布在pos~(data_size_list2.len-1)之间
        if final_pos < pos + len(self.data_size_list2) - 1:
            return 0
        # 有1/len(self.data_size_list2)的概率不满足上一个if  ?
        # 理论上不会运行到此处,因此可以插入运行断言  ?
        # assert False

        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021
Ejemplo n.º 2
0
    def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size >= 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        pos = bisect.bisect_left(self.data_size_list,
                                 buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list))
        if final_pos < len(self.data_size_list):
            return self.data_size_list[
                final_pos] - buf_size - self.server_info.overhead

        pos = bisect.bisect_left(self.data_size_list2,
                                 buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list2))
        if final_pos < len(self.data_size_list2):
            return self.data_size_list2[
                final_pos] - buf_size - self.server_info.overhead
        if final_pos < pos + len(self.data_size_list2) - 1:
            return 0

        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021
Ejemplo n.º 3
0
    def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size >= 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        pos = bisect.bisect_left(self.data_size_list,
                                 buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list))
        # 假设random均匀分布,则越长的原始数据长度越容易if false
        if final_pos < len(self.data_size_list):
            return self.data_size_list[
                final_pos] - buf_size - self.server_info.overhead

        # 上面if false后选择2号补全数组,此处有更精细的长度分段
        pos = bisect.bisect_left(self.data_size_list2,
                                 buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list2))
        if final_pos < len(self.data_size_list2):
            return self.data_size_list2[
                final_pos] - buf_size - self.server_info.overhead
        # final_pos 总是分布在pos~(data_size_list2.len-1)之间
        if final_pos < pos + len(self.data_size_list2) - 1:
            return 0
        # 有1/len(self.data_size_list2)的概率不满足上一个if  ?
        # 理论上不会运行到此处,因此可以插入运行断言  ?
        # assert False

        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021
Ejemplo n.º 4
0
    def rnd_data_len(self, buf_size, last_hash, random):
        random.init_from_bin_len(last_hash, buf_size)
        other_data_size = buf_size + self.server_info.overhead
        if other_data_size >= self.data_size_list0[-1]:
            return 0

        pos = bisect.bisect_left(self.data_size_list0, other_data_size)
        return self.data_size_list0[pos] - other_data_size
Ejemplo n.º 5
0
    def rnd_data_len(self, buf_size, last_hash, random):
        other_data_size = buf_size + self.server_info.overhead
        if other_data_size >= self.data_size_list0[-1]:
            return 0

        random.init_from_bin_len(last_hash, buf_size)
        pos = bisect.bisect_left(self.data_size_list0, other_data_size)
        final_pos = pos + random.next() % (len(self.data_size_list0) - pos)
        return self.data_size_list0[final_pos] - other_data_size
Ejemplo n.º 6
0
    def rnd_data_len(self, buf_size, last_hash, random):
        random.init_from_bin_len(last_hash, buf_size)
        other_data_size = buf_size + self.server_info.overhead
        # if other_data_size > the bigest item in data_size_list0, not padding any data
        if other_data_size >= self.data_size_list0[-1]:
            return 0

        # use the mini size in the data_size_list0
        pos = bisect.bisect_left(self.data_size_list0, other_data_size)
        return self.data_size_list0[pos] - other_data_size
Ejemplo n.º 7
0
 def rnd_data_len(self, buf_size, last_hash, random):
     if buf_size > 1440:
         return 0
     random.init_from_bin_len(last_hash, buf_size)
     if buf_size > 1300:
         return random.next() % 31
     if buf_size > 900:
         return random.next() % 127
     if buf_size > 400:
         return random.next() % 521
     return random.next() % 1021
Ejemplo n.º 8
0
    def rnd_data_len(self, buf_size, last_hash, random):
        other_data_size = buf_size + self.server_info.overhead
        # if other_data_size > the bigest item in data_size_list0, not padding any data
        if other_data_size >= self.data_size_list0[-1]:
            return 0

        random.init_from_bin_len(last_hash, buf_size)
        pos = bisect.bisect_left(self.data_size_list0, other_data_size)
        # random select a size in the leftover data_size_list0
        final_pos = pos + random.next() % (len(self.data_size_list0) - pos)
        return self.data_size_list0[final_pos] - other_data_size
Ejemplo n.º 9
0
 def rnd_data_len(self, buf_size, last_hash, random):
     if buf_size > 1440:
         return 0
     random.init_from_bin_len(last_hash, buf_size)
     if buf_size > 1300:
         return random.next() % 31
     if buf_size > 900:
         return random.next() % 127
     if buf_size > 400:
         return random.next() % 521
     return random.next() % 1021
Ejemplo n.º 10
0
    def rnd_data_len(self, buf_size, last_hash, random):
        other_data_size = buf_size + self.server_info.overhead
        # if other_data_size > the bigest item in data_size_list0, not padding any data
        if other_data_size >= self.data_size_list0[-1]:
            return 0

        random.init_from_bin_len(last_hash, buf_size)
        pos = bisect.bisect_left(self.data_size_list0, other_data_size)
        # random select a size in the leftover data_size_list0
        final_pos = pos + random.next() % (len(self.data_size_list0) - pos)
        return self.data_size_list0[final_pos] - other_data_size
Ejemplo n.º 11
0
 def recv_rnd_data_len(self, buf_size, last_hash, random):
     if buf_size + self.server_info.overhead > self.recv_tcp_mss:
         random.init_from_bin_len(last_hash, buf_size)
         return random.next() % 521
     if buf_size >= 1440 or buf_size + self.server_info.overhead == self.send_tcp_mss:
         return 0
     random.init_from_bin_len(last_hash, buf_size)
     if buf_size > 1300:
         return random.next() % 31
     if buf_size > 900:
         return random.next() % 127
     if buf_size > 400:
         return random.next() % 521
     return random.next() % (self.recv_tcp_mss - buf_size - self.server_info.overhead)
Ejemplo n.º 12
0
    def rnd_data_len(self, buf_size, last_hash, random):
        other_data_size = buf_size + self.server_info.overhead
        random.init_from_bin_len(last_hash, buf_size)
        if other_data_size >= self.data_size_list0[-1]:
            if other_data_size >= 1440:
                return 0
            if other_data_size > 1300:
                return random.next() % 31
            if other_data_size > 900:
                return random.next() % 127
            if other_data_size > 400:
                return random.next() % 521
            return random.next() % 1021

        pos = bisect.bisect_left(self.data_size_list0, other_data_size)
        final_pos = pos + random.next() % (len(self.data_size_list0) - pos)
        return self.data_size_list0[final_pos] - other_data_size
Ejemplo n.º 13
0
    def rnd_data_len(self, buf_size, last_hash, random):
        other_data_size = buf_size + self.server_info.overhead
        # 一定要在random使用前初始化,以保证服务器与客户端同步,保证包大小验证结果正确
        random.init_from_bin_len(last_hash, buf_size)
        # final_pos 总是分布在pos~(data_size_list0.len-1)之间
        # 除非data_size_list0中的任何值均过小使其全部都无法容纳buf
        if other_data_size >= self.data_size_list0[-1]:
            if other_data_size >= 1440:
                return 0
            if other_data_size > 1300:
                return random.next() % 31
            if other_data_size > 900:
                return random.next() % 127
            if other_data_size > 400:
                return random.next() % 521
            return random.next() % 1021

        pos = bisect.bisect_left(self.data_size_list0, other_data_size)
        # random select a size in the leftover data_size_list0
        final_pos = pos + random.next() % (len(self.data_size_list0) - pos)
        return self.data_size_list0[final_pos] - other_data_size
Ejemplo n.º 14
0
    def rnd_data_len(self, buf_size, last_hash, random):
        other_data_size = buf_size + self.server_info.overhead
        # 一定要在random使用前初始化,以保证服务器与客户端同步,保证包大小验证结果正确
        random.init_from_bin_len(last_hash, buf_size)
        # final_pos 总是分布在pos~(data_size_list0.len-1)之间
        # 除非data_size_list0中的任何值均过小使其全部都无法容纳buf
        if other_data_size >= self.data_size_list0[-1]:
            if other_data_size >= 1440:
                return 0
            if other_data_size > 1300:
                return random.next() % 31
            if other_data_size > 900:
                return random.next() % 127
            if other_data_size > 400:
                return random.next() % 521
            return random.next() % 1021

        pos = bisect.bisect_left(self.data_size_list0, other_data_size)
        # random select a size in the leftover data_size_list0
        final_pos = pos + random.next() % (len(self.data_size_list0) - pos)
        return self.data_size_list0[final_pos] - other_data_size
Ejemplo n.º 15
0
    def rnd_data_len(self, buf_size, last_hash, random):
        if buf_size >= 1440:
            return 0
        random.init_from_bin_len(last_hash, buf_size)
        pos = bisect.bisect_left(self.data_size_list, buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list))
        if final_pos < len(self.data_size_list):
            return self.data_size_list[final_pos] - buf_size - self.server_info.overhead

        pos = bisect.bisect_left(self.data_size_list2, buf_size + self.server_info.overhead)
        final_pos = pos + random.next() % (len(self.data_size_list2))
        if final_pos < len(self.data_size_list2):
            return self.data_size_list2[final_pos] - buf_size - self.server_info.overhead
        if final_pos < pos + len(self.data_size_list2) - 1:
            return 0

        if buf_size > 1300:
            return random.next() % 31
        if buf_size > 900:
            return random.next() % 127
        if buf_size > 400:
            return random.next() % 521
        return random.next() % 1021