identify handler reads data on request from the host
This commit is contained in:
parent
32c55bcaf2
commit
e0a94b6092
|
@ -4,6 +4,7 @@ from typing import Sequence
|
||||||
from multiaddr import Multiaddr
|
from multiaddr import Multiaddr
|
||||||
|
|
||||||
from libp2p.crypto.keys import PublicKey
|
from libp2p.crypto.keys import PublicKey
|
||||||
|
from libp2p.host.host_interface import IHost
|
||||||
from libp2p.network.stream.net_stream_interface import INetStream
|
from libp2p.network.stream.net_stream_interface import INetStream
|
||||||
from libp2p.typing import StreamHandlerFn, TProtocol
|
from libp2p.typing import StreamHandlerFn, TProtocol
|
||||||
|
|
||||||
|
@ -20,13 +21,15 @@ def _multiaddr_to_bytes(maddr: Multiaddr) -> bytes:
|
||||||
return maddr.to_bytes()
|
return maddr.to_bytes()
|
||||||
|
|
||||||
|
|
||||||
def identify_handler_for(
|
def identify_handler_for(host: IHost) -> StreamHandlerFn:
|
||||||
public_key: PublicKey, laddrs: Sequence[Multiaddr], protocols: Sequence[TProtocol]
|
|
||||||
) -> StreamHandlerFn:
|
|
||||||
async def handle_identify(stream: INetStream) -> None:
|
async def handle_identify(stream: INetStream) -> None:
|
||||||
peer_id = stream.muxed_conn.peer_id
|
peer_id = stream.muxed_conn.peer_id
|
||||||
logger.debug("received a request for %s from %s", ID, peer_id)
|
logger.debug("received a request for %s from %s", ID, peer_id)
|
||||||
|
|
||||||
|
public_key = host.get_public_key()
|
||||||
|
laddrs = host.get_addrs()
|
||||||
|
protocols = host.get_mux().get_protocols()
|
||||||
|
|
||||||
protobuf = Identify(
|
protobuf = Identify(
|
||||||
protocol_version=PROTOCOL_VERSION,
|
protocol_version=PROTOCOL_VERSION,
|
||||||
agent_version=AGENT_VERSION,
|
agent_version=AGENT_VERSION,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user