Clients can communicate together (without any innondation)
Signed-off-by: Yohann D'ANELLO <ynerant@crans.org>
This commit is contained in:
parent
9561912ac6
commit
a28975c895
|
@ -47,11 +47,17 @@ class Squinnondation:
|
||||||
|
|
||||||
if not instance.args.bind_only:
|
if not instance.args.bind_only:
|
||||||
hazelnut = Hazelnut(address=instance.client_address, port=instance.client_port)
|
hazelnut = Hazelnut(address=instance.client_address, port=instance.client_port)
|
||||||
|
squirrel.hazelnuts[(instance.client_address, instance.client_port)] = hazelnut
|
||||||
|
|
||||||
|
Worm(squirrel).start()
|
||||||
|
|
||||||
|
while True:
|
||||||
|
msg = f"<{squirrel.nickname}> {input(f'<{squirrel.nickname}> ')}"
|
||||||
|
for hazelnut in list(squirrel.hazelnuts.values()):
|
||||||
pkt = Packet()
|
pkt = Packet()
|
||||||
pkt.magic = 95
|
pkt.magic = 95
|
||||||
pkt.version = 0
|
pkt.version = 0
|
||||||
tlv = DataTLV()
|
tlv = DataTLV()
|
||||||
msg = f"Hello world, my name is {squirrel.nickname}!"
|
|
||||||
tlv.data = msg.encode("UTF-8")
|
tlv.data = msg.encode("UTF-8")
|
||||||
tlv.sender_id = 42
|
tlv.sender_id = 42
|
||||||
tlv.nonce = 18
|
tlv.nonce = 18
|
||||||
|
@ -60,8 +66,6 @@ class Squinnondation:
|
||||||
pkt.body_length = tlv.length + 2
|
pkt.body_length = tlv.length + 2
|
||||||
squirrel.send_packet(hazelnut, pkt)
|
squirrel.send_packet(hazelnut, pkt)
|
||||||
|
|
||||||
Worm(squirrel).start()
|
|
||||||
|
|
||||||
|
|
||||||
class TLV:
|
class TLV:
|
||||||
"""
|
"""
|
||||||
|
@ -418,16 +422,3 @@ class Worm(Thread):
|
||||||
print("An error occured while receiving a packet: ", error)
|
print("An error occured while receiving a packet: ", error)
|
||||||
else:
|
else:
|
||||||
print(pkt.body[0].data.decode('UTF-8'))
|
print(pkt.body[0].data.decode('UTF-8'))
|
||||||
pkt = Packet()
|
|
||||||
pkt.magic = 95
|
|
||||||
pkt.version = 0
|
|
||||||
pkt.body = []
|
|
||||||
tlv = DataTLV()
|
|
||||||
msg = f"Hello my dear hazelnut, I am {self.squirrel.nickname}!"
|
|
||||||
tlv.data = msg.encode("UTF-8")
|
|
||||||
tlv.sender_id = 42
|
|
||||||
tlv.nonce = 18
|
|
||||||
tlv.length = len(msg) + 1 + 1 + 8 + 4
|
|
||||||
pkt.body.append(tlv)
|
|
||||||
pkt.body_length = tlv.length + 2
|
|
||||||
self.squirrel.send_packet(hazelnut, pkt)
|
|
||||||
|
|
Loading…
Reference in New Issue