Ignore:
Timestamp:
Apr 13, 2009 6:30:49 PM (15 years ago)
Author:
bennylp
Message:

More ticket #780: destroy TURN session if it receives 437 (Allocation Mismatch) response

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjnath/src/pjnath/turn_session.c

    r2589 r2590  
    12421242        } 
    12431243 
    1244         /* Otherwise if this is REFRESH response, notify application 
     1244        /* Otherwise if this is not ALLOCATE response, notify application 
    12451245         * that session has been TERMINATED. 
    12461246         */ 
    1247         if (method==PJ_STUN_REFRESH_METHOD) { 
     1247        if (method!=PJ_STUN_ALLOCATE_METHOD) { 
    12481248            set_state(sess, PJ_TURN_STATE_DEALLOCATED); 
    12491249            sess_shutdown(sess, status); 
     
    14591459            const pj_str_t *err_msg = NULL; 
    14601460 
    1461             if (status == PJ_SUCCESS) { 
     1461            pj_assert(status != PJ_SUCCESS); 
     1462 
     1463            if (response) { 
    14621464                const pj_stun_errcode_attr *err_attr; 
    14631465                err_attr = (const pj_stun_errcode_attr*) 
     
    14671469                    status = PJ_STATUS_FROM_STUN_CODE(err_attr->err_code); 
    14681470                    err_msg = &err_attr->reason; 
    1469                 } else { 
    1470                     status = PJNATH_EINSTUNMSG; 
    14711471                } 
    14721472            } 
     
    14941494        } else { 
    14951495            /* Failed ChannelBind response */ 
    1496             pj_str_t err_msg = {"", 0}; 
    1497  
    1498             if (status == PJ_SUCCESS) { 
     1496            pj_str_t reason = {"", 0}; 
     1497            int err_code = 0; 
     1498            char errbuf[PJ_ERR_MSG_SIZE]; 
     1499 
     1500            pj_assert(status != PJ_SUCCESS); 
     1501 
     1502            if (response) { 
    14991503                const pj_stun_errcode_attr *err_attr; 
    15001504                err_attr = (const pj_stun_errcode_attr*) 
     
    15021506                                                 PJ_STUN_ATTR_ERROR_CODE, 0); 
    15031507                if (err_attr) { 
     1508                    err_code = err_attr->err_code; 
    15041509                    status = PJ_STATUS_FROM_STUN_CODE(err_attr->err_code); 
    1505                     err_msg = err_attr->reason; 
    1506                 } else { 
    1507                     status = PJNATH_EINSTUNMSG; 
     1510                    reason = err_attr->reason; 
    15081511                } 
     1512            } else { 
     1513                err_code = status; 
     1514                reason = pj_strerror(status, errbuf, sizeof(errbuf)); 
    15091515            } 
    15101516 
    1511             PJ_LOG(4,(sess->obj_name, "ChannelBind failed: %.*s", 
    1512                       (int)err_msg.slen, err_msg.ptr)); 
     1517            PJ_LOG(1,(sess->obj_name, "ChannelBind failed: %d/%.*s", 
     1518                      err_code, (int)reason.slen, reason.ptr)); 
     1519 
     1520            if (err_code == PJ_STUN_SC_ALLOCATION_MISMATCH) { 
     1521                /* Allocation mismatch means allocation no longer exists */ 
     1522                on_session_fail(sess, PJ_STUN_CHANNEL_BIND_METHOD, 
     1523                                status, &reason); 
     1524                return; 
     1525            } 
    15131526        } 
    15141527 
     
    15291542            pj_str_t reason; 
    15301543 
    1531             if (status != PJ_SUCCESS) { 
    1532                 err_code = status; 
    1533                 reason = pj_strerror(status, errbuf, sizeof(errbuf)); 
    1534             } else { 
     1544            pj_assert(status != PJ_SUCCESS); 
     1545 
     1546            if (response) { 
    15351547                const pj_stun_errcode_attr *eattr; 
    15361548 
     
    15451557                    reason = pj_str("?"); 
    15461558                } 
     1559            } else { 
     1560                err_code = status; 
     1561                reason = pj_strerror(status, errbuf, sizeof(errbuf)); 
    15471562            } 
    15481563 
     
    15621577                    invalidate_perm(sess, perm); 
    15631578                } 
     1579            } 
     1580 
     1581            if (err_code == PJ_STUN_SC_ALLOCATION_MISMATCH) { 
     1582                /* Allocation mismatch means allocation no longer exists */ 
     1583                on_session_fail(sess, PJ_STUN_CREATE_PERM_METHOD, 
     1584                                status, &reason); 
     1585                return; 
    15641586            } 
    15651587        } 
Note: See TracChangeset for help on using the changeset viewer.