2017-11-03 06:26:43 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-11-06 18:36:11 +00:00
|
|
|
#include "libp2p/utils/vector.h"
|
|
|
|
|
2017-11-10 01:57:11 +00:00
|
|
|
#define IDENTIFY_PROTOCOL_VERSION "ipfs/0.1.0"
|
|
|
|
#define IDENTIFY_AGENT_VERSION "c-ipfs/1.0"
|
|
|
|
|
2017-11-03 06:26:43 +00:00
|
|
|
typedef struct {
|
|
|
|
// publicKey is this node's public key (which also gives its node.ID)
|
|
|
|
// - may not need to be sent, as secure channel implies it has been sent.
|
|
|
|
// - then again, if we change / disable secure channel, may still want it.
|
|
|
|
char *PublicKey;
|
|
|
|
// listenAddrs are the multiaddrs the sender node listens for open connections on
|
|
|
|
char **ListenAddrs;
|
|
|
|
// protocols are the services this node is running
|
|
|
|
char **Protocols;
|
|
|
|
// oservedAddr is the multiaddr of the remote endpoint that the sender node perceives
|
|
|
|
// this is useful information to convey to the other side, as it helps the remote endpoint
|
|
|
|
// determine whether its connection to the local peer goes through NAT.
|
|
|
|
char *ObservedAddr;
|
|
|
|
// protocolVersion determines compatibility between peers
|
|
|
|
char *ProtocolVersion;
|
|
|
|
// agentVersion is like a UserAgent string in browsers, or client version in bittorrent
|
|
|
|
// includes the client name and client.
|
|
|
|
char *AgentVersion;
|
|
|
|
char *XXX_unrecognized;
|
|
|
|
} Identify;
|
|
|
|
|
2017-11-06 12:27:03 +00:00
|
|
|
struct IdentifyContext {
|
|
|
|
struct Stream* parent_stream;
|
2017-11-06 21:38:55 +00:00
|
|
|
struct Stream* stream;
|
2017-11-06 12:27:03 +00:00
|
|
|
};
|
|
|
|
|
2017-11-03 06:26:43 +00:00
|
|
|
int libp2p_identify_can_handle(const struct StreamMessage* msg);
|
2017-11-08 15:51:43 +00:00
|
|
|
int libp2p_identify_send_protocol(struct Stream* stream);
|
|
|
|
int libp2p_identify_receive_protocol(struct Stream* stream);
|
2017-11-10 01:57:11 +00:00
|
|
|
Identify* libp2p_identify_new();
|
|
|
|
void libp2p_identify_free(Identify* in);
|
2017-11-10 02:06:43 +00:00
|
|
|
char *libp2p_identify_new_item(char *item, size_t size);
|
|
|
|
int libp2p_identify_array_add_item(char ***array, char *item);
|
|
|
|
int libp2p_identify_protobuf_encode(const Identify* in, unsigned char* buffer, size_t max_buffer_size, size_t* bytes_written);
|
|
|
|
int libp2p_identify_protobuf_decode(const unsigned char* in, size_t in_size, Identify** out);
|
2017-11-10 01:54:19 +00:00
|
|
|
int libp2p_identify_handle_message(const struct StreamMessage* msg, struct Stream* stream, void* protocol_context);
|
2017-11-03 06:26:43 +00:00
|
|
|
int libp2p_identify_shutdown(void* protocol_context);
|
|
|
|
struct Libp2pProtocolHandler* libp2p_identify_build_protocol_handler(struct Libp2pVector* handlers);
|
2017-11-06 12:27:03 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
* Create a new stream that negotiates the identify protocol
|
|
|
|
*
|
|
|
|
* NOTE: This will be sent by our side (us asking them).
|
|
|
|
* Incoming "Identify" requests should be handled by the
|
|
|
|
* external protocol handler, not this function.
|
|
|
|
*
|
|
|
|
* @param parent_stream the parent stream
|
|
|
|
* @returns a new Stream that can talk "identify"
|
|
|
|
*/
|
|
|
|
struct Stream* libp2p_identify_stream_new(struct Stream* parent_stream);
|
|
|
|
|