c-libp2p/conn/transport_dialer.c

39 lines
1.1 KiB
C
Raw Normal View History

2017-02-13 18:26:41 +00:00
#include <stdlib.h>
#include "libp2p/conn/transport_dialer.h"
2017-02-13 22:41:31 +00:00
struct TransportDialer* libp2p_conn_transport_dialer_new(struct MultiAddress* multiaddr) {
2017-02-13 18:26:41 +00:00
struct TransportDialer* out = (struct TransportDialer*)malloc(sizeof(struct TransportDialer));
if (out != NULL) {
2017-02-13 22:41:31 +00:00
out->multiaddr = (struct MultiAddress*)malloc(sizeof(struct MultiAddress));
2017-02-13 18:26:41 +00:00
if (out->multiaddr == NULL) {
2017-02-13 22:41:31 +00:00
libp2p_conn_transport_dialer_free(out);
return NULL;
}
if (multiaddress_copy(multiaddr, out->multiaddr) == 0) {
libp2p_conn_transport_dialer_free(out);
2017-02-13 18:26:41 +00:00
return NULL;
}
}
return out;
}
/**
* free resources from a TransportDialer struct
* @param in the struct to be freed
*/
void libp2p_conn_transport_dialer_free(struct TransportDialer* in) {
free(in);
}
/**
* Given a list of dialers, find the appropriate dialer for this multiaddress
* @param transport_dialers a list of dialers
* @param multiaddr the address
* @returns a connection, or NULL if no appropriate dialer was found
*/
2017-02-13 22:41:31 +00:00
struct Connection* libp2p_conn_transport_dialer_get(struct Libp2pLinkedList* transport_dialers, struct MultiAddress* multiaddr) {
2017-02-13 18:26:41 +00:00
//TODO: implement this method
return NULL;
}