Implemented the first three phases of neighbour management (warning: for testing purposes, the delays before any action have been reduced)
This commit is contained in:
@ -162,32 +162,33 @@ class HelloTLV(TLV):
|
||||
if not squirrel.is_active(sender) :
|
||||
sender.id = self.source_id #The sender we are given misses an id
|
||||
else :
|
||||
timeHL = squirrel.activehazelnuts[(sender.address, sender.port)]
|
||||
if self.is_long and dest_id == squirrel.id :
|
||||
timeHL = squirrel.activehazelnuts[(str(sender.address), sender.port)]
|
||||
if self.is_long and self.dest_id == squirrel.id :
|
||||
timeHL = time.time()
|
||||
#elif source_id != sender.id :
|
||||
#That neighbour is lying about its ID
|
||||
squirrel.remove_from_potential(sender.address, sender.port)
|
||||
|
||||
squirrel.activehazelnuts[(sender.address, sender.port)] = [sender, timeH,\
|
||||
timeHL, True]
|
||||
squirrel.add_system_message("Aaaawwww, someone spoke to me and said me Hello smiling_face_with_"
|
||||
+ (":3_hearts:" if self.is_long else "smiling_eyes:"))
|
||||
squirrel.activehazelnuts[(str(sender.address), sender.port)] = [sender, timeH,\
|
||||
timeHL]
|
||||
squirrel.nbNS += 1
|
||||
squirrel.add_system_message(f"Aaaawwww, {self.source_id} spoke to me and said me Hello "
|
||||
+ ("long" if self.is_long else "short"))
|
||||
|
||||
@property
|
||||
def is_long(self) -> bool:
|
||||
return self.length == 16
|
||||
|
||||
@staticmethod
|
||||
def construct(length: str, squirrel: Any) -> "HelloTLV":
|
||||
def construct(length: int, squirrel: Any, destination: Any = None) -> "HelloTLV":
|
||||
tlv = HelloTLV()
|
||||
tlv.type = 2
|
||||
tlv.source_id = squirrel.id if squirrel else 0
|
||||
if length == "short":
|
||||
if (destination is None) or destination.id == -1 or length == 8:
|
||||
tlv.length = 8
|
||||
tlv.dest_id = None #if the destination id is not known, or
|
||||
#if the destination was not precised, send a short hello
|
||||
else :
|
||||
tlv.length = 16
|
||||
tlv.dest_id = None
|
||||
tlv.dest_id = destination.id
|
||||
return tlv
|
||||
|
||||
|
||||
@ -322,14 +323,14 @@ class AckTLV(TLV):
|
||||
tlv.nonce = nonce
|
||||
return tlv
|
||||
|
||||
|
||||
class GoAwayTLV(TLV):
|
||||
class GoAwayType(Enum):
|
||||
class GoAwayType(Enum):
|
||||
UNKNOWN = 0
|
||||
EXIT = 1
|
||||
TIMEOUT = 2
|
||||
PROTOCOL_VIOLATION = 3
|
||||
|
||||
class GoAwayTLV(TLV):
|
||||
|
||||
type: int = 6
|
||||
length: int
|
||||
code: GoAwayType
|
||||
@ -350,15 +351,15 @@ class GoAwayTLV(TLV):
|
||||
def handle(self, squirrel: Any, sender: Any) -> None:
|
||||
if squirrel.is_active(sender) :
|
||||
squirrel.activehazelnuts.pop((sender.addess, sender.port))
|
||||
squirrel.potentialhazelnuts[(sender.address, sender.port)] = sender
|
||||
squirrel.add_system_message("Some told me that he went away : "+message)
|
||||
squirrel.potentialhazelnuts[(str(sender.address), sender.port)] = sender
|
||||
squirrel.add_system_message("Some told me that he went away : "+self.message)
|
||||
|
||||
@staticmethod
|
||||
def construct(GAtype: GoAwayType, message: str) -> "Pad1TLV":
|
||||
def construct(GAtype: GoAwayType, message: str) -> "GoAwayTLV":
|
||||
tlv = GoAwayTLV()
|
||||
tlv.type = 6
|
||||
tlv.code = GAtype
|
||||
tlv.message = message.encode("UTF-8")
|
||||
tlv.message = message
|
||||
tlv.length = 1 + len(tlv.message)
|
||||
return tlv
|
||||
|
||||
|
Reference in New Issue
Block a user