c-libp2p/include/libp2p/conn/dialer.h

47 lines
1.4 KiB
C
Raw Normal View History

2017-02-13 13:47:55 +00:00
/***
* A local dialer. Uses MultiAddr to figure out the best way to
2017-02-13 18:26:41 +00:00
* connect to a client, then returns an open Connection that can be
* closed, read from and written to.
2017-02-13 13:47:55 +00:00
*/
#include "libp2p/crypto/key.h"
2017-02-13 18:26:41 +00:00
#include "multiaddr/multiaddr.h"
2017-02-13 22:41:31 +00:00
#include "libp2p/conn/connection.h"
#include "libp2p/conn/transport_dialer.h"
2017-02-13 13:47:55 +00:00
struct Dialer {
/**
* These two are used to create connections
*/
char* peer_id; // the local peer ID as null terminated string
struct PrivateKey* private_key; // used to initiate secure connections, can be NULL, and connections will not be secured
/**
* A linked list of transport dialers. A transport dialer can be selected
* based on the MultiAddr being dialed. Most common: TCP and UDP
*/
2017-02-13 18:26:41 +00:00
struct Libp2pLinkedList* transport_dialers;
2017-02-13 13:47:55 +00:00
//TODO: See dial.go, need to implement Protector
2017-02-13 18:26:41 +00:00
struct TransportDialer* fallback_dialer; // the default dialer. NOTE: this should not be in the list of transport_dialers
2017-02-13 13:47:55 +00:00
};
2017-02-13 18:26:41 +00:00
/**
* Create a Dialer with the specified local information
*/
struct Dialer* libp2p_conn_dialer_new(char* peer_id, struct PrivateKey* private_key);
/**
* free resources from the Dialer
*/
void libp2p_conn_dialer_free(struct Dialer* in);
/**
* Retrieve a Connection struct from the dialer
* @param dialer the dialer to use
* @param muiltiaddress who to connect to
* @returns a Connection, or NULL
*/
2017-02-13 22:41:31 +00:00
struct Connection* libp2p_conn_dialer_get_connection(struct Dialer* dialer, struct MultiAddress* multiaddress);