31 lines
No EOL
1.1 KiB
Python
31 lines
No EOL
1.1 KiB
Python
from . import base
|
|
from source import packets, structures
|
|
|
|
|
|
class PeerEvent(base.BaseEvent):
|
|
"""
|
|
Event reacting to receiving information about another machine
|
|
"""
|
|
|
|
def handle(self, packet: packets.PeerPacket, address: tuple):
|
|
# ignore peers with a banned key
|
|
if self.manager.communication.is_peer_banned(packet.public_key):
|
|
return
|
|
|
|
# update our peers database to add new peer information
|
|
peer = structures.Peer(
|
|
public_key=packet.public_key,
|
|
allowed_public_key_hashes=self.manager.communication.get_allowed_peers(),
|
|
master=packet.master,
|
|
)
|
|
self.manager.peer.peers[address] = peer
|
|
|
|
# if the peer is trusted
|
|
if peer.is_trusted(self.manager):
|
|
# make sure we trust the peers trusted by this peer
|
|
for public_key_hash in peer.allowed_public_key_hashes:
|
|
self.manager.communication.trust_peer_hash(public_key_hash)
|
|
|
|
# add the peer as a time source and allow it to use us as a time source
|
|
self.manager.clock.add_source(address[0])
|
|
self.manager.clock.allow_client(address[0]) |