basic-host and remove context

This commit is contained in:
zixuanzh
2018-10-21 12:55:45 -04:00
parent 5fd7cbe0eb
commit 9e64202e5c
7 changed files with 19 additions and 29 deletions

View File

@ -8,23 +8,23 @@ from .host_interface import IHost
class BasicHost(IHost):
# default options constructor
def __init__(self, context, network):
self.context = context
self.network = network
def __init__(self, _network):
self.network = _network
# self.stream_handlers = {}
def get_id(self):
"""
:return: peer_id of host
"""
pass
return self.network.get_peer_id()
def get_network(self):
"""
:return: network instance of host
"""
pass
return self.network
def mux(self):
def get_mux(self):
"""
:return: mux instance of host
"""
@ -37,15 +37,17 @@ class BasicHost(IHost):
:param stream_handler: a stream handler function
:return: true if successful
"""
pass
return self.network.set_stream_handler(protocol_id, stream_handler)
# protocol_id can be a list of protocol_ids
# stream will decide which protocol_id to run on
def new_stream(self, context, peer_id, protocol_id):
def new_stream(self, peer_id, protocol_id):
"""
:param context: a context instance
:param peer_id: peer_id that host is connecting
:param proto_id: protocol id that stream runs on
:return: true if successful
"""
pass
stream = self.network.new_stream(peer_id)
stream.set_protocol(protocol_id)
return stream