Ejemplo n.º 1
0
    def print_table(self):
        header_format = '%6s %40s %10s %15s %5s %4s %8s'
        data_format =   '%6d %40r %10s %15s %5d %4d %9.2f'
        header = header_format % (
            'bucket', 'id', 'version', 'ip', 'port', 'rtt', 'uptime(h)')
        #TODO: format uptime as hh:mm
        thick_line = '=' * 95
        thin_line = '-' * 95
        print thick_line
        print data_format % (-1, self.my_node.id,
                             version_repr(self.my_node.version),
                             self.my_node.addr[0], self.my_node.addr[1],
                             0, 0)
        print thin_line
        print header
        print thin_line

        current_time = time.time()
        for rnode in self.get_main_rnodes():
            if rnode.rtt == 99:
                rtt = rnode.real_rtt
            else:
                rtt = rnode.rtt
            print data_format % (
                self.my_node.id.distance(rnode.id).log,
                rnode.id, version_repr(rnode.version),
                rnode.addr[0], rnode.addr[1],
                rtt * 1000,
                (current_time - rnode.creation_ts)/3600)
        print thin_line
        print header
        print thick_line
Ejemplo n.º 2
0
def save(my_id, rnodes, filename):
    f = open(filename, 'w')
    f.write('%r\n' % my_id)
    for rnode in rnodes:
        if rnode.rtt == 99:
            rtt = rnode.real_rtt
        else:
            rtt = rnode.rtt
        f.write('%d %r %8s %15s %5d %4d %6d\n' %
                (my_id.distance(rnode.id).log, rnode.id,
                 version_repr(rnode.version), rnode.addr[0], rnode.addr[1],
                 rtt * 1000, time.time() - rnode.creation_ts))
    f.close()
Ejemplo n.º 3
0
def save(my_id, rnodes, filename):
    f = open(filename, 'w')
    f.write('%r\n' % my_id)
    for rnode in rnodes:
        if rnode.rtt == 99:
            rtt = rnode.real_rtt
        else:
            rtt = rnode.rtt
        f.write('%d %r %8s %15s %5d %4d %6d\n' % (
                my_id.distance(rnode.id).log,
                rnode.id, version_repr(rnode.version),
                rnode.addr[0], rnode.addr[1],
                rtt * 1000,
                time.time() -rnode.creation_ts ))
    f.close()