Navigation


Changeset 894:43fb27a9037f in freeDiameter for libfdcore


Ignore:
Timestamp:
Nov 30, 2012, 6:51:49 AM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Intrumented socket reception to store the timestamp along the received buffer

Location:
libfdcore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/cnxctx.c

    r816 r894  
    641641        }
    642642       
     643        CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &conn->cc_tls_para.recvon), /* continue */ );
     644       
    643645        return ret;
    644646}
     
    696698                ssize_t ret = 0;
    697699                size_t  received = 0;
     700                struct timespec recv_on;
    698701
    699702                do {
     
    718721
    719722                /* Ok, now we can really receive the data */
    720                 CHECK_MALLOC_DO(  newmsg = malloc( length ), goto fatal );
     723                CHECK_MALLOC_DO(  newmsg = malloc( length + sizeof(struct timespec) ), goto fatal );
    721724                memcpy(newmsg, header, sizeof(header));
    722725
     
    732735                        received += ret;
    733736                }
     737               
     738                /* Piggy-tail the timestamp of reception */
     739                CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &recv_on), /* continue */ );
     740                memcpy(newmsg + length, &recv_on, sizeof(struct timespec));
    734741               
    735742                /* We have received a complete message, pass it to the daemon */
     
    782789                        continue;
    783790                }
    784                
     791                /* Note: the real size of buf is bufsz + struct timespec */
    785792                CHECK_FCT_DO( fd_event_send( fd_cnx_target_queue(conn), event, bufsz, buf), goto fatal );
    786793               
     
    920927int fd_tls_rcvthr_core(struct cnxctx * conn, gnutls_session_t session)
    921928{
     929        struct timespec * rcv_on;
     930       
     931        void * ptr = gnutls_transport_get_ptr(session);
     932        if (ptr == conn) {
     933                rcv_on = &conn->cc_tls_para.recvon;
     934        } else {
     935                struct sctps_ctx * ctx = (struct sctps_ctx *) ptr;
     936                rcv_on = &ctx->recvon;
     937        }
     938       
     939       
    922940        /* No guarantee that GnuTLS preserves the message boundaries, so we re-build it as in TCP */
    923941        do {
     
    927945                ssize_t ret = 0;
    928946                size_t  received = 0;
     947                struct timespec recv_on;
    929948
    930949                do {
     
    949968
    950969                /* Ok, now we can really receive the data */
    951                 CHECK_MALLOC(  newmsg = malloc( length ) );
     970                CHECK_MALLOC(  newmsg = malloc( length + sizeof(struct timespec)) );
    952971                memcpy(newmsg, header, sizeof(header));
    953972
     
    963982                        received += ret;
    964983                }
     984               
     985                /* The timestamp of the last TLS chunk received for this rebuilt message lives close to the session pointer, we piggyback it */
     986                memcpy(newmsg + length, rcv_on, sizeof(struct timespec));
    965987               
    966988                /* We have received a complete message, pass it to the daemon */
  • libfdcore/cnxctx.h

    r808 r894  
    6666                int                              mode;          /* GNUTLS_CLIENT / GNUTLS_SERVER */
    6767                gnutls_session_t                 session;       /* Session object (stream #0 in case of SCTP) */
     68                struct timespec                  recvon;        /* Timestamp of the last chunk of data received on this session -- before uncipher */
    6869        }               cc_tls_para;
    6970
     
    130131                size_t   offset;
    131132        }                partial;       /* If the pull function did not read the full content of first message in raw, it stores it here for next read call. */
     133        struct timespec  recvon;        /* Timestamp of the last chunk of data received on this stream -- before uncipher */
    132134        pthread_t        thr;           /* Thread to decrypt raw data in this pair of streams */
    133135        gnutls_session_t session;       /* TLS context using this pair of streams -- except if strid == 0, in that case session is outside the array */
  • libfdcore/fdcore-internal.h

    r815 r894  
    215215        ,FDEVP_TERMINATE
    216216       
    217         /* A connection object has received a message. (data contains the buffer) */
     217        /* A connection object has received a message. (data contains the buffer + struct timespec piggytailed -- unaligned) */
    218218        ,FDEVP_CNX_MSG_RECV
    219219                         
  • libfdcore/sctp.c

    r817 r894  
    10681068        size_t                   mempagesz = sysconf(_SC_PAGESIZE); /* We alloc buffer by memory pages for efficiency */
    10691069        int                      timedout = 0;
     1070        struct timespec          recv_on;
    10701071       
    10711072        TRACE_ENTRY("%p %p %p %p %p", conn, strid, buf, len, event);
     
    10861087        /* We will loop while all data is not received. */
    10871088incomplete:
    1088         if (datasize == bufsz) {
     1089        if (datasize == bufsz - sizeof(struct timespec)) {
    10891090                /* The buffer is full, enlarge it */
    10901091                bufsz += mempagesz;
    1091                 CHECK_MALLOC( data = realloc(data, bufsz) );
     1092                CHECK_MALLOC( data = realloc(data, bufsz ) );
    10921093        }
    10931094        /* the new data will be received following the preceding */
    10941095        memset(&iov,  0, sizeof(iov));
    10951096        iov.iov_base = data + datasize ;
    1096         iov.iov_len  = bufsz - datasize;
     1097        iov.iov_len  = bufsz - sizeof(struct timespec) - datasize;
    10971098
    10981099        /* Receive data from the socket */
     
    11881189        }
    11891190       
     1191        /* Piggy-tail the timestamp of reception */
     1192        CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &recv_on), /* continue */ );
     1193        memcpy(data + datasize, &recv_on, sizeof(struct timespec));
     1194               
    11901195        /* From this point, we have received a message */
    11911196        *event = FDEVP_CNX_MSG_RECV;
  • libfdcore/sctps.c

    r808 r894  
    9292                                /* Demux this message to the appropriate fifo, another thread will pull, gnutls process, and send to target queue */
    9393                                if (strid < conn->cc_sctp_para.pairs) {
     94                                        /* Note, here the timespec is piggytailed to buf */
    9495                                        CHECK_FCT_DO(fd_event_send(conn->cc_sctps_data.array[strid].raw_recv, event, bufsz, buf), goto fatal );
    9596                                } else {
     
    195196                        return -1;
    196197                }
     198                if (ev == FDEVP_CNX_MSG_RECV) {
     199                        memcpy(&ctx->recvon, ctx->partial.buf + ctx->partial.bufsz, sizeof(struct timespec)); /* retrieve piggy-tailed ts */
     200                }
    197201        }
    198202               
Note: See TracChangeset for help on using the changeset viewer.