| 858 | } |
| 859 | |
| 860 | static struct command_result *handle_your_peer_storage(struct command *cmd, |
| 861 | const char *buf, |
| 862 | const jsmntok_t *params) |
| 863 | { |
| 864 | struct node_id node_id; |
| 865 | u8 *payload, *payload_deserialise; |
| 866 | const char *err; |
| 867 | struct chanbackup *cb = chanbackup(cmd->plugin); |
| 868 | |
| 869 | err = json_scan(cmd, buf, params, |
| 870 | "{payload:%,peer_id:%}", |
| 871 | JSON_SCAN_TAL(cmd, json_tok_bin_from_hex, &payload), |
| 872 | JSON_SCAN(json_to_node_id, &node_id)); |
| 873 | if (err) { |
| 874 | plugin_err(cmd->plugin, |
| 875 | "`your_peer_storage` response did not scan %s: %.*s", |
| 876 | err, json_tok_full_len(params), |
| 877 | json_tok_full(buf, params)); |
| 878 | } |
| 879 | |
| 880 | if (fromwire_peer_storage(cmd, payload, &payload_deserialise)) { |
| 881 | struct peer_backup *pb; |
| 882 | |
| 883 | if (!cb->handle_their_peer_backup) |
| 884 | return command_hook_success(cmd); |
| 885 | |
| 886 | /* BOLT #1: |
| 887 | * The receiver of `peer_storage`: |
| 888 | * - If it offered `option_provide_storage`: |
| 889 | * - if it has an open channel with the sender: |
| 890 | * - MUST store the message. |
| 891 | * - MAY store the message anyway. |
| 892 | */ |
| 893 | /* We store if we have a datastore slot for it |
| 894 | * (otherwise, this fails). We create those once it |
| 895 | * has a channel, though the user could also create an |
| 896 | * empty one if they wanted to */ |
| 897 | |
| 898 | /* BOLT #1: |
| 899 | * - If it does store the message: |
| 900 | * - MAY delay storage to ratelimit peer to no more than one |
| 901 | * update per minute. |
| 902 | * - MUST replace the old `blob` with the latest received. |
| 903 | */ |
| 904 | pb = backup_map_get(cb->backups, &node_id); |
| 905 | if (!pb) |
| 906 | return command_hook_success(cmd); |
| 907 | |
| 908 | tal_free(pb->data); |
| 909 | pb->data = tal_steal(pb, payload_deserialise); |
| 910 | return commit_peer_backup(cmd, pb); |
| 911 | } else if (fromwire_peer_storage_retrieval(cmd, payload, &payload_deserialise)) { |
| 912 | crypto_secretstream_xchacha20poly1305_state crypto_state; |
| 913 | |
| 914 | plugin_log(cmd->plugin, LOG_DBG, |
| 915 | "Received peer_storage from peer."); |
| 916 | |
| 917 | if (!cb->send_our_peer_backup) |
nothing calls this directly
no test coverage detected