inc/natfwstunclient.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006-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:    Provides STUN Client services.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef CSTUNCLIENT_H
       
    22 #define CSTUNCLIENT_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <in_sock.h>
       
    26 #include "natfwstunclientdefs.h"
       
    27 
       
    28 class MSTUNClientObserver;
       
    29 class CDeltaTimer;
       
    30 class CSTUNClientImplementation;
       
    31 class MNcmConnectionMultiplexer;
       
    32 
       
    33 /**
       
    34  * A class for creating STUN bindings towards a particular STUN server.
       
    35  * During the initialization resolves the STUN server address using 
       
    36  * DNS queries and obtains a shared secret from the STUN server 
       
    37  * if required. Supports also STUN relay.
       
    38  * Client should set credentials if pre-provisioned ( also known as 
       
    39  * long term credentials ) just after NewL is called.
       
    40  * MSTUNClientObserver::STUNClientInitCompleted notifies when
       
    41  * STUN Client is initialized.
       
    42  *
       
    43  * @lib stunclient.lib
       
    44  */
       
    45 class CSTUNClient : public CBase
       
    46     {
       
    47 public:
       
    48 
       
    49     /**
       
    50      * Two-phased constructor.
       
    51      * Starts the initialization procedures for STUN Client.
       
    52      * MSTUNClientObserver::STUNClientInitCompleted gets called 
       
    53      * when the object is ready to be used.
       
    54      *
       
    55      * @param   aRetransmitInterval the initial retransmit interval 
       
    56      *          for STUN Binding Requests.
       
    57      * @param   aServerAddress FQDN or IP address of the STUN server.
       
    58      *          If FQDN, assumed to be a domain for which a SRV query 
       
    59      *          is performed. If SRV query fails a A/AAAA query is performed.
       
    60      * @param   aServerPort if not zero, 
       
    61      *          server port to be used instead of STUN default port. 
       
    62      * @param   aServiceName Client must tell used servicename
       
    63      *          "stun" if STUN used,
       
    64      *          "stun-relay" if STUN relay used.
       
    65      * @param   aSocketServ a connected socket server session
       
    66      * @param   aConnection an active connection started by the client
       
    67      *          with RConnection::Start()
       
    68      * @param   aTimer Timer services
       
    69      * @param   aObserver a callback for STUN Client event notifications
       
    70      * @param   aObtainSharedSecret if ETrue obtains a shared secret 
       
    71      *          which will be used for the STUN Binding Requests.
       
    72      *          If EFalse STUN Binding Requests will be sent without 
       
    73      *          the shared secret related attributes.
       
    74      * @param   aFailIfNoSRVRecordsFound if ETrue,
       
    75      *          MSTUNClientObserver::STUNClientInitCompleted 
       
    76      *          will be called with KErrNotFound, 
       
    77      *          if no SRV records for aSTUNServer with UDP were not found.
       
    78      * @param   aIcmpReceiverUsed Desides whether icmp receiver is
       
    79      *          instantiated in STUN client
       
    80      * @param   aMultiplexer Connection multiplexer.
       
    81      * @param   aTransportProtocol Transport protocol to use.
       
    82      */
       
    83     IMPORT_C static CSTUNClient* NewL( 
       
    84         TInt aRetransmitInterval,
       
    85         const TDesC8& aServerAddress,
       
    86         TUint aServerPort,
       
    87         const TDesC8& aServiceName,
       
    88         RSocketServ& aSocketServ,
       
    89         RConnection& aConnection,
       
    90         CDeltaTimer& aTimer,
       
    91         MSTUNClientObserver& aObserver,
       
    92         TBool aObtainSharedSecret=ETrue,
       
    93         TBool aFailIfNoSRVRecordsFound=EFalse,
       
    94         TBool aIcmpReceiverUsed=ETrue,
       
    95         MNcmConnectionMultiplexer* aMultiplexer=NULL,
       
    96         TTransportProtocol aTransportProtocol=EUdpProtocol );
       
    97     
       
    98     /**
       
    99      * Two-phased constructor.
       
   100      * Creates a new instance of CSTUNClient for ICE connectivity checks.
       
   101      * Starts the initialization procedures for STUN Client.
       
   102      * MSTUNClientObserver::STUNClientInitCompleted gets called 
       
   103      * when the object is ready to be used.
       
   104      *
       
   105      * @since   s60 v3.2
       
   106      * @param   aRetransmitInterval the initial retransmit interval 
       
   107      *          for STUN Binding Requests.
       
   108      * @param   aTimer Timer services
       
   109      * @param   aObserver a callback for STUN Client event notifications
       
   110      * @param   aMultiplexer Connection multiplexer.
       
   111      * @param   aTransportProtocol Used transport protocol.
       
   112      */
       
   113     IMPORT_C static CSTUNClient* NewL( 
       
   114         TInt aRetransmitInterval,
       
   115         CDeltaTimer& aTimer,
       
   116         MSTUNClientObserver& aObserver,
       
   117         MNcmConnectionMultiplexer* aMultiplexer=NULL,
       
   118         TTransportProtocol aTransportProtocol=EUdpProtocol );
       
   119 
       
   120     /**
       
   121      * Two-phased constructor.
       
   122      */
       
   123     IMPORT_C static CSTUNClient* NewLC( 
       
   124         TInt aRetransmitInterval,
       
   125         const TDesC8& aServerAddress,
       
   126         TUint aServerPort,
       
   127         const TDesC8& aServiceName,
       
   128         RSocketServ& aSocketServ,
       
   129         RConnection& aConnection,
       
   130         CDeltaTimer& aTimer,
       
   131         MSTUNClientObserver& aObserver,
       
   132         TBool aObtainSharedSecret=ETrue,
       
   133         TBool aFailIfNoSRVRecordsFound=EFalse,
       
   134         TBool aIcmpReceiverUsed=ETrue,
       
   135         MNcmConnectionMultiplexer* aMultiplexer=NULL,
       
   136         TTransportProtocol aTransportProtocol=EUdpProtocol );
       
   137     
       
   138     /**
       
   139      * Two-phased constructor.
       
   140      */
       
   141     IMPORT_C static CSTUNClient* NewLC( 
       
   142         TInt aRetransmitInterval,
       
   143         CDeltaTimer& aTimer,
       
   144         MSTUNClientObserver& aObserver,
       
   145         MNcmConnectionMultiplexer* aMultiplexer=NULL,
       
   146         TTransportProtocol aTransportProtocol=EUdpProtocol );
       
   147 
       
   148     /**
       
   149      * Destructor.
       
   150      */
       
   151     IMPORT_C ~CSTUNClient();
       
   152 
       
   153     /**
       
   154      * Check whether this STUN Client has been properly initialized
       
   155      * and can be used to create STUN bindings.
       
   156      *    
       
   157      * @return   ETrue if the client is initialized, otherwise EFalse
       
   158      */
       
   159     IMPORT_C TBool IsInitialized() const;
       
   160 
       
   161     /**
       
   162      * Gets the STUN server address and port used for 
       
   163      * when sending Binding Requests.
       
   164      *
       
   165      * @pre     IsInitialized() == ETrue
       
   166      * @leave   KErrNotReady if IsInitialized() == EFalse
       
   167      * @leave   KErrNotFound if STUN client has no responding addresses left
       
   168      * @return  STUN server used to keep the NAT bindings alive
       
   169      */
       
   170     IMPORT_C const TInetAddr& STUNServerAddrL() const;
       
   171     
       
   172     /**
       
   173      * Sets credentials for the STUN server used.
       
   174      * These credentials override any existing ones. They are used to
       
   175      * obtain short term shared secret or act as credentials as they are.
       
   176      *
       
   177      * @pre     aUsername's length must be larger than zero and multiple of 4.
       
   178      * @pre     aPassword's length must be larger than zero and multiple of 4.
       
   179      * @param   aUsername username
       
   180      * @param   aPassword password
       
   181      * @return  void
       
   182      */
       
   183     IMPORT_C void SetCredentialsL( const TDesC8& aUsername,
       
   184         const TDesC8& aPassword );
       
   185 
       
   186     /**
       
   187      * Tells if the Binding Requests will be sent protected with the
       
   188      * MESSAGE-INTEGRITY attribute.
       
   189      *
       
   190      * @return   ETrue if message integrity is used, EFalse otherwise
       
   191      */
       
   192     IMPORT_C TBool SharedSecretObtained() const;
       
   193 
       
   194     /**
       
   195      * Requests a new UNSAF transaction ID. ID's type is
       
   196      * TNATFWUNSAFTransactionID but it is casted as a descriptor as
       
   197      * only TURN Plug-in needs to obtain the ID from STUN Client API.
       
   198      *
       
   199      * @since   s60 v3.2
       
   200      * @param   aTransactionID OUT: New Transaction ID
       
   201      * @return  void
       
   202      */
       
   203     IMPORT_C void ObtainTransactionIDL( TDesC8& aTransactionID );
       
   204     
       
   205     CSTUNClientImplementation& Implementation();
       
   206 
       
   207 private:
       
   208 
       
   209     CSTUNClient();
       
   210 
       
   211     CSTUNClient( const CSTUNClient& aClient );
       
   212     
       
   213     void ConstructL( TInt aRetransmitInterval,
       
   214                      const TDesC8& aServerAddress,
       
   215                      TUint aServerPort,
       
   216                      const TDesC8& aServiceName,
       
   217                      RSocketServ& aSocketServ,
       
   218                      RConnection& aConnection,
       
   219                      CDeltaTimer& aTimer,
       
   220                      MSTUNClientObserver& aObserver,
       
   221                      TBool aObtainSharedSecret,
       
   222                      TBool aFailIfNoSRVRecordsFound,
       
   223                      TBool aIcmpReceiverUsed,
       
   224                      MNcmConnectionMultiplexer* aMultiplexer,
       
   225                      TTransportProtocol aTransportProtocol );
       
   226 
       
   227     void ConstructL( TInt aRetransmitInterval,
       
   228                      CDeltaTimer& aTimer,
       
   229                      MSTUNClientObserver& aObserver,
       
   230                      MNcmConnectionMultiplexer* aMultiplexer,
       
   231                      TTransportProtocol aTransportProtocol );
       
   232 
       
   233 private: // Data
       
   234 
       
   235     /** 
       
   236      * Implementation.
       
   237      * Own.
       
   238      */ 
       
   239     CSTUNClientImplementation* iImplementation;
       
   240 
       
   241 private:
       
   242 
       
   243     __DECLARE_TEST;
       
   244     };
       
   245 
       
   246 #endif // CSTUNCLIENT_H
       
   247