natfw/natfwicecandidatehandler/inc/cicechecklist.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:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef C_CICECHECKLIST_H
       
    22 #define C_CICECHECKLIST_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <badesca.h>
       
    26 #include "miceconnchecklistener.h"
       
    27 #include "ticecheckqueitem.h"
       
    28 #include "natfwinternaldefs.h"    //UNIT_TEST
       
    29 
       
    30 class CIceConnectivityCheck;
       
    31 class CIceCheckPrioritizer;
       
    32 class CIceSessionData;
       
    33 class CNATFWCandidate;
       
    34 class CNATFWCandidatePair;
       
    35 class CIceCandidatePrioritizer;
       
    36 class MIceChecklistObserver;
       
    37 class CIceConnectionHandler;
       
    38 class TInetAddr;
       
    39 class CIceValidList;
       
    40 
       
    41 /**
       
    42  *  ICE check list for a stream collection (e.g. SDP media stream).
       
    43  *
       
    44  *  @lib icecandidatehandler.dll
       
    45  *  @since S60 v3.2
       
    46  */
       
    47 class CIceCheckList : public CBase, public MIceConnCheckListener
       
    48     {
       
    49 
       
    50     UNIT_TEST( UT_CIceCheckList )
       
    51     UNIT_TEST( UT_CIceCheckHandler )
       
    52     
       
    53 public:
       
    54 
       
    55     /**  ICE check list states */
       
    56     enum TIceCheckListState
       
    57         {
       
    58         EIceCheckListRunning        = 1,
       
    59         EIceCheckListCompleted      = 2,
       
    60         EIceCheckListFailed         = 3
       
    61         };
       
    62 
       
    63     /**
       
    64      * Two-phased constructor.
       
    65      * @param   aClient                 The client
       
    66      * @param   aStreamCollectionId     The stream collection
       
    67      * @param   aSessionData            The session data
       
    68      * @param   aConnHandler            The connection handler
       
    69      */
       
    70     static CIceCheckList* NewL( 
       
    71         MIceChecklistObserver& aClient,
       
    72         TUint aStreamCollectionId,
       
    73         CIceSessionData& aSessionData,
       
    74         CIceConnectionHandler& aConnHandler );
       
    75 
       
    76     /**
       
    77      * Two-phased constructor.
       
    78      * @param   aClient                 The client
       
    79      * @param   aStreamCollectionId     The stream collection
       
    80      * @param   aSessionData            The session data
       
    81      * @param   aConnHandler            The connection handler
       
    82      */
       
    83     static CIceCheckList* NewLC( 
       
    84         MIceChecklistObserver& aClient,
       
    85         TUint aStreamCollectionId,
       
    86         CIceSessionData& aSessionData,
       
    87         CIceConnectionHandler& aConnHandler );
       
    88 
       
    89     /**
       
    90      * Destructor.
       
    91      */
       
    92     virtual ~CIceCheckList();
       
    93 
       
    94     /**
       
    95      * For usage with CPeriodic.
       
    96      */
       
    97     static TInt TimerFired( TAny* aObject );
       
    98 
       
    99     /**
       
   100      * Return state of the checklist.
       
   101      * 
       
   102      * @since   S60 v3.2
       
   103      * @return  Sate of the checklist
       
   104      */
       
   105     TIceCheckListState State() const;
       
   106 
       
   107     /**
       
   108      * Returns stream collection id for the check list.
       
   109      * 
       
   110      * @since   S60 v3.2
       
   111      * @return  Stream collection identifier
       
   112      */
       
   113     TUint StreamCollectionId() const;
       
   114 
       
   115     /**
       
   116      * Prepares check list before candidate pair checks are started.
       
   117      * Used with check list corresponding first SDP media line (ICE 5.7 )
       
   118      *
       
   119      * @since   S60 v3.2
       
   120      */
       
   121     void InitializeCheckListL();
       
   122 
       
   123     /**
       
   124      * Prepares check list before candidate pair checks are started.
       
   125      * Used for activation after check list for first media line has
       
   126      * completed first check for the last media component.
       
   127      *
       
   128      * @since   S60 v3.2
       
   129      * @param   aFoundation     The foundation to match
       
   130      */
       
   131     void InitializeCheckListL( const TDesC8& aFoundation );
       
   132 
       
   133     /**
       
   134      * Starts perform periodic connectivity checks.
       
   135      *
       
   136      * @since   S60 v3.2
       
   137      * @param   anInterval      The time interval for pacing checks
       
   138      */
       
   139     void StartPerformChecksL( 
       
   140         const TTimeIntervalMicroSeconds32& anInterval );
       
   141     
       
   142     /**
       
   143      * Restarts check list (due to ICE restart).
       
   144      *
       
   145      * @since   S60 v3.2
       
   146      * @param   anInterval      The time interval for pacing checks     
       
   147      */
       
   148     void RestartCheckListL( const TTimeIntervalMicroSeconds32& anInterval );
       
   149      
       
   150     /**
       
   151      * Updates check list with peer selected candidate pairs. ICE processing
       
   152      * is completed with help of new information.
       
   153      * 
       
   154      * @since   S60 v3.2
       
   155      * @param   aPeerSelectedPairs  Peer selected candidate pairs
       
   156      */
       
   157     void UpdateCheckListL( 
       
   158         RPointerArray<CNATFWCandidatePair>& aPeerSelectedPairs );
       
   159     
       
   160     /**
       
   161      * Updates check list with updated set of remote candidates. 
       
   162      * ICE processing is completed with help of new information.
       
   163      * 
       
   164      * @since   S60 v3.2
       
   165      * @param   aRemoteCands        All remote candidates known currently
       
   166      */
       
   167     void UpdateCheckListL( 
       
   168         RPointerArray<CNATFWCandidate>& aRemoteCands );
       
   169     
       
   170     /**
       
   171      * Called when incoming STUN request has come.
       
   172      * If aFromAddr == aPeerAddr relay isn't used.
       
   173      *
       
   174      * @since   S60 v3.2
       
   175      * @param   aLocalAddr          To which local address request came
       
   176      * @param   aFromAddr           Where request came from as seen by socket
       
   177      * @param   aPeerAddr           Real remote address where request came from
       
   178      * @param   aPriority           Priority from request
       
   179      * @param   aRemoteFavored      Whether candidate pair checked is favored
       
   180                                     by remote peer
       
   181      */
       
   182     void STUNRequestReceivedL( const TInetAddr& aLocalAddr,
       
   183         const TInetAddr& aFromAddr, const TInetAddr& aPeerAddr,
       
   184         TUint aPriority, TBool aRemoteFavored );
       
   185     
       
   186     /**
       
   187      * Indicates whether relay is used for some selected pair.
       
   188      *
       
   189      * @since   S60 v3.2
       
   190      * @return  ETrue if relay is used
       
   191      */
       
   192     TBool RelayUsedForSelectedPairL() const;
       
   193     
       
   194     /**
       
   195      * Recomputes pair priorities according to the new role.
       
   196      *
       
   197      * @since   S60 v3.2
       
   198      */
       
   199     void RecomputePairPriorities();
       
   200 
       
   201 // from base class MIceConnCheckListener
       
   202 
       
   203     /**
       
   204      * From MIceConnCheckListener.
       
   205      * Notifies result of a check.
       
   206      *
       
   207      * @since   S60 v3.2
       
   208      * @param   aCompletionCode     The completion code
       
   209      * @param   aCheck              The check which was completed
       
   210      * @param   aValidatedPair      Candidate pair validated by the check
       
   211      */
       
   212     void CheckCompletedL( 
       
   213         TInt aCompletionCode,
       
   214         const CIceConnectivityCheck& aCheck,
       
   215         CNATFWCandidatePair* aValidatedPair );
       
   216 
       
   217     /**
       
   218      * From MIceConnCheckListener.
       
   219      * Notifies result of a nomination check.
       
   220      *
       
   221      * @since   S60 v3.2
       
   222      * @param   aCompletionCode     The completion code
       
   223      * @param   aCheck              The check
       
   224      * @param   aValidatedPair      Candidate pair validated by the check
       
   225      */
       
   226     void NominationCompletedL( 
       
   227         TInt aCompletionCode,
       
   228         const CIceConnectivityCheck& aCheck,
       
   229         const CNATFWCandidatePair& aValidatedPair );
       
   230     
       
   231 private:
       
   232 
       
   233     CIceCheckList(
       
   234         MIceChecklistObserver& aClient,
       
   235         TUint aStreamCollectionId,
       
   236         CIceSessionData& aSessionData,
       
   237         CIceConnectionHandler& aConnHandler );
       
   238 
       
   239     void ConstructL();
       
   240 
       
   241     void GenerateCheckListL( 
       
   242         RPointerArray<CIceConnectivityCheck>& aCheckList );
       
   243     
       
   244     void PairCandidatesL(
       
   245         RPointerArray<CIceConnectivityCheck>& aCheckList,
       
   246         RPointerArray<CNATFWCandidate>& aLocalCandidates,
       
   247         RPointerArray<CNATFWCandidate>& aRemoteCandidates );
       
   248     
       
   249     TBool CompatibleCandidates( const CNATFWCandidate& aCand1, 
       
   250         const CNATFWCandidate& aCand2 ) const;
       
   251     
       
   252     void PruneChecksL( RPointerArray<CIceConnectivityCheck>& aChecks );
       
   253     
       
   254     void ReplaceReflexiveCandidatesWithBaseL( 
       
   255         RPointerArray<CIceConnectivityCheck>& aChecks );
       
   256     
       
   257     void OnTimerFiredL();
       
   258     
       
   259     TUint PriorityForPeerReflCandL( 
       
   260         const CNATFWCandidate& aLocalCandidate ) const;
       
   261         
       
   262     void HandleTriggeredCheckL( const CNATFWCandidatePair& aPair );
       
   263     
       
   264     void UpdateCheckListStateL();
       
   265     
       
   266     void RemovePendingChecks( TUint aComponentId );
       
   267     
       
   268     void GetComponentIdsL( RArray<TUint>& aComponentIds ) const;
       
   269     
       
   270     TInt FindCheckInState( TInt aStateMask );
       
   271     
       
   272     TInt FindCheckInState( TInt aStateMask, TUint aComponentId );
       
   273     
       
   274     TInt FindCheckInState( TInt aStateMask, const TInetAddr& aRemoteAddr );
       
   275     
       
   276     TInt FindCheck( const CNATFWCandidatePair& aPair );
       
   277     
       
   278     void SetStateL( TIceCheckListState aState );
       
   279     
       
   280     void DoLosingPairProcessingL( 
       
   281         const RPointerArray<CNATFWCandidatePair>& aSelectedPairs );
       
   282     
       
   283     void NominateCandidatePairsL();
       
   284     
       
   285     TBool CheckListFrozen();
       
   286     
       
   287     void EnqueueCheckL( CIceConnectivityCheck& aCheck,
       
   288         CIceConnectivityCheck::TIceCheckType aType, TUint aLocalPriority );
       
   289     
       
   290     TBool DequeueCheckL();
       
   291     
       
   292     TUint RetransmissionTimeOut() const;
       
   293 
       
   294     CDesC8ArrayFlat* FoundationsForCollectionL( TUint aStreamCollectionId ) const;
       
   295     
       
   296     TUint LowestComponentId( RArray<TUint>& aComponentIds ) const;
       
   297     
       
   298     TBool NominationExecuted() const;
       
   299     
       
   300     void InitializeCheckList( const TDesC8& aFoundation, 
       
   301         TInt aExcludedComponentId );
       
   302         
       
   303 private: // data
       
   304 
       
   305     /**
       
   306      * ICE check list state.
       
   307      */
       
   308     TIceCheckListState iState;
       
   309 
       
   310     /**
       
   311      * Stream collection for which this check list is.
       
   312      */
       
   313     TUint iStreamCollectionId;
       
   314     
       
   315     /**
       
   316      * Timer interval for pacing checks.
       
   317      */
       
   318     TTimeIntervalMicroSeconds32 iInterval;
       
   319     
       
   320     /**
       
   321      * Client notified about a result of the check.
       
   322      * Not own.
       
   323      */
       
   324     MIceChecklistObserver& iClient;
       
   325     
       
   326     /**
       
   327      * The session data.
       
   328      * Not own.
       
   329      */
       
   330     CIceSessionData& iSessionData;
       
   331     
       
   332     /**
       
   333      * Connection handler.
       
   334      * Not own.
       
   335      */
       
   336     CIceConnectionHandler& iConnHandler;
       
   337 
       
   338     /**
       
   339      * Ordered list of checks to be executed.
       
   340      * Own.
       
   341      */
       
   342     RPointerArray<CIceConnectivityCheck> iChecks;
       
   343     
       
   344     /**
       
   345      * Check queue for congestion control purposes.
       
   346      * Own.
       
   347      */
       
   348     RArray<TIceCheckQueItem> iCheckQue;
       
   349     
       
   350     /**
       
   351      * Prioritizer for the checks.
       
   352      * Own.
       
   353      */
       
   354     CIceCheckPrioritizer* iCheckPrioritizer;
       
   355     
       
   356     /**
       
   357      * Prioritizer for the local candidates.
       
   358      * Own.
       
   359      */
       
   360     CIceCandidatePrioritizer* iCandPrioritizer;
       
   361 
       
   362     /**
       
   363      * Timer for connectivity check triggering.
       
   364      * Own.
       
   365      */
       
   366     CPeriodic* iTimer;
       
   367     
       
   368     /**
       
   369      * Valid list.
       
   370      * Own.
       
   371      */
       
   372     CIceValidList* iValidList;
       
   373 
       
   374     /**
       
   375      * Component identifiers.
       
   376      * Own.
       
   377      */
       
   378     RArray<TUint> iComponentIds;
       
   379 
       
   380     /**
       
   381      * Remote selected candidate pairs.
       
   382      * Own.
       
   383      */
       
   384     RPointerArray<CNATFWCandidatePair> iSelectedPairs;
       
   385     };
       
   386 
       
   387 
       
   388 #endif // C_CICECHECKLIST_H