peers shall now share their trusted peers list
This commit is contained in:
parent
ab745aa75a
commit
ad49484de9
4 changed files with 16 additions and 1 deletions
|
@ -15,5 +15,6 @@ class PeerEvent(base.BaseEvent):
|
|||
# update our peers database to add new peer information
|
||||
self.manager.peer.peers[address] = structures.Peer(
|
||||
public_key=packet.public_key,
|
||||
master=packet.master
|
||||
allowed_public_key_hashes=self.manager.communication.get_allowed_peers(),
|
||||
master=packet.master,
|
||||
)
|
||||
|
|
|
@ -13,6 +13,11 @@ class BaseTrustedEvent(BaseEvent, abc.ABC):
|
|||
def handle(self, packet: packets.base.BasePacket, address: tuple) -> None:
|
||||
# get the peer that sent the message
|
||||
peer = self.manager.peer.peers.get(address)
|
||||
|
||||
# check if it is trusted
|
||||
if peer is None or not peer.is_trusted(self.manager):
|
||||
raise UntrustedPeerException(peer)
|
||||
|
||||
# make sure we trust the peer trusted by this peer
|
||||
for public_key_hash in peer.allowed_public_key_hashes:
|
||||
self.manager.communication.trust_peer_hash(public_key_hash)
|
||||
|
|
|
@ -319,3 +319,9 @@ class CommunicationManager:
|
|||
"""
|
||||
|
||||
return hashlib.sha256(public_key).hexdigest() in self._banned_peers
|
||||
|
||||
def get_allowed_peers(self) -> set[str]:
|
||||
return self._trusted_peers
|
||||
|
||||
def get_banned_peers(self) -> set[str]:
|
||||
return self._banned_peers
|
||||
|
|
|
@ -13,6 +13,9 @@ class Peer:
|
|||
# secret symmetric key
|
||||
secret_key: Optional[bytes] = dataclasses.field(default=None, repr=False)
|
||||
|
||||
# additional public key hashes used by this peer
|
||||
allowed_public_key_hashes: set[bytes] = dataclasses.field(default=set, repr=False)
|
||||
|
||||
# when did the peer last communication with us occurred
|
||||
last_interaction: datetime = dataclasses.field(default_factory=datetime.now)
|
||||
|
||||
|
|
Loading…
Reference in a new issue