Navigation


Changeset 16:013ce9851131 in freeDiameter for freeDiameter/p_psm.c


Ignore:
Timestamp:
Oct 2, 2009, 6:57:06 PM (15 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Started including TLS code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • freeDiameter/p_psm.c

    r14 r16  
    3737
    3838const char *peer_state_str[] = {
    39           "STATE_ZOMBIE"
     39          "STATE_NEW"
    4040        , "STATE_OPEN"
    4141        , "STATE_CLOSED"
     
    4646        , "STATE_SUSPECT"
    4747        , "STATE_REOPEN"
     48        , "STATE_ZOMBIE"
    4849        };
    4950
     
    123124}
    124125
     126/* Wait for the next event in the PSM, or timeout */
    125127static int psm_ev_timedget(struct fd_peer * peer, int *code, void ** data)
    126128{
     
    142144       
    143145        return 0;
    144 }       
    145 
    146 /* The state machine thread */
     146}
     147
     148/* The state machine thread (controler) */
    147149static void * p_psm_th( void * arg )
    148150{
    149151        struct fd_peer * peer = (struct fd_peer *)arg;
    150152        int created_started = started;
     153        int event;
     154        void * ev_data;
    151155       
    152156        CHECK_PARAMS_DO( CHECK_PEER(peer), ASSERT(0) );
     
    161165        }
    162166       
    163         /* Wait that the PSM are authorized to start in the daemon */
    164         CHECK_FCT_DO( fd_psm_waitstart(), goto end );
    165        
    166167        /* The state machine starts in CLOSED state */
    167168        peer->p_hdr.info.pi_state = STATE_CLOSED;
     169       
     170        /* Wait that the PSM are authorized to start in the daemon */
     171        CHECK_FCT_DO( fd_psm_waitstart(), goto psm_end );
    168172       
    169173        /* Initialize the timer */
     
    174178        }
    175179       
    176 psm:
    177         do {
    178                 int event;
    179                 void * ev_data;
    180                
    181                 /* Get next event */
    182                 CHECK_FCT_DO( psm_ev_timedget(peer, &event, &ev_data), goto end );
    183                 TRACE_DEBUG(FULL, "'%s'\t<-- '%s'\t(%p)\t'%s'",
    184                                 STATE_STR(peer->p_hdr.info.pi_state),
    185                                 fd_pev_str(event), ev_data,
    186                                 peer->p_hdr.info.pi_diamid);
    187                
    188                 /* Now, the action depends on the current state and the incoming event */
    189                
    190        
    191         } while (1);   
    192        
    193        
    194 end:   
    195         /* set STATE_ZOMBIE */
    196         pthread_cleanup_pop(1);
     180psm_loop:
     181        /* Get next event */
     182        CHECK_FCT_DO( psm_ev_timedget(peer, &event, &ev_data), goto psm_end );
     183        TRACE_DEBUG(FULL, "'%s'\t<-- '%s'\t(%p)\t'%s'",
     184                        STATE_STR(peer->p_hdr.info.pi_state),
     185                        fd_pev_str(event), ev_data,
     186                        peer->p_hdr.info.pi_diamid);
     187
     188        /* Now, the action depends on the current state and the incoming event */
     189
     190        /* The following two states are impossible */
     191        ASSERT( peer->p_hdr.info.pi_state != STATE_NEW );
     192        ASSERT( peer->p_hdr.info.pi_state != STATE_ZOMBIE );
     193
     194        /* Purge invalid events */
     195        if (!CHECK_EVENT(event)) {
     196                TRACE_DEBUG(INFO, "Invalid event received in PSM '%s' : %d", peer->p_hdr.info.pi_diamid, event);
     197                goto psm_loop;
     198        }
     199
     200        /* Handle the (easy) debug event now */
     201        if (event == FDEVP_DUMP_ALL) {
     202                fd_peer_dump(peer, ANNOYING);
     203                goto psm_loop;
     204        }
     205
     206        /* Requests to terminate the peer object */
     207        if (event == FDEVP_TERMINATE) {
     208                switch (peer->p_hdr.info.pi_state) {
     209                        case STATE_CLOSING:
     210                        case STATE_WAITCNXACK:
     211                        case STATE_WAITCNXACK_ELEC:
     212                        case STATE_WAITCEA:
     213                        case STATE_SUSPECT:
     214                                /* In these cases, we just cleanup the peer object and terminate now */
     215                                TODO("Cleanup the PSM: terminate connection object, ...");
     216                        case STATE_CLOSED:
     217                                /* Then we just terminate the PSM */
     218                                goto psm_end;
     219                               
     220                        case STATE_OPEN:
     221                        case STATE_REOPEN:
     222                                /* We cannot just close the conenction, we have to send a DPR first */
     223                                TODO("Send DPR, mark the peer as CLOSING");
     224                                goto psm_loop;
     225                }
     226        }
     227       
     228        /* MSG_RECEIVED: fd_p_expi_update(struct fd_peer * peer ) */
     229        /* If timeout or OPEN : call cb if defined */
     230
     231        /* Default action : the handling has not yet been implemented. */
     232        TODO("Missing handler in PSM : '%s'\t<-- '%s'", STATE_STR(peer->p_hdr.info.pi_state), fd_pev_str(event));
     233        if (event == FDEVP_PSM_TIMEOUT) {
     234                /* We have not handled timeout in this state, let's postpone next alert */
     235                psm_next_timeout(peer, 0, 60);
     236        }
     237       
     238        goto psm_loop;
     239       
     240psm_end:
     241        pthread_cleanup_pop(1); /* set STATE_ZOMBIE */
    197242        return NULL;
    198243}       
     
    205250{
    206251        TRACE_ENTRY("%p", peer);
    207         TODO("");
    208         return ENOTSUP;
     252       
     253        /* Check the peer and state are OK */
     254        CHECK_PARAMS( CHECK_PEER(peer) && (peer->p_hdr.info.pi_state == STATE_NEW) );
     255       
     256        /* Create the PSM controler thread */
     257        CHECK_POSIX( pthread_create( &peer->p_psm, NULL, p_psm_th, peer ) );
     258       
     259        /* We're done */
     260        return 0;
    209261}
    210262
     
    214266        TRACE_ENTRY("%p", peer);
    215267        CHECK_PARAMS( CHECK_PEER(peer) );
    216         CHECK_FCT( fd_event_send(peer->p_events, FDEVP_TERMINATE, NULL) );
     268        if (peer->p_hdr.info.pi_state != STATE_ZOMBIE) {
     269                CHECK_FCT( fd_event_send(peer->p_events, FDEVP_TERMINATE, NULL) );
     270        } else {
     271                TRACE_DEBUG(FULL, "Peer '%s' was already terminated", peer->p_hdr.info.pi_diamid);
     272        }
    217273        return 0;
    218274}
     
    225281        TODO("Cancel IN thread");
    226282        TODO("Cancel OUT thread");
    227         TODO("Cleanup the connection");
     283        TODO("Cleanup the peer connection object");
     284        TODO("Cleanup the message queues (requeue)");
    228285        return;
    229286}
Note: See TracChangeset for help on using the changeset viewer.