Implemented the fourth phase of neighbour management (the type of addresses sometimes changes in the cide, this should be addressed, there also remains a lot of debugging printing)
This commit is contained in:
@ -10,7 +10,7 @@ import re
|
||||
import socket
|
||||
import time
|
||||
|
||||
from .messages import Packet, DataTLV, HelloTLV, GoAwayTLV, GoAwayType
|
||||
from .messages import Packet, DataTLV, HelloTLV, GoAwayTLV, GoAwayType, NeighbourTLV
|
||||
|
||||
|
||||
class Hazelnut:
|
||||
@ -85,7 +85,7 @@ class Squirrel(Hazelnut):
|
||||
"""
|
||||
Returns a new hazelnut (with no id nor nickname)
|
||||
"""
|
||||
hazelnut = Hazelnut(address=address, port=port)
|
||||
hazelnut = Hazelnut(address=str(address), port=port)
|
||||
return hazelnut
|
||||
|
||||
def is_active(self, hazel: Hazelnut) -> bool :
|
||||
@ -550,6 +550,7 @@ class Squirrel(Hazelnut):
|
||||
self.potentialhazelnuts[(str(hazelnut[0].address), hazelnut[0].port)] = hazelnut[0]
|
||||
|
||||
self.refresh_lock.release()
|
||||
|
||||
|
||||
def send_neighbours(self) -> None:
|
||||
"""
|
||||
@ -559,9 +560,16 @@ class Squirrel(Hazelnut):
|
||||
self.refresh_lock.acquire()
|
||||
|
||||
nbNS = 0
|
||||
#for hazelnut in self.activehazelnuts.values() :
|
||||
# if time.time()-hazelnut[2]<2*60: #could send the same to all neighbour, but it means that neighbour A could receive a message with itself in it -> if the others do not pay attention, trouble
|
||||
|
||||
#could send the same to all neighbour, but it means that neighbour A could receive a message with itself in it -> if the others do not pay attention, trouble
|
||||
for hazelnut in self.activehazelnuts.values() :
|
||||
if time.time()-hazelnut[2]<=2*60:
|
||||
nbNS+=1
|
||||
ntlv = NeighbourTLV().construct(hazelnut[0].address,hazelnut[0].port)
|
||||
pkt = Packet().construct(ntlv)
|
||||
for destination in self.activehazelnuts.values() :
|
||||
if destination[0].id != hazelnut[0].id :
|
||||
self.send_packet(destination[0], pkt)
|
||||
self.nbNS = nbNS
|
||||
|
||||
self.refresh_lock.release()
|
||||
|
||||
@ -623,7 +631,9 @@ class HazelManager(Thread):
|
||||
self.squirrel.verify_activity()
|
||||
|
||||
#Fourth part: verify symmetric neighbours and send NeighbourTLV every minute
|
||||
|
||||
if time.time()-self.last_neighbour > 10: #60 :
|
||||
self.squirrel.send_neighbours()
|
||||
self.last_neighbour = time.time()
|
||||
|
||||
|
||||
class Message:
|
||||
|
Reference in New Issue
Block a user