debugging yamux and go

This commit is contained in:
John Jones 2017-11-27 09:06:57 -05:00
parent f96209fc4b
commit f3db50c3ba
7 changed files with 80 additions and 14 deletions

View file

@ -81,7 +81,6 @@
<buildTargets> <buildTargets>
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget> <buildTarget>all</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand> <useDefaultCommand>true</useDefaultCommand>
@ -89,7 +88,6 @@
</target> </target>
<target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget> <buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand> <useDefaultCommand>true</useDefaultCommand>
@ -97,7 +95,6 @@
</target> </target>
<target name="rebuild" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="rebuild" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>rebuild</buildTarget> <buildTarget>rebuild</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand> <useDefaultCommand>true</useDefaultCommand>
@ -105,13 +102,39 @@
</target> </target>
<target name="clean" path="thirdparty" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="clean" path="thirdparty" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget> <buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand> <useDefaultCommand>false</useDefaultCommand>
<runAllBuilders>true</runAllBuilders> <runAllBuilders>true</runAllBuilders>
</target> </target>
<target name="all" path="test" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="clean" path="test" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="rebuild" path="test" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>rebuild</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="clean" path="thirdparty/ipfsaddr" targetID="org.eclipse.cdt.build.MakeTargetBuilder"> <target name="clean" path="thirdparty/ipfsaddr" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand> <buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget> <buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError> <stopOnError>true</stopOnError>
<useDefaultCommand>false</useDefaultCommand> <useDefaultCommand>false</useDefaultCommand>

View file

