The address property of a hazel is now a string. The whole code has been changed accordingly.
This commit is contained in:
@ -3,7 +3,7 @@
|
||||
from datetime import datetime
|
||||
from random import randint
|
||||
from typing import Any, Tuple
|
||||
from ipaddress import IPv6Address
|
||||
#from ipaddress import IPv6Address
|
||||
from threading import Thread, RLock
|
||||
import curses
|
||||
import re
|
||||
@ -30,7 +30,7 @@ class Hazelnut:
|
||||
# See https://fr.wikipedia.org/wiki/Adresse_IPv6_mappant_IPv4
|
||||
address = "::ffff:" + socket.getaddrinfo(address, None, socket.AF_INET)[0][4][0]
|
||||
|
||||
self.address = IPv6Address(address)
|
||||
self.address = address #IPv6Address(address)
|
||||
self.port = port
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ class Squirrel(Hazelnut):
|
||||
# Create UDP socket
|
||||
self.socket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
|
||||
# Bind the socket
|
||||
self.socket.bind((str(self.address), self.port))
|
||||
self.socket.bind((self.address, self.port))
|
||||
|
||||
self.squinnondation = instance
|
||||
|
||||
@ -79,13 +79,13 @@ class Squirrel(Hazelnut):
|
||||
#to have.
|
||||
|
||||
self.add_system_message(f"Listening on {self.address}:{self.port}")
|
||||
self.add_system_message(f"I am {self.id}")
|
||||
self.add_system_message(f"I am {self.id}}")
|
||||
|
||||
def new_hazel(self, address: IPv6Address, port: int) -> Hazelnut:
|
||||
def new_hazel(self, address: str, port: int) -> Hazelnut:
|
||||
"""
|
||||
Returns a new hazelnut (with no id nor nickname)
|
||||
"""
|
||||
hazelnut = Hazelnut(address=str(address), port=port)
|
||||
hazelnut = Hazelnut(address=address, port=port)
|
||||
return hazelnut
|
||||
|
||||
def is_active(self, hazel: Hazelnut) -> bool :
|
||||
@ -94,8 +94,8 @@ class Squirrel(Hazelnut):
|
||||
def is_potential(self, hazel: Hazelnut) -> bool :
|
||||
return (hazel.address, hazel.port) in self.potentialhazelnuts
|
||||
|
||||
def remove_from_potential(self, address: IPv6Address, port: int)-> None:
|
||||
self.potentialhazelnuts.pop((str(address), port), None)
|
||||
def remove_from_potential(self, address: str, port: int)-> None:
|
||||
self.potentialhazelnuts.pop((address, port), None)
|
||||
|
||||
def find_hazelnut(self, address: str, port: int) -> Hazelnut:
|
||||
"""
|
||||
@ -124,7 +124,7 @@ class Squirrel(Hazelnut):
|
||||
Send a raw packet to a client.
|
||||
"""
|
||||
self.refresh_lock.acquire()
|
||||
res = self.socket.sendto(data, (str(client.address), client.port))
|
||||
res = self.socket.sendto(data, (client.address, client.port))
|
||||
self.refresh_lock.release()
|
||||
return res
|
||||
|
||||
@ -546,8 +546,8 @@ class Squirrel(Hazelnut):
|
||||
gatlv = GoAwayTLV().construct(GoAwayType.TIMEOUT, "you did not talk to me")
|
||||
pkt = Packet().construct(gatlv)
|
||||
self.send_packet(hazelnut[0], pkt)
|
||||
self.activehazelnuts.pop((str(hazelnut[0].address), hazelnut[0].port))
|
||||
self.potentialhazelnuts[(str(hazelnut[0].address), hazelnut[0].port)] = hazelnut[0]
|
||||
self.activehazelnuts.pop((hazelnut[0].address, hazelnut[0].port))
|
||||
self.potentialhazelnuts[(hazelnut[0].address, hazelnut[0].port)] = hazelnut[0]
|
||||
|
||||
self.refresh_lock.release()
|
||||
|
||||
|
Reference in New Issue
Block a user