浏览代码

*** empty log message ***

Bogdan-Andrei Iancu 24 年之前
父节点
当前提交
ca6852b2d0
共有 5 个文件被更改,包括 44 次插入24 次删除
  1. 1 1
      modules/tm/Makefile
  2. 0 2
      modules/tm/h_table.h
  3. 28 16
      modules/tm/t_funcs.c
  4. 13 3
      modules/tm/timer.c
  5. 2 2
      modules/tm/timer.h

+ 1 - 1
modules/tm/Makefile

@@ -13,7 +13,7 @@ depends= $(sources:.c=.d)
 NAME=tm.so
 
 SHLIB_LD_FLAGS= -shared
-LIBS= #-lpthread
+LIBS= -lpthread
 
 ifeq ($(ARCH), SunOS)
 LDFLAGS=-O2 -G

+ 0 - 2
modules/tm/h_table.h

@@ -3,9 +3,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#ifdef THREADS
 #include <pthread.h>
-#endif
 #include <arpa/inet.h>
 
 #include "../../msg_parser.h"

+ 28 - 16
modules/tm/t_funcs.c

@@ -198,6 +198,8 @@ int t_lookup_request( struct sip_msg* p_msg, char* foo, char* bar  )
  */
 int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int dest_port_param )
 {
+   unsigned int dest_ip     = dest_ip_param;
+   unsigned int dest_port  = dest_port_param;
    int	branch = 0;	/* we don't do any forking right now */
 
    /* it's about the same transaction or not? */
@@ -226,8 +228,6 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
    /* if it's forwarded for the first time ; else the request is retransmited from the transaction buffer */
    if ( T->outbound_request[branch]==NULL )
    {
-      unsigned int dest_ip     = dest_ip_param;
-      unsigned int dest_port  = dest_port_param;
       unsigned int len;
       char               *buf;
 
@@ -265,11 +265,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
       /* store */
       DBG("DEBUG: t_forward: building outbound request\n");
       T->outbound_request[branch]->tl[RETRASMISSIONS_LIST].payload = &(T->outbound_request[branch]);
-      T->outbound_request[branch]->dest_ip         = dest_ip;
-      T->outbound_request[branch]->dest_port      = dest_port;
       T->outbound_request[branch]->to.sin_family = AF_INET;
-      T->outbound_request[branch]->to.sin_port     =  dest_port;
-      T->outbound_request[branch]->to.sin_addr.s_addr =  dest_ip;
 
       if (add_branch_label( T, p_msg , branch )==-1) return -1;
       buf = build_req_buf_from_sip_req  ( p_msg, &len);
@@ -286,7 +282,7 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
 
       DBG("DEBUG: t_forward: starting timers (retrans and FR)\n");
       /*sets and starts the FINAL RESPONSE timer */
-      add_to_tail_of_timer_list( hash_table , &(T->outbound_request[branch]->tl[FR_TIMER_LIST]) , FR_TIMER_LIST, FR_TIME_OUT );
+      //add_to_tail_of_timer_list( hash_table , &(T->outbound_request[branch]->tl[FR_TIMER_LIST]) , FR_TIMER_LIST, FR_TIME_OUT );
 
       /* sets and starts the RETRANS timer */
       T->outbound_request[branch]->timeout_ceiling  = RETR_T2;
@@ -298,6 +294,10 @@ int t_forward( struct sip_msg* p_msg , unsigned int dest_ip_param , unsigned int
 	T->outbound_request[branch]->bufflen, T->outbound_request[branch]->bufflen,
 	 T->outbound_request[branch]->buffer);
    /* send the request */
+   T->outbound_request[branch]->dest_ip         = dest_ip;
+   T->outbound_request[branch]->dest_port      = dest_port;
+   T->outbound_request[branch]->to.sin_port     =  dest_port;
+   T->outbound_request[branch]->to.sin_addr.s_addr =  dest_ip;
    udp_send( T->outbound_request[branch]->buffer , T->outbound_request[branch]->bufflen ,
                     (struct sockaddr*)&(T->outbound_request[branch]->to) , sizeof(struct sockaddr_in) );
    return 1;
@@ -1006,7 +1006,7 @@ int t_build_and_send_ACK( struct cell *Trans, unsigned int branch)
    memcpy( p, MY_BRANCH, MY_BRANCH_LEN );
    p+=MY_BRANCH_LEN;
 
-   n=snprintf( p, ack_buf + MAX_ACK_LEN - p, 
+   n=snprintf( p, ack_buf + MAX_ACK_LEN - p,
                  ".%x.%x.%x%s",
                  Trans->hash_index, Trans->label, branch, CRLF );
 
@@ -1037,8 +1037,8 @@ int t_build_and_send_ACK( struct cell *Trans, unsigned int branch)
 	goto error;
    }
    /* CSeq, EoH */
-   n=snprintf( p, ack_buf + MAX_ACK_LEN - p, 
-                 "Cseq: %*s ACK%s%s", get_cseq(p_msg)->number.len, 
+   n=snprintf( p, ack_buf + MAX_ACK_LEN - p,
+                 "Cseq: %*s ACK%s%s", get_cseq(p_msg)->number.len,
 		get_cseq(p_msg)->number.s, CRLF, CRLF );
    if (n==-1) {
 	LOG(L_ERR, "ERROR: t_build_and_send_ACK: no enough memory for Cseq\n");
@@ -1069,16 +1069,20 @@ void retransmission_handler( void *attr)
    struct retrans_buff* r_buf = (struct retrans_buff*)attr;
 
    /* the transaction is already removed from RETRANSMISSION_LIST by the timer */
+   DBG("DEBUG: retransmission_handler : payload received=%p\n",attr);
 
    /* computs the new timeout. */
    if ( r_buf->timeout_value<r_buf->timeout_ceiling )
       r_buf->timeout_value *=2;
 
    /* retransmision */
-   udp_send( r_buf->buffer, r_buf->bufflen, (struct sockaddr*)&(r_buf->to) , sizeof(struct sockaddr_in) );
+   DBG("DEBUG: retransmission_handler : resending\n");
+   //udp_send( r_buf->buffer, r_buf->bufflen, (struct sockaddr*)&(r_buf->to) , sizeof(struct sockaddr_in) );
 
    /* re-insert into RETRASMISSIONS_LIST */
+   DBG("DEBUG: retransmission_handler : before insert\n");
    insert_into_timer_list( hash_table , &(r_buf->tl[RETRASMISSIONS_LIST]) , RETRASMISSIONS_LIST , r_buf->timeout_value );
+   DBG("DEBUG: retransmission_handler : after insert\n");
 }
 
 
@@ -1090,6 +1094,7 @@ void final_response_handler( void *attr)
 
    /* the transaction is already removed from FR_LIST by the timer */
    /* send a 408 */
+   DBG("DEBUG: final_response_handler : sending 408\n");
    t_send_reply( p_cell->inbound_request , 408 , "Request Timeout" );
    /* put it on WT_LIST - transaction is over */
    t_put_on_wait(  p_cell->inbound_request );
@@ -1104,6 +1109,7 @@ void wait_handler( void *attr)
 
    /* the transaction is already removed from WT_LIST by the timer */
    /* the cell is removed from the hash table */
+   DBG("DEBUG: wait_handler : removing from table\n");
     remove_from_hash_table( hash_table, p_cell );
    /* put it on DEL_LIST - sch for del */
     add_to_tail_of_timer_list( hash_table, &(p_cell->dele_tl), DELETE_LIST, DEL_TIME_OUT );
@@ -1119,12 +1125,21 @@ void delete_handler( void *attr)
    /* the transaction is already removed from DEL_LIST by the timer */
     /* if is not refenceted -> is deleted*/
     if ( p_cell->ref_counter==0 )
+    {
+       DBG("DEBUG: delete_handler : delete transaction\n");
        free_cell( p_cell );
+    }
     else
+    {
+       DBG("DEBUG: delete_handler : re post for delete\n");
        /* else it's readded to del list for future del */
        add_to_tail_of_timer_list( hash_table, &(p_cell->dele_tl), DELETE_LIST, DEL_TIME_OUT );
+    }
 }
 
+
+
+
 /* append appropriate branch labels for fast reply-transaction matching
    to outgoing requests
 */
@@ -1133,7 +1148,7 @@ int add_branch_label( struct cell *trans, struct sip_msg *p_msg, int branch )
 	char *c;
 	short n;
 
-	n=snprintf( p_msg->add_to_branch_s+p_msg->add_to_branch_len, 
+	n=snprintf( p_msg->add_to_branch_s+p_msg->add_to_branch_len,
 		  MAX_BRANCH_PARAM_LEN - p_msg->add_to_branch_len,
 		 ".%x.%x.%x",
 		 trans->hash_index, trans->label, branch );
@@ -1141,8 +1156,5 @@ int add_branch_label( struct cell *trans, struct sip_msg *p_msg, int branch )
 	if (n==-1) {
 		LOG(L_ERR, "ERROR: add_branch_label: too small branch buffer\n");
 		return -1;
-	} else {
-		p_msg->add_to_branch_len += n;
-		return 0;
-	}
+	} else return 0;
 }

+ 13 - 3
modules/tm/timer.c

@@ -1,4 +1,5 @@
 #include "timer.h"
+#include "../../dprint.h"
 
 
 /* put a new cell into a list nr. list_id within a hash_table;
@@ -10,6 +11,7 @@ void add_to_tail_of_timer_list( struct s_table* hash_table , struct timer_link*
 
    tl->time_out = time_out + hash_table->time;
    tl->next_tl= 0;
+   DBG("DEBUG: add_to_tail_of_timer[%d]: %d, %p\n",list_id,tl->time_out,tl);
 
    /* the entire timer list is locked now -- noone else can manipulate it */
    lock( timer_list->mutex );
@@ -38,16 +40,19 @@ void insert_into_timer_list( struct s_table* hash_table , struct timer_link* new
    struct timer_link  *tl;
 
    new_tl->time_out = time_out + hash_table->time;
+   DBG("DEBUG: insert_into_timer[%d]: %d, %p\n",list_id,new_tl->time_out,new_tl);
 
     /* if we have an empty list*/
    if ( !timer_list->first_tl )
    {
+      DBG("DEBUG: insert_into_timer[%d]: empty list\n",list_id);
       new_tl->next_tl= 0;
       new_tl->prev_tl = 0;
       lock( timer_list->mutex );
       timer_list->first_tl = new_tl;
       timer_list->last_tl = new_tl;
       unlock( timer_list->mutex );
+      return;
    }
 
    for( tl=timer_list->first_tl ; tl && tl->time_out<new_tl->time_out ; tl=tl->next_tl );
@@ -83,6 +88,7 @@ void insert_into_timer_list( struct s_table* hash_table , struct timer_link* new
 void remove_from_timer_list( struct s_table* hash_table , struct timer_link* tl , int list_id)
 {
    struct timer* timers=&(hash_table->timers[ list_id ]);
+   DBG("DEBUG: remove_from_timer[%d]: %d, %p \n",list_id,tl->time_out,tl);
 
    if (tl->next_tl || tl->prev_tl || (!tl->next_tl && !tl->prev_tl && tl==timers->first_tl)   )
    {
@@ -113,16 +119,20 @@ struct timer_link  *remove_from_timer_list_from_head( struct s_table* hash_table
 
    if  (tl)
    {
+      DBG("DEBUG: remove_from_timer_head[%d]: %d , p=%p , next=%p\n",list_id,tl->time_out,tl,tl->next_tl);
       lock( timers->mutex  );
       timers->first_tl = tl->next_tl;
-     if (!timers->first_tl)
+      if (!timers->first_tl)
          timers->last_tl=0;
-     else
+      else
          tl->next_tl->prev_tl = 0;
       unlock( timers->mutex );
       tl->next_tl = 0;
       tl->prev_tl = 0;
    }
+   else
+      DBG("DEBUG: remove_from_timer_head[%d]: list is empty! nothing to remove!\n",list_id);
+
 
    return tl;
 }
@@ -147,7 +157,7 @@ void * timer_routine(void * attr)
       a_sec.tv_usec = 0;
       select( 0 , 0 , 0 ,0 , &a_sec );
       (*time)++;
-      printf("%d\n", *time);
+      DBG("%d\n", *time);
 
       for( id=0 ; id<NR_OF_TIMER_LISTS ; id++ )
          while ( timers[ id ].first_tl && timers[ id ].first_tl->time_out <= *time )

+ 2 - 2
modules/tm/timer.h

@@ -12,11 +12,11 @@ enum lists { RETRASMISSIONS_LIST, FR_TIMER_LIST, WT_TIMER_LIST, DELETE_LIST, NR_
 
 /* FINAL_RESPONSE_TIMER ... tells how long should the transaction engine
    wait if no final response comes back*/
-#define FR_TIME_OUT     64
+#define FR_TIME_OUT     8
 
 /* WAIT timer ... tells how long state should persist in memory after
    a transaction was finalized*/
-#define WT_TIME_OUT      16
+#define WT_TIME_OUT      8
 
 /* DELETE timer ... tells how long should the transaction persist in memory
    after it was removed from the hash table and before it will be deleted */