view libfdcore/fdcore-internal.h @ 1481:c9e9f8a71946

Update to 3GPP TS 32.299 V15.7.0 (2019-06) Add AVPs: - 3GPP-OC-Rating-Group, Unsigned32, code 1321 - 3GPP-OC-Request-Type, Enumerated, code 1322 - 3GPP-OC-Specific-Reduction, Grouped, code 1320 - 3GPP-PS-Data-Off-Status-32.299, Enumerated, code 4406 - API-Content, UTF8String, code 1309 - API-Direction, Enumerated, code 1310 - API-Identifier, OctetString, code 1311 - API-Invocation-Timestamp, Time, code 1312 - API-Network-Service-Node, Enumerated, code 1315 - API-Result-Code, Unsigned32, code 1313 - API-Size, Unsigned64, code 1314 - APN-Rate-Control, Grouped, code 3933 - APN-Rate-Control-Downlink, Grouped, code 3934 - APN-Rate-Control-Uplink, Grouped, code 3935 - Access-Network-Info-Change, Grouped, code 4401 - Additional-Exception-Reports, Enumerated, code 3936 - Announcement-Identifier, Unsigned32, code 3905 - Announcement-Information, Grouped, code 3904 - Announcement-Order, Unsigned32, code 3906 - Announcing-PLMN-ID, UTF8String, code 4408 - Announcing-UE-HPLMN-Identifier, UTF8String, code 3426 - Announcing-UE-VPLMN-Identifier, UTF8String, code 3427 - Application-Specific-Data, OctetString, code 3458 - Authorised-QoS, UTF8String, code 849 - BSSID, UTF8String, code 2716 - Basic-Service-Code, Grouped, code 3411 - Bearer-Capability, OctetString, code 3412 - CN-Operator-Selection-Entity, Enumerated, code 3421 - CP-CIoT-EPS-Optimisation-Indicator, Enumerated, code 3930 - CPDT-Information, Grouped, code 3927 - Called-Identity, UTF8String, code 3916 - Called-Identity-Change, Grouped, code 3917 - Cellular-Network-Information, OctetString, code 3924 - Charging-Per-IP-CAN-Session-Indicator, Enumerated, code 4400 - Civic-Address-Information, UTF8String, code 1305 - Coverage-Info, Grouped, code 3459 - Coverage-Status, Enumerated, code 3428 - Discoveree-UE-HPLMN-Identifier, UTF8String, code 4402 - Discoveree-UE-VPLMN-Identifier, UTF8String, code 4403 - Discoverer-UE-HPLMN-Identifier, UTF8String, code 4404 - Discoverer-UE-VPLMN-Identifier, UTF8String, code 4405 - EPDG-Address, Address, code 3425 - Enhanced-Diagnostics, Grouped, code 3901 - Exposure-Function-API-Information, Grouped, code 1316 - FE-Identifier-List, UTF8String, code 4413 - Forwarding-Pending, Enumerated, code 3415 - IMS-Visited-Network-Identifier, UTF8String, code 2713 - ISUP-Cause, Grouped, code 3416 - ISUP-Cause-Diagnostics, OctetString, code 3422 - ISUP-Cause-Location, Unsigned32, code 3423 - ISUP-Cause-Value, Unsigned32, code 3424 - ISUP-Location-Number, OctetString, code 3414 - Instance-Id, UTF8String, code 3402 - Inter-UE-Transfer, Enumerated, code 3902 - Language, UTF8String, code 3914 - Layer-2-Group-ID, OctetString, code 3429 - Location-Info, Grouped, code 3460 - MBMS-Charged-Party, Enumerated, code 2323 - MSC-Address, OctetString, code 3417 - MTC-IWF-Address, Address, code 3406 - Monitored-PLMN-Identifier, UTF8String, code 3430 - Monitoring-Event-Configuration-Activity, Integer32, code 3919 - Monitoring-Event-Functionality, Integer32, code 3922 - Monitoring-Event-Information, Grouped, code 3921 - Monitoring-Event-Report-Data, Grouped, code 3920 - Monitoring-Event-Report-Number, Unsigned32, code 3923 - Monitoring-UE-HPLMN-Identifier, UTF8String, code 3431 - Monitoring-UE-Identifier, UTF8String, code 3432 - Monitoring-UE-VPLMN-Identifier, UTF8String, code 3433 - NIDD-Submission, Grouped, code 3928 - Network-Call-Reference-Number, OctetString, code 3418 - PC3-Control-Protocol-Cause, Integer32, code 3434 - PC3-EPC-Control-Protocol-Cause, Integer32, code 3435 - PC5-Radio-Technology, Enumerated, code 1300 - Play-Alternative, Enumerated, code 3913 - Privacy-Indicator, Enumerated, code 3915 - ProSe-3rd-Party-Application-ID, UTF8String, code 3440 - ProSe-Direct-Communication-Reception-Data-Container, Grouped, code 3461 - ProSe-Direct-Communication-Transmission-Data-Container, Grouped, code 3441 - ProSe-Direct-Discovery-Model, Enumerated, code 3442 - ProSe-Event-Type, Enumerated, code 3443 - ProSe-Function-IP-Address, Address, code 3444 - ProSe-Function-PLMN-Identifier, UTF8String, code 3457 - ProSe-Functionality, Enumerated, code 3445 - ProSe-Group-IP-Multicast-Address, Address, code 3446 - ProSe-Information, Grouped, code 3447 - ProSe-Range-Class, Enumerated, code 3448 - ProSe-Reason-For-Cancellation, Enumerated, code 3449 - ProSe-Request-Timestamp, Time, code 3450 - ProSe-Role-Of-UE, Enumerated, code 3451 - ProSe-Source-IP-Address, Address, code 3452 - ProSe-Target-Layer-2-ID, OctetString, code 4410 - ProSe-UE-ID, OctetString, code 3453 - ProSe-UE-to-Network-Relay-UE-ID, OctetString, code 4409 - Proximity-Alert-Indication, Enumerated, code 3454 - Proximity-Alert-Timestamp, Time, code 3455 - Proximity-Cancellation-Timestamp, Time, code 3456 - Quota-Indicator, Enumerated, code 3912 - RAN-End-Time, Time, code 1301 - RAN-Secondary-RAT-Usage-Report, Grouped, code 1302 - RAN-Start-Time, Time, code 1303 - Radio-Frequency, OctetString, code 3462 - Radio-Parameter-Set-Info, Grouped, code 3463 - Radio-Parameter-Set-Values, OctetString, code 3464 - Radio-Resources-Indicator, Integer32, code 3465 - Rate-Control-Max-Message-Size, Unsigned32, code 3937 - Rate-Control-Max-Rate, Unsigned32, code 3938 - Rate-Control-Time-Unit, Unsigned32, code 3939 - Reason-Header, UTF8String, code 3401 - Related-Change-Condition-Information, Grouped, code 3925 - Related-IMS-Charging-Identifier, UTF8String, code 2711 - Related-IMS-Charging-Identifier-Node, Address, code 2712 - Related-Trigger, Grouped, code 3926 - Relay-IP-address, Address, code 4411 - Requested-PLMN-Identifier, UTF8String, code 3436 - Requestor-PLMN-Identifier, UTF8String, code 3437 - Role-Of-ProSe-Function, Enumerated, code 3438 - Route-Header-Received, UTF8String, code 3403 - Route-Header-Transmitted, UTF8String, code 3404 - SCEF-Address, Address, code 1317 - SCS-AS-Address, Grouped, code 3940 - SCS-Address, Address, code 3941 - SCS-Realm, DiameterIdentity, code 3942 - SGi-PtP-Tunnelling-Method, Enumerated, code 3931 - SM-Device-Trigger-Indicator, Enumerated, code 3407 - SM-Device-Trigger-Information, Grouped, code 3405 - SM-Sequence-Number, Unsigned32, code 3408 - SMS-Result, Unsigned32, code 3409 - Secondary-RAT-Type, OctetString, code 1304 - Serving-Node-Identity, DiameterIdentity, code 3929 - Start-of-Charging, Time, code 3419 - TAD-Identifier, Enumerated, code 2717 - TLTRI, Unsigned32, code 1318 - TWAG-Address, Address, code 3903 - TWAN-User-Location-Info, Grouped, code 2714 - Target-IP-Address, Address, code 4412 - Teleservice, OctetString, code 3413 - Time-First-Reception, Time, code 3466 - Time-First-Transmission, Time, code 3467 - Time-Indicator, Unsigned32, code 3911 - Transmitter-Info, Grouped, code 3468 - UNI-PDU-CP-Only-Flag, Enumerated, code 3932 - UWAN-User-Location-Info, Grouped, code 3918 - Unused-Quota-Timer, Unsigned32, code 4407 - Usage-Information-Report-Sequence-Number, Integer32, code 3439 - VCS-Information, Grouped, code 3410 - VLR-Number, OctetString, code 3420 - Variable-Part, Grouped, code 3907 - Variable-Part-Order, Unsigned32, code 3908 - Variable-Part-Type, Unsigned32, code 3909 - Variable-Part-Value, UTF8String, code 3910 - WLAN-Operator-Id, Grouped, code 1306 - WLAN-Operator-Name, UTF8String, code 1307 - WLAN-PLMN-Id, UTF8String, code 1308 3GPP TS 32.299 V11.8.0 (2013-07) renamed LCS-Requestor-Id (1239) to LCS-Requestor-ID (1239). 3GPP TS 32.299 V11.8.0 (2013-07) renamed LCS-Requestor-Id-String (1240) to LCS-Requestor-ID-String (1240). 3GPP TS 32.299 V13.1.0 (2015-06) renamed PoC-User-Role-info-Units (1254) to PoC-User-Role-Info-Units (1254). 3GPP TS 32.299 V11.10.0 (2013-12) renamed Status (2702) to Status-Code (2702), and then 3GPP TS 32.299 V11.14.0 (2014-12) renamed Status-Code (2702) to Status-AS-Code (2702).
author Luke Mewburn <luke@mewburn.net>
date Thu, 26 Mar 2020 15:26:18 +1100
parents 239ba25870d8
children 407e0a889c7e
line wrap: on
line source

