mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
Peer tests and minor peer features/bug fixes.
This commit is contained in:
@ -13,6 +13,9 @@ class PeerData(IPeerData):
|
||||
def add_protocols(self, protocols):
|
||||
self.protocols.extend(protocols)
|
||||
|
||||
def set_protocols(self, protocols):
|
||||
self.protocols = protocols
|
||||
|
||||
def add_addrs(self, addrs):
|
||||
self.addrs.extend(addrs)
|
||||
|
||||
|
||||
@ -2,48 +2,62 @@ from abc import ABC, abstractmethod
|
||||
|
||||
class IPeerData(ABC):
|
||||
|
||||
"""
|
||||
:return: all protocols associated with given peer
|
||||
"""
|
||||
@abstractmethod
|
||||
def get_protocols(self):
|
||||
"""
|
||||
:return: all protocols associated with given peer
|
||||
"""
|
||||
pass
|
||||
|
||||
"""
|
||||
:param protocols: protocols to add
|
||||
"""
|
||||
@abstractmethod
|
||||
def add_protocols(self, protocols):
|
||||
"""
|
||||
:param protocols: protocols to add
|
||||
"""
|
||||
pass
|
||||
|
||||
"""
|
||||
:param addrs: multiaddresses to add
|
||||
"""
|
||||
@abstractmethod
|
||||
def set_protocols(self, protocols):
|
||||
"""
|
||||
:param protocols: protocols to add
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_addrs(self, addrs):
|
||||
"""
|
||||
:param addrs: multiaddresses to add
|
||||
"""
|
||||
pass
|
||||
|
||||
"""
|
||||
:return: all multiaddresses
|
||||
"""
|
||||
@abstractmethod
|
||||
def get_addrs(self):
|
||||
"""
|
||||
:return: all multiaddresses
|
||||
"""
|
||||
pass
|
||||
|
||||
"""
|
||||
Clear all addresses
|
||||
"""
|
||||
@abstractmethod
|
||||
def clear_addrs(self):
|
||||
"""
|
||||
Clear all addresses
|
||||
"""
|
||||
pass
|
||||
|
||||
"""
|
||||
:param key: key in KV pair
|
||||
:param val: val to associate with key
|
||||
:raise Exception: unsuccesful put
|
||||
"""
|
||||
@abstractmethod
|
||||
def put_metadata(self, key, val):
|
||||
"""
|
||||
:param key: key in KV pair
|
||||
:param val: val to associate with key
|
||||
:raise Exception: unsuccesful put
|
||||
"""
|
||||
pass
|
||||
|
||||
"""
|
||||
:param key: key in KV pair
|
||||
:return: val for key
|
||||
:raise Exception: key not found
|
||||
"""
|
||||
@abstractmethod
|
||||
def get_metadata(self, key):
|
||||
"""
|
||||
:param key: key in KV pair
|
||||
:return: val for key
|
||||
:raise Exception: key not found
|
||||
"""
|
||||
pass
|
||||
|
||||
@ -38,6 +38,10 @@ class PeerStore(IPeerStore):
|
||||
peer = self.__create_or_get_peer(peer_id)
|
||||
peer.add_protocols(protocols)
|
||||
|
||||
def set_protocols(self, peer_id, protocols):
|
||||
peer = self.__create_or_get_peer(peer_id)
|
||||
peer.set_protocols(protocols)
|
||||
|
||||
def peers(self):
|
||||
return self.peer_map.keys()
|
||||
|
||||
@ -55,7 +59,7 @@ class PeerStore(IPeerStore):
|
||||
peer.put_metadata(key, val)
|
||||
|
||||
def add_addr(self, peer_id, addr, ttl):
|
||||
self.add_addrs(self, peer_id, [addr])
|
||||
self.add_addrs(peer_id, [addr], ttl)
|
||||
|
||||
def add_addrs(self, peer_id, addrs, ttl):
|
||||
# Ignore ttl for now
|
||||
|
||||
@ -2,7 +2,7 @@ from abc import ABC, abstractmethod
|
||||
from .addrbook_interface import IAddrBook
|
||||
from .peermetadata_interface import IPeerMetadata
|
||||
|
||||
class IPeerStore(ABC, IAddrBook, IPeerMetadata):
|
||||
class IPeerStore(IAddrBook, IPeerMetadata):
|
||||
|
||||
def __init__(self):
|
||||
IPeerMetadata.__init__(self)
|
||||
|
||||
Reference in New Issue
Block a user