now puting result of get_value in the return buffer

This commit is contained in:
jmjatlanta 2017-09-28 08:24:57 -05:00
parent 3d425bb30f
commit 296d164e84
3 changed files with 17 additions and 3 deletions

View file

@ -63,6 +63,7 @@ struct HttpResponse* ipfs_core_http_response_new() {
if (response != NULL) { if (response != NULL) {
response->content_type = NULL; response->content_type = NULL;
response->bytes = NULL; response->bytes = NULL;
response->bytes_size = 0;
} }
return response; return response;
} }

View file

@ -72,9 +72,17 @@ int ipfs_routing_generic_get_value (ipfs_routing* routing, const unsigned char *
libp2p_logger_error("offline", "Unable to call API for dht get.\n"); libp2p_logger_error("offline", "Unable to call API for dht get.\n");
return 0; return 0;
} }
//TODO: put results in val *vlen = strlen(response);
fprintf(stdout, "%s", response); if (*vlen > 0) {
return 1; *val = malloc(*vlen + 1);
uint8_t* ptr = (uint8_t*)*val;
if (ptr == NULL) {
return 0;
}
memcpy(ptr, response, *vlen);
ptr[*vlen] = 0;
retVal = 1;
}
} else { } else {
struct HashtableNode* node = NULL; struct HashtableNode* node = NULL;
*val = NULL; *val = NULL;

View file

@ -373,6 +373,9 @@ int ipfs_routing_online_get_value (ipfs_routing* routing, const unsigned char *k
struct Libp2pVector *peers = NULL; struct Libp2pVector *peers = NULL;
int retVal = 0; int retVal = 0;
// just to be sure
*buffer_size = 0;
// find a provider // find a provider
routing->FindProviders(routing, key, key_size, &peers); routing->FindProviders(routing, key, key_size, &peers);
if (peers == NULL) { if (peers == NULL) {
@ -423,6 +426,8 @@ int ipfs_routing_online_get_value (ipfs_routing* routing, const unsigned char *k
} }
} }
} }
if (buffer_size == 0)
goto exit;
} }
retVal = 1; retVal = 1;