Adding providers to providerstore on kademlia call
This commit is contained in:
parent
053d33cec3
commit
0a6b4b621c
3 changed files with 20 additions and 15 deletions
|
@ -32,6 +32,6 @@ struct ProviderStore* libp2p_providerstore_new();
|
||||||
*/
|
*/
|
||||||
void libp2p_providerstore_free(struct ProviderStore* in);
|
void libp2p_providerstore_free(struct ProviderStore* in);
|
||||||
|
|
||||||
void libp2p_providerstore_add(struct ProviderStore* store, unsigned char* hash, int hash_size, unsigned char* peer_id, int peer_id_size);
|
int libp2p_providerstore_add(struct ProviderStore* store, unsigned char* hash, int hash_size, unsigned char* peer_id, int peer_id_size);
|
||||||
|
|
||||||
int libp2p_providerstore_get(struct ProviderStore* store, unsigned char* hash, int hash_size, unsigned char** peer_id, int *peer_id_size);
|
int libp2p_providerstore_get(struct ProviderStore* store, unsigned char* hash, int hash_size, unsigned char** peer_id, int *peer_id_size);
|
||||||
|
|
|
@ -42,7 +42,7 @@ void libp2p_providerstore_free(struct ProviderStore* in) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void libp2p_providerstore_add(struct ProviderStore* store, unsigned char* hash, int hash_size, unsigned char* peer_id, int peer_id_size) {
|
int libp2p_providerstore_add(struct ProviderStore* store, unsigned char* hash, int hash_size, unsigned char* peer_id, int peer_id_size) {
|
||||||
struct ProviderEntry* entry = (struct ProviderEntry*)malloc(sizeof(struct ProviderEntry));
|
struct ProviderEntry* entry = (struct ProviderEntry*)malloc(sizeof(struct ProviderEntry));
|
||||||
entry->hash = malloc(hash_size);
|
entry->hash = malloc(hash_size);
|
||||||
memcpy(entry->hash, hash, hash_size);
|
memcpy(entry->hash, hash, hash_size);
|
||||||
|
@ -51,6 +51,7 @@ void libp2p_providerstore_add(struct ProviderStore* store, unsigned char* hash,
|
||||||
memcpy(entry->peer_id, peer_id, peer_id_size);
|
memcpy(entry->peer_id, peer_id, peer_id_size);
|
||||||
entry->peer_id_size = peer_id_size;
|
entry->peer_id_size = peer_id_size;
|
||||||
libp2p_utils_vector_add(store->provider_entries, entry);
|
libp2p_utils_vector_add(store->provider_entries, entry);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int libp2p_providerstore_get(struct ProviderStore* store, unsigned char* hash, int hash_size, unsigned char** peer_id, int *peer_id_size) {
|
int libp2p_providerstore_get(struct ProviderStore* store, unsigned char* hash, int hash_size, unsigned char** peer_id, int *peer_id_size) {
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "libp2p/net/stream.h"
|
#include "libp2p/net/stream.h"
|
||||||
#include "libp2p/routing/dht_protocol.h"
|
#include "libp2p/routing/dht_protocol.h"
|
||||||
#include "libp2p/record/message.h"
|
#include "libp2p/record/message.h"
|
||||||
|
#include "libp2p/utils/logger.h"
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
|
@ -124,24 +125,27 @@ int libp2p_routing_dht_handle_add_provider(struct SessionContext* session, struc
|
||||||
libp2p_logger_debug("dht_protocol", "In add_provider\n");
|
libp2p_logger_debug("dht_protocol", "In add_provider\n");
|
||||||
|
|
||||||
//TODO: verify peer signature
|
//TODO: verify peer signature
|
||||||
|
/*
|
||||||
if (message->record != NULL && message->record->author != NULL && message->record->author_size > 0
|
if (message->record != NULL && message->record->author != NULL && message->record->author_size > 0
|
||||||
&& message->key != NULL && message->key_size > 0) {
|
&& message->key != NULL && message->key_size > 0)
|
||||||
peer = libp2p_peer_new();
|
*/
|
||||||
peer->id_size = message->record->author_size;
|
struct Libp2pLinkedList* current = message->provider_peer_head;
|
||||||
peer->id = malloc(peer->id_size);
|
while(current != NULL) {
|
||||||
//TODO: Add addresses
|
struct Libp2pPeer* peer = (struct Libp2pPeer*)current->item;
|
||||||
memcpy(peer->id, message->record->author, message->record->author_size);
|
|
||||||
if (!libp2p_peerstore_add_peer(peerstore, peer))
|
if (!libp2p_peerstore_add_peer(peerstore, peer))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
if (!libp2p_providerstore_add(providerstore, message->key, message->key_size, peer->id, peer->id_size))
|
||||||
*result_buffer_size = libp2p_message_protobuf_encode_size(message);
|
|
||||||
*result_buffer = (unsigned char*)malloc(*result_buffer_size);
|
|
||||||
if (*result_buffer == NULL)
|
|
||||||
goto exit;
|
goto exit;
|
||||||
if (!libp2p_message_protobuf_encode(message, *result_buffer, *result_buffer_size, result_buffer_size))
|
|
||||||
goto exit;
|
|
||||||
libp2p_logger_debug("dht_protocol", "add_provider protobuf'd the message. Returning results.\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*result_buffer_size = libp2p_message_protobuf_encode_size(message);
|
||||||
|
*result_buffer = (unsigned char*)malloc(*result_buffer_size);
|
||||||
|
if (*result_buffer == NULL)
|
||||||
|
goto exit;
|
||||||
|
if (!libp2p_message_protobuf_encode(message, *result_buffer, *result_buffer_size, result_buffer_size))
|
||||||
|
goto exit;
|
||||||
|
libp2p_logger_debug("dht_protocol", "add_provider protobuf'd the message. Returning results.\n");
|
||||||
|
|
||||||
retVal = 1;
|
retVal = 1;
|
||||||
exit:
|
exit:
|
||||||
if (retVal != 1) {
|
if (retVal != 1) {
|
||||||
|
|
Loading…
Reference in a new issue