|
reSIProcate/stack
9694
|
00001 #if !defined(RESIP_TRANSPORTSELECTOR_HXX) 00002 #define RESIP_TRANSPORTSELECTOR_HXX 00003 00004 #ifndef WIN32 00005 #include <sys/select.h> 00006 #endif 00007 00008 #include <map> 00009 #include <vector> 00010 00011 #include "rutil/Data.hxx" 00012 #include "rutil/Fifo.hxx" 00013 #include "rutil/GenericIPAddress.hxx" 00014 #include "resip/stack/Transport.hxx" 00015 #include "resip/stack/DnsInterface.hxx" 00016 #include "rutil/SelectInterruptor.hxx" 00017 00018 00019 #include "resip/stack/SecurityTypes.hxx" 00020 class TestTransportSelector; 00021 00022 namespace osc 00023 { 00024 class Stack; 00025 } 00026 00027 namespace resip 00028 { 00029 00030 class DnsHandler; 00031 class Message; 00032 class TransactionMessage; 00033 class SipMessage; 00034 class TransactionController; 00035 class Security; 00036 class Compression; 00037 class FdPollGrp; 00038 00052 class TransportSelector 00053 { 00054 public: 00055 TransportSelector(Fifo<TransactionMessage>& fifo, Security* security, DnsStub& dnsStub, Compression &compression); 00056 virtual ~TransportSelector(); 00061 bool hasDataToSend() const; 00062 00066 void shutdown(); 00067 00069 bool isFinished() const; 00070 00073 void setPollGrp(FdPollGrp *pollGrp); 00074 00076 // thread than the TransactionController; this will allow the thread to be 00077 // interrupted when poke() is called. 00078 void createSelectInterruptor(); 00079 00083 void process(FdSet& fdset); 00084 void process(); 00086 void buildFdSet(FdSet& fdset); 00087 00090 void poke(); 00091 void addTransport( std::auto_ptr<Transport> transport, bool immediate); 00092 00093 DnsResult* createDnsResult(DnsHandler* handler); 00094 00095 void dnsResolve(DnsResult* result, SipMessage* msg); 00096 00102 bool transmit( SipMessage* msg, Tuple& target, SendData* sendData=0 ); 00103 00105 void retransmit(const SendData& msg); 00106 00107 void closeConnection(const Tuple& peer); 00108 00109 unsigned int sumTransportFifoSizes() const; 00110 00111 unsigned int getTimeTillNextProcessMS(); 00112 Fifo<TransactionMessage>& stateMacFifo() { return mStateMacFifo; } 00113 00114 void registerMarkListener(MarkListener* listener); 00115 void unregisterMarkListener(MarkListener* listener); 00116 void setEnumSuffixes(const std::vector<Data>& suffixes); 00117 00118 static Tuple getFirstInterface(bool is_v4, TransportType type); 00119 void terminateFlow(const resip::Tuple& flow); 00120 void enableFlowTimer(const resip::Tuple& flow); 00121 00122 void setCongestionManager(CongestionManager* manager) 00123 { 00124 for(TransportList::iterator i=mSharedProcessTransports.begin(); 00125 i!=mSharedProcessTransports.end();++i) 00126 { 00127 (*i)->setCongestionManager(manager); 00128 } 00129 00130 for(TransportList::iterator i=mHasOwnProcessTransports.begin(); 00131 i!=mHasOwnProcessTransports.end();++i) 00132 { 00133 (*i)->setCongestionManager(manager); 00134 } 00135 } 00136 00137 private: 00138 void addTransportInternal( std::auto_ptr<Transport> transport); 00139 void checkTransportAddQueue(); 00140 Connection* findConnection(const Tuple& dest) const; 00141 Transport* findTransportBySource(Tuple& src, const SipMessage* msg) const; 00142 Transport* findLoopbackTransportBySource(bool ignorePort, Tuple& src) const; 00143 Transport* findTransportByDest(const Tuple& dest); 00144 Transport* findTransportByVia(SipMessage* msg, const Tuple& dest, 00145 Tuple& src) const; 00146 Transport* findTlsTransport(const Data& domain,TransportType type,IpVersion ipv) const; 00147 Tuple determineSourceInterface(SipMessage* msg, const Tuple& dest) const; 00148 00149 DnsInterface mDns; 00150 Fifo<TransactionMessage>& mStateMacFifo; 00151 Security* mSecurity;// for computing identity header 00152 00153 // specific port and interface 00154 typedef std::map<Tuple, Transport*> ExactTupleMap; 00155 ExactTupleMap mExactTransports; 00156 00157 // specific port, ANY interface 00158 typedef std::map<Tuple, Transport*, Tuple::AnyInterfaceCompare> AnyInterfaceTupleMap; 00159 AnyInterfaceTupleMap mAnyInterfaceTransports; 00160 00161 // ANY port, specific interface 00162 typedef std::map<Tuple, Transport*, Tuple::AnyPortCompare> AnyPortTupleMap; 00163 AnyPortTupleMap mAnyPortTransports; 00164 00165 // ANY port, ANY interface 00166 typedef std::map<Tuple, Transport*, Tuple::AnyPortAnyInterfaceCompare> AnyPortAnyInterfaceTupleMap; 00167 AnyPortAnyInterfaceTupleMap mAnyPortAnyInterfaceTransports; 00168 00169 std::vector<Transport*> mTransports; // owns all Transports 00170 00174 class TlsTransportKey 00175 { 00176 public: 00177 TlsTransportKey(const resip::Data& domain, resip::TransportType type, resip::IpVersion version) 00178 :mDomain(domain), 00179 mType(type), 00180 mVersion(version) 00181 {} 00182 00183 TlsTransportKey(const TlsTransportKey& orig) 00184 { 00185 mDomain=orig.mDomain; 00186 mType=orig.mType; 00187 mVersion=orig.mVersion; 00188 } 00189 00190 ~TlsTransportKey(){} 00191 bool operator<(const TlsTransportKey& rhs) const 00192 { 00193 if(mDomain < rhs.mDomain) 00194 { 00195 return true; 00196 } 00197 else if(mDomain == rhs.mDomain) 00198 { 00199 if(mType < rhs.mType) 00200 { 00201 return true; 00202 } 00203 else if(mType == rhs.mType) 00204 { 00205 return mVersion < rhs.mVersion; 00206 } 00207 } 00208 return false; 00209 } 00210 00211 resip::Data mDomain; 00212 resip::TransportType mType; 00213 resip::IpVersion mVersion; 00214 00215 private: 00216 TlsTransportKey(); 00217 }; 00218 00219 typedef std::map<TlsTransportKey, Transport*> TlsTransportMap ; 00220 00221 TlsTransportMap mTlsTransports; 00222 00223 typedef std::vector<Transport*> TransportList; 00224 TransportList mSharedProcessTransports; 00225 TransportList mHasOwnProcessTransports; 00226 00227 typedef std::multimap<Tuple, Transport*, Tuple::AnyPortAnyInterfaceCompare> TypeToTransportMap; 00228 TypeToTransportMap mTypeToTransportMap; 00229 00230 // fake socket for connect() and route table lookups 00231 mutable Socket mSocket; 00232 mutable Socket mSocket6; 00233 00234 // An AF_UNSPEC addr_in for rapid unconnect 00235 GenericIPAddress mUnspecified; 00236 GenericIPAddress mUnspecified6; 00237 00239 Compression &mCompression; 00240 osc::Stack *mSigcompStack; 00241 00242 // epoll support, for sharedprocess transports 00243 FdPollGrp* mPollGrp; 00244 00245 int mAvgBufferSize; 00246 Fifo<Transport> mTransportsToAdd; 00247 std::auto_ptr<SelectInterruptor> mSelectInterruptor; 00248 FdPollItemHandle mInterruptorHandle; 00249 00250 friend class TestTransportSelector; 00251 friend class SipStack; // for debug only 00252 }; 00253 00254 } 00255 00256 #endif 00257 00258 /* ==================================================================== 00259 * The Vovida Software License, Version 1.0 00260 * 00261 * Copyright (c) 2000 Vovida Networks, Inc. All rights reserved. 00262 * 00263 * Redistribution and use in source and binary forms, with or without 00264 * modification, are permitted provided that the following conditions 00265 * are met: 00266 * 00267 * 1. Redistributions of source code must retain the above copyright 00268 * notice, this list of conditions and the following disclaimer. 00269 * 00270 * 2. Redistributions in binary form must reproduce the above copyright 00271 * notice, this list of conditions and the following disclaimer in 00272 * the documentation and/or other materials provided with the 00273 * distribution. 00274 * 00275 * 3. The names "VOCAL", "Vovida Open Communication Application Library", 00276 * and "Vovida Open Communication Application Library (VOCAL)" must 00277 * not be used to endorse or promote products derived from this 00278 * software without prior written permission. For written 00279 * permission, please contact vocal@vovida.org. 00280 * 00281 * 4. Products derived from this software may not be called "VOCAL", nor 00282 * may "VOCAL" appear in their name, without prior written 00283 * permission of Vovida Networks, Inc. 00284 * 00285 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED 00286 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00287 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND 00288 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL VOVIDA 00289 * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES 00290 * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL, 00291 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00292 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00293 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00294 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00295 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 00296 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 00297 * DAMAGE. 00298 * 00299 * ==================================================================== 00300 * 00301 * This software consists of voluntary contributions made by Vovida 00302 * Networks, Inc. and many individuals on behalf of Vovida Networks, 00303 * Inc. For more information on Vovida Networks, Inc., please see 00304 * <http://www.vovida.org/>. 00305 * 00306 * vi: set shiftwidth=3 expandtab: 00307 */
1.7.5.1