Add interfaces for Address Book, PeerStore Metadata, and Peerstore

This commit is contained in:
Stuckinaboot 2018-10-20 16:55:15 -04:00
parent 48dfd9a77a
commit eacb7eac6d
3 changed files with 125 additions and 0 deletions

View File

@ -0,0 +1,51 @@
from abc import ABC, abstractmethod
class IAddrBook(ABC):
def __init__(self, context):
self.context = context
@abstractmethod
def add_addr(self, peerID, addr, ttl):
"""
Calls add_addrs(peerID, [addr], ttl)
:param peerID: the peer to add address for
:param addr: multiaddress of the peer
:param ttl: time-to-live for the address (after this time, address is no longer valid)
"""
pass
@abstractmethod
def add_addrs(self, peerID, addrs []ma.Multiaddr, ttl time.Duration):
"""
Adds addresses for a given peer all with the same time-to-live. If one of the
addresses already exists for the peer and has a longer TTL, no operation should take place.
If one of the addresses exists with a shorter TTL, extend the TTL to equal param ttl.
:param peerID: the peer to add address for
:param addr: multiaddresses of the peer
:param ttl: time-to-live for the address (after this time, address is no longer valid
"""
pass
@abstractmethod
def addrs(self, peerID):
"""
:param peerID: peer to get addresses of
:return: all known (and valid) addresses for the given peer
"""
pass
@abstractmethod
def clear_addrs(self, peerID):
"""
Removes all previously stored addresses
:param peerID: peer to remove addresses of
"""
pass
@abstractmethod
def peers_with_addrs(self):
"""
:return: all of the peer IDs stored with addresses
"""
pass

View File

@ -0,0 +1,25 @@
from abc import ABC, abstractmethod
class IPeerMetadata(ABC):
def __init__(self, context):
self.context = context
@abstractmethod
def get(self, peerID, key):
"""
:param peerID: peer ID to lookup key for
:param key: key to look up
:return: value at key for given peer, error
"""
pass
@abstractmethod
def put(self, peerID, key, val):
"""
:param peerID: peer ID to lookup key for
:param key: key to associate with peer
:param val: value to associated with key
:return: error
"""
pass

View File

@ -0,0 +1,49 @@
from abc import ABC, abstractmethod
from .addrbook_interace import IAddrBook
from .peermetadata_interface import IPeerMetadata
class IPeerStore(ABC, IAddrBook, IPeerMetadata):
def __init__(self, context):
self.context = context
@abstractmethod
def peer_info(self, peerID):
"""
:param peerID: peer ID to get info for
:return: peer info object
"""
pass
@abstractmethod
def get_protocols(self, peerID):
"""
:param peerID: peer ID to get protocols for
:return: protocols (as strings), error
"""
pass
@abstractmethod
def add_protocols(self, peerID, protocols):
"""
:param peerID: peer ID to add protocols for
:param protocols: protocols to add
:return: error
"""
pass
@abstractmethod
def set_protocols(self, peerID, protocols):
"""
:param peerID: peer ID to set protocols for
:param protocols: protocols to set
:return: error
"""
pass
@abstractmethod
def peers(self):
"""
:return: all of the peer IDs stored in peer store
"""
pass