mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
define interfaces
This commit is contained in:
25
network/network_interface.py
Normal file
25
network/network_interface.py
Normal file
@ -0,0 +1,25 @@
|
||||
from abc import ABC
|
||||
|
||||
class Network(ABC):
|
||||
|
||||
def __init__(self, context, my_peer_id, peer_store):
|
||||
self.context = context
|
||||
self.my_peer_id = my_peer_id
|
||||
self.peer_store = peer_store
|
||||
|
||||
@abstractmethod
|
||||
def set_stream_handler(stream_handler):
|
||||
"""
|
||||
:param stream_handler: a stream handler instance
|
||||
:return: true if successful
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def new_stream(context, peer_id):
|
||||
"""
|
||||
:param context: context instance
|
||||
:param peer_id: peer_id of destination
|
||||
:return: stream instance
|
||||
"""
|
||||
pass
|
||||
38
network/stream_interface.py
Normal file
38
network/stream_interface.py
Normal file
@ -0,0 +1,38 @@
|
||||
from abc import ABC
|
||||
|
||||
class Stream(ABC):
|
||||
|
||||
def __init__(self, context, peer_id):
|
||||
self.context = context
|
||||
self.peer_id = peer_id
|
||||
|
||||
@abstractmethod
|
||||
def protocol():
|
||||
"""
|
||||
:return: protocol id that stream runs on
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def set_protocol(protocol_id):
|
||||
"""
|
||||
:param protocol_id: protocol id that stream runs on
|
||||
:return: true if successful
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def read():
|
||||
"""
|
||||
read from stream
|
||||
:return: bytes of input
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def write(bytes):
|
||||
"""
|
||||
write to stream
|
||||
:return: number of bytes written
|
||||
"""
|
||||
pass
|
||||
4
network/swarm.py
Normal file
4
network/swarm.py
Normal file
@ -0,0 +1,4 @@
|
||||
from interface import Network
|
||||
|
||||
class Swarm(Network):
|
||||
pass
|
||||
Reference in New Issue
Block a user