dht.proto 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. service DHT {
  6. // find out recipient's DHTID and possibly update its routing table
  7. rpc rpc_ping(PingRequest) returns (PingResponse);
  8. // request a node to store one or multiple data items (key - value - expiration)
  9. rpc rpc_store(StoreRequest) returns (StoreResponse);
  10. // for given keys, request values (if stored) or a list of peers that are likely to have them
  11. rpc rpc_find(FindRequest) returns (FindResponse);
  12. }
  13. message NodeInfo {
  14. // note: both node_id and port are optional: if specified, ask peer to add you to its routing table;
  15. // if either node_id or port is absent, simply request recipient info (for client-only mode)
  16. bytes node_id = 1; // sender's own node id serialized with DHTID.to_bytes()
  17. int32 rpc_port = 2; // port to which sender listens for DHT RPCs
  18. string endpoint = 3; // (optional) node's preferred return address
  19. }
  20. message PingRequest {
  21. RequestAuthInfo auth = 1;
  22. NodeInfo peer = 2; // (optional) sender's own node info, same behavior as in DHT.rpc_ping
  23. bool validate = 3; // set to True if sender wants to validate that he is accessible and synchronized
  24. }
  25. message PingResponse {
  26. ResponseAuthInfo auth = 1;
  27. NodeInfo peer = 2; // respondent's node id, for you to update routing table
  28. string sender_endpoint = 3; // echo sender's visible endpoint - used to infer his ip address
  29. double dht_time = 4; // recipient's local DHT time - used to soft-synchronize peers
  30. bool available = 5; // if validate = True, this flag asserts that the sender is available for ping
  31. }
  32. message StoreRequest {
  33. RequestAuthInfo auth = 1;
  34. // three lists of the same length representing dht keys, dht values and expiration
  35. repeated bytes keys = 2; // keys in the form of DHTID.generate(raw_key).to_bytes()
  36. repeated bytes subkeys = 3; // serialized subkeys for DictionaryDHTValue type. None means no subkey
  37. repeated bytes values = 4; // serialized value for i-th key
  38. repeated double expiration_time = 5; // expirations for i-th key (type = DHTExpiration)
  39. repeated bool in_cache = 6; // if in_cache[i], store i-th key in cache, else store normally
  40. NodeInfo peer = 7; // (optional) sender's own node info, same behavior as in DHT.rpc_ping
  41. }
  42. message StoreResponse {
  43. ResponseAuthInfo auth = 1;
  44. repeated bool store_ok = 2; // for every key, True means store accepted, False means store rejected/failed
  45. NodeInfo peer = 3; // respondent's node id, for you to update routing table
  46. }
  47. message FindRequest {
  48. RequestAuthInfo auth = 1;
  49. repeated bytes keys = 2; // a list of DHTID search keys encoded as bytes
  50. NodeInfo peer = 3; // optional, same behavior as in DHT.ping
  51. }
  52. enum ResultType {NOT_FOUND = 0; FOUND_REGULAR = 1; FOUND_DICTIONARY = 2;}
  53. message FindResult {
  54. ResultType type = 1; // NONE | REGULAR | DICTIONARY
  55. bytes value = 2; // n/a | serialized value | serialized DictionaryDHTValue with serialized fields
  56. double expiration_time = 3; // n/a | expiration time | DictionaryDHTValue.latest_expiration_time
  57. // two aligned arrays: DHTIDs and Endpoints for nearest peers (sorted by XOR distance)
  58. repeated bytes nearest_node_ids = 4; // DHTIDs serialized with node_id.to_bytes()
  59. repeated string nearest_endpoints = 5; // e.g. 123.123.123.123:1337 or [2a21:6с8:b192:2105]:8888
  60. }
  61. message FindResponse {
  62. ResponseAuthInfo auth = 1;
  63. repeated FindResult results = 2; // for each item, return value/expiration (if found) and nearest peers
  64. NodeInfo peer = 3; // respondent's node id, for you to update routing table
  65. }