This commit is contained in:
Eichhornchen 2021-01-07 18:13:20 +01:00
parent eae4f13066
commit a8d38faa62
2 changed files with 6 additions and 18 deletions

View File

@ -198,22 +198,6 @@ class HelloTLV(TLV):
if not self.is_long:
user.send_packet(sender, Packet.construct(HelloTLV.construct(16, user, sender)))
def handle_multicast(self, user: Any, sender: Any) -> None:
if sender.id > 0 and sender.id != self.source_id:
user.add_system_message(f"A client known as the id {sender.id} declared that it uses "
f"the id {self.source_id}.")
sender.id = self.source_id
if self.source_id == user.id:
sender.marked_as_banned = True
if not sender.active:
sender.id = self.source_id # The sender we are given misses an id
# Add entry to/actualize the active peers dictionnary
user.update_peer_table(sender)
user.add_system_message(f"{self.source_id} sent me a Hello on multicast")
@property
def is_long(self) -> bool:

View File

@ -106,6 +106,8 @@ class User(Peer):
if self.squinnondation.multicast:
# Create multicast socket
self.multicast_socket = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
# Allows address to be reused
self.multicast_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
self.multicast_socket.bind(('', 1212)) #listen on all interfaces?
# To join the group, we need to give setsockopt a binary packed representation of the multicast group's address and on what interfaces we will listen (here all)
mreq = struct.pack("16s15s", socket.inet_pton(socket.AF_INET6, "ff02::4242:4242"), bytes(socket.INADDR_ANY)) #The string "16s15s" corresponds to the packing options: here it packs the arguments into a 16-byte string and a 15-byte string.
@ -1061,6 +1063,7 @@ class Multicastlistener(Thread):
self.user = user
def run(self) -> None:
self.user.add_system_message("running")
while True:
try:
pkt, peer = self.user.receive_hello_multicast()
@ -1074,8 +1077,9 @@ class Multicastlistener(Thread):
continue
for tlv in pkt.body:
if tlv.type==2 and tlv.length==8: # Only short hello TLVs allowed
tlv.handle_multicast(self.user, peer)
# We are only supposed to receive HelloTlVs via this communication mean
self.user.add_system_message("Via multicast :")
tlv.handle(self.user, peer)
self.user.refresh_history()
self.user.refresh_input()