/*********************************************************************************************************
* Software License Agreement (BSD License)                                                               *
* Author: Sebastien Decugis <sdecugis@freediameter.net>							 *
*													 *
* Copyright (c) 2013, WIDE Project and NICT								 *
* All rights reserved.											 *
* 													 *
* Redistribution and use of this software in source and binary forms, with or without modification, are  *
* permitted provided that the following conditions are met:						 *
* 													 *
* * Redistributions of source code must retain the above 						 *
*   copyright notice, this list of conditions and the 							 *
*   following disclaimer.										 *
*    													 *
* * Redistributions in binary form must reproduce the above 						 *
*   copyright notice, this list of conditions and the 							 *
*   following disclaimer in the documentation and/or other						 *
*   materials provided with the distribution.								 *
* 													 *
* * Neither the name of the WIDE Project or NICT nor the 						 *
*   names of its contributors may be used to endorse or 						 *
*   promote products derived from this software without 						 *
*   specific prior written permission of WIDE Project and 						 *
*   NICT.												 *
* 													 *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED *
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR *
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 	 *
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 	 *
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR *
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF   *
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.								 *
*********************************************************************************************************/

/* This file contains the definitions for internal use in the freeDiameter core library */

#ifndef _FDCORE_INTERNAL_H
#define _FDCORE_INTERNAL_H

