Beginnings of stream locking

This commit is contained in:
jmjatlanta 2017-10-12 12:38:00 -05:00
parent b399762d82
commit cfde84b15c
2 changed files with 27 additions and 22 deletions

View file

@ -333,7 +333,8 @@ int ipfs_core_http_process_swarm_connect(struct IpfsNode* local_node, struct Htt
return 0;
}
sprintf((char*)response->bytes, json, address);
libp2p_peer_free(new_peer);
// getting rid of the peer here will close the connection. That's not what we want
//libp2p_peer_free(new_peer);
multiaddress_free(ma);
return 1;

View file

@ -96,7 +96,9 @@ void* ipfs_bitswap_engine_peer_request_processor_start(void* ctx) {
if (current_peer_entry->sessionContext == NULL || current_peer_entry->sessionContext->default_stream == NULL) {
current_peer_entry->connection_type = CONNECTION_TYPE_NOT_CONNECTED;
} else {
//libp2p_logger_debug("bitswap_engine", "We're connected to %s. Lets see if there is a message waiting for us.\n", libp2p_peer_id_to_string(current_peer_entry));
// check the network to see if there is anything waiting for us (if the stream is idle)
if (libp2p_stream_try_lock(current_peer_entry->sessionContext->default_stream)) {
libp2p_logger_error("bitswap_engine", "I have the lock for peer %s.\n", libp2p_peer_id_to_string(current_peer_entry));
int retVal = current_peer_entry->sessionContext->default_stream->peek(current_peer_entry->sessionContext);
if (retVal < 0) {
libp2p_logger_debug("bitswap_engine", "We thought we were connected, but Peek reported an error.\n");
@ -121,6 +123,8 @@ void* ipfs_bitswap_engine_peer_request_processor_start(void* ctx) {
libp2p_peer_handle_connection_error(current_peer_entry);
}
}
libp2p_stream_unlock(current_peer_entry->sessionContext->default_stream);
}
}
} else {
if (current_peer_entry->is_local) {