natfw/inc/natfwstunrelaybinding.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 relay binding services.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef CSTUNRELAYBINDING_H
       
    22 #define CSTUNRELAYBINDING_H
       
    23 
       
    24 #include <e32base.h>
       
    25 #include "natfwbindingbase.h"
       
    26 
       
    27 /**
       
    28  * A class for sending Allocate Requests and 
       
    29  * obtaining the public IP address as seen by the STUN relay server.
       
    30  *
       
    31  * @lib      natfwstunclient.lib
       
    32  * @since    s60 v3.2
       
    33  */
       
    34 class CSTUNRelayBinding : public CBinding
       
    35     {
       
    36 public:
       
    37 
       
    38     /**
       
    39      * Two-phased constructor.
       
    40      *
       
    41      * @since   s60 v3.2
       
    42      * @pre     aSTUNClient.IsInitialized()
       
    43      * @param   aSTUNClient an initialized STUNClient
       
    44      * @param   aStreamId Stream identifier
       
    45      * @param   aConnectionId Connection identifier
       
    46      */
       
    47     IMPORT_C static CSTUNRelayBinding* NewL( CSTUNClient& aSTUNClient, 
       
    48         TUint aStreamId, TUint aConnectionId );
       
    49 
       
    50     /**
       
    51      * Two-phased constructor.
       
    52      *
       
    53      * @since   s60 v3.2
       
    54      * @pre     aSTUNClient.IsInitialized()
       
    55      * @param   aSTUNClient an initialised STUN client
       
    56      * @param   aStreamId Stream identifier
       
    57      * @param   aConnectionId Connection identifier
       
    58      */
       
    59     IMPORT_C static CSTUNRelayBinding* NewLC( CSTUNClient& aSTUNClient, 
       
    60         TUint aStreamId, TUint aConnectionId );        
       
    61 
       
    62     /**
       
    63      * Destructor.
       
    64      */
       
    65     IMPORT_C ~CSTUNRelayBinding();
       
    66 
       
    67     /**
       
    68      * Executes STUN relay binding request.
       
    69      * Refreshes the binding causing a new Allocate Request to be sent
       
    70      * to the STUN relay server. The public IP address is available when 
       
    71      * MSTUNClientObserver gets called.
       
    72      * If application provided credentials with CSTUNClient::SetCredentialsL
       
    73      * or if parameter aObtainSharedSecret was ETrue when CSTUNClient was
       
    74      * created, USERNAME and MESSAGE-INTEGRITY attributes are put into the
       
    75      * Binding Request.
       
    76      *
       
    77      * @since   s60 v3.2
       
    78      * @param   aRtoValue Retransmission timeout(0 = default value to be used)
       
    79      * @return  void
       
    80      */
       
    81     IMPORT_C void AllocateRequestL( TUint aRtoValue );
       
    82 
       
    83     /**
       
    84      * Once the client wants to primarily receive from one peer, it can send
       
    85      * SetActiveDestination request.
       
    86      *
       
    87      * @since   s60 v3.2
       
    88      * @param   aRemoteAddr Specified remote address
       
    89      * @param   aTimerValue Timer value got from server
       
    90      * @return  void
       
    91      */
       
    92     IMPORT_C void SetActiveDestinationRequestL( 
       
    93         const TInetAddr& aRemoteAddr, TUint32& aTimerValue );
       
    94 
       
    95     /**
       
    96      * After successfully AllocateRequestL and AddressResolved() calling
       
    97      * relayed transport address can be queried. 
       
    98      *  
       
    99      * @since   s60 v3.2
       
   100      * @return  relay transport address
       
   101      */
       
   102     IMPORT_C const TInetAddr& RelayAddr() const;
       
   103 
       
   104     /**
       
   105      * Transmission of data towards a peer
       
   106      * through the relay can be done using the SendIndicationL.
       
   107      * Indication does not generate response.
       
   108      *
       
   109      * @since   s60 v3.2
       
   110      * @param   aRemoteAddr     Address to send to (remote agent)
       
   111      * @param   aData           Data to send to remote agent. Use KNullDesC8
       
   112      *                          if there is no data available.
       
   113      * @param   aAddFingerprint true if fingerprint is added
       
   114      * @return  void
       
   115      */
       
   116     IMPORT_C void SendIndicationL( const TInetAddr& aRemoteAddr, 
       
   117         const TDesC8& aData, TBool aAddFingerprint );
       
   118         
       
   119     /**
       
   120      * ConnectRequestL is used (when obtained an
       
   121      * allocated transport address that is TCP) to request server to open
       
   122      * TCP connection to specific destination address.
       
   123      *
       
   124      * @since   s60 v3.2
       
   125      * @param   aRemoteAddr Specific remote address
       
   126      * @return  void
       
   127      */
       
   128     IMPORT_C void ConnectRequestL( const TInetAddr& aRemoteAddr );
       
   129 
       
   130     /**
       
   131      * From CBinding.
       
   132      * Cancels previously issued AllocateRequestL.
       
   133      *
       
   134      * @since   s60 v3.2
       
   135      * @return  void
       
   136      */
       
   137     IMPORT_C void CancelRequest();
       
   138 
       
   139     /**
       
   140      * From CBinding.
       
   141      * Checks whether the public address has a value set.
       
   142      *
       
   143      * @since   s60 v3.2
       
   144      * @return  ETrue if the public address has been obtained, 
       
   145      *          otherwise EFalse. 
       
   146      */
       
   147     IMPORT_C TBool AddressResolved() const;    
       
   148 
       
   149     /**
       
   150      * From CBinding.
       
   151      * Gets the public address for this binding as seen in public network.
       
   152      * If AddressResolved function returns EFalse, the return value of
       
   153      * this function is not defined.
       
   154      *
       
   155      * @since   s60 v3.2
       
   156      * @return public address
       
   157      */
       
   158     IMPORT_C const TInetAddr& PublicAddr() const;
       
   159 
       
   160     /**
       
   161      * From CBinding.
       
   162      * This method should be called when receiving data
       
   163      * from the socket shared with this binding and 
       
   164      * the data cannot be handled by client.
       
   165      *
       
   166      * @since   s60 v3.2
       
   167      * @param   aData data received
       
   168      * @param   aConsumed on return ETrue if the data was accepted,
       
   169      *          otherwise EFalse.
       
   170      * @param   aRemoteAddr remote address from remote address attribute
       
   171      * @return  Decoded data if data is indication and not unsaf message,
       
   172      *          otherwise NULL. Ownership is transferred.
       
   173      */
       
   174     IMPORT_C HBufC8* HandleDataL( 
       
   175         const TDesC8& aData, TBool& aConsumed, TInetAddr& aRemoteAddr );
       
   176 
       
   177     /**
       
   178      * From CBinding.
       
   179      * ICE specific attributes can be set for the request.
       
   180      *  
       
   181      * @since   s60 v3.2
       
   182      * @param   aAttributes     Contains ICE specific attributes.
       
   183      * @return  void
       
   184      */
       
   185     IMPORT_C void SetICESpecificAttributes( 
       
   186         const TICEAttributes& aAttributes );
       
   187 
       
   188     /**
       
   189      * From CBinding.
       
   190      * Returns used stream Id
       
   191      *
       
   192      * @since   s60 v3.2
       
   193      * @return  stream Id
       
   194      */
       
   195     IMPORT_C TUint StreamId() const;
       
   196 
       
   197     /**
       
   198      * From CBinding.
       
   199      * Returns used connection Id
       
   200      *
       
   201      * @since   s60 v3.2
       
   202      * @return  connection Id
       
   203      */
       
   204     IMPORT_C TUint ConnectionId() const;
       
   205         
       
   206     /**
       
   207      * From CBinding.
       
   208      * Returns alternate server transport address.
       
   209      *
       
   210      * @since   s60 v3.2
       
   211      * @return alternate server address
       
   212      */
       
   213     IMPORT_C const TInetAddr& AlternateServerAddr() const;
       
   214 
       
   215     /**
       
   216      * From CBinding.
       
   217      * Returns realm value from error response.
       
   218      *
       
   219      * @since   s60 v3.2
       
   220      * @return realm from error response         
       
   221      */
       
   222     IMPORT_C const HBufC8* RealmFromResponse() const;          
       
   223             
       
   224     /**
       
   225      * From CBinding.
       
   226      * Returns the associated CSTUNClient instance.
       
   227      *
       
   228      * @since   s60 v3.2
       
   229      * @return  CSTUNClient, or NULL if the CSTUNClient has been deleted        
       
   230      */
       
   231     IMPORT_C const CSTUNClient* STUNClient() const;
       
   232 
       
   233 
       
   234 protected:
       
   235 
       
   236     /**
       
   237      * From CBinding.
       
   238      * Returns the implementation instance.        
       
   239      */
       
   240     CBindingImplementation& Implementation();
       
   241     
       
   242     /**
       
   243      * From CBinding.
       
   244      * Returns a non-modifiable implementation instance.        
       
   245      */
       
   246     const CBindingImplementation& Implementation() const;
       
   247 
       
   248 private:
       
   249 
       
   250     CSTUNRelayBinding();
       
   251     CSTUNRelayBinding( const CBinding& aBinding );
       
   252 
       
   253     void ConstructL( CSTUNClient& aSTUNClient, TUint aStreamId,
       
   254         TUint aConnectionId );
       
   255     
       
   256     // This constructor is not used in this implementation    
       
   257     void ConstructL( CSTUNClient& aSTUNClient, RSocket& aSocket );
       
   258     
       
   259     __DECLARE_TEST;
       
   260     };
       
   261 
       
   262 #endif // CSTUNRELAYBINDING_H
       
   263