reSIProcate/stack  9694
Transport.hxx
Go to the documentation of this file.
00001 #if !defined(RESIP_TRANSPORT_HXX)
00002 #define RESIP_TRANSPORT_HXX
00003 
00004 #include "rutil/BaseException.hxx"
00005 #include "rutil/Data.hxx"
00006 #include "rutil/FdSetIOObserver.hxx"
00007 #include "rutil/ProducerFifoBuffer.hxx"
00008 #include "resip/stack/TransportFailure.hxx"
00009 #include "resip/stack/Tuple.hxx"
00010 #include "resip/stack/NameAddr.hxx"
00011 #include "resip/stack/Compression.hxx"
00012 #include "resip/stack/SendData.hxx"
00013 
00014 namespace resip
00015 {
00016 
00017 class TransactionMessage;
00018 class SipMessage;
00019 class Connection;
00020 class Compression;
00021 class FdPollGrp;
00022 
00055 #define RESIP_TRANSPORT_FLAG_NOBIND      (1<<0)
00056 #define RESIP_TRANSPORT_FLAG_RXALL       (1<<1)
00057 #define RESIP_TRANSPORT_FLAG_TXALL       (1<<2)
00058 #define RESIP_TRANSPORT_FLAG_KEEP_BUFFER (1<<3)
00059 #define RESIP_TRANSPORT_FLAG_TXNOW       (1<<4)
00060 #define RESIP_TRANSPORT_FLAG_OWNTHREAD   (1<<5)
00061 
00072 class Transport : public FdSetIOObserver
00073 {
00074    public:
00075 
00076   
00083       class Exception : public BaseException
00084       {
00085          public:
00086             Exception(const Data& msg, const Data& file, const int line);
00087             const char* name() const { return "TransportException"; }
00088       };
00089       
00100       Transport(Fifo<TransactionMessage>& rxFifo, 
00101                 const GenericIPAddress& address,
00102                 const Data& tlsDomain = Data::Empty, // !dcm! where is this used?
00103                 AfterSocketCreationFuncPtr socketFunc = 0,
00104                 Compression &compression = Compression::Disabled
00105          );
00106 
00128       Transport(Fifo<TransactionMessage>& rxFifo, 
00129                 int portNum, 
00130                 IpVersion version, 
00131                 const Data& interfaceObj,
00132                 const Data& tlsDomain = Data::Empty,
00133                 AfterSocketCreationFuncPtr socketFunc = 0,
00134                 Compression &compression = Compression::Disabled,
00135                 unsigned transportFlags = 0
00136          );
00137 
00138       virtual ~Transport();
00139 
00145       virtual bool isFinished() const=0;
00146       
00147       std::auto_ptr<SendData> makeSendData( const Tuple& tuple, const Data& data, const Data& tid, const Data &sigcompId = Data::Empty);
00148       
00157       virtual void send(std::auto_ptr<SendData> data)=0;
00158 
00166       virtual void poke(){};
00167 
00183       virtual void process(FdSet& fdset) = 0;
00184 
00189       virtual void buildFdSet( FdSet& fdset) =0;
00190 
00191       virtual unsigned int getTimeTillNextProcessMS(){return UINT_MAX;}
00192 
00197       virtual void process() = 0;
00198 
00199       virtual void setPollGrp(FdPollGrp *grp) = 0;
00200 
00205       void flowTerminated(const Tuple& flow);
00206       void keepAlivePong(const Tuple& flow);
00207 
00211       void fail(const Data& tid,
00212             TransportFailure::FailureReason reason = TransportFailure::Failure,
00213             int subCode = 0);
00214 
00221       static void error(int e);
00222 
00223       // These methods are used by the TransportSelector
00224       const Data& interfaceName() const { return mInterface; }
00225 
00226       int port() const { return mTuple.getPort(); } 
00227     
00229       bool isV4() const { return mTuple.isV4(); } // !dcm! -- deprecate ASAP
00230 
00231       IpVersion ipVersion() const { return mTuple.ipVersion(); }
00232     
00238       const Data& tlsDomain() const { return mTlsDomain; }
00239       const sockaddr& boundInterface() const { return mTuple.getSockaddr(); }
00240       const Tuple& getTuple() const { return mTuple; }
00241     
00243       virtual TransportType transport() const =0 ;
00244       virtual bool isReliable() const =0;
00245       virtual bool isDatagram() const =0;
00246 
00251       virtual bool hasSpecificContact() const { return false; }
00252 
00261       bool basicCheck(const SipMessage& msg);
00262 
00263       void makeFailedResponse(const SipMessage& msg,
00264                               int responseCode = 400,
00265                               const char * warning = 0);
00266       std::auto_ptr<SendData> make503(SipMessage& msg,
00267                                       UInt16 retryAfter);
00268 
00269       std::auto_ptr<SendData> make100(SipMessage& msg);
00270       void setRemoteSigcompId(SipMessage&msg, Data& id);
00271       // mark the received= and rport parameters if necessary
00272       static void stampReceived(SipMessage* request);
00273 
00284       virtual bool shareStackProcessAndSelect() const=0;
00285 
00295       virtual void startOwnProcessing()=0;
00296 
00298       virtual bool hasDataToSend() const = 0;
00299       
00310       virtual void shutdown()
00311       {
00312          // !jf! should use the fifo to pass this in
00313          mShuttingDown = true;
00314       }
00315 
00316       // also used by the TransportSelector.
00317       // requires that the two transports be
00318       bool operator==(const Transport& rhs) const;
00319 
00320       //# queued messages on this transport
00321       virtual unsigned int getFifoSize() const=0;
00322 
00323       void callSocketFunc(Socket sock);
00324 
00325       virtual void setCongestionManager(CongestionManager* manager)
00326       {
00327          mCongestionManager=manager;
00328       }
00329 
00330       CongestionManager::RejectionBehavior getRejectionBehaviorForIncoming() const
00331       {
00332          if(mCongestionManager)
00333          {
00334             return mCongestionManager->getRejectionBehavior(&mStateMachineFifo.getFifo());
00335          }
00336          return CongestionManager::NORMAL;
00337       }
00338 
00339       UInt32 getExpectedWaitForIncoming() const
00340       {
00341          return (UInt32)mStateMachineFifo.getFifo().expectedWaitTimeMilliSec()/1000;
00342       }
00343 
00344       // called by Connection to deliver a received message
00345       virtual void pushRxMsgUp(TransactionMessage* msg);
00346 
00347       // set the receive buffer length (SO_RCVBUF)
00348       virtual void setRcvBufLen(int buflen) { };        // make pure?
00349 
00350       // Storing and retrieving transport specific record-route header
00351       virtual void setRecordRoute(const NameAddr& recordRoute) { mRecordRoute = recordRoute; mHasRecordRoute = true; }
00352       virtual bool hasRecordRoute() const { return mHasRecordRoute; }
00353       virtual const NameAddr& getRecordRoute() const { assert(mHasRecordRoute); return mRecordRoute; }
00354 
00355       inline unsigned int getKey() const {return mKey;} 
00356 
00357    protected:
00358       friend class TransportSelector;
00359       inline void setKey(unsigned int pKey) { mKey = pKey;}
00360 
00361       Data mInterface;
00362       Tuple mTuple;
00363       NameAddr mRecordRoute;
00364       bool mHasRecordRoute;
00365       unsigned int mKey;
00366 
00367       CongestionManager* mCongestionManager;
00368       ProducerFifoBuffer<TransactionMessage> mStateMachineFifo; // passed in
00369       bool mShuttingDown;
00370 
00371       void setTlsDomain(const Data& domain) { mTlsDomain = domain; }
00372    private:
00373       static const Data transportNames[MAX_TRANSPORT];
00374       friend EncodeStream& operator<<(EncodeStream& strm, const Transport& rhs);
00375 
00376       Data mTlsDomain;
00377    protected:
00378       AfterSocketCreationFuncPtr mSocketFunc;
00379       Compression &mCompression;
00380       unsigned mTransportFlags;
00381 };
00382 
00383 EncodeStream& operator<<(EncodeStream& strm, const Transport& rhs);
00384 
00385 }
00386 
00387 #endif
00388 
00389 /* ====================================================================
00390  * The Vovida Software License, Version 1.0
00391  *
00392  * Copyright (c) 2000 Vovida Networks, Inc.  All rights reserved.
00393  *
00394  * Redistribution and use in source and binary forms, with or without
00395  * modification, are permitted provided that the following conditions
00396  * are met:
00397  *
00398  * 1. Redistributions of source code must retain the above copyright
00399  *    notice, this list of conditions and the following disclaimer.
00400  *
00401  * 2. Redistributions in binary form must reproduce the above copyright
00402  *    notice, this list of conditions and the following disclaimer in
00403  *    the documentation and/or other materials provided with the
00404  *    distribution.
00405  *
00406  * 3. The names "VOCAL", "Vovida Open Communication Application Library",
00407  *    and "Vovida Open Communication Application Library (VOCAL)" must
00408  *    not be used to endorse or promote products derived from this
00409  *    software without prior written permission. For written
00410  *    permission, please contact vocal@vovida.org.
00411  *
00412  * 4. Products derived from this software may not be called "VOCAL", nor
00413  *    may "VOCAL" appear in their name, without prior written
00414  *    permission of Vovida Networks, Inc.
00415  *
00416  * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESSED OR IMPLIED
00417  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00418  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND
00419  * NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL VOVIDA
00420  * NETWORKS, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT DAMAGES
00421  * IN EXCESS OF $1,000, NOR FOR ANY INDIRECT, INCIDENTAL, SPECIAL,
00422  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00423  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00424  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
00425  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00426  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
00427  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
00428  * DAMAGE.
00429  *
00430  * ====================================================================
00431  *
00432  * This software consists of voluntary contributions made by Vovida
00433  * Networks, Inc. and many individuals on behalf of Vovida Networks,
00434  * Inc.  For more information on Vovida Networks, Inc., please see
00435  * <http://www.vovida.org/>.
00436  *
00437  * vi: set shiftwidth=3 expandtab:
00438  */