From 9402f3184142c27be5171e505fd35658d3248daa Mon Sep 17 00:00:00 2001 From: jmjatlanta Date: Mon, 25 Sep 2017 06:57:17 -0500 Subject: [PATCH] Modified ipfs_core_http_request_free --- core/api.c | 4 +- core/http_request.c | 7 ++-- test/config.test1 | 2 +- test/config.test1.wo_journal | 77 ++++++++++++++++++++++++++++++++++++ test/config.test2 | 2 +- test/config.test2.wo_journal | 77 ++++++++++++++++++++++++++++++++++++ test/core/test_api.h | 22 +++++------ test/journal/test_journal.h | 4 +- test/routing/test_routing.h | 2 +- test/testit.c | 2 + 10 files changed, 178 insertions(+), 21 deletions(-) create mode 100644 test/config.test1.wo_journal create mode 100644 test/config.test2.wo_journal diff --git a/core/api.c b/core/api.c index 5ba8c4f..2372ca6 100644 --- a/core/api.c +++ b/core/api.c @@ -480,7 +480,7 @@ void *api_connection_thread (void *ptr) // once we leave the building of the req struct, do we need to do more? This flag will tell us. int further_processing_necessary = 0; - if (strcmp(buf + req.method, "GET")==0) { + if (strncmp(buf + req.method, "GET", 3)==0) { if (strcmp (req.buf + req.path, "/")==0 || strcmp (req.buf + req.path, "/webui")==0 || strcmp (req.buf + req.path, "/webui/")==0) { @@ -504,7 +504,7 @@ void *api_connection_thread (void *ptr) // move out of the if to do further processing } // end of GET - } else if (strcmp(buf + req.method, "POST")==0) { + } else if (strncmp(buf + req.method, "POST", 4)==0) { // TODO: Handle gzip/json POST requests. p = header_value_cmp(&req, "Content-Type:", "multipart/form-data;"); diff --git a/core/http_request.c b/core/http_request.c index 7413cf8..808560d 100644 --- a/core/http_request.c +++ b/core/http_request.c @@ -44,9 +44,10 @@ void ipfs_core_http_request_free(struct HttpRequest* request) { libp2p_utils_vector_free(request->params); } if (request->arguments != NULL) { - for(int i = 0; i < request->arguments->total; i++) { - free((char*)libp2p_utils_vector_get(request->arguments, i)); - } + // arguments should not be dynamically allocated + //for(int i = 0; i < request->arguments->total; i++) { + // free((char*)libp2p_utils_vector_get(request->arguments, i)); + //} libp2p_utils_vector_free(request->arguments); } free(request); diff --git a/test/config.test1 b/test/config.test1 index b9bf874..f0296b8 100644 --- a/test/config.test1 +++ b/test/config.test1 @@ -5,7 +5,7 @@ }, "Datastore": { "Type": "lmdb", - "Path": "/tmp/ipfs_1/.ipfs/datastore", + "Path": "/tmp/ipfs_1/datastore", "StorageMax": "10GB", "StorageGCWatermark": 90, "GCPeriod": "1h", diff --git a/test/config.test1.wo_journal b/test/config.test1.wo_journal new file mode 100644 index 0000000..b0ed4b6 --- /dev/null +++ b/test/config.test1.wo_journal @@ -0,0 +1,77 @@ +{ + "Identity": { + "PeerID": "QmZVoAZGFfinB7MQQiDzB84kWaDPQ95GLuXdemJFM2r9b4", + "PrivKey": "CAASpgkwggSiAgEAAoIBAQCApYAN/RWPZqfuLp96dB7wyR11r58Yy2v7l0ebAW/Sq5zBtg6Jrvmg5Nwx9lLUWa75VmwC6B+70cbdE7g+668VknjkyDxODYimGMsMeAcr0IKRludPjSYThbP3UOmeQdu+5ifSBcJ9Atsr/b1kNSntEyixm33boUIv+m2VI5rU9I81bzbPsnBEx4I4BDduJB/tJ0SSCQs3SQJdFtj+XoypZeShtPW/L2p8K9q/GI6dLNxHIKqJwaED6gBhmlRHAA9hqV3RJZ1Hh9ztYa9IM1k13A7SjvedDIdqrAIlAAUW2uKO1HiAEyLCykPqZsm/y8f4tfsHjnSk3RpDhaNlRGX5AgMBAAECggEAKWcaQ2ZEXhaHzVwr71kX7B6N4KZY6b3uTtZtMTHRL1gT5zQUkbNCm8mMJHhGSBlk+tIZiQXz0Jq/Cb+i+H0ZqDOvvNHEtsocRHiOQMEQbcV5gCm04CFpM7dAKEReK5S+iD3CaxF3eoxExW+wWGPTznzwB9knNFw91Psf8XO4DPkBAZfe3prmiKBDg74Cy1hAzBHGp15/4oU9gyaZop0Oe1UA+NEeGCTZgDcIOLYbPjH6tRF0xw2Usuh2IiwkUqrdRWwO0ZlaBD9jSCxQ4evbgIAOtni0+qbbeIlXQGPn3XFSZjwsdS7b/CPe8Gbtoy+akuoHOV9Rje/0ZAJTN4KjQQKBgQDgH76D7yr57Tcga18EoWJcGJvvvt/m0NfjtSoz901uK60qf5MnNbUXYKF33j5XW9V9+WRde0IqxZkwDIAuk6Bx/oYqI/DgvQ/Me/8np4R7K6Tjb3PNtHCGNtuGU2qJthCcCZ629lej3y5bwLtwfhjUwHSRzwQXlnJnHa49KZ1AvQKBgQCS8XY9aA6cBaCk8WDoTxMVSrr5P0QMKWbgHqylsUvZsTCj07+Ob87gnZjyGgPfIn9pF9gMeuExyHj/+c1P54Z0dPBeL4KQx1UpvgyJTLuFe1csR2Q8qAp6GOiEojXJ0Tc4yUsVwSKmCCsW9f2EiXCP24TqwedllfKoazvbaJZD7QKBgCjugzvTNTUZ1qSMF3lgA/ev4uLBKGEeKR+EGaYN9000mtaVIAncLCuN0U9z/ky0D+SG5IaSGT54ggadcdePzJClHFmb4MUaokUFLE9Qr8hS6zVCSJL77kUExcjdeSqXXqcwtpTRnqXl/7BwHYto7B4G3AM5HJU2O8SLTiQLcpW9AoGASXYl4rUu+Jlnoo56ICnIJJDjwM/8OQhJwioTrhJhFUgcRQsLbS5AgtLHL+IJpXgdsnCVNkgIZVcQBwjft97LvVTpBm1CHRdKYD//DHUsGqN7BUv7tMdd1YS2WfiuY2MQ9HbN7uZLaC4VPLlmMOh1ObZJUQP3pzW7xq81kY9L8FECgYA92LvEamYLzbisdb6XvA6d5+jUXtt3v8/2e1tNKSUuvBCLxWy5IqObgHTCaCHJH8E/bAEmOVaxXdzpS484Q8Hbai+NBVjnPB/yINCN4WgScBRFr3691HeQ1ejeEKSzELg1QDau7jo7CSZFO1ZHCR01T7HZCrcuLaG7DxAx/Y+i8A==" + }, + "Datastore": { + "Type": "lmdb", + "Path": "/tmp/ipfs_1/datastore", + "StorageMax": "10GB", + "StorageGCWatermark": 90, + "GCPeriod": "1h", + "Params": null, + "NoSync": false, + "HashOnRead": false, + "BloomFilterSize": 0 + }, + "Addresses": { + "Swarm": [ + "/ip4/0.0.0.0/tcp/4001", + "/ip6/::/tcp/4001" + ], + "API": "/ip4/127.0.0.1/tcp/5002", + "Gateway": "(null)" + }, + "Mounts": { + "IPFS": "/ipfs", + "IPNS": "/ipns", + "FuseAllowOther": false + }, + "Discovery": { + "MDNS": { + "Enabled": true, + "Interval": 10 + } + }, + "Ipns": { + "RepublishedPeriod": "", + "RecordLifetime": "", + "ResolveCacheSize": 128 + }, + "Bootstrap": [ + "/ip4/127.0.0.1/tcp/4002/ipfs/QmcDW1t4QQBGAs2HSig8xkUhPxFZzmewAeFdsmp6q6nyY5" + ], + "Tour": { + "Last": "" + }, + "Gateway": { + "HTTPHeaders": { + "Access-Control-Allow-Origin": [ + "*" + ], + "Access-Control-Allow-Methods": [ + "GET" + ], + "Access-Control-Allow-Headers": [ + "X-Requested-With" + ] + }, + "RootRedirect": "" + "Writable": false + "PathPrefixes": [] + }, + "SupernodeRouting": { + "Servers": null + }, "API": { + "HTTPHeaders": null + }, + "Swarm": { + "AddrFilters": null + }, + "Replication": { + "Announce": 1, + "AnnounceMinutes": 60, + "Peers": [ + ] + } +} \ No newline at end of file diff --git a/test/config.test2 b/test/config.test2 index 898f372..87e9467 100644 --- a/test/config.test2 +++ b/test/config.test2 @@ -5,7 +5,7 @@ }, "Datastore": { "Type": "lmdb", - "Path": "/tmp/ipfs_2/.ipfs/datastore", + "Path": "/tmp/ipfs_2/datastore", "StorageMax": "10GB", "StorageGCWatermark": 90, "GCPeriod": "1h", diff --git a/test/config.test2.wo_journal b/test/config.test2.wo_journal new file mode 100644 index 0000000..d21ed94 --- /dev/null +++ b/test/config.test2.wo_journal @@ -0,0 +1,77 @@ +{ + "Identity": { + "PeerID": "QmcDW1t4QQBGAs2HSig8xkUhPxFZzmewAeFdsmp6q6nyY5", + "PrivKey": "CAASqQkwggSlAgEAAoIBAQDqghv+79zy4dcP+8GCSa9kfoD9zF1gpOO/gnfjLUd9BTzY1MXX7pzGsztRnLOFtuSAqZmg9iEgnrNbLpGqYdHxSRU7taH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IUwW14H7upADOI6uaUUjztRUKmo8/D5tGb1IpPCY1RLPEgbYsrpxSjiRAwKBgQDpcSY7cIJ4PW/qd6ZfpZSi3JN6pbBPMnwowFSS0dlX0IBNjStIGgrWbX/xBnvOy75ALkaonyPmuH2WLbn+ArZhTS8lBTe52TvMq3W+4r3YIxNdO97DUGf7vm5qtG6YrzRl3ZE1WGgmsAm2o+13B39UYQSbvnZykHCKpJokgO24NQKBgQDbb3U0Xy5gceTR5XbYUkdkPj0kxEMtYzTXh30dztTld2dKDIbAtVe8t2zinNuLUCqpu5+lCCN3qiYCNWEB5NZp6jAra6wzz483clw30sMYdtwh1NnTqP+i6WbxXagSamwp2555Xc7n3BpnX68BpoTi2cmPjWHhBGFjoOTLxI4ZQQ==" + }, + "Datastore": { + "Type": "lmdb", + "Path": "/tmp/ipfs_2/datastore", + "StorageMax": "10GB", + "StorageGCWatermark": 90, + "GCPeriod": "1h", + "Params": null, + "NoSync": false, + "HashOnRead": false, + "BloomFilterSize": 0 + }, + "Addresses": { + "Swarm": [ + "/ip4/0.0.0.0/tcp/4002", + "/ip6/::/tcp/4002" + ], + "API": "/ip4/127.0.0.1/tcp/5002", + "Gateway": "(null)" + }, + "Mounts": { + "IPFS": "/ipfs", + "IPNS": "/ipns", + "FuseAllowOther": false + }, + "Discovery": { + "MDNS": { + "Enabled": true, + "Interval": 10 + } + }, + "Ipns": { + "RepublishedPeriod": "", + "RecordLifetime": "", + "ResolveCacheSize": 128 + }, + "Bootstrap": [ + "/ip4/127.0.0.1/tcp/4001/ipfs/QmZVoAZGFfinB7MQQiDzB84kWaDPQ95GLuXdemJFM2r9b4" + ], + "Tour": { + "Last": "" + }, + "Gateway": { + "HTTPHeaders": { + "Access-Control-Allow-Origin": [ + "*" + ], + "Access-Control-Allow-Methods": [ + "GET" + ], + "Access-Control-Allow-Headers": [ + "X-Requested-With" + ] + }, + "RootRedirect": "" + "Writable": false + "PathPrefixes": [] + }, + "SupernodeRouting": { + "Servers": null + }, "API": { + "HTTPHeaders": null + }, + "Swarm": { + "AddrFilters": null + }, + "Replication": { + "Announce": 1, + "AnnounceMinutes": 60, + "Peers": [ + ] + } +} \ No newline at end of file diff --git a/test/core/test_api.h b/test/core/test_api.h index 9e3decc..638ca94 100644 --- a/test/core/test_api.h +++ b/test/core/test_api.h @@ -9,7 +9,7 @@ #include "ipfs/namesys/name.h" int test_core_api_startup_shutdown() { - char* repo_path = "/tmp/ipfs_1/.ipfs"; + char* repo_path = "/tmp/ipfs_1"; char* peer_id = NULL; int retVal = 0; @@ -47,9 +47,9 @@ int test_core_api_object_cat() { pthread_t daemon_thread2; int thread_started1 = 0; int thread_started2 = 0; - char* ipfs_path1 = "/tmp/ipfs_1/.ipfs"; + char* ipfs_path1 = "/tmp/ipfs_1"; char* config_file1 = "config.test1"; - char* ipfs_path2 = "/tmp/ipfs_2/.ipfs"; + char* ipfs_path2 = "/tmp/ipfs_2"; char* config_file2 = "config.test2"; struct FSRepo* fs_repo = NULL; char hash[256] = ""; @@ -136,9 +136,9 @@ int test_core_api_name_resolve() { int thread_started1 = 0; int thread_started2 = 0; char* ipfs_path1 = "/tmp/ipfs_1"; - char* config_file1 = "config.test1"; + char* config_file1 = "config.test1.wo_journal"; char* ipfs_path2 = "/tmp/ipfs_2"; - char* config_file2 = "config.test2"; + char* config_file2 = "config.test2.wo_journal"; struct FSRepo* fs_repo = NULL; char hash[256] = ""; char peer_id1[256] = ""; @@ -178,12 +178,6 @@ int test_core_api_name_resolve() { ipfs_node_free(&api_pth, local_node); ipfs_hashtable_node_free(node); - // publish name on server 1 - args = cli_arguments_new(6, publish_args); - ipfs_name(args); - cli_arguments_free(args); - args = NULL; - libp2p_logger_debug("test_api", "*** Firing up daemons ***\n"); pthread_create(&daemon_thread1, NULL, test_daemon_start, (void*)ipfs_path1); thread_started1 = 1; @@ -192,6 +186,12 @@ int test_core_api_name_resolve() { sleep(3); + // publish name on server 1 + args = cli_arguments_new(6, publish_args); + ipfs_name(args); + cli_arguments_free(args); + args = NULL; + // use a client of server2 to to ask for the "name resolve" on server 1 args = cli_arguments_new(6, resolve_args); if (ipfs_name(args) == 0) { diff --git a/test/journal/test_journal.h b/test/journal/test_journal.h index 6923e2e..a6a00b8 100644 --- a/test/journal/test_journal.h +++ b/test/journal/test_journal.h @@ -79,7 +79,7 @@ int test_journal_server_1() { int retVal = 0; pthread_t daemon_thread; int thread_started = 0; - char* ipfs_path = "/tmp/ipfs_1/.ipfs"; + char* ipfs_path = "/tmp/ipfs_1"; char* config_file = "config.test1"; struct FSRepo* fs_repo = NULL; @@ -191,7 +191,7 @@ int test_journal_server_2() { sleep(45); // see if we have the file that we should have... - if (!have_file_in_blockstore("/tmp/ipfs_2/.ipfs/blockstore", "2PD7A7OALR6OCEDZNKYAX363LMX3SBXZQPD3IAVTT")) { + if (!have_file_in_blockstore("/tmp/ipfs_2/blockstore", "2PD7A7OALR6OCEDZNKYAX363LMX3SBXZQPD3IAVTT")) { libp2p_logger_error("test_journal", "We don't have the file that we think we should.\n"); goto exit; } else { diff --git a/test/routing/test_routing.h b/test/routing/test_routing.h index e992ca7..277a28b 100644 --- a/test/routing/test_routing.h +++ b/test/routing/test_routing.h @@ -22,7 +22,7 @@ */ int test_routing_put_value() { int retVal = 0; - char* ipfs_path_publisher = "/tmp/ipfs_1/.ipfs"; + char* ipfs_path_publisher = "/tmp/ipfs_1"; char* peer_id_publisher = NULL; struct MultiAddress* ma_publisher = NULL; pthread_t thread_publisher; diff --git a/test/testit.c b/test/testit.c index 369140b..aad602c 100644 --- a/test/testit.c +++ b/test/testit.c @@ -51,6 +51,7 @@ const char* names[] = { "test_cid_protobuf_encode_decode", "test_core_api_startup_shutdown", "test_core_api_object_cat", + "test_core_api_name_resolve", "test_daemon_startup_shutdown", "test_datastore_list_journal", "test_journal_db", @@ -116,6 +117,7 @@ int (*funcs[])(void) = { test_cid_protobuf_encode_decode, test_core_api_startup_shutdown, test_core_api_object_cat, + test_core_api_name_resolve, test_daemon_startup_shutdown, test_datastore_list_journal, test_journal_db,