Fix for object get when api not running
This commit is contained in:
parent
058a1d64ab
commit
81e103f1e0
7 changed files with 48 additions and 24 deletions
|
@ -31,18 +31,18 @@ int ipfs_exporter_get_node(struct IpfsNode* local_node, const unsigned char* has
|
|||
int retVal = 0;
|
||||
struct KademliaMessage* msg = NULL;
|
||||
|
||||
if (local_node->routing->GetValue(local_node->routing, hash, hash_size, (void**)&buffer, &buffer_size)) {
|
||||
libp2p_logger_debug("exporter", "get_node got a value. Converting it to a HashtableNode\n");
|
||||
// unprotobuf
|
||||
if (!ipfs_hashtable_node_protobuf_decode(buffer, buffer_size, result)) {
|
||||
libp2p_logger_debug("exporter", "Conversion to HashtableNode not successful\n");
|
||||
goto exit;
|
||||
}
|
||||
} else {
|
||||
if (!local_node->routing->GetValue(local_node->routing, hash, hash_size, (void**)&buffer, &buffer_size)) {
|
||||
libp2p_logger_debug("exporter", "get_node got no value. Returning false.\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
libp2p_logger_debug("exporter", "get_node got a value. Converting it to a HashtableNode\n");
|
||||
// unprotobuf
|
||||
if (!ipfs_hashtable_node_protobuf_decode(buffer, buffer_size, result)) {
|
||||
libp2p_logger_debug("exporter", "Conversion to HashtableNode not successful\n");
|
||||
goto exit;
|
||||
}
|
||||
|
||||
// copy in the hash
|
||||
(*result)->hash_size = hash_size;
|
||||
(*result)->hash = malloc(hash_size);
|
||||
|
|
|
@ -30,6 +30,7 @@ struct IpfsRouting {
|
|||
* @param 3 the size of the key
|
||||
* @param 4 a place to store the value
|
||||
* @param 5 the size of the value
|
||||
* @returns true(1) on success, false(0) otherwise
|
||||
*/
|
||||
int (*GetValue) (struct IpfsRouting*, const unsigned char*, size_t, void**, size_t*);
|
||||
/**
|
||||
|
|
23
main/main.c
23
main/main.c
|
@ -150,40 +150,40 @@ int parse_arguments(int argc, char** argv) {
|
|||
* The beginning
|
||||
*/
|
||||
int main(int argc, char** argv) {
|
||||
|
||||
int retVal = 0;
|
||||
strip_quotes(argc, argv);
|
||||
// CliArguments is the new way to do it. Eventually, all will use this structure
|
||||
struct CliArguments* args = cli_arguments_new(argc, argv);
|
||||
if (args != NULL) {
|
||||
// until then, use the old way
|
||||
int retVal = parse_arguments(argc, argv);
|
||||
switch (retVal) {
|
||||
int cmd = parse_arguments(argc, argv);
|
||||
switch (cmd) {
|
||||
case (INIT):
|
||||
return ipfs_repo_init(argc, argv);
|
||||
retVal = ipfs_repo_init(argc, argv);
|
||||
break;
|
||||
case (ADD):
|
||||
ipfs_import_files(args);
|
||||
retVal = ipfs_import_files(args);
|
||||
break;
|
||||
case (OBJECT_GET):
|
||||
ipfs_exporter_object_get(argc, argv);
|
||||
retVal = ipfs_exporter_object_get(argc, argv);
|
||||
break;
|
||||
case(GET):
|
||||
//ipfs_exporter_get(argc, argv);
|
||||
//break;
|
||||
case (CAT):
|
||||
ipfs_exporter_object_cat(args);
|
||||
retVal = ipfs_exporter_object_cat(args);
|
||||
break;
|
||||
case (DNS):
|
||||
ipfs_dns(argc, argv);
|
||||
retVal = ipfs_dns(argc, argv);
|
||||
break;
|
||||
case (DAEMON):
|
||||
ipfs_daemon(argc, argv);
|
||||
retVal = ipfs_daemon(argc, argv);
|
||||
break;
|
||||
case (PING):
|
||||
ipfs_ping(argc, argv);
|
||||
retVal = ipfs_ping(argc, argv);
|
||||
break;
|
||||
case (NAME):
|
||||
ipfs_name(args);
|
||||
retVal = ipfs_name(args);
|
||||
break;
|
||||
default:
|
||||
libp2p_logger_error("main", "Invalid command line arguments.\n");
|
||||
|
@ -192,4 +192,5 @@ int main(int argc, char** argv) {
|
|||
cli_arguments_free(args);
|
||||
}
|
||||
libp2p_logger_free();
|
||||
exit(retVal == 1 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
|
|
|
@ -38,11 +38,20 @@ int ipfs_routing_generic_put_value (ipfs_routing* offlineRouting, const unsigned
|
|||
return 0; // success.
|
||||
}
|
||||
|
||||
/***
|
||||
* Get a value from the merkledag
|
||||
* @param routing the context
|
||||
* @param key the key
|
||||
* @param key_size the size of the key
|
||||
* @param val where to put the results
|
||||
* @param vlen the size of the results
|
||||
* @returns true(1) on success, false(0) otherwise
|
||||
*/
|
||||
int ipfs_routing_generic_get_value (ipfs_routing* routing, const unsigned char *key, size_t key_size, void **val, size_t *vlen)
|
||||
{
|
||||
struct HashtableNode* node = NULL;
|
||||
*val = NULL;
|
||||
int retVal = -1;
|
||||
int retVal = 0;
|
||||
|
||||
if (!ipfs_merkledag_get(key, key_size, &node, routing->local_node->repo)) {
|
||||
goto exit;
|
||||
|
@ -53,14 +62,14 @@ int ipfs_routing_generic_get_value (ipfs_routing* routing, const unsigned char *
|
|||
*val = malloc(protobuf_size);
|
||||
|
||||
if (ipfs_hashtable_node_protobuf_encode(node, *val, protobuf_size, vlen) == 0) {
|
||||
goto exit;
|
||||
goto exit;
|
||||
}
|
||||
|
||||
retVal = 0;
|
||||
retVal = 1;
|
||||
exit:
|
||||
if (node != NULL)
|
||||
ipfs_hashtable_node_free(node);
|
||||
if (retVal != 0 && *val != NULL) {
|
||||
if (retVal != 1 && *val != NULL) {
|
||||
free(*val);
|
||||
*val = NULL;
|
||||
}
|
||||
|
|
|
@ -363,6 +363,7 @@ int ipfs_routing_online_get_peer_value(ipfs_routing* routing, const struct Libp2
|
|||
* @param key_size the size of the key
|
||||
* @param buffer where to put the results
|
||||
* @param buffer_size the length of the buffer
|
||||
* @returns true(1) on success, false(0) otherwise
|
||||
*/
|
||||
int ipfs_routing_online_get_value (ipfs_routing* routing, const unsigned char *key, size_t key_size, void **buffer, size_t *buffer_size)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#!/bin/bash
|
||||
|
||||
./run_test.sh test_1.sh
|
||||
./run_test.sh test_2.sh
|
||||
|
||||
|
|
|
@ -4,8 +4,19 @@ source ./test_helpers.sh
|
|||
|
||||
IPFS="../../main/ipfs --config /tmp/ipfs_1"
|
||||
|
||||
function check_failure() {
|
||||
FUNC=$1;
|
||||
RESULT=$2;
|
||||
if [ $RESULT -eq 0 ]; then
|
||||
echo "";
|
||||
else
|
||||
echo "Failure in $FUNC. The return value was $RESULT";
|
||||
fi
|
||||
}
|
||||
|
||||
function pre {
|
||||
eval "$IPFS" init;
|
||||
check_failure "pre" $?
|
||||
}
|
||||
|
||||
function post {
|
||||
|
@ -16,7 +27,7 @@ function post {
|
|||
function body {
|
||||
create_hello_world;
|
||||
eval "$IPFS" add hello.txt
|
||||
eval "$IPFS" object cat Qm123456
|
||||
eval "$IPFS" cat QmYAXgX8ARiriupMQsbGXtKdDyGzWry1YV3sycKw1qqmgH
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue