sociomantic-tsunami / dhtproto

Distributed Hash Table protocol definition, client, fake node, and tests
Boost Software License 1.0
5 stars 22 forks source link

Add minimalist DHT API for scripting #165

Open gavin-norman-sociomantic opened 6 years ago

gavin-norman-sociomantic commented 6 years ago

Currently, initialising and using a DHT client involves a lot of boilerplate, making it unsuitable for use in quick D scripts.

The ideal would be for things like this to work:

void main ( )
{
  Dht.connect("dht.nodes");
  Dht.update!(S)(key,
    ( ref S deserialized_record )
    {
      // changes made to deserialized_record will be written back to the DHT
    }
  );
}
Geod24 commented 6 years ago

Wouldn't it be better to use dhtcli in D scripts ? That would also ensure it can be used in any script, not only D

gavin-norman-sociomantic commented 6 years ago

The basic problem is that we need an easy way to modify records in a DHT, for testing. (Read a record, deserialize the struct, change some fields, serialize, write back.) There's no easy way to do this with dhtcli. We did discuss using some kind of struct <-> json converter, say, but I think that'd be a lot more work to develop than the above suggestion would.

Geod24 commented 6 years ago

Read a record, deserialize the struct, change some fields, serialize, write back.

What I did back in the day for a very similar use case was:

That utility was less than 100 LoCs (but only handled deserialization). @christoph-wasicki-sociomantic might still have it hanging around.

gavin-norman-sociomantic commented 6 years ago

Right, the point is that it requires knowledge of the serialized struct, though, right? That alone locks us into the D domain.

Geod24 commented 6 years ago

Right, the point is that it requires knowledge of the serialized struct, though, right? Right, the point is that it requires knowledge of the serialized struct, though, right?

Sorry, I don't understand your point here. You have a similar use case in profileview, where one can give either the channel or the struct type as argument and have the other one being automatically deduced. The only difference is generating machine readable output as opposed to human readable one. And once it's in JSON, it's accessible to anyone, not just D.

gavin-norman-sociomantic commented 6 years ago

My point is that it always requires D code that knows the type of the struct to be deserialized, either to implement a DHT client API that automatically deserializes or a struct -> json deserializer. I guess you weren't suggesting otherwise, though.

It's really a question of what is simpler to implement and more convenient to use.

gavin-norman-sociomantic commented 6 years ago

I agree that a solution that works via json would be more generic, of course, but we have to think about what is more directly convenient to us right now. (We can also implement both solutions, down the line. There's no reason to have to choose one or the other.)