#include <freeDiameter/freeDiameter-host.h>
#include <freeDiameter/libfdcore.h>

#ifdef DISABLE_SCTP
#undef IPPROTO_SCTP
#define IPPROTO_SCTP	(2 = 4) /* some compilation error to spot the references */
#endif /* DISABLE_SCTP */

#ifndef HAVE_AI_ADDRCONFIG
#define AI_ADDRCONFIG 0 /* ignore this flag at the moment */
#endif /* HAVE_AI_ADDRCONFIG */

/* Timeout for establishing a connection */
#ifndef CNX_TIMEOUT
#define  CNX_TIMEOUT	10	/* in seconds */
#endif /* CNX_TIMEOUT */

/* Timeout for receiving a CER after incoming connection is established */
#ifndef INCNX_TIMEOUT
#define  INCNX_TIMEOUT	 20	/* in seconds */
#endif /* INCNX_TIMEOUT */

/* Timeout for receiving a CEA after CER is sent */
#ifndef CEA_TIMEOUT
#define  CEA_TIMEOUT	10	/* in seconds */
#endif /* CEA_TIMEOUT */

/* The timeout value to wait for answer to a DPR */
#ifndef DPR_TIMEOUT
#define DPR_TIMEOUT 	15	/* in seconds */
#endif /* DPR_TIMEOUT */

