comparison freeDiameter/p_psm.c @ 40:7e1deaa89540

Some progress on the PSM
author Sebastien Decugis <sdecugis@nict.go.jp>
date Fri, 06 Nov 2009 13:05:36 +0900
parents 68c1890f7049
children f4d94bc65e1f
comparison
equal deleted inserted replaced
39:d7535cf7bab5 40:7e1deaa89540
245 void fd_psm_cleanup(struct fd_peer * peer, int terminate) 245 void fd_psm_cleanup(struct fd_peer * peer, int terminate)
246 { 246 {
247 /* Move to CLOSED state: failover messages, stop OUT thread, unlink peer from active list */ 247 /* Move to CLOSED state: failover messages, stop OUT thread, unlink peer from active list */
248 CHECK_FCT_DO( fd_psm_change_state(peer, STATE_CLOSED), /* continue */ ); 248 CHECK_FCT_DO( fd_psm_change_state(peer, STATE_CLOSED), /* continue */ );
249 249
250
251 fd_p_cnx_abort(peer, terminate); 250 fd_p_cnx_abort(peer, terminate);
252 251
253 if (peer->p_cnxctx) { 252 if (peer->p_cnxctx) {
254 fd_cnx_destroy(peer->p_cnxctx); 253 fd_cnx_destroy(peer->p_cnxctx);
255 peer->p_cnxctx = NULL; 254 peer->p_cnxctx = NULL;
465 } 464 }
466 465
467 /* Handle the LL message and update the expiry timer appropriately */ 466 /* Handle the LL message and update the expiry timer appropriately */
468 switch (hdr->msg_code) { 467 switch (hdr->msg_code) {
469 case CC_CAPABILITIES_EXCHANGE: 468 case CC_CAPABILITIES_EXCHANGE:
470 CHECK_FCT_DO( fd_p_ce_handle(&msg, peer), goto psm_end ); 469 CHECK_FCT_DO( fd_p_ce_msgrcv(&msg, (hdr->msg_flags & CMD_FLAG_REQUEST), peer), goto psm_end );
471 break; 470 break;
472 471
473 case CC_DISCONNECT_PEER: 472 case CC_DISCONNECT_PEER:
474 CHECK_FCT_DO( fd_p_dp_handle(&msg, peer), goto psm_end ); 473 CHECK_FCT_DO( fd_p_dp_handle(&msg, (hdr->msg_flags & CMD_FLAG_REQUEST), peer), goto psm_end );
475 break; 474 break;
476 475
477 case CC_DEVICE_WATCHDOG: 476 case CC_DEVICE_WATCHDOG:
478 CHECK_FCT_DO( fd_p_dw_handle(&msg, peer), goto psm_end ); 477 CHECK_FCT_DO( fd_p_dw_handle(&msg, (hdr->msg_flags & CMD_FLAG_REQUEST), peer), goto psm_end );
479 break; 478 break;
480 479
481 default: 480 default:
482 /* Unknown / unexpected / invalid message */ 481 /* Unknown / unexpected / invalid message */
483 fd_log_debug("Received an unknown local message from peer '%s', discarded.\n", peer->p_hdr.info.pi_diamid); 482 fd_log_debug("Received an unknown local message from peer '%s', discarded.\n", peer->p_hdr.info.pi_diamid);
587 /* Loop */ 586 /* Loop */
588 free(ev_data); 587 free(ev_data);
589 goto psm_loop; 588 goto psm_loop;
590 } 589 }
591 590
591 /* A new connection has been established with the remote peer */
592 if (event == FDEVP_CNX_ESTABLISHED) {
593 struct cnxctx * cnx = ev_data;
594
595 /* Release the resources of the thread */
596 CHECK_POSIX_DO( pthread_join( peer->p_ini_thr, NULL), /* ignore, it is not a big deal */);
597 peer->p_ini_thr = (pthread_t)NULL;
598
599 switch (peer->p_hdr.info.runtime.pir_state) {
600 case STATE_WAITCNXACK_ELEC:
601 case STATE_WAITCNXACK:
602 fd_p_ce_handle_newcnx(peer, cnx);
603 break;
604
605 default:
606 /* Just abort the attempt and continue */
607 TRACE_DEBUG(FULL, "Connection attempt successful but current state is %s, closing...", STATE_STR(peer->p_hdr.info.runtime.pir_state));
608 fd_cnx_destroy(cnx);
609 }
610
611 goto psm_loop;
612 }
613
592 /* The timeout for the current state has been reached */ 614 /* The timeout for the current state has been reached */
593 if (event == FDEVP_PSM_TIMEOUT) { 615 if (event == FDEVP_PSM_TIMEOUT) {
594 switch (peer->p_hdr.info.runtime.pir_state) { 616 switch (peer->p_hdr.info.runtime.pir_state) {
595 case STATE_OPEN: 617 case STATE_OPEN:
596 case STATE_REOPEN: 618 case STATE_REOPEN:
611 fd_psm_cleanup(peer, 0); 633 fd_psm_cleanup(peer, 0);
612 fd_psm_next_timeout(peer, 1, peer->p_hdr.info.config.pic_tctimer ?: fd_g_config->cnf_timer_tc); 634 fd_psm_next_timeout(peer, 1, peer->p_hdr.info.config.pic_tctimer ?: fd_g_config->cnf_timer_tc);
613 break; 635 break;
614 636
615 case STATE_WAITCNXACK_ELEC: 637 case STATE_WAITCNXACK_ELEC:
616 TODO("Abort initiating side, handle the receiver side"); 638
639 /* Abort the initiating side */
640 fd_p_cnx_abort(peer, 0);
641
642 /* Handle receiver side */
643 CHECK_FCT_DO( fd_p_ce_winelection(peer), goto psm_end );
617 break; 644 break;
618 } 645 }
619 } 646 }
620 647
621 /* Default action : the handling has not yet been implemented. [for debug only] */ 648 /* Default action : the handling has not yet been implemented. [for debug only] */
622 TODO("Missing handler in PSM : '%s'\t<-- '%s'", STATE_STR(peer->p_hdr.info.runtime.pir_state), fd_pev_str(event)); 649 TODO("Missing handler in PSM : '%s'\t<-- '%s'", STATE_STR(peer->p_hdr.info.runtime.pir_state), fd_pev_str(event));
623 if (event == FDEVP_PSM_TIMEOUT) { 650 if (event == FDEVP_PSM_TIMEOUT) {
624 /* We have not handled timeout in this state, let's postpone next alert */ 651 /* We have not handled timeout in this state, let's postpone next alert to avoid flood */
625 fd_psm_next_timeout(peer, 0, 60); 652 fd_psm_next_timeout(peer, 0, 60);
626 } 653 }
627 654
628 goto psm_loop; 655 goto psm_loop;
629 656
"Welcome to our mercurial repository"