def __init__(self, udp_socket, ip_address, node_id):
        ''' Node class constructor.

            Arguments:
                udp_socket:
                    udp socket to be used for communications in this network.
                ip_address:
                    IP address that we're listening on. Needed for some messages to other nodes (eg. ROUTING_INFO).
                
                node_id:
                    node_id of this node to be used in this network.

            Notes:
                Takes node_id in its constructor - this is divergent from the spec.
                However, this makes more sense than taking it in JoinNetwork - 
                otherwise, the first node in a network would not know its id
                This constructor also does the job of "init" from the spec.
                Also takes ip_address from

        '''
        self.node_id = node_id
        self.ip_address = ip_address
        self.udp_socket = udp_socket
        self.routing_table = routing_table.RoutingTable()
        self.routing_table_lock = threading.Lock()
        self.net_id = 0
        # The acks_waiting dict is a map of (ip, port) -> threads waiting to be ACKed.
        # The threads count down from N seconds and then throws an error.
        # We tell the thread to stop counting down when an ACK is received for that address.
        self.acks_waiting = {}
        self.acks_waiting_lock = threading.Lock()
        # LevelDB is a string/string key -> value store. We just use it to persistently store
        # URL -> frequency for our word.
        self.db = leveldb.LevelDB("./db")
Beispiel #2
0
    def __init__(self, filename, intervalBetweenMessages=1, random=False, timeoutPeriod=15, garbageCollectionPeriod=15):
        threading.Thread.__init__(self)
        self.filename = filename
        data = json.load(open(self.filename))
        self.config_file_check(data)
        self.routing_id = data["router-id"]
        self.input_ports = data["input-ports"]
        self.output_ports = data["outputs"]
        self.input_sockets_list = []
        self.socket_creator()
        self.routing_table = routing_table.RoutingTable(data)
        self.alive = False

        print(self.routing_table.getPrettyTable())

        # Timer settings
        self.timer_interval = intervalBetweenMessages
        self.timer_value = 0
        self.triggered_update_cooldown_timer_value = 0
        self.hasRecentlyTriggeredUpdate = False
        self.timeout_period = timeoutPeriod
        self.garbage_collection_period = garbageCollectionPeriod
        self.random = random
        self.ready_for_periodic_update = False
        self.ready_for_triggered_update = False
Beispiel #3
0
def make_node_10():
    src_node = node.Node('123', 10, 0)
    neighbors = [
        node.Node('123', 11, 1),
        node.Node('123', 13, 5),
    ]
    src_routing_table = routing_table.RoutingTable(neighbors, src_node)
    return src_node, src_routing_table
Beispiel #4
0
def make_node_16():
    node16 = node.Node('123', 16, 0)
    neighbors_16 = [
        node.Node('123', 15, 1),
        node.Node('123', 13, 1),
    ]
    node16_routing_table = routing_table.RoutingTable(neighbors_16, node16)
    return node16, node16_routing_table
Beispiel #5
0
def make_node_15():
    node15 = node.Node('123', 15, 0)
    neighbors_15 = [
        node.Node('123', 11, 1),
        node.Node('123', 16, 1),
    ]
    node15_routing_table = routing_table.RoutingTable(neighbors_15, node15)
    return node15, node15_routing_table
Beispiel #6
0
def make_node_13():
    node13 = node.Node('123', 13, 0)
    neighbors_13 = [
        node.Node('123', 10, 5),
        node.Node('123', 11, 7),
    ]
    node13_routing_table = routing_table.RoutingTable(neighbors_13, node13)
    return node13, node13_routing_table
Beispiel #7
0
 def __init__(self, config):
     """
         Creates a new server with a configuration.
     """
     self.rt = routing_table.RoutingTable(config, self.log)
     self.config = config
     self.input_ports = []
     self.periodic_timer = None
     self.loglines = []
Beispiel #8
0
def make_node_11():
    node11 = node.Node('123', 11, 0)
    neighbors_11 = [
        node.Node('123', 10, 1),
        node.Node('123', 13, 7),
        node.Node('123', 15, 1),
    ]
    node11_routing_table = routing_table.RoutingTable(neighbors_11, node11)
    return node11, node11_routing_table
Beispiel #9
0
    def __init__(self, my_node, msg_f, bootstrapper):
        self.my_node = my_node
        self.msg_f = msg_f

        self.table = routing_table.RoutingTable(my_node, [
            8,
        ] * 160)
        # This is just for testing:
        self.maintenance_counter = 0
Beispiel #10
0
    def __init__(self, my_node, bootstrap_nodes):
        self.my_node = my_node
        #Copy the bootstrap list
        self.bootstrap_nodes = iter(bootstrap_nodes)

        self.table = routing_table.RoutingTable(my_node, [
            8,
        ] * 160)
        # This is just for testing:
        self.maintenance_counter = 0