Ported to Python 3
This commit is contained in:
32
bootstrap.py
32
bootstrap.py
@@ -1,10 +1,19 @@
|
||||
# -*- mode: python; indent-tabs-mode: nil; py-indent-offset: 4; coding: utf-8 -*-
|
||||
import random
|
||||
|
||||
global LOG
|
||||
import logging
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
iNUM_NODES = 6
|
||||
|
||||
class Node(object):
|
||||
|
||||
def __init__(self, ip, port, tox_key, rand):
|
||||
self._ip, self._port, self._tox_key, self.rand = ip, port, tox_key, rand
|
||||
def __init__(self, ip, port, tox_key, rand=0):
|
||||
self._ip = ip
|
||||
self._port = port
|
||||
self._tox_key = tox_key
|
||||
self.rand = rand
|
||||
|
||||
def get_data(self):
|
||||
return self._ip, self._port, self._tox_key
|
||||
@@ -12,6 +21,16 @@ class Node(object):
|
||||
|
||||
def node_generator():
|
||||
nodes = []
|
||||
try:
|
||||
from wrapper_tests.support_testing import generate_nodes
|
||||
all = generate_nodes()
|
||||
random.shuffle(all)
|
||||
for elt in all[:iNUM_NODES]:
|
||||
nodes.append(Node(*elt))
|
||||
return nodes
|
||||
except Exception as e:
|
||||
LOG.warn(e)
|
||||
# drop through
|
||||
ips = [
|
||||
"144.76.60.215", "23.226.230.47", "195.154.119.113", "biribiri.org",
|
||||
"46.38.239.179", "178.62.250.138", "130.133.110.14", "104.167.101.29",
|
||||
@@ -76,8 +95,9 @@ def node_generator():
|
||||
"5625A62618CB4FCA70E147A71B29695F38CC65FF0CBD68AD46254585BE564802",
|
||||
"31910C0497D347FF160D6F3A6C0E317BAFA71E8E03BC4CBB2A185C9D4FB8B31E"
|
||||
]
|
||||
for i in xrange(len(ips)):
|
||||
nodes.append(Node(ips[i], ports[i], ids[i], random.randint(0, 1000000)))
|
||||
arr = sorted(nodes, key=lambda x: x.rand)[:4]
|
||||
for elem in arr:
|
||||
for i in range(len(ips)):
|
||||
nodes.append(Node(ips[i], ports[i], ids[i]) )
|
||||
arr = sorted(nodes)
|
||||
random.shuffle(arr)
|
||||
for elem in arr[:iNUM_NODES]:
|
||||
yield elem.get_data()
|
||||
|
||||
Reference in New Issue
Block a user