@ -312,7 +312,15 @@ int ipfs_core_http_process_swarm_connect(struct IpfsNode* local_node, struct Htt
multiaddress_free(ma); multiaddress_free(ma);
return 0; return 0;
} }
// ok, we're good. Send stuff back to the user // ok, we're good. Start a thread to listen to them, and send stuff back to the user
// JMJ Debug - just put a loop here for testing
while(1) {
int retVal = ipfs_null_listen_and_handle(new_peer->sessionContext->default_stream, local_node->protocol_handlers);
if (retVal < 0)
break;
else
sleep(1);
}
*resp = ipfs_core_http_response_new(); *resp = ipfs_core_http_response_new();
struct HttpResponse* response = *resp; struct HttpResponse* response = *resp;
if (response == NULL) { if (response == NULL) {

View file

@ -34,6 +34,31 @@
static int null_shutting_down = 0; static int null_shutting_down = 0;
/***
* Listens on a particular stream, and marshals the request
* @param stream the stream to listen to
* @param protocol_handlers a vector of protocol handlers
* @returns <0 on error, 0 if we shouldn't handle this anymore, or 1 on success
*/
int ipfs_null_listen_and_handle(struct Stream* stream, struct Libp2pVector* protocol_handlers) {
struct StreamMessage* results = NULL;
int retVal = 0;
// Read from the network
if (!stream->read(stream->stream_context, &results, DEFAULT_NETWORK_TIMEOUT)) {
libp2p_logger_error("null", "Unable to read from network. Exiting.\n");
return retVal;
}
if (results != NULL) {
libp2p_logger_debug("null", "Attempting to marshal %d bytes from network.\n", results->data_size);
retVal = libp2p_protocol_marshal(results, stream, protocol_handlers);
libp2p_logger_debug("null", "The return value from the attempt to marshal %d bytes was %d.\n", results->data_size, retVal);
libp2p_stream_message_free(results);
} else {
libp2p_logger_debug("null", "Attempted read, but results were null. This is normal.\n");
}
return retVal;
}
/** /**
* We've received a new connection. Find out what they want. * We've received a new connection. Find out what they want.
* *
@ -59,20 +84,13 @@ void ipfs_null_connection (void *ptr) {
libp2p_logger_info("null", "Connection %d, count %d\n", connection_param->file_descriptor, *(connection_param->count)); libp2p_logger_info("null", "Connection %d, count %d\n", connection_param->file_descriptor, *(connection_param->count));
// try to read from the network // try to read from the network
struct StreamMessage *results = 0;
// handle the call // handle the call
for(;;) { for(;;) {
// Read from the network // Read from the network
if (!session->default_stream->read(session->default_stream->stream_context, &results, DEFAULT_NETWORK_TIMEOUT)) { retVal = ipfs_null_listen_and_handle(session->default_stream, connection_param->local_node->protocol_handlers);
// problem reading
break;
}
if (results != NULL) {
retVal = libp2p_protocol_marshal(results, session->default_stream, connection_param->local_node->protocol_handlers);
libp2p_stream_message_free(results);
}
if (retVal < 0) { if (retVal < 0) {
// exit the loop on error // exit the loop on error
libp2p_logger_debug("null", "Exiting loop due to retVal being %d.\n", retVal);
break; break;
} }
} // end of loop } // end of loop

View file

@ -18,6 +18,8 @@
#include "ipfs/exchange/bitswap/want_manager.h" #include "ipfs/exchange/bitswap/want_manager.h"
int ipfs_bitswap_can_handle(const struct StreamMessage* msg) { int ipfs_bitswap_can_handle(const struct StreamMessage* msg) {
if (msg == NULL || msg->data == NULL || msg->data_size == 0)
return 0;
char* result = strnstr((char*)msg->data, "/ipfs/bitswap", msg->data_size); char* result = strnstr((char*)msg->data, "/ipfs/bitswap", msg->data_size);
if(result == NULL || result != (char*)msg->data) if(result == NULL || result != (char*)msg->data)
return 0; return 0;

View file

@ -19,6 +19,8 @@
* @returns true(1) if the protocol in incoming is something we can handle. False(0) otherwise. * @returns true(1) if the protocol in incoming is something we can handle. False(0) otherwise.
*/ */
int ipfs_journal_can_handle(const struct StreamMessage* msg) { int ipfs_journal_can_handle(const struct StreamMessage* msg) {
if (msg == NULL || msg->data_size == 0 || msg->data == NULL)
return 0;
const char* protocol = "/ipfs/journalio/1.0.0"; const char* protocol = "/ipfs/journalio/1.0.0";
if (msg->data_size < 21) if (msg->data_size < 21)
return 0; return 0;

View file

@ -43,3 +43,5 @@ all: test_ipfs
clean: clean:
rm -f *.o rm -f *.o
rm -f test_ipfs rm -f test_ipfs
rebuild: clean all

View file

@ -15,6 +15,11 @@ int test_compat_go_join_swarm() {
pthread_t daemon_thread; pthread_t daemon_thread;
struct FSRepo* fs_repo = NULL; struct FSRepo* fs_repo = NULL;
libp2p_logger_add_class("test_api");
libp2p_logger_add_class("yamux");
libp2p_logger_add_class("identify");
libp2p_logger_add_class("null");
// Here is the connection information for the GO version: // Here is the connection information for the GO version:
char* remote_string = "/ip4/10.211.55.2/tcp/4001/ipfs/QmacSE6bCZiAu7nrYkhPATaSoL2q9BszkKzbX6fCiXuBGA"; char* remote_string = "/ip4/10.211.55.2/tcp/4001/ipfs/QmacSE6bCZiAu7nrYkhPATaSoL2q9BszkKzbX6fCiXuBGA";
@ -32,7 +37,13 @@ int test_compat_go_join_swarm() {
// try to connect to a remote swarm // try to connect to a remote swarm
struct IpfsNode *local_node = NULL; struct IpfsNode *local_node = NULL;
ipfs_node_offline_new(ipfs_path1, &local_node); ipfs_node_offline_new(ipfs_path1, &local_node);
ipfs_swarm_connect(local_node, remote_string); if (!ipfs_swarm_connect(local_node, remote_string)) {
libp2p_logger_error("test_api", "Unable to do swarm connect.\n");
goto exit;
}
// see what the remote will do
sleep(20);
retVal = 1; retVal = 1;
exit: exit: