-
Notifications
You must be signed in to change notification settings - Fork 188
WIP: libp2p-record module in reference with go-libp2p-record #776
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
Conversation
|
@seetadev: The go-libp2p-record repo: https://github.com/libp2p/go-libp2p-record. has been reflected on the py-libp2p side with all the interfaces. ad860c0 is only about the go-libp2p-record repo, will included tests, and would be ready for a separate review and feedback. The next step would be integrating the records routing and management in the services. Wish to confirm that now I have to look into these 3 protocols right? to integrate records:
|
|
@lla-dane : Absolutely — you're on the right track. Thank you for sharing the updates. Yes, please go ahead and start with Kademlia DHT integration first. This will be the foundational layer for key-value record storage and retrieval, including IPNS entries, and will naturally set the stage for the subsequent integration of IPNS and PubSub features. Once Kademlia DHT is implemented and tested, the next steps would be:
Each of these steps builds progressively on the prior one, so the current plan and sequencing make perfect sense. Also, your work in ad860c0 mapping out the interfaces from CCing @sumanjeet0012 and @acul71 for their inputs and feedback as you proceed with kad-dht integration. |
4aa2a04 to
8e80443
Compare
|
@seetadev: I explored integrating libp2p-record module in kad-dht just like the way, it is done in go-libp2p. I have made the following changes till now in kad_dht:
def __init__(
self,
host: IHost,
mode: DHTMode,
validator: NamespacedValidator | None = None,
validator_changed: bool = False,
protocol_prefix: TProtocol = PROTOCOL_PREFIX,
enable_providers: bool = True,
enable_values: bool = True,in the image of
Adding a few inline comments also |
| if self.validator is not None: | ||
| # Dont allow local users to put bad values | ||
| self.validator.validate(key.decode("utf-8"), value) | ||
|
|
||
| old = self.value_store.get(key) | ||
| if old is not None and old != value: | ||
| # Select which value is better | ||
| try: | ||
| index = self.validator.select(key.decode("utf-8"), [value, old]) | ||
| if index != 0: | ||
| raise ValueError( | ||
| "Refusing to replace newer value with the older one" | ||
| ) | ||
| except Exception as e: | ||
| logger.debug(f"Validation select error for key {key.hex()}: {e}") | ||
| raise |
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.
Added this code in the put_value function to validate the key/value pair that we receive in the put_value function's params. Reference from go-libp2p: PutValue
So what happens in go-libp2p PutValue function is we receive the key/value and key: str is in type string. and then we pass the key/value to the respective namespace_validator to get it validated.
So now the problem is, in py-libp2p side in put_value function, we receive key: bytes in bytes format which is different from go-libp2p.
So I would like some pointers on how to proceed @seetadev @sumanjeet0012
|
There is also a difference in the code design in the kad-dht utilities in py and go: In go libp2p, we store the def put(self, key: bytes, value: bytes, validity: float = 0.0) -> None:
...
self.store[key] = (value, validity)
...Simply storing the value and validity corresponding to the key. But in the go-libp2p side we are storing like this: rec := record.MakePutRecord(key, value)
rec.TimeReceived = internal.FormatRFC3339(time.Now())
err = dht.putLocal(ctx, key, rec)
if err != nil {
return err
}Creating a record with key/value pair and then storing it in the local in the form of record corresponding to the key. So this is the difference in code design. So what should I do, shall I refactor the py side as per the go-libp2p?? |
8021338 to
c131c82
Compare
|
@lla-dane |
760bf9b to
bb3e781
Compare
|
This PR is continued at #890 |
WIP: The libp2p-record module for py-libp2p in reference with the go-libp2p-record repo.
Reference: https://github.com/libp2p/go-libp2p-record