mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-09 22:50:54 +00:00
Fix a minor bug for pb optional field
In `Pubsub.continuously_read_stream`, it checks whether this is a
control message enclosed in RPC message with `if rpc_incoming.control:`.
However, in pb2, the condition is always true because a default value is
returned when a field is not set. Solved it by changing it to
`if rpc_incoming.HasField("control"):`.
This commit is contained in:
@ -159,7 +159,11 @@ class Pubsub:
|
|||||||
for message in rpc_incoming.subscriptions:
|
for message in rpc_incoming.subscriptions:
|
||||||
self.handle_subscription(peer_id, message)
|
self.handle_subscription(peer_id, message)
|
||||||
|
|
||||||
if rpc_incoming.control:
|
# pylint: disable=line-too-long
|
||||||
|
# NOTE: Check if `rpc_incoming.control` is set through `HasField`.
|
||||||
|
# This is necessary because `control` is an optional field in pb2.
|
||||||
|
# Ref: https://developers.google.com/protocol-buffers/docs/reference/python-generated#singular-fields-proto2
|
||||||
|
if rpc_incoming.HasField("control"):
|
||||||
# Pass rpc to router so router could perform custom logic
|
# Pass rpc to router so router could perform custom logic
|
||||||
await self.router.handle_rpc(rpc_incoming, peer_id)
|
await self.router.handle_rpc(rpc_incoming, peer_id)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user