Navigation


Changeset 1186:56c36d1007b4 in freeDiameter for libfdcore/sctp3436.c


Ignore:
Timestamp:
Jun 7, 2013, 7:48:34 PM (11 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Further preparation of the DTLS integration. Some cleanups in the GNUTLS handling.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/sctp3436.c

    r1181 r1186  
    5252 We also have a demux thread that reads the socket and store received data in the appropriate fifo
    5353 
    54  We have one gnutls_session per stream pair, and as many streams that read the gnutls records and save incoming data to the target queue.
     54 We have one gnutls_session per stream pair, and as many threads that read the gnutls records and save incoming data to the target queue.
    5555 
    5656This complexity is required because we cannot read a socket for a given stream only; we can only get the next message and find its stream.
    5757*/
    5858
    59 /* TODO: change this whole wrapper to DTLS which should not require many different threads */
     59/* Note that this mechanism is replaced by DTLS in RFC6733 */
    6060
    6161/*************************************************************/
     
    164164/*************************************************************/
    165165
     166#ifdef GNUTLS_VERSION_300
     167/* Check if data is available for gnutls on a given context */
     168static int sctp3436_pull_timeout(gnutls_transport_ptr_t tr, unsigned int ms)
     169{
     170        struct sctp3436_ctx * ctx = (struct sctp3436_ctx *) tr;
     171        struct timespec tsstore, *ts = NULL;
     172        int ret;
     173       
     174        TRACE_ENTRY("%p %d", tr, ms);
     175       
     176        if (ctx->partial.buf)
     177                return 1; /* data is already available for pull */
     178       
     179        if (ms) {
     180                CHECK_SYS_DO(  clock_gettime(CLOCK_REALTIME, &tsstore),  return -1  );
     181                tsstore.tv_nsec += (long)ms * 1000000;
     182                tsstore.tv_sec += tsstore.tv_nsec / 1000000000L;
     183                tsstore.tv_nsec %= 1000000000L;
     184                ts = &tsstore;
     185        }
     186       
     187        ret = fd_fifo_select ( ctx->raw_recv, ts );
     188        if (ret < 0) {
     189                errno = -ret;
     190                ret = -1;
     191        }
     192               
     193        return ret;
     194}
     195#endif /* GNUTLS_VERSION_300 */
     196
    166197/* Send data over the connection, called by gnutls */
     198#ifndef GNUTLS_VERSION_212
    167199static ssize_t sctp3436_push(gnutls_transport_ptr_t tr, const void * data, size_t len)
    168200{
    169201        struct sctp3436_ctx * ctx = (struct sctp3436_ctx *) tr;
     202        struct iovec iov;
    170203       
    171204        TRACE_ENTRY("%p %p %zd", tr, data, len);
    172205        CHECK_PARAMS_DO( tr && data, { errno = EINVAL; return -1; } );
    173206       
    174         CHECK_FCT_DO( fd_sctp_sendstr(ctx->parent, ctx->strid, (uint8_t *)data, len), return -1 );
    175        
    176         return len;
    177 }
     207        iov.iov_base = (void *)data;
     208        iov.iov_len  = len;
     209       
     210        return fd_sctp_sendstrv(ctx->parent, ctx->strid, &iov, 1);
     211}
     212#else /*  GNUTLS_VERSION_212 */
     213static ssize_t sctp3436_pushv(gnutls_transport_ptr_t tr, const giovec_t * iov, int iovcnt)
     214{
     215        struct sctp3436_ctx * ctx = (struct sctp3436_ctx *) tr;
     216       
     217        TRACE_ENTRY("%p %p %d", tr, iov, iovcnt);
     218        CHECK_PARAMS_DO( tr && iov, { errno = EINVAL; return -1; } );
     219       
     220        return fd_sctp_sendstrv(ctx->parent, ctx->strid, (const struct iovec *)iov, iovcnt);
     221}
     222#endif /*  GNUTLS_VERSION_212 */
    178223
    179224/* Retrieve data received on a stream and already demultiplexed */
     
    238283        /* starting version 2.12, this call is not needed */
    239284        GNUTLS_TRACE( gnutls_transport_set_lowat( session, 0 ) );
     285#else  /* GNUTLS_VERSION_300 */
     286        /* but in 3.0 we have to provide the pull_timeout callback */
     287        GNUTLS_TRACE( gnutls_transport_set_pull_timeout_function( session, sctp3436_pull_timeout ) );
    240288#endif /* GNUTLS_VERSION_300 */
    241289       
    242290        /* Set the push and pull callbacks */
    243291        GNUTLS_TRACE( gnutls_transport_set_pull_function(session, sctp3436_pull) );
     292#ifndef GNUTLS_VERSION_212
    244293        GNUTLS_TRACE( gnutls_transport_set_push_function(session, sctp3436_push) );
     294#else /* GNUTLS_VERSION_212 */
     295        GNUTLS_TRACE( gnutls_transport_set_vec_push_function(session, sctp3436_pushv) );
     296#endif /* GNUTLS_VERSION_212 */
    245297
    246298        return;
Note: See TracChangeset for help on using the changeset viewer.