dht.proto 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. syntax = "proto3";
  2. import "auth.proto";
  3. // this protocol defines how Hivemind nodes form a distributed hash table.
  4. // For more info, see https://learning-at-home.readthedocs.io/en/latest/modules/dht.html or help(hivemind.dht.DHTNode)
  5. message NodeInfo {
  6. // note: both node_id and port are optional: if specified, ask peer to add you to its routing table;
  7. // if either node_id or port is absent, simply request recipient info (for client-only mode)
  8. bytes node_id = 1; // sender's own node id serialized with DHTID.to_bytes()
  9. }
  10. message PingRequest {
  11. RequestAuthInfo auth = 1;
  12. NodeInfo peer = 2; // (optional) sender's own node info, same behavior as in DHT.rpc_ping
  13. bool validate = 3; // set to True if sender wants to validate that he is accessible and synchronized
  14. }
  15. message PingResponse {
  16. ResponseAuthInfo auth = 1;
  17. NodeInfo peer = 2; // respondent's node id, for you to update routing table
  18. double dht_time = 4; // recipient's local DHT time - used to soft-synchronize peers
  19. bool available = 5; // if validate = True, this flag asserts that the sender is available for ping
  20. }
  21. message StoreRequest {
  22. RequestAuthInfo auth = 1;
  23. // three lists of the same length representing dht keys, dht values and expiration
  24. repeated bytes keys = 2; // keys in the form of DHTID.generate(raw_key).to_bytes()
  25. repeated bytes subkeys = 3; // serialized subkeys for DictionaryDHTValue type. None means no subkey
  26. repeated bytes values = 4; // serialized value for i-th key
  27. repeated double expiration_time = 5; // expirations for i-th key (type = DHTExpiration)
  28. repeated bool in_cache = 6; // if in_cache[i], store i-th key in cache, else store normally
  29. NodeInfo peer = 7; // (optional) sender's own node info, same behavior as in DHT.rpc_ping
  30. }
  31. message StoreResponse {
  32. ResponseAuthInfo auth = 1;
  33. repeated bool store_ok = 2; // for every key, True means store accepted, False means store rejected/failed
  34. NodeInfo peer = 3; // respondent's node id, for you to update routing table
  35. }
  36. message FindRequest {
  37. RequestAuthInfo auth = 1;
  38. repeated bytes keys = 2; // a list of DHTID search keys encoded as bytes
  39. NodeInfo peer = 3; // optional, same behavior as in DHT.ping
  40. }
  41. enum ResultType {NOT_FOUND = 0; FOUND_REGULAR = 1; FOUND_DICTIONARY = 2;}
  42. message FindResult {
  43. ResultType type = 1; // NONE | REGULAR | DICTIONARY
  44. bytes value = 2; // n/a | serialized value | serialized DictionaryDHTValue with serialized fields
  45. double expiration_time = 3; // n/a | expiration time | DictionaryDHTValue.latest_expiration_time
  46. // two aligned arrays: DHTIDs and PeerIDs for nearest peers (sorted by XOR distance)
  47. repeated bytes nearest_node_ids = 4; // DHTIDs of the nearest peers serialized with node_id.to_bytes()
  48. repeated bytes nearest_peer_ids = 5; // libp2p PeerIDs of the nearest peers
  49. }
  50. message FindResponse {
  51. ResponseAuthInfo auth = 1;
  52. repeated FindResult results = 2; // for each item, return value/expiration (if found) and nearest peers
  53. NodeInfo peer = 3; // respondent's node id, for you to update routing table
  54. }