The address property of a hazel is now a string. The whole code has been changed accordingly.

This commit is contained in:
eichhornchen
2020-12-28 15:00:36 +01:00
parent c4e03ed427
commit 913f804f5e
2 changed files with 20 additions and 20 deletions

View File

@ -2,7 +2,7 @@
# SPDX-License-Identifier: GPL-3.0-or-later
import re
from typing import Any, List, Optional
from ipaddress import IPv6Address
#from ipaddress import IPv6Address
from enum import Enum
import socket
import sys
@ -162,12 +162,12 @@ class HelloTLV(TLV):
sender.id = self.source_id #The sender we are given misses an id
timeHL = time.time()
else :
timeHL = squirrel.activehazelnuts[(str(sender.address), sender.port)]
timeHL = squirrel.activehazelnuts[(sender.address, sender.port)]
if self.is_long and self.dest_id == squirrel.id :
timeHL = time.time()
squirrel.remove_from_potential(sender.address, sender.port)
squirrel.activehazelnuts[(str(sender.address), sender.port)] = [sender, timeH,\
squirrel.activehazelnuts[(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 "
@ -195,13 +195,13 @@ class HelloTLV(TLV):
class NeighbourTLV(TLV):
type: int = 3
length: int
ip_address: IPv6Address
ip_address: str
port: int
def unmarshal(self, raw_data: bytes) -> None:
self.type = raw_data[0]
self.length = raw_data[1]
self.ip_address = IPv6Address(raw_data[2:18])
self.ip_address = raw_data[2:18]#IPv6Address()
self.port = int.from_bytes(raw_data[18:20], sys.byteorder)
def marshal(self) -> bytes:
@ -211,12 +211,12 @@ class NeighbourTLV(TLV):
self.port.to_bytes(2, sys.byteorder)
def handle(self, squirrel: Any, sender: Any) -> None:
if not (str(self.ip_address),self.port) in squirrel.activehazelnuts and not (str(self.ip_address),self.port) in squirrel.potentialhazelnuts:
squirrel.potentialhazelnuts[(str(self.ip_address), self.port)] = squirrel.new_hazel(self.ip_address, self.port)
if not (self.ip_address,self.port) in squirrel.activehazelnuts and not (self.ip_address,self.port) in squirrel.potentialhazelnuts:
squirrel.potentialhazelnuts[(self.ip_address, self.port)] = squirrel.new_hazel(self.ip_address, self.port)
squirrel.add_system_message(f"New potential friend {self.ip_address}:{self.port}!")
@staticmethod
def construct(address: IPv6Address, port: int) -> "NeighbourTLV":
def construct(address: str, port: int) -> "NeighbourTLV":
tlv = NeighbourTLV()
tlv.type = 3
tlv.length = 18 #A priori...
@ -351,7 +351,7 @@ 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[(str(sender.address), sender.port)] = sender
squirrel.potentialhazelnuts[(sender.address, sender.port)] = sender
squirrel.add_system_message("Some told me that he went away : "+self.message)
@staticmethod