natfw/natfwicecandidatehandler/inc/cicecheckhandler.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_CICECHECKHANDLER_H
       
    22 #define C_CICECHECKHANDLER_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include "natfwconnectivityapidefs.h"
       
    26 #include <in_sock.h>
       
    27 #include "natfwstunsrvobserver.h"
       
    28 #include "micechecklistobserver.h"
       
    29 #include "natfwinternaldefs.h"    //UNIT_TEST
       
    30 
       
    31 class CIceSessionData;
       
    32 class CIceCheckList;
       
    33 class CNATFWSTUNSrvClientSession;
       
    34 class MNcmConnectionMultiplexer;
       
    35 class CIceConnectionHandler;
       
    36 class CIceCandidatePrioritizer;
       
    37 class MIceNatPluginEventObs;
       
    38 class CNATFWCredentials;
       
    39 class CNATFWCandidate;
       
    40 class CNATFWCandidatePair;
       
    41 
       
    42 /**
       
    43  *  Manages check lists and listens to incoming checks.
       
    44  *
       
    45  *  @lib icecandidatehandler.dll
       
    46  *  @since S60 v3.2
       
    47  */
       
    48 class CIceCheckHandler
       
    49         : 
       
    50         public CBase, 
       
    51         public MNATFWStunSrvObserver,
       
    52         public MIceChecklistObserver
       
    53     {
       
    54 
       
    55     UNIT_TEST( UT_CIceCheckHandler )
       
    56    
       
    57 public:
       
    58 
       
    59     /**  ICE processing state across all media streams */
       
    60     enum TIceProcessingState
       
    61         {
       
    62         EIceRunning     = 1,    // There is checks in progress
       
    63         EIceCompleted   = 2     // All check lists has completed
       
    64         };
       
    65 
       
    66     /**
       
    67      * Two-phased constructor.
       
    68      * @param   aSessionData        Session data
       
    69      * @param   aMultiplexer        Multiplexer
       
    70      * @param   aConnHandler        Connection handler
       
    71      * @param   aEventObserver      Observer for events
       
    72      */
       
    73     static CIceCheckHandler* NewL( 
       
    74         CIceSessionData& aSessionData,
       
    75         MNcmConnectionMultiplexer& aMultiplexer,
       
    76         CIceConnectionHandler& aConnHandler,
       
    77         MIceNatPluginEventObs& aEventObserver );
       
    78 
       
    79     /**
       
    80      * Two-phased constructor.
       
    81      * @param   aSessionData        Session data
       
    82      * @param   aMultiplexer        Multiplexer
       
    83      * @param   aConnHandler        Connection handler
       
    84      * @param   aEventObserver      Observer for events
       
    85      */
       
    86     static CIceCheckHandler* NewLC(
       
    87         CIceSessionData& aSessionData,
       
    88         MNcmConnectionMultiplexer& aMultiplexer,
       
    89         CIceConnectionHandler& aConnHandler,
       
    90         MIceNatPluginEventObs& aEventObserver );
       
    91 
       
    92     /**
       
    93      * Destructor.
       
    94      */
       
    95     virtual ~CIceCheckHandler();
       
    96 
       
    97     /** 
       
    98      * Sets local or remote credentials. Local credentials are needed for
       
    99      * incoming STUN-request authentication.
       
   100      *
       
   101      * @since   S60 v3.2
       
   102      * @param   aCredentials        The credentials
       
   103      */
       
   104     void SetCredentialsL( const CNATFWCredentials& aCredentials );
       
   105     
       
   106     /**
       
   107      * Start perform connectivity checks. Local & remote candidates and
       
   108      * credentials for them must be stored before starting.
       
   109      *
       
   110      * @since   S60 v3.2
       
   111      */
       
   112     void PerformConnectivityChecksL();
       
   113 
       
   114     /**
       
   115      * Updates ICE processing with peer selected candidate pairs.
       
   116      * 
       
   117      * @since   S60 v3.2
       
   118      * @param   aPeerSelectedPairs  Peer selected candidate pairs
       
   119      */
       
   120     void UpdateIceProcessingL( 
       
   121         RPointerArray<CNATFWCandidatePair>& aPeerSelectedPairs );
       
   122     
       
   123     /**
       
   124      * Updates ICE processing with updated set of remote candidates.
       
   125      * 
       
   126      * @since   S60 v3.2
       
   127      * @param   aRemoteCands        All remote candidates known currently
       
   128      */
       
   129     void UpdateIceProcessingL( 
       
   130         RPointerArray<CNATFWCandidate>& aRemoteCands );
       
   131     
       
   132     /**
       
   133      * Cleanups all data related to the specified stream collection.
       
   134      *
       
   135      * @since   S60 v3.2
       
   136      * @param   aCollectionId       The collection identifier
       
   137      */
       
   138     void CleanupCollectionData( TUint aCollectionId );
       
   139 
       
   140 // from base class MNATFWStunSrvObserver
       
   141 
       
   142     /**
       
   143      * From MNATFWStunSrvObserver.
       
   144      * Called by NAT FW STUN server when incoming STUN request has come.
       
   145      * If aFromAddr == aPeerAddr relay isn't used.
       
   146      *
       
   147      * @since   S60 v3.2
       
   148      * @param   aLocalAddr          To which local address request came
       
   149      * @param   aFromAddr           Where request came from as seen by socket
       
   150      * @param   aPeerAddr           Real remote address where request came from
       
   151      * @param   aPriority           Priority from request
       
   152      * @param   aRemoteFavored      Whether candidate pair checked is favored
       
   153                                     by remote peer
       
   154      */
       
   155     void STUNRequestReceivedL( const TInetAddr& aLocalAddr,
       
   156         const TInetAddr& aFromAddr, const TInetAddr& aPeerAddr,
       
   157         TUint aPriority, TBool aRemoteFavored );
       
   158         
       
   159     /**
       
   160      * From MNATFWStunSrvObserver.
       
   161      * Called by NATFW STUN Server if role conflict is present between agents
       
   162      * and local agent needs to change its role.
       
   163      *
       
   164      * @since   S60 v3.2
       
   165      * @param   aDesiredRole        Desired role
       
   166      */
       
   167     void RoleChangeNeeded( TNATFWIceRole aDesiredRole );
       
   168 
       
   169 // from base class MIceChecklistObserver
       
   170 
       
   171     /**
       
   172      * From MIceChecklistObserver.
       
   173      * Indicates that check list has completed, either succesfully or not.
       
   174      *
       
   175      * @since   S60 v3.2
       
   176      * @param   aChecklist      The checklist which was completed
       
   177      * @param   aSelectedPairs  The selected pairs for components
       
   178      */
       
   179     void ChecklistCompletedL( 
       
   180         const CIceCheckList& aChecklist, 
       
   181         const RPointerArray<CNATFWCandidatePair>& aSelectedPairs );
       
   182 
       
   183     /**
       
   184      * From MIceChecklistObserver.
       
   185      * Indicates that check list has completed, either succesfully or not.
       
   186      *
       
   187      * @since   S60 v3.2
       
   188      * @param   aChecklist      The checklist which was completed
       
   189      * @param   aFailedComps    The failed components
       
   190      * @param   aErrCode        The completion code
       
   191      */
       
   192     void ChecklistCompletedL( 
       
   193         const CIceCheckList& aChecklist,
       
   194         const RArray<TUint>& aFailedComps,
       
   195         TInt aErrCode );
       
   196     
       
   197     /**
       
   198      * From MIceChecklistObserver.
       
   199      * Indicates that those checks in other checklists, which have same
       
   200      * foundation could be now unfrozen as an optimization.
       
   201      *
       
   202      * @since   S60 v3.2
       
   203      * @param   aChecklist      The checklist reporting event
       
   204      * @param   aFoundation     The foundation
       
   205      */
       
   206     void ComponentsHaveValidPairsL( 
       
   207         const CIceCheckList& aChecklist, const TDesC8& aFoundation );
       
   208 
       
   209 private:
       
   210 
       
   211     CIceCheckHandler( 
       
   212         CIceSessionData& aSessionData,
       
   213         MNcmConnectionMultiplexer& aMultiplexer,
       
   214         CIceConnectionHandler& aConnHandler,
       
   215         MIceNatPluginEventObs& aEventObserver );
       
   216 
       
   217     void ConstructL();
       
   218     
       
   219     void FormChecklistsL();
       
   220     
       
   221     CIceCheckList* ChecklistByCollectionId( TUint aStreamCollId );
       
   222 
       
   223     CIceCheckList* ChecklistByCollectionIdL( TUint aStreamCollId );
       
   224     
       
   225     void SetState( TIceProcessingState aState );
       
   226     
       
   227     void HandleNewCollectionsL();
       
   228     
       
   229     void HandleIceRestartsL();
       
   230     
       
   231     TInt NumOfActiveCheckLists();
       
   232     
       
   233     void UpdateStunServerParamsL();
       
   234     
       
   235     void ExecuteBufferedTriggeredChecksL();
       
   236     
       
   237     void UnFreezeCheckListsL(
       
   238         const CIceCheckList& aExcludedList, const TDesC8& aFoundation );
       
   239     
       
   240     void UpdateICEProcessingStateL( const CIceCheckList& aCheckList );
       
   241     
       
   242     class TIceTriggeredCheckInfo
       
   243         {
       
   244         public:
       
   245             TIceTriggeredCheckInfo( const TInetAddr& aLocalAddr,
       
   246                 const TInetAddr& aFromAddr, const TInetAddr& aPeerAddr,
       
   247                 TUint aPriority, TBool aRemoteFavored )
       
   248                 :
       
   249                 iLocalAddr( aLocalAddr ),
       
   250                 iFromAddr( aFromAddr ),
       
   251                 iPeerAddr( aPeerAddr ),
       
   252                 iPriority( aPriority ),
       
   253                 iRemoteFavored( aRemoteFavored ) { }
       
   254         
       
   255             const TInetAddr& LocalAddr() const  { return iLocalAddr; }
       
   256             const TInetAddr& FromAddr() const { return iFromAddr; }
       
   257             const TInetAddr& PeerAddr() const { return iPeerAddr; }
       
   258             TUint Priority() const { return iPriority; }
       
   259             TBool IsRemoteFavored() const { return iRemoteFavored; }
       
   260         
       
   261         private:
       
   262         
       
   263             TInetAddr iLocalAddr;
       
   264             TInetAddr iFromAddr;
       
   265             TInetAddr iPeerAddr;
       
   266             TUint iPriority;
       
   267             TBool iRemoteFavored;
       
   268         };
       
   269     
       
   270 private: // data
       
   271 
       
   272     /**
       
   273      * ICE processing state across all media streams.
       
   274      */
       
   275     TIceProcessingState iState;
       
   276 
       
   277     /**
       
   278      * The session data.
       
   279      * Not own.
       
   280      */
       
   281     CIceSessionData& iSessionData;
       
   282 
       
   283     /**
       
   284      * The multiplexer.
       
   285      * Not own.
       
   286      */
       
   287     MNcmConnectionMultiplexer& iMultiplexer;
       
   288 
       
   289     /**
       
   290      * The connection handler.
       
   291      * Not own.
       
   292      */
       
   293     CIceConnectionHandler& iConnHandler;
       
   294 
       
   295     /**
       
   296      * Event observer for NAT-plugin events.
       
   297      * Not own.
       
   298      */
       
   299     MIceNatPluginEventObs& iEventObserver;
       
   300 
       
   301     /**
       
   302      * The checklists.
       
   303      * Own.
       
   304      */
       
   305     RPointerArray<CIceCheckList> iCheckLists;
       
   306 
       
   307     /**
       
   308      * STUN server instance used for STUN request receiving.
       
   309      * Own.  
       
   310      */
       
   311     CNATFWSTUNSrvClientSession* iStunSrv;
       
   312 
       
   313     /**
       
   314      * Current credentials for ICE restart detection.
       
   315      * Own.  
       
   316      */
       
   317     RPointerArray<CNATFWCredentials> iCurCredentials;
       
   318 
       
   319     /**
       
   320      * Buffered triggered checks.
       
   321      * Own.  
       
   322      */
       
   323     RArray<TIceTriggeredCheckInfo> iBufferedChecks;
       
   324     };
       
   325 
       
   326 #endif // C_CICECHECKHANDLER_H