Changeset 3c3259132706c07bf0046e922945974c0993f469

Show
Ignore:
Timestamp:
12/21/07 19:52:21 (8 months ago)
Author:
Pierre d'Herbemont <pdherbemont@videolan.org>
git-committer:
Pierre d'Herbemont <pdherbemont@videolan.org> 1198263141 +0000
git-parent:

[54b8548a2f59a53851ecb2ab71047d712b4639af]

git-author:
Pierre d'Herbemont <pdherbemont@videolan.org> 1198263141 +0000
Message:

modules/services_discovery/sap.c: Don't trust announcement down packet, but support implicit timeout.
* As suggested in the RFC we remove the discovered media if there is no new packet after three average packet period. (implicit timeout).
* Announcement of removal packet can be used to silently replace an announce by an other.
* Add a timeout argument to net_Select.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • include/vlc_network.h

    r5b7e0b5 r3c32591  
    124124VLC_EXPORT( ssize_t, __net_Read, ( vlc_object_t *p_this, int fd, const v_socket_t *, uint8_t *p_data, size_t i_data, vlc_bool_t b_retry ) ); 
    125125 
    126 #define net_Select(a,b,c,d,e) __net_Select(VLC_OBJECT(a),b,c,d,e
    127 VLC_EXPORT( ssize_t, __net_Select, ( vlc_object_t *p_this, const int *pi_fd, int i_fd, uint8_t *p_data, size_t i_data ) ); 
     126#define net_Select(a,b,c,d,e,f) __net_Select(VLC_OBJECT(a),b,c,d,e,f
     127VLC_EXPORT( ssize_t, __net_Select, ( vlc_object_t *p_this, const int *pi_fd, int i_fd, uint8_t *p_data, size_t i_data, int i_timeout ) ); 
    128128 
    129129#define net_Write(a,b,c,d,e) __net_Write(VLC_OBJECT(a),b,c,d,e) 
  • modules/services_discovery/sap.c

    r23b12fc r3c32591  
    211211{ 
    212212    mtime_t i_last; 
     213    mtime_t i_period; 
     214    uint8_t i_period_trust; 
    213215 
    214216    uint16_t    i_hash; 
     
    540542        i_read = net_Select( p_sd, p_sd->p_sys->pi_fd, 
    541543                             p_sd->p_sys->i_fd, p_buffer, 
    542                              MAX_SAP_BUFFER ); 
     544                             MAX_SAP_BUFFER, 500 ); 
    543545 
    544546        /* Check for items that need deletion */ 
     
    546548        { 
    547549            mtime_t i_timeout = ( mtime_t ) 1000000 * p_sd->p_sys->i_timeout; 
    548  
    549             if( mdate() - p_sd->p_sys->pp_announces[i]->i_last > i_timeout ) 
     550            sap_announce_t * p_announce = p_sd->p_sys->pp_announces[i]; 
     551            mtime_t i_last_period = mdate() - p_announce->i_last; 
     552             
     553            /* Remove the annoucement, if the last announcement was 1 hour ago 
     554             * or if the last packet emitted was 3 times the average time 
     555             * between two packets */ 
     556            if( ( p_announce->i_period_trust > 5 && i_last_period > 3 * p_announce->i_period ) || 
     557                i_last_period > i_timeout ) 
    550558            { 
    551                 RemoveAnnounce( p_sd, p_sd->p_sys->pp_announces[i] ); 
     559                RemoveAnnounce( p_sd, p_announce ); 
    552560            } 
    553561        } 
     
    738746    for( i = 0 ; i< p_sd->p_sys->i_announces ; i++ ) 
    739747    { 
     748        sap_announce_t * p_announce = p_sd->p_sys->pp_announces[i]; 
    740749        /* FIXME: slow */ 
    741750        /* FIXME: we create a new announce each time the sdp changes */ 
    742         if( IsSameSession( p_sd->p_sys->pp_announces[i]->p_sdp, p_sdp ) ) 
    743         { 
    744             if( b_need_delete ) 
     751        if( IsSameSession( p_announce->p_sdp, p_sdp ) ) 
     752        { 
     753            /* We don't support delete announcement as they can easily 
     754             * Be used to highjack an announcement by a third party. 
     755             * Intead we cleverly implement Implicit Announcement removal. 
     756             * 
     757             * if( b_need_delete ) 
     758             *    RemoveAnnounce( p_sd, p_sd->p_sys->pp_announces[i]); 
     759             * else 
     760             */ 
     761 
     762            if( !b_need_delete ) 
    745763            { 
    746                 RemoveAnnounce( p_sd, p_sd->p_sys->pp_announces[i]); 
    747             } 
    748             else 
    749             { 
    750                 p_sd->p_sys->pp_announces[i]->i_last = mdate(); 
     764                /* No need to go after six, as we start to trust the 
     765                 * average period at six */ 
     766                if( p_announce->i_period_trust <= 5 ) 
     767                    p_announce->i_period_trust++; 
     768 
     769                /* Compute the average period */ 
     770                p_announce->i_period = (p_announce->i_period + (mdate() - p_announce->i_last)) / 2; 
     771                p_announce->i_last = mdate(); 
    751772            } 
    752773            FreeSDP( p_sdp ); p_sdp = NULL; 
     
    775796 
    776797    p_sap->i_last = mdate(); 
     798    p_sap->i_period = 0; 
     799    p_sap->i_period_trust = 0; 
    777800    p_sap->i_hash = i_hash; 
    778801    p_sap->p_sdp = p_sdp; 
  • src/network/io.c

    r69d48f0 r3c32591  
    257257net_ReadInner (vlc_object_t *restrict p_this, unsigned fdc, const int *fdv, 
    258258               const v_socket_t *const *restrict vsv, 
    259                uint8_t *restrict p_buf, size_t i_buflen, vlc_bool_t waitall) 
     259               uint8_t *restrict p_buf, size_t i_buflen, vlc_bool_t waitall, 
     260               int timeout) 
    260261{ 
    261262    size_t i_total = 0; 
     
    282283        } 
    283284 
    284         switch (poll (ufd, fdc, 500)) 
     285        switch (poll (ufd, fdc, timeout ? timeout : 500)) 
    285286        { 
    286287            case -1: 
     
    288289 
    289290            case 0: // timeout 
     291                if( timeout ) return 0; 
    290292                continue; 
    291293        } 
     
    400402    return net_ReadInner( p_this, 1, &(int){ fd }, 
    401403                          &(const v_socket_t *){ p_vs }, 
    402                           buf, len, b_retry ); 
     404                          buf, len, b_retry, 0 ); 
    403405} 
    404406 
     
    408410 ***************************************************************************** 
    409411 * Read from several sockets. Takes data from the first socket that has some. 
     412 * if timeout is zero, net_Select will wait indefinitely. timeout is in 
     413 * millisecond. 
    410414 *****************************************************************************/ 
    411415ssize_t __net_Select( vlc_object_t *restrict p_this, 
    412416                      const int *restrict fds, int nfd, 
    413                       uint8_t *restrict buf, size_t len ) 
     417                      uint8_t *restrict buf, size_t len, 
     418                      int timeout ) 
    414419{ 
    415420    const v_socket_t *vsv[nfd]; 
     
    417422 
    418423    return net_ReadInner( p_this, nfd, fds, vsv, 
    419                           buf, len, VLC_FALSE ); 
     424                          buf, len, VLC_FALSE, timeout ); 
    420425} 
    421426