-
Notifications
You must be signed in to change notification settings - Fork 147
chore(kad_dht): centralize shared values in common.py file #695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LVivona The code looks clean and well-structured.
I’ve shared a few suggestions which may be addressed.
libp2p/kad_dht/routing_table.py
Outdated
@@ -243,7 +239,7 @@ async def _ping_peer(self, peer_id: ID) -> bool: | |||
raise ValueError(f"Peer {peer_id} not in bucket") | |||
|
|||
# Default protocol ID for Kademlia DHT | |||
protocol_id = TProtocol("/ipfs/kad/1.0.0") | |||
protocol_id = PROTOCOL_ID |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use PROTOCOL_ID directly in the stream creation statement:
stream = await self.host.new_stream(peer_id, [PROTOCOL_ID])
This makes the assignment protocol_id = PROTOCOL_ID unnecessary and can be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Within peer_routing.py
there exist PROTOCOL_ID as well, should I set it to just PROTOCOL_ID, or is it necessary within the state of the object PeerRouting
PeerRouting
def __init__(self, host: IHost, routing_table: RoutingTable):
"""
Initialize the peer routing service.
:param host: The libp2p host
:param routing_table: The Kademlia routing table
"""
self.host = host
self.routing_table = routing_table
self.protocol_id = PROTOCOL_ID
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LVivona Since PROTOCOL_ID is now defined in common.py, it can be imported and used as a global constant wherever needed. Therefore, there is no longer a need to store it in the state of the PeerRouting object.
So you can remove self.protocol_id = PROTOCOL_ID
and use PROTOCOL_ID
directly wherever applicable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay perfect
libp2p/kad_dht/routing_table.py
Outdated
) | ||
from .pb.kademlia_pb2 import Message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import this using the multiline import style to maintain consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad I'm not sure how I missed that one.
While running the workflow locally, I noticed there was a test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LVivona The pull request looks good to me. All requested changes have been addressed.
@seetadev All feedback has been addressed. Please run the CI/CD tests, and if all tests pass, we can proceed with merging the pull request. |
What was wrong?
The kad_dht module contained repeated definitions of commonly used variables, leading to redundancy and reduced maintainability.
How was it fixed?
A new common.py file was introduced to centralize shared default values and constants, promoting reuse and improving code clarity.
To-Do
Cute Animal Picture