Passing SessionContext instead of Stream
This commit is contained in:
parent
3a68619016
commit
ac5a622400
6 changed files with 9 additions and 5 deletions
|
@ -16,7 +16,7 @@
|
||||||
enum WireType ipfs_cid_message_fields[] = { WIRETYPE_VARINT, WIRETYPE_VARINT, WIRETYPE_LENGTH_DELIMITED };
|
enum WireType ipfs_cid_message_fields[] = { WIRETYPE_VARINT, WIRETYPE_VARINT, WIRETYPE_LENGTH_DELIMITED };
|
||||||
|
|
||||||
|
|
||||||
size_t ipfs_cid_protobuf_encode_size(struct Cid* cid) {
|
size_t ipfs_cid_protobuf_encode_size(const struct Cid* cid) {
|
||||||
if (cid != NULL)
|
if (cid != NULL)
|
||||||
return 11+12+cid->hash_length+11;
|
return 11+12+cid->hash_length+11;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -658,6 +658,8 @@ int ipfs_bitswap_message_add_wantlist_items(struct BitswapMessage* message, stru
|
||||||
for(int i = 0; i < cids->total; i++) {
|
for(int i = 0; i < cids->total; i++) {
|
||||||
const struct Cid* cid = (const struct Cid*)libp2p_utils_vector_get(cids, i);
|
const struct Cid* cid = (const struct Cid*)libp2p_utils_vector_get(cids, i);
|
||||||
struct WantlistEntry* entry = ipfs_bitswap_wantlist_entry_new();
|
struct WantlistEntry* entry = ipfs_bitswap_wantlist_entry_new();
|
||||||
|
entry->block_size = ipfs_cid_protobuf_encode_size(cid);
|
||||||
|
entry->block = (unsigned char*) malloc(entry->block_size);
|
||||||
if (!ipfs_cid_protobuf_encode(cid, entry->block, entry->block_size, &entry->block_size)) {
|
if (!ipfs_cid_protobuf_encode(cid, entry->block, entry->block_size, &entry->block_size)) {
|
||||||
// TODO: we should do more than return a half-baked list
|
// TODO: we should do more than return a half-baked list
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -34,7 +34,7 @@ int ipfs_bitswap_network_send_message(const struct BitswapContext* context, stru
|
||||||
memcpy(buf, "/ipfs/bitswap/1.1.0\n", 20);
|
memcpy(buf, "/ipfs/bitswap/1.1.0\n", 20);
|
||||||
buf_size += 20;
|
buf_size += 20;
|
||||||
// send it
|
// send it
|
||||||
int bytes_written = peer->sessionContext->default_stream->write(peer->sessionContext->default_stream, buf, buf_size);
|
int bytes_written = peer->sessionContext->default_stream->write(peer->sessionContext, buf, buf_size);
|
||||||
if (bytes_written <= 0) {
|
if (bytes_written <= 0) {
|
||||||
free(buf);
|
free(buf);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -61,7 +61,7 @@ int ipfs_cid_protobuf_decode(unsigned char* buffer, size_t buffer_length, struct
|
||||||
* @param incoming the struct to encode
|
* @param incoming the struct to encode
|
||||||
* @returns the number of approximate bytes
|
* @returns the number of approximate bytes
|
||||||
*/
|
*/
|
||||||
size_t ipfs_cid_protobuf_encode_size(struct Cid* incoming);
|
size_t ipfs_cid_protobuf_encode_size(const struct Cid* incoming);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new CID based on the given hash
|
* Create a new CID based on the given hash
|
||||||
|
|
|
@ -87,6 +87,10 @@ int ipfs_routing_online_find_remote_providers(struct IpfsRouting* routing, const
|
||||||
struct Libp2pLinkedList * current_provider_peer_list_item = return_message->provider_peer_head;
|
struct Libp2pLinkedList * current_provider_peer_list_item = return_message->provider_peer_head;
|
||||||
while (current_provider_peer_list_item != NULL) {
|
while (current_provider_peer_list_item != NULL) {
|
||||||
struct Libp2pPeer *current_peer = current_provider_peer_list_item->item;
|
struct Libp2pPeer *current_peer = current_provider_peer_list_item->item;
|
||||||
|
// if we can find the peer in the peerstore, use that one instead
|
||||||
|
struct Libp2pPeer* peerstorePeer = libp2p_peerstore_get_peer(routing->local_node->peerstore, (unsigned char*)current_peer->id, current_peer->id_size);
|
||||||
|
if (peerstorePeer != NULL)
|
||||||
|
current_peer = peerstorePeer;
|
||||||
libp2p_utils_vector_add(*peers, libp2p_peer_copy(current_peer));
|
libp2p_utils_vector_add(*peers, libp2p_peer_copy(current_peer));
|
||||||
current_provider_peer_list_item = current_provider_peer_list_item->next;
|
current_provider_peer_list_item = current_provider_peer_list_item->next;
|
||||||
}
|
}
|
||||||
|
|
|
@ -304,8 +304,6 @@ int test_bitswap_retrieve_file_known_remote() {
|
||||||
multiaddress_free(ma_peer1);
|
multiaddress_free(ma_peer1);
|
||||||
ipfs_node_online_new(ipfs_path, &ipfs_node2);
|
ipfs_node_online_new(ipfs_path, &ipfs_node2);
|
||||||
|
|
||||||
ipfs_node2->routing->Bootstrap(ipfs_node2->routing);
|
|
||||||
|
|
||||||
if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hello_world_hash, strlen(hello_world_hash), &cid))
|
if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hello_world_hash, strlen(hello_world_hash), &cid))
|
||||||
goto exit;
|
goto exit;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue