static void test_content_dedup(gconstpointer test_data) { guint num_duplicates = *(guint*)test_data; void change_chunk_hash(GSList *beans, guint start) { guint8 counter = start; for (GSList *cursor = beans; cursor; cursor = cursor->next) { if (DESCR(cursor->data) == &descr_struct_CHUNKS) { GByteArray *hash = CHUNKS_get_hash(cursor->data); hash->data[0] = counter; CHUNKS_set_hash(cursor->data, hash); // no-op because same pointer counter++; } else if (DESCR(cursor->data) == &descr_struct_CONTENTS_HEADERS) { GByteArray *hash = g_byte_array_sized_new(16); GRID_INFO("---- forging content hash ----"); for (guint8 i = 0; i < 16; i++) { hash->data[i] = i + 1; } CONTENTS_HEADERS_set_hash(cursor->data, hash); } } }
GError* m2v2_json_load_single_chunk (struct json_object *j, gpointer *pbean) { GError *err = NULL; GByteArray *hid = NULL, *hash = NULL; struct bean_CHUNKS_s *chunk = NULL; struct json_object *jid, *jcontent, *jhash, *jsize, *jctime, *jpos; struct oio_ext_json_mapping_s mapping[] = { {"id", &jid, json_type_string, 1}, {"hash", &jhash, json_type_string, 1}, {"size", &jsize, json_type_int, 1}, {"ctime", &jctime, json_type_int, 0}, {"content", &jcontent, json_type_string, 1}, {"pos", &jpos, json_type_string, 1}, {NULL, NULL, 0, 0} }; *pbean = NULL; if (NULL != (err = oio_ext_extract_json (j, mapping))) return err; hid = metautils_gba_from_hexstring(json_object_get_string(jid)); if (!hid) { err = NEWERROR(CODE_BAD_REQUEST, "Invalid header, not hexa id"); goto exit; } hash = metautils_gba_from_hexstring(json_object_get_string(jhash)); if (!hash) { err = NEWERROR(CODE_BAD_REQUEST, "Invalid chunk, not hexa header id"); goto exit; } chunk = _bean_create (&descr_struct_CHUNKS); CHUNKS_set2_id (chunk, json_object_get_string(jid)); CHUNKS_set_hash (chunk, hash); CHUNKS_set_size (chunk, json_object_get_int64(jsize)); CHUNKS_set_ctime (chunk, !jctime ? g_get_real_time() / G_TIME_SPAN_SECOND : json_object_get_int64(jctime)); CHUNKS_set_content (chunk, hid); CHUNKS_set2_position (chunk, json_object_get_string (jpos)); *pbean = chunk; chunk = NULL; exit: metautils_gba_unref (hid); metautils_gba_unref (hash); _bean_clean (chunk); return err; }