From 35d795df940aef18db0730512c790adae2f704cb Mon Sep 17 00:00:00 2001 From: John Jones Date: Tue, 28 Nov 2017 23:58:28 -0500 Subject: [PATCH] test_compat_go now negotiating yamux --- conn/dialer.c | 2 +- yamux/yamux.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/conn/dialer.c b/conn/dialer.c index 89fbc05..a3d7da0 100644 --- a/conn/dialer.c +++ b/conn/dialer.c @@ -141,7 +141,7 @@ int libp2p_conn_dialer_join_swarm(const struct Dialer* dialer, struct Libp2pPeer return 0; libp2p_logger_debug("dialer", "We successfully negotiated multistream over secio.\n"); // yamux over multistream - new_stream = libp2p_yamux_stream_new(new_stream, 0, NULL); + new_stream = libp2p_yamux_stream_new(peer->sessionContext->default_stream, 0, NULL); if (new_stream != NULL) { if (!libp2p_yamux_stream_ready(peer->sessionContext, 5)) return 0; diff --git a/yamux/yamux.c b/yamux/yamux.c index 12e96ad..4f569be 100644 --- a/yamux/yamux.c +++ b/yamux/yamux.c @@ -270,6 +270,11 @@ int libp2p_yamux_read(void* stream_context, struct StreamMessage** message, int ctx = (struct YamuxContext*)stream_context; } + if (ctx->state != yamux_stream_est) { + libp2p_logger_debug("yamux", "read: Yamux still not inited, so passing to lower protocol.\n"); + return ctx->stream->parent_stream->read(ctx->stream->parent_stream->stream_context, message, timeout_secs); + } + struct Stream* parent_stream = libp2p_yamux_get_parent_stream(stream_context); if (channel != NULL && channel->channel != 0) { libp2p_logger_debug("yamux", "Data received on yamux stream %d.\n", channel->channel); @@ -623,6 +628,7 @@ struct Stream* libp2p_yamux_stream_new(struct Stream* parent_stream, int am_serv out->read_raw = libp2p_yamux_read_raw; out->handle_upgrade = libp2p_yamux_handle_upgrade; out->address = parent_stream->address; + out->socket_mutex = parent_stream->socket_mutex; // build YamuxContext struct YamuxContext* ctx = libp2p_yamux_context_new(out); if (ctx == NULL) {