Copy default data to avoid undesirable mutations
This commit is contained in:
parent
d0c8b7d8af
commit
15cabb1c33
|
@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, List, Sequence
|
||||||
|
|
||||||
import multiaddr
|
import multiaddr
|
||||||
|
|
||||||
from libp2p.host.defaults import DEFAULT_HOST_PROTOCOLS
|
from libp2p.host.defaults import get_default_protocols
|
||||||
from libp2p.host.exceptions import StreamFailure
|
from libp2p.host.exceptions import StreamFailure
|
||||||
from libp2p.network.network_interface import INetwork
|
from libp2p.network.network_interface import INetwork
|
||||||
from libp2p.network.stream.net_stream_interface import INetStream
|
from libp2p.network.stream.net_stream_interface import INetStream
|
||||||
|
@ -45,12 +45,13 @@ class BasicHost(IHost):
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
network: INetwork,
|
network: INetwork,
|
||||||
default_protocols: "OrderedDict[TProtocol, StreamHandlerFn]" = DEFAULT_HOST_PROTOCOLS,
|
default_protocols: "OrderedDict[TProtocol, StreamHandlerFn]" = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self._network = network
|
self._network = network
|
||||||
self._network.set_stream_handler(self._swarm_stream_handler)
|
self._network.set_stream_handler(self._swarm_stream_handler)
|
||||||
self.peerstore = self._network.peerstore
|
self.peerstore = self._network.peerstore
|
||||||
# Protocol muxing
|
# Protocol muxing
|
||||||
|
default_protocols = default_protocols or get_default_protocols()
|
||||||
self.multiselect = Multiselect(default_protocols)
|
self.multiselect = Multiselect(default_protocols)
|
||||||
self.multiselect_client = MultiselectClient()
|
self.multiselect_client = MultiselectClient()
|
||||||
|
|
||||||
|
|
|
@ -5,3 +5,7 @@ if TYPE_CHECKING:
|
||||||
from libp2p.typing import TProtocol, StreamHandlerFn
|
from libp2p.typing import TProtocol, StreamHandlerFn
|
||||||
|
|
||||||
DEFAULT_HOST_PROTOCOLS: "OrderedDict[TProtocol, StreamHandlerFn]" = OrderedDict()
|
DEFAULT_HOST_PROTOCOLS: "OrderedDict[TProtocol, StreamHandlerFn]" = OrderedDict()
|
||||||
|
|
||||||
|
|
||||||
|
def get_default_protocols() -> "OrderedDict[TProtocol, StreamHandlerFn]":
|
||||||
|
return DEFAULT_HOST_PROTOCOLS.copy()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user