2017-10-11 16:23:25 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "libp2p/net/protocol.h"
|
2017-10-23 23:03:38 +00:00
|
|
|
#include "libp2p/net/stream.h"
|
|
|
|
|
|
|
|
/***
|
|
|
|
* Declarations for the Yamux protocol
|
|
|
|
*/
|
2017-10-11 16:23:25 +00:00
|
|
|
|
2017-11-02 19:45:17 +00:00
|
|
|
static const int yamux_default_timeout = 10;
|
|
|
|
|
|
|
|
/***
|
|
|
|
* Context struct for Yamux
|
|
|
|
*/
|
|
|
|
struct YamuxContext {
|
|
|
|
struct Stream* stream;
|
|
|
|
struct yamux_session* session;
|
2017-11-06 12:27:03 +00:00
|
|
|
struct Libp2pVector* channels;
|
2017-11-02 19:45:17 +00:00
|
|
|
};
|
|
|
|
|
2017-10-11 16:23:25 +00:00
|
|
|
/**
|
|
|
|
* Build a handler that can handle the yamux protocol
|
|
|
|
*/
|
|
|
|
struct Libp2pProtocolHandler* yamux_build_protocol_handler();
|
2017-10-12 15:12:22 +00:00
|
|
|
/***
|
|
|
|
* Send the yamux protocol out the default stream
|
|
|
|
* NOTE: if we initiate the connection, we should expect the same back
|
|
|
|
* @param context the SessionContext
|
|
|
|
* @returns true(1) on success, false(0) otherwise
|
|
|
|
*/
|
|
|
|
int yamux_send_protocol(struct SessionContext* context);
|
2017-10-12 17:37:40 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
* Check to see if the reply is the yamux protocol header we expect
|
|
|
|
* NOTE: if we initiate the connection, we should expect the same back
|
|
|
|
* @param context the SessionContext
|
|
|
|
* @returns true(1) on success, false(0) otherwise
|
|
|
|
*/
|
|
|
|
int yamux_receive_protocol(struct SessionContext* context);
|
2017-10-23 23:03:38 +00:00
|
|
|
|
|
|
|
struct Stream* libp2p_yamux_stream_new(struct Stream* parent_stream);
|
2017-11-06 12:27:03 +00:00
|
|
|
|
|
|
|
/****
|
|
|
|
* Add a stream "channel" to the yamux handler
|
|
|
|
* @param ctx the context
|
|
|
|
* @param stream the stream to add
|
|
|
|
* @returns true(1) on success, false(0) otherwise
|
|
|
|
*/
|
|
|
|
int libp2p_yamux_stream_add(struct YamuxContext* ctx, struct Stream* stream);
|