testing_api_cmd_block_common.h (6190B)
1 /* 2 This file is part of SYNC 3 Copyright (C) 2014-2026 Taler Systems SA 4 5 SYNC is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as 7 published by the Free Software Foundation; either version 3, or 8 (at your option) any later version. 9 10 SYNC is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public 16 License along with SYNC; see the file COPYING. If not, see 17 <http://www.gnu.org/licenses/> 18 */ 19 /** 20 * @file testing/testing_api_cmd_block_common.h 21 * @brief shared internal state for block upload commands 22 * @author Iván Ávalos 23 */ 24 #ifndef TESTING_API_CMD_BLOCK_COMMON_H 25 #define TESTING_API_CMD_BLOCK_COMMON_H 26 27 #include "platform.h" 28 #include "sync/sync_service.h" 29 #include "sync/sync_testing_lib.h" 30 #include <taler/taler_util.h> 31 #include <taler/taler_signatures.h> 32 #include <taler/taler_testing_lib.h> 33 #include <taler/merchant/common.h> 34 #include <gnunet/gnunet_curl_lib.h> 35 36 37 /** 38 * Maximum number of object references a block command can carry. 39 */ 40 #define MAX_BLOCK_OBJECT_REFS 32 41 42 43 /** 44 * State for a "block upload" CMD. 45 */ 46 struct BlockUploadState 47 { 48 49 /** 50 * Eddsa private key. 51 */ 52 struct SYNC_AccountPrivateKeyP sync_priv; 53 54 /** 55 * Eddsa public key. 56 */ 57 struct SYNC_AccountPublicKeyP sync_pub; 58 59 /** 60 * Nonce for the block. 61 */ 62 struct SYNC_BlockNonce nonce; 63 64 /** 65 * Nonce of the preceding block, all zeros for none. 66 */ 67 struct SYNC_BlockNonce prev_nonce; 68 69 /** 70 * Nonce of the succeeding block, all zeros for none. 71 */ 72 struct SYNC_BlockNonce next_nonce; 73 74 /** 75 * Hash of old data, all zeros for append. 76 */ 77 struct GNUNET_HashCode old_data_hash; 78 79 /** 80 * Hash of new block data (exposed as curr_hash trait). 81 */ 82 struct GNUNET_HashCode new_data_hash; 83 84 /** 85 * URL of the sync backend. 86 */ 87 const char *sync_url; 88 89 /** 90 * Reference to a command that can provide account keys, 91 * NULL to generate fresh keys. 92 */ 93 const char *upload_reference; 94 95 /** 96 * Function to process a reference command: inherit keys, 97 * nonce, old_data_hash, and/or set prev_nonce depending 98 * on the upload mode (retry, append-after, update, etc.). 99 * 100 * @param[in,out] bus state to populate 101 * @param ref reference command to inherit from 102 * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure 103 */ 104 enum GNUNET_GenericReturnValue 105 (*process_ref)( 106 struct BlockUploadState *bus, 107 const struct TALER_TESTING_Command *ref); 108 109 /** 110 * Function to start the upload operation. 111 */ 112 struct SYNC_BlockOperation * 113 (*start_upload)( 114 struct GNUNET_CURL_Context *ctx, 115 const char *sync_url, 116 const struct SYNC_AccountPrivateKeyP *sync_priv, 117 const struct SYNC_BlockNonce *nonce, 118 const struct SYNC_BlockNonce *prev_nonce, 119 const struct SYNC_BlockNonce *next_nonce, 120 const struct GNUNET_HashCode *old_data_hash, 121 size_t block_data_size, 122 const void *block_data, 123 size_t refs_len, 124 const struct SYNC_ObjectUID *object_uids, 125 const int16_t *object_incs, 126 const struct SYNC_BlockListEntry *prev_entry, 127 SYNC_BlockOperationCallback cb, 128 void *cb_cls); 129 130 /** 131 * Block data to upload. 132 */ 133 const void *block_data; 134 135 /** 136 * Number of bytes in @e block_data. 137 */ 138 size_t block_data_size; 139 140 /** 141 * Number of entries in @e object_uids and @e object_incs. 142 */ 143 unsigned int refs_len; 144 145 /** 146 * Array of object UIDs referenced by this block (array of 147 * @e refs_len, up to #MAX_BLOCK_OBJECT_REFS). 148 */ 149 struct SYNC_ObjectUID object_uids[MAX_BLOCK_OBJECT_REFS]; 150 151 /** 152 * Array of reference count adjustments (array of @e refs_len, 153 * up to #MAX_BLOCK_OBJECT_REFS). 154 */ 155 int16_t object_incs[MAX_BLOCK_OBJECT_REFS]; 156 157 /** 158 * Hash over the object references of this block. 159 */ 160 struct GNUNET_HashCode refs_hash; 161 162 /** 163 * Entry of the block at @e prev_nonce (the tail on an append), 164 * used to build its relink signature; NULL if there is no such 165 * block. 166 */ 167 struct SYNC_BlockListEntry prev_entry; 168 169 /** 170 * True if the relink target entry is available. 171 */ 172 bool have_relink_target; 173 174 /** 175 * Expected HTTP status code. 176 */ 177 unsigned int http_status; 178 179 /** 180 * The interpreter state. 181 */ 182 struct TALER_TESTING_Interpreter *is; 183 184 /** 185 * Payment order ID extracted from the 402 taler://pay URI. 186 */ 187 char *payment_order_id; 188 189 /** 190 * Claim token extracted from the 402 taler://pay URI. 191 */ 192 struct TALER_ClaimTokenP claim_token; 193 194 /** 195 * Handle for the library block upload operation. 196 */ 197 struct SYNC_BlockOperation *bop; 198 }; 199 200 201 /** 202 * Copy the account key pair offered by @a ref into @a bus. 203 * 204 * @param[in,out] bus state to populate 205 * @param ref reference command to inherit the keys from 206 * @return #GNUNET_OK on success, #GNUNET_SYSERR if @a ref 207 * does not offer the account key traits 208 */ 209 enum GNUNET_GenericReturnValue 210 SYNC_TESTING_inherit_account_keys_ ( 211 struct BlockUploadState *bus, 212 const struct TALER_TESTING_Command *ref); 213 214 215 /** 216 * Run a "block upload" CMD. 217 * 218 * @param cls closure. 219 * @param cmd command currently being run. 220 * @param is interpreter state. 221 */ 222 void 223 SYNC_TESTING_block_upload_run_ ( 224 void *cls, 225 const struct TALER_TESTING_Command *cmd, 226 struct TALER_TESTING_Interpreter *is); 227 228 229 /** 230 * Free the state of a "block upload" CMD, and possibly 231 * cancel it if it did not complete. 232 * 233 * @param cls closure. 234 * @param cmd command being freed. 235 */ 236 void 237 SYNC_TESTING_block_upload_cleanup_ ( 238 void *cls, 239 const struct TALER_TESTING_Command *cmd); 240 241 242 /** 243 * Offer the internal data of a "block upload" CMD to other commands. 244 * 245 * @param cls closure 246 * @param[out] ret result (could be anything) 247 * @param trait name of the trait 248 * @param index index number of the object to extract. 249 * @return #GNUNET_OK on success 250 */ 251 enum GNUNET_GenericReturnValue 252 SYNC_TESTING_block_upload_traits_ ( 253 void *cls, 254 const void **ret, 255 const char *trait, 256 unsigned int index); 257 258 259 #endif