* - connect to a remote server with fd_cnx_cli_connect
*
* 2) Initialization
* - if TLS is started first, call fd_cnx_handshake
* - otherwise to receive clear messages, call fd_cnx_start_clear. fd_cnx_handshake can be called later.
*
* 3) Usage
* - fd_cnx_receive, fd_cnx_send : exchange messages on this connection (send is synchronous, receive is not).
* - fd_cnx_recv_setaltfifo : when a message is received, the event is sent to an external fifo list. fd_cnx_receive does not work when the alt_fifo is set.
* - fd_cnx_getid : retrieve a descriptive string for the connection (for debug)
* - fd_cnx_getremoteid : identification of the remote peer (IP address or fqdn)
* - fd_cnx_getcred : get the remote peer TLS credentials, after handshake
* - fd_cnx_getendpoints : get the endpoints (IP) of the connection
*
* 4) End
* - fd_cnx_destroy
*/
/* The connection context structure */
structcnxctx{
charcc_id[60];/* The name of this connection */
charcc_remid[60];/* Id of remote peer */
intcc_socket;/* The socket object of the connection -- <=0 if no socket is created */
intcc_proto;/* IPPROTO_TCP or IPPROTO_SCTP */
intcc_tls;/* Is TLS already started ? */
structfifo*cc_events;/* Events occuring on the connection */
pthread_tcc_mgr;/* manager thread for the connection */
structfifo*cc_incoming;/* FIFO queue of messages received on the connection */
uint16_tcc_port;/* Remote port of the connection, when we are client */
structfd_listcc_ep_remote;/* The remote address(es) of the connection */
structfd_listcc_ep_local;/* The local address(es) of the connection */
structfifo*cc_alt;/* alternate fifo to send FDEVP_CNX_MSG_RECV events to. */
/* If cc_proto == SCTP */
struct{
intstr_out;/* Out streams */
...
...
@@ -57,13 +89,13 @@ struct cnxctx {
intpairs;/* max number of pairs ( = min(in, out)) */
intnext;/* # of stream the next message will be sent to */
}cc_sctp_para;
/* If cc_tls == true */
struct{
intmode;/* GNUTLS_CLIENT / GNUTLS_SERVER */
gnutls_session_tsession;/* Session object (stream #0 in case of SCTP) */
}cc_tls_para;
/* If both conditions */
struct{
gnutls_session_t*res_sessions;/* Sessions of other pairs of streams, resumed from the first */
...
...
@@ -72,62 +104,232 @@ struct cnxctx {
};
/* Initialize a context structure from a socket */