natfw/natfwicecandidatehandler/inc/ciceconnectivitycheck.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    Performs connectivity check.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef C_CICECONNECTIVITYCHECK_H
       
    22 #define C_CICECONNECTIVITYCHECK_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include "ciceconnectionhandler.h"
       
    26 #include "miceconncheckobserver.h"
       
    27 
       
    28 class MIceConnCheckListener;
       
    29 class CNATFWCandidatePair;
       
    30 class CNATFWCandidate;
       
    31 class TInetAddr;
       
    32 class CIceSessionData;
       
    33 
       
    34 /**
       
    35  *  Performs periodic and triggered end-to-end connectivity checks.
       
    36  *
       
    37  *  Connectivity check consists of STUN-request sending and response
       
    38  *  processing.
       
    39  *
       
    40  *  @lib icecandidatehandler
       
    41  *  @since S60 v3.2
       
    42  */
       
    43 class CIceConnectivityCheck 
       
    44     : 
       
    45     public CBase,
       
    46     public MIceConnCheckObserver
       
    47     {
       
    48 
       
    49     UNIT_TEST( UT_CIceConnectivityCheck )
       
    50     UNIT_TEST( UT_CIceCheckList )
       
    51 
       
    52 public:
       
    53 
       
    54     /**  ICE check states */
       
    55     enum TIceCheckState
       
    56         {
       
    57         EIceCheckWaiting        = 1,
       
    58         EIceCheckInProgress     = 2,
       
    59         EIceCheckSucceed        = 4,
       
    60         EIceCheckFailed         = 8,
       
    61         EIceCheckFrozen         = 16
       
    62         };
       
    63 
       
    64     /** ICE check types */
       
    65     enum TIceCheckType
       
    66         {
       
    67         EIceCheckTypePeriodic   = 1,
       
    68         EIceCheckTypeTriggered  = 2,
       
    69         EIceCheckTypeNomination = 3
       
    70         };
       
    71 
       
    72     /**
       
    73      * Two-phased constructor.
       
    74      * @param   aClient             The client issuing check
       
    75      * @param   aLocalCand          The local candidate
       
    76      * @param   aRemoteCand         The remote candidate
       
    77      * @param   aConnHandler        The connection handler
       
    78      * @param   aSessionData        The session data
       
    79      */
       
    80     static CIceConnectivityCheck* NewL( 
       
    81         MIceConnCheckListener& aClient,
       
    82         const CNATFWCandidate& aLocalCand,
       
    83         const CNATFWCandidate& aRemoteCand,
       
    84         CIceConnectionHandler& aConnHandler,
       
    85         CIceSessionData& aSessionData );
       
    86 
       
    87     /**
       
    88      * Two-phased constructor.
       
    89      * @param   aClient             The client issuing check
       
    90      * @param   aLocalCand          The local candidate
       
    91      * @param   aRemoteCand         The remote candidate
       
    92      * @param   aConnHandler        The connection handler
       
    93      * @param   aSessionData        The session data
       
    94      */
       
    95     static CIceConnectivityCheck* NewLC(
       
    96         MIceConnCheckListener& aClient,
       
    97         const CNATFWCandidate& aLocalCand,
       
    98         const CNATFWCandidate& aRemoteCand,
       
    99         CIceConnectionHandler& aConnHandler,
       
   100         CIceSessionData& aSessionData );
       
   101     
       
   102     /** 
       
   103      * Destructor.
       
   104      */
       
   105     virtual ~CIceConnectivityCheck();
       
   106     
       
   107     /**
       
   108      * Compare priorities of two connectivity checks.
       
   109      *
       
   110      * @since   S60 v3.2
       
   111      * @param   aA         The first check for comparison
       
   112      * @param   aB         The second check for comparison
       
   113      */
       
   114     static TInt ComparePriorities( 
       
   115         const CIceConnectivityCheck& aA, 
       
   116         const CIceConnectivityCheck& aB );
       
   117 
       
   118     /**
       
   119      * Implements TIdentityRelation regarding transport addresses.
       
   120      *
       
   121      * @since   S60 v3.2
       
   122      * @param   aItem1              The first item for comparison
       
   123      * @param   aItem2              The second item for comparison
       
   124      * @return  ETrue if checks match
       
   125      */
       
   126     static TBool MatchAddresses( 
       
   127         const CIceConnectivityCheck& aItem1, 
       
   128         const CIceConnectivityCheck& aItem2 );
       
   129 
       
   130     /** 
       
   131      * Initializes the check. After that check is ready to be performed.
       
   132      *
       
   133      * @since   S60 v3.2
       
   134      */
       
   135     void Initialize();
       
   136     
       
   137     /**
       
   138      * Executes connectivity check.
       
   139      * 
       
   140      * @since   S60 v3.2
       
   141      * @param   aType           Connectivity check type
       
   142      * @param   aPriority       The priority to be included in the check
       
   143      * @param   aRtoValue       The retransmission timeout value in ms
       
   144      */
       
   145     void PerformConnCheckL( TIceCheckType aType, TUint aPriority, 
       
   146         TUint aRtoValue );
       
   147     
       
   148     /** 
       
   149      * Resends earlier performed connectivity check in order to nominate pair.
       
   150      *
       
   151      * @since   S60 v3.2
       
   152      * @param   aRtoValue       The retransmission timeout value in ms
       
   153      */
       
   154     void PerformNominationL( TUint aRtoValue );
       
   155     
       
   156     /** 
       
   157      * Return whether check is nominated.
       
   158      *
       
   159      * @since   S60 v3.2
       
   160      * @return  ETrue if check is nominated
       
   161      */
       
   162     TBool Nominated() const;
       
   163     
       
   164     /** 
       
   165      * Set information from the remote check received for the same pair.
       
   166      * This information is needed for valid pair construction.
       
   167      *
       
   168      * @since   S60 v3.2
       
   169      * @param   aPriority       Priority of the remote check
       
   170      * @param   aFavored        Favored status from the remote check
       
   171      */
       
   172     void SetRemoteCheckInfo( TUint aPriority, TBool aFavored );
       
   173     
       
   174     /** 
       
   175      * Cancels the check.
       
   176      *
       
   177      * @since   S60 v3.2
       
   178      */
       
   179     void Cancel();
       
   180     
       
   181     /** 
       
   182      * Return stream identifier where this check is done.
       
   183      *
       
   184      * @since   S60 v3.2
       
   185      * @return  Stream identifier
       
   186      */
       
   187     TUint StreamId() const;
       
   188     
       
   189     /** 
       
   190      * Return identifier of the component for which this check is for.
       
   191      *
       
   192      * @since   S60 v3.2
       
   193      * @return  Component identifier
       
   194      */
       
   195     TUint ComponentId() const;
       
   196     
       
   197     /**
       
   198      * Returns stream collection id of the check.
       
   199      * 
       
   200      * @since   S60 v3.2
       
   201      * @return  Stream collection identifier
       
   202      */
       
   203     TUint StreamCollectionId() const;
       
   204     
       
   205     /** 
       
   206      * Return current state of the connectivity check.
       
   207      *
       
   208      * @since   S60 v3.2
       
   209      * @return  Current state
       
   210      */
       
   211     TIceCheckState State() const;
       
   212     
       
   213     /** 
       
   214      * Return candidate pair validated with this check.
       
   215      *
       
   216      * @since   S60 v3.2
       
   217      * @return  Validated candidate pair
       
   218      */
       
   219     const CNATFWCandidatePair* ValidatedPair() const;
       
   220     
       
   221     /** 
       
   222      * Returns candidate pair for which check is created.
       
   223      *
       
   224      * @since   S60 v3.2
       
   225      * @return  Candidate pair
       
   226      */
       
   227     const CNATFWCandidatePair& CandidatePair() const;
       
   228 
       
   229 // From base class MIceConnectionObserver
       
   230 
       
   231     void ConnCheckCompletedL(
       
   232         TInt aCompletionCode,
       
   233         const TInetAddr& aLocalAddr,
       
   234         const TInetAddr& aPeerAddr,
       
   235         const TInetAddr& aMappedAddr );
       
   236 
       
   237 private:
       
   238 
       
   239     CIceConnectivityCheck( 
       
   240         MIceConnCheckListener& aClient,
       
   241         CIceConnectionHandler& aConnHandler,
       
   242         CIceSessionData& aSessionData );
       
   243 
       
   244     void ConstructL( 
       
   245         const CNATFWCandidate& aLocalCand,
       
   246         const CNATFWCandidate& aRemoteCand );
       
   247     
       
   248     CNATFWCandidatePair* CreateValidatedPairL( 
       
   249         const TInetAddr& aMappedAddr );
       
   250     
       
   251 private: // data
       
   252 
       
   253     /**
       
   254      * Current state of the ICE check.
       
   255      */
       
   256     TIceCheckState iState;
       
   257     
       
   258     /**
       
   259      * Type of the connectivity check.
       
   260      */
       
   261     TIceCheckType iType;
       
   262     
       
   263     /**
       
   264      * Priority used with binding request.
       
   265      */
       
   266     TUint iPriority;
       
   267     
       
   268     /**
       
   269      * Priority from check which triggered this check.
       
   270      */
       
   271     TUint iRemotePriority;
       
   272     
       
   273     /** 
       
   274      * Indicates is this pair favored by remote party.
       
   275      */
       
   276     TBool iRemoteFavored;
       
   277     
       
   278     /**
       
   279      * Whether check is nominated.
       
   280      */
       
   281     TBool iIsNominated;
       
   282     
       
   283     /**
       
   284      * Connection used for connectivity checks.
       
   285      */
       
   286     TUint iConnectionId;
       
   287     
       
   288     /**
       
   289      * Indicates that resend has been issued.
       
   290      */
       
   291     TBool iResendInProgress;
       
   292     
       
   293     /**
       
   294      * Client notified about a result of the check.
       
   295      * Not own.
       
   296      */
       
   297     MIceConnCheckListener& iClient;
       
   298     
       
   299     /**
       
   300      * The connection handler.
       
   301      * Not own.
       
   302      */
       
   303     CIceConnectionHandler& iConnHandler;
       
   304     
       
   305     /**
       
   306      * The session data.
       
   307      * Not own.
       
   308      */
       
   309     CIceSessionData& iSessionData;
       
   310     
       
   311     /**
       
   312      * Validated candidate pair.
       
   313      * Own.
       
   314      */
       
   315     CNATFWCandidatePair* iValidatedPair;
       
   316     
       
   317     /**
       
   318      * Pair to test for connectivity.
       
   319      * Own.
       
   320      */
       
   321     CNATFWCandidatePair* iCandidatePair;
       
   322     
       
   323     };
       
   324 
       
   325 #endif // C_CICECONNECTIVITYCHECK_H