/* Delay where the connection is maintained opened to allow exchanging remaining pending answers after DPR/DPA */
#ifndef GRACE_TIMEOUT
#define GRACE_TIMEOUT   1	/* in seconds */
#endif /* GRACE_TIMEOUT */

/* The Vendor-Id to advertise in CER/CEA */
#ifndef MY_VENDOR_ID
#define MY_VENDOR_ID	0 	/* Reserved value to tell it must be ignored */
#endif /* MY_VENDOR_ID */



/* Configuration */
int fd_conf_init();
int fd_conf_deinit();
int fd_conf_parse();
int fddparse(struct fd_config * conf); /* yacc generated */
int fd_conf_stream_to_gnutls_datum(FILE * pemfile, gnutls_datum_t *out);


/* Extensions */
int fd_ext_add( char * filename, char * conffile );
int fd_ext_load();
int fd_ext_term(void);

/* Messages */
int fd_msg_init(void);
extern struct dict_object * fd_dict_avp_OSI; /* Origin-State-Id */
extern struct dict_object * fd_dict_cmd_CER; /* Capabilities-Exchange-Request */
extern struct dict_object * fd_dict_cmd_DWR; /* Device-Watchdog-Request */
extern struct dict_object * fd_dict_avp_DC;  /* Disconnect-Cause */
extern struct dict_object * fd_dict_cmd_DPR; /* Disconnect-Peer-Request */

/* Global message queues */
extern struct fifo * fd_g_incoming; /* all messages received from other peers, except local messages (CER, ...) */
extern struct fifo * fd_g_outgoing; /* messages to be sent to other peers on the network following routing procedure */
extern struct fifo * fd_g_local; /* messages to be handled to local extensions */
/* Message queues */
int fd_queues_init(void);
int fd_queues_init_after_conf(void);
int fd_queues_fini(struct fifo ** queue);

/* Trigged events */
int fd_event_trig_call_cb(int trigger_val);
int fd_event_trig_fini(void);

/* Create all the dictionary objects defined in the Diameter base RFC. */
int fd_dict_base_protocol(struct dictionary * dict);

/* Routing */
int fd_rtdisp_init(void);
int fd_rtdisp_cleanstop(void);
int fd_rtdisp_fini(void);
int fd_rtdisp_cleanup(void);

/* Sentinel for the sent requests list */
struct sr_list {
	struct fd_list 	srs; /* requests ordered by hop-by-hop id */
	struct fd_list  exp; /* requests that have a timeout set, ordered by timeout */
	long            cnt; /* number of requests in the srs list */
	long		cnt_lost; /* number of requests that have not been answered in time. 
				     It is decremented when an unexpected answer is received, so this may not be accurate. */
	pthread_mutex_t	mtx; /* mutex to protect these lists */
	pthread_cond_t  cnd; /* cond var used by the thread that handles timeouts */
	pthread_t       thr; /* the thread that handles timeouts (expirecb called in separate forked threads) */
};

/* Peers */
struct fd_peer { /* The "real" definition of the peer structure */
	
	/* The public data */
	struct peer_hdr	 p_hdr;
	
	/* Eye catcher, EYEC_PEER */
	int		 p_eyec;
	#define EYEC_PEER	0x373C9336
	
	/* Origin of this peer object, for debug */
	char		*p_dbgorig;
	
	/* State of the peer, and its lock */
	enum peer_state	 p_state;
	pthread_mutex_t  p_state_mtx;
	
	/* Chaining in peers sublists */
	struct fd_list	 p_actives;	/* list of peers in the STATE_OPEN state -- used by routing */
	struct fd_list	 p_expiry; 	/* list of expiring peers, ordered by their timeout value */
	struct timespec	 p_exp_timer;	/* Timestamp where the peer will expire; updated each time activity is seen on the peer (except DW) */
	
	/* Some flags influencing the peer state machine */
	struct {
		unsigned pf_responder	: 1;	/* The peer has been created to handle incoming connection */
		unsigned pf_delete	: 1;	/* Destroy the peer when the connection is terminated */
		unsigned pf_localterm	: 1;	/* If the latest DPR/DPA was initiated from this side */
		
		unsigned pf_dw_pending 	: 1;	/* A DWR message was sent and not answered yet */
		
		unsigned pf_cnx_pb	: 1;	/* The peer was disconnected because of watchdogs; must exchange 3 watchdogs before putting back to normal */
		unsigned pf_reopen_cnt	: 2;	/* remaining DW to be exchanged after re-established connection */
		
	}		 p_flags;
	
	/* The events queue, peer state machine thread, timer for states timeouts */
	struct fifo	*p_events;	/* The mutex of this FIFO list protects also the state and timer information */
	pthread_t	 p_psm;
	struct timespec	 p_psm_timer;
	
	/* Outgoing message queue, and thread managing sending the messages */
	struct fifo	*p_tosend;
	pthread_t	 p_outthr;
	
	/* The next hop-by-hop id value for the link, only read & modified by p_outthr */
	uint32_t	 p_hbh;
	
	/* Sent requests (for fallback), list of struct sentreq ordered by hbh */
	struct sr_list	 p_sr;
	struct fifo	*p_tofailover;
	
	/* Pending received requests not yet answered (count only) */
	long		 p_reqin_count; /* We use p_state_mtx to protect this value */
	
	/* Data for transitional states before the peer is in OPEN state */
	struct {
		struct cnxctx * p_receiver;	/* Only used in case of election */
		struct msg    * p_cer;		/* Only used in case of election */
		
		pthread_t	p_ini_thr;	/* Initiator thread for establishing a connection */
		struct fd_list  p_connparams;	/* The list of connection attempts, see p_cnx.c */
	};
	
	/* connection context: socket and related information */
	struct cnxctx	*p_cnxctx;
	
	/* Callback for peer validation after the handshake */
	int		(*p_cb2)(struct peer_info *);
	
	/* Callback on initial connection success / failure after the peer was added */
	void 		(*p_cb)(struct peer_info *, void *);
	void 		*p_cb_data;
	
};
#define CHECK_PEER( _p ) \
	(((_p) != NULL) && (((struct fd_peer *)(_p))->p_eyec == EYEC_PEER))

#define fd_peer_getstate(peer)  fd_peer_get_state((struct peer_hdr *)(peer))


/* Events codespace for struct fd_peer->p_events */
enum {
	/* request to terminate this peer : disconnect, requeue all messages */
	FDEVP_TERMINATE = 1500
	
	/* A connection object has received a message. (data contains the buffer + padding + struct fd_msg_pmdl) */
	,FDEVP_CNX_MSG_RECV
			 
	/* A connection object has encountered an error (disconnected). */
	,FDEVP_CNX_ERROR
	
	/* Endpoints of a connection have been changed (multihomed SCTP). */
	,FDEVP_CNX_EP_CHANGE
	
	/* The connection is being shutdown (SCTP notification). */
	,FDEVP_CNX_SHUTDOWN
	
	/* A new connection (with a CER) has been received */
	,FDEVP_CNX_INCOMING
	
	/* A new connection has been established to the remote peer (event data is the cnxctx object) */
	,FDEVP_CNX_ESTABLISHED
	
	/* A connection attempt (initiator side) has failed */
	,FDEVP_CNX_FAILED
	
	/* The PSM state is expired */
	,FDEVP_PSM_TIMEOUT
	
};
#define CHECK_PEVENT( _e ) \
	(((int)(_e) >= FDEVP_TERMINATE) && ((int)(_e) <= FDEVP_PSM_TIMEOUT))
/* The following macro is actually called in p_psm.c -- another solution would be to declare it static inline */
#define DECLARE_PEV_STR()				\
const char * fd_pev_str(int event)			\
{							\
	switch (event) {				\
		case_str(FDEVP_TERMINATE);		\
		case_str(FDEVP_CNX_MSG_RECV);		\
		case_str(FDEVP_CNX_ERROR);		\
		case_str(FDEVP_CNX_EP_CHANGE);		\
		case_str(FDEVP_CNX_INCOMING);		\
		case_str(FDEVP_CNX_ESTABLISHED);	\
		case_str(FDEVP_CNX_FAILED);		\
		case_str(FDEVP_PSM_TIMEOUT);		\
	}						\
	TRACE_DEBUG(FULL, "Unknown event : %d", event);	\
	return "Unknown event";				\
}
const char * fd_pev_str(int event);

/* The data structure for FDEVP_CNX_INCOMING event */
struct cnx_incoming {
	struct msg	* cer;		/* the CER message received on this connection */
	struct cnxctx	* cnx;		/* The connection context */
	int  		  validate;	/* The peer is new, it must be validated (by an extension) or error CEA to be sent */
};

/* Functions */
int  fd_peer_fini();
int  fd_peer_alloc(struct fd_peer ** ptr);
int  fd_peer_free(struct fd_peer ** ptr);
int fd_peer_handle_newCER( struct msg ** cer, struct cnxctx ** cnx );
/* fd_peer_add declared in freeDiameter.h */
int fd_peer_validate( struct fd_peer * peer );
void fd_peer_failover_msg(struct fd_peer * peer);

/* Peer expiry */
int fd_p_expi_init(void);
int fd_p_expi_fini(void);
int fd_p_expi_update(struct fd_peer * peer );

/* Peer state machine */
int  fd_psm_start();
int  fd_psm_begin(struct fd_peer * peer );
int  fd_psm_terminate(struct fd_peer * peer, char * reason );
void fd_psm_abord(struct fd_peer * peer );
void fd_psm_next_timeout(struct fd_peer * peer, int add_random, int delay);
int fd_psm_change_state(struct fd_peer * peer, int new_state);
void fd_psm_cleanup(struct fd_peer * peer, int terminate);

/* Peer out */
int fd_out_send(struct msg ** msg, struct cnxctx * cnx, struct fd_peer * peer, int update_reqin_cnt);
int fd_out_start(struct fd_peer * peer);
int fd_out_stop(struct fd_peer * peer);

/* Initiating connections */
int fd_p_cnx_init(struct fd_peer * peer);
void fd_p_cnx_abort(struct fd_peer * peer, int cleanup_all);

/* Peer sent requests cache */
int fd_p_sr_store(struct sr_list * srlist, struct msg **req, uint32_t *hbhloc, uint32_t hbh_restore);
int fd_p_sr_fetch(struct sr_list * srlist, uint32_t hbh, struct msg **req);
int fd_p_sr_start(struct sr_list * srlist);
int fd_p_sr_stop(struct sr_list * srlist);
void fd_p_sr_failover(struct sr_list * srlist);

/* Local Link messages (CER/CEA, DWR/DWA, DPR/DPA) */
int fd_p_ce_msgrcv(struct msg ** msg, int req, struct fd_peer * peer);
int fd_p_ce_handle_newCER(struct msg ** msg, struct fd_peer * peer, struct cnxctx ** cnx, int valid);
int fd_p_ce_handle_newcnx(struct fd_peer * peer, struct cnxctx * initiator);
int fd_p_ce_process_receiver(struct fd_peer * peer);
void fd_p_ce_clear_cnx(struct fd_peer * peer, struct cnxctx ** cnx_kept);
int fd_p_dw_handle(struct msg ** msg, int req, struct fd_peer * peer);
int fd_p_dw_timeout(struct fd_peer * peer);
int fd_p_dw_reopen(struct fd_peer * peer);
int fd_p_dp_handle(struct msg ** msg, int req, struct fd_peer * peer);
int fd_p_dp_initiate(struct fd_peer * peer, char * reason);
int fd_p_dp_newdelay(struct fd_peer * peer);

