# HG changeset patch # User Sebastien Decugis # Date 1218072925 -32400 # Node ID 67ec7dba49b18c5472646ef12a3ec560bb7ad94f # Parent 953b8cc6357a5b0ed4b18243f1b3819814802341 A few progress, still lot to do diff -r 953b8cc6357a -r 67ec7dba49b1 waaad/peer-internal.h --- a/waaad/peer-internal.h Tue Aug 05 17:26:05 2008 +0900 +++ b/waaad/peer-internal.h Thu Aug 07 10:35:25 2008 +0900 @@ -59,6 +59,7 @@ #include #include #include +#include /* States of a peer */ typedef enum { @@ -66,14 +67,14 @@ STATE_DISABLED = 1, /* No connexion must be attempted */ STATE_OPEN, /* Connexion established */ /* Transitional states */ - STATE_CLOSED, /* No connexion established */ + STATE_SUSPECT, /* Connexion established but maybe broken */ + STATE_CLOSED, /* No connexion established, will re-attempt after TcTimer. */ STATE_CLOSING, /* the connexion is being shutdown */ STATE_WAIT_CNX, /* Trying to establish a connexion at transport level, waiting for ACK/NACK or new cnx initiated by remote peer (concurrent attempts) */ STATE_WAIT_CEA /* CER has been sent, waiting for CEA or timeout */ /* TBC... */ /* Other states from the RFC: are they needed? Wait-Conn-Ack/Elect, Wait-Returns */ - /* Also need the states for "Suspect" peers from the watchdog mechanism. */ } peer_state_t; @@ -101,8 +102,12 @@ struct _pi *next; struct _pi *prev; struct _peer *top; + struct _pi *sentinel; } _pi_t; +/* Flags definitions */ +#define PEERFL_DYNAMIC ( 1 << 0 ) /* The peer is not statically configured and will expire */ +#define PEERFL_EXPIRETS ( 1 << 1 ) /* The peer expires at the p_expire time. If not set, the peer expires at transport disconnection */ /* Peer internal description */ typedef struct _peer { @@ -110,14 +115,21 @@ _pi_t p_global; /* List of peers this peer belongs to */ _pi_t p_active; /* Sublist containing only the active peers */ + /* For debug only */ + uint32_t p_eyec; /* An eyecatcher to verify object is valid. Must be PEER_EYEC. */ + /* Peer data */ char *p_diamid; /* The Diameter-Id of this peer, once known */ + char *p_realm; /* pointer to the beginning of the realm in the diamid string. */ uint32_t p_hbh; /* current Hop-by-hop value */ pthread_mutex_t p_lock; /* Mutex to protect this object */ /* Peer state */ peer_state_t p_state; /* State of the peer */ pthread_t p_psm; /* The thread handling this peer state machine. */ + uint32_t p_flags; /* Some PEERFL_* flags */ + struct timespec p_expire; /* Lifetime of the peer, for dynamic peers */ + struct timespec p_ts; /* multi-purpose timespec (meaning depends on the state) */ /* Messages handling */ meq_t *p_in_q; /* Incoming message queue */ @@ -145,34 +157,49 @@ } _peer_t; /* The peers global vars */ -extern _pi_t g_peer_list_all; /* The peers for which the diameter id is known */ +extern _pi_t g_peer_list_valid; /* The peers for which the diameter id is known */ extern _pi_t g_peer_list_active; /* Sentinel for the p_active list, sublist of g_peer_list_all */ extern _pi_t g_peer_list_unknown; /* List of the peers that have not yet advertized their Diameter-Id */ -extern pthread_mutex_t g_peer_list_lock; /* Protect the lists */ +extern _pi_t g_peer_list_deleted; /* Peers that have expired and are in grace period for being removed */ +extern pthread_mutex_t g_peer_list_lock; /* Protect the lists. We use only one lock for simplicity. */ + +/* The eye-catcher value */ +#define PEER_EYEC 0x23350B7 + +/* Cast macro */ +#define _P( _peerptr_ ) ((_peer_t *)( _peerptr_ )) +#define _PI( _piptr_ ) ( (_pi_t *) (_piptr_) ) + +/* Check macro */ +#define VALIDATE_PEER( _peer_ ) \ + (((_peer_) != NULL) \ + && (_P(_peer_)->p_eyec == PEER_EYEC) \ + && (_PI(_peer_)->sentinel != &g_peer_list_deleted)) + /* * The functions */ -/* Terminate a thread by cancelling it */ -int _peer_cancel_th(pthread_t * thread); - -/* Code of the listening threads */ -void * _peer_listen_th(void * arg); - /* Open listening sockets */ int _listen_sctp(int * sock); int _listen_tcp(int * sock); -/* Code of the thread for the peer state machine */ +/* Code of the listening thread (one per listening socket) */ +void * _peer_listen_th(void * arg); + +/* Code of the thread for the peer state machine (one per peer) */ void * _peer_state_machine_th(void * arg); -/* Code of the thread for outgoing messages */ +/* Code of the thread for outgoing messages (one per peer) */ void * _peer_out_th(void * arg); -/* Code of the thread for incoming messages */ +/* Code of the thread for incoming messages (one per peer) */ void * _peer_in_th(void * arg); +/* Terminate a thread by canceling it */ +int _peer_cancel_th(pthread_t * thread); + #endif /* ! _PEER_INTERNAL_H */