|
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: Handles priorization of local candidates |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include <e32base.h> |
|
22 #include "natfwcandidate.h" |
|
23 #include <cnatfwsettingsapi.h> |
|
24 #include <mnatfwicesettings.h> |
|
25 #include "cicecandidateprioritizer.h" |
|
26 #include "icecandidatehandlerlogs.h" |
|
27 |
|
28 const TUint KLocalPrefSingleHomedUdp = 65535; |
|
29 |
|
30 /** powers of 2 */ |
|
31 const TUint K2ToPowerOf24 = 2^24; |
|
32 const TUint K2ToPowerOf12 = 2^12; |
|
33 const TUint K2ToPowerOf9 = 2^9; |
|
34 const TUint K2ToPowerOf8 = 2^8; |
|
35 const TUint K2ToPowerOf0 = 2^0; |
|
36 |
|
37 /** max component Id */ |
|
38 const TUint KMaxComponentId = 256; |
|
39 |
|
40 // ======== MEMBER FUNCTIONS ======== |
|
41 |
|
42 CIceCandidatePrioritizer::CIceCandidatePrioritizer() |
|
43 { |
|
44 __ICEDP( "CIceCandidatePrioritizer::CIceCandidatePrioritizer" ) |
|
45 } |
|
46 |
|
47 |
|
48 void CIceCandidatePrioritizer::ConstructL( const TDesC8& aDomain ) |
|
49 { |
|
50 iNatSettings = CNATFWNatSettingsApi::NewL( aDomain ); |
|
51 |
|
52 } |
|
53 |
|
54 |
|
55 CIceCandidatePrioritizer* CIceCandidatePrioritizer::NewL( |
|
56 const TDesC8& aDomain ) |
|
57 { |
|
58 __ICEDP( "CIceCandidatePrioritizer::NewL" ) |
|
59 |
|
60 CIceCandidatePrioritizer* self |
|
61 = CIceCandidatePrioritizer::NewLC( aDomain ); |
|
62 CleanupStack::Pop( self ); |
|
63 |
|
64 return self; |
|
65 } |
|
66 |
|
67 |
|
68 CIceCandidatePrioritizer* CIceCandidatePrioritizer::NewLC( |
|
69 const TDesC8& aDomain ) |
|
70 { |
|
71 __ICEDP( "CIceCandidatePrioritizer::NewLC" ) |
|
72 |
|
73 CIceCandidatePrioritizer* self = new( ELeave ) CIceCandidatePrioritizer(); |
|
74 CleanupStack::PushL( self ); |
|
75 |
|
76 self->ConstructL( aDomain ); |
|
77 |
|
78 return self; |
|
79 } |
|
80 |
|
81 |
|
82 CIceCandidatePrioritizer::~CIceCandidatePrioritizer() |
|
83 { |
|
84 __ICEDP( "CIceCandidatePrioritizer::~CIceCandidatePrioritizer" ) |
|
85 |
|
86 delete iNatSettings; |
|
87 } |
|
88 |
|
89 |
|
90 // --------------------------------------------------------------------------- |
|
91 // prioritize candidate |
|
92 // --------------------------------------------------------------------------- |
|
93 // |
|
94 void CIceCandidatePrioritizer::PrioritizeL( CNATFWCandidate& aCandidate ) const |
|
95 { |
|
96 __ICEDP( "CIceCandidatePrioritizer::PrioritizeL" ) |
|
97 |
|
98 TInt type_preference( 0 ); |
|
99 TInt direction_pref( 0 ); |
|
100 const MNATFWIceSettings& settings = iNatSettings->IceSettingsL(); |
|
101 |
|
102 switch( aCandidate.Type() ) |
|
103 { |
|
104 // UDP candidate types |
|
105 case CNATFWCandidate::EHost: |
|
106 { |
|
107 settings.GetPrefValue( MNATFWIceSettings::EPrefHostCandidate, |
|
108 type_preference ); |
|
109 break; |
|
110 } |
|
111 case CNATFWCandidate::EServerReflexive: |
|
112 { |
|
113 settings.GetPrefValue( |
|
114 MNATFWIceSettings::EPrefServerReflexiveCandidate, |
|
115 type_preference ); |
|
116 break; |
|
117 } |
|
118 case CNATFWCandidate::EPeerReflexive: |
|
119 { |
|
120 settings.GetPrefValue( |
|
121 MNATFWIceSettings::EPrefPeerReflexiveCandidate, |
|
122 type_preference ); |
|
123 |
|
124 // safety check for invalid provisioning |
|
125 if ( MNATFWIceSettings::KPrefValueDisabled == type_preference ) |
|
126 { |
|
127 type_preference = 0; |
|
128 } |
|
129 break; |
|
130 } |
|
131 case CNATFWCandidate::ERelay: |
|
132 { |
|
133 settings.GetPrefValue( MNATFWIceSettings::EPrefRelayCandidate, |
|
134 type_preference ); |
|
135 break; |
|
136 } |
|
137 |
|
138 default: |
|
139 { |
|
140 __ICEDP( "CIceCandidatePrioritizer::Prioritize, DEFAULT" ) |
|
141 ASSERT( EFalse ); |
|
142 break; |
|
143 } |
|
144 } |
|
145 |
|
146 ASSERT( MNATFWIceSettings::KPrefValueDisabled != type_preference ); |
|
147 ASSERT( MNATFWIceSettings::KPrefValueDisabled != direction_pref ); |
|
148 |
|
149 TInt transport_pref( 0 ); |
|
150 switch( aCandidate.TransportProtocol() ) |
|
151 { |
|
152 case KProtocolInetUdp: |
|
153 settings.GetPrefValue( MNATFWIceSettings::EPrefUdpTransport, |
|
154 transport_pref ); |
|
155 break; |
|
156 |
|
157 case KProtocolInetTcp: |
|
158 settings.GetPrefValue( MNATFWIceSettings::EPrefTcpTransport, |
|
159 transport_pref ); |
|
160 break; |
|
161 |
|
162 default: |
|
163 __ICEDP( "CIceCandidatePrioritizer::Prioritize, DEFAULT" ) |
|
164 ASSERT( EFalse ); |
|
165 break; |
|
166 } |
|
167 |
|
168 ASSERT( MNATFWIceSettings::KPrefValueDisabled != transport_pref ); |
|
169 |
|
170 TUint local_preference = KLocalPrefSingleHomedUdp; |
|
171 if ( KProtocolInetTcp == aCandidate.TransportProtocol() ) |
|
172 { |
|
173 TUint other_pref = 0; |
|
174 local_preference = K2ToPowerOf12 * transport_pref + \ |
|
175 K2ToPowerOf9 * direction_pref + \ |
|
176 K2ToPowerOf0 * other_pref; |
|
177 } |
|
178 |
|
179 TUint component_ID = aCandidate.ComponentId(); |
|
180 TUint priority = K2ToPowerOf24 * type_preference + \ |
|
181 K2ToPowerOf8 * local_preference + \ |
|
182 K2ToPowerOf0 * ( KMaxComponentId - component_ID ); |
|
183 |
|
184 aCandidate.SetPriority( priority ); |
|
185 } |