/* Active peers -- routing process should only ever take the read lock, the write lock is managed by PSMs */
extern struct fd_list fd_g_activ_peers;
extern pthread_rwlock_t fd_g_activ_peers_rw; /* protect the list */


/* Server sockets */
int  fd_servers_start();
int  fd_servers_stop();

/* Connection contexts -- there are also definitions in cnxctx.h for the relevant files */
struct cnxctx * fd_cnx_serv_tcp(uint16_t port, int family, struct fd_endpoint * ep);
struct cnxctx * fd_cnx_serv_sctp(uint16_t port, struct fd_list * ep_list);
int             fd_cnx_serv_listen(struct cnxctx * conn);
struct cnxctx * fd_cnx_serv_accept(struct cnxctx * serv);
struct cnxctx * fd_cnx_cli_connect_tcp(sSA * sa, socklen_t addrlen);
struct cnxctx * fd_cnx_cli_connect_sctp(int no_ip6, uint16_t port, struct fd_list * list);
int             fd_cnx_start_clear(struct cnxctx * conn, int loop);
void		fd_cnx_sethostname(struct cnxctx * conn, DiamId_t hn);
int		fd_cnx_proto_info(struct cnxctx * conn, char * buf, size_t len);
#define ALGO_HANDSHAKE_DEFAULT	0 /* TLS for TCP, DTLS for SCTP */
#define ALGO_HANDSHAKE_3436	1 /* For TLS for SCTP also */
int             fd_cnx_handshake(struct cnxctx * conn, int mode, int algo, char * priority, void * alt_creds);
char *          fd_cnx_getid(struct cnxctx * conn);
int		fd_cnx_getproto(struct cnxctx * conn);
int		fd_cnx_getTLS(struct cnxctx * conn);
int		fd_cnx_is_unordered_delivery_supported(struct cnxctx * conn);
int		fd_cnx_unordered_delivery(struct cnxctx * conn, int is_allowed);
int             fd_cnx_getcred(struct cnxctx * conn, const gnutls_datum_t **cert_list, unsigned int *cert_list_size);
int 		fd_cnx_get_local_eps(struct fd_list * list);
int             fd_cnx_getremoteeps(struct cnxctx * conn, struct fd_list * eps);
char *          fd_cnx_getremoteid(struct cnxctx * conn);
int             fd_cnx_receive(struct cnxctx * conn, struct timespec * timeout, unsigned char **buf, size_t * len);
int             fd_cnx_recv_setaltfifo(struct cnxctx * conn, struct fifo * alt_fifo); /* send FDEVP_CNX_MSG_RECV event to the fifo list */
int             fd_cnx_send(struct cnxctx * conn, unsigned char * buf, size_t len);
void            fd_cnx_destroy(struct cnxctx * conn);
#ifdef GNUTLS_VERSION_300
int             fd_tls_verify_credentials_2(gnutls_session_t session);
#endif /* GNUTLS_VERSION_300 */

/* Internal calls of the hook mechanism */
void   fd_hook_call(enum fd_hook_type type, struct msg * msg, struct fd_peer * peer, void * other, struct fd_msg_pmdl * pmdl);
void   fd_hook_associate(struct msg * msg, struct fd_msg_pmdl * pmdl);
int    fd_hooks_init(void);
size_t fd_msg_pmdl_sizewithoverhead(size_t datalen);
struct fd_msg_pmdl * fd_msg_pmdl_get_inbuf(uint8_t * buf, size_t datalen); 

#endif /* _FDCORE_INTERNAL_H */
"Welcome to our mercurial repository"