remote.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Inter Asterisk Exchange 2
00005  * 
00006  * A class to describe the node we are talking to.
00007  * 
00008  * Open Phone Abstraction Library (OPAL)
00009  *
00010  * Copyright (c) 2005 Indranet Technologies Ltd.
00011  *
00012  * The contents of this file are subject to the Mozilla Public License
00013  * Version 1.0 (the "License"); you may not use this file except in
00014  * compliance with the License. You may obtain a copy of the License at
00015  * http://www.mozilla.org/MPL/
00016  *
00017  * Software distributed under the License is distributed on an "AS IS"
00018  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
00019  * the License for the specific language governing rights and limitations
00020  * under the License.
00021  *
00022  * The Original Code is Open Phone Abstraction Library.
00023  *
00024  * The Initial Developer of the Original Code is Indranet Technologies Ltd.
00025  *
00026  * The author of this code is Derek J Smithies
00027  *
00028  * $Revision: 21421 $
00029  * $Author: dereksmithies $
00030  * $Date: 2008-10-30 00:36:33 +0000 (Thu, 30 Oct 2008) $
00031  */
00032 
00033 #ifndef OPAL_IAX2_REMOTE_H
00034 #define OPAL_IAX2_REMOTE_H
00035 
00036 #ifndef _PTLIB_H
00037 #include <ptlib.h>
00038 #endif
00039 
00040 #include <opal/buildopts.h>
00041 
00042 #if OPAL_IAX2
00043 
00044 #include <ptlib/sockets.h>
00045 
00046 #if OPAL_PTLIB_SSL_AES
00047 #include <openssl/aes.h>
00048 #endif
00049 
00050 #ifdef P_USE_PRAGMA
00051 #pragma interface
00052 #endif
00053 
00054 class IAX2FullFrame;
00055 
00056 
00059 class IAX2Remote : public PObject
00060 { 
00061   PCLASSINFO(IAX2Remote, PObject);
00062   
00063  public:
00064   
00066   IAX2Remote();
00067   
00068   virtual ~IAX2Remote() { };
00069   
00072   PINDEX DestCallNumber() { return destCallNumber; }
00073   
00077   PINDEX SourceCallNumber() { return sourceCallNumber; }
00078  
00080   virtual void PrintOn(ostream & strm) const; 
00081   
00083   enum {
00084     callNumberUndefined = 0xffff 
00085   };
00086   
00088   PIPSocket::Address RemoteAddress() { return remoteAddress; }
00089   
00093   PString BuildConnectionTokenId();
00094 
00096   PString BuildOurConnectionTokenId();
00097 
00099   PINDEX   RemotePort() { return remotePort; }
00100   
00102   void Assign(IAX2Remote &);
00103   
00105   void SetRemoteAddress(PIPSocket::Address &newVal) { remoteAddress = newVal; }
00106   
00108   void SetRemoteAddress(int newVal) { remoteAddress = newVal; }
00109   
00111   void SetRemotePort (PINDEX newVal) { remotePort = newVal; }
00112   
00114   void SetSourceCallNumber(PINDEX newVal) { sourceCallNumber = newVal; }
00115   
00117   void SetDestCallNumber(PINDEX newVal) { destCallNumber = newVal; }
00118   
00122   PBoolean operator == (IAX2Remote & other);
00123   
00126   PBoolean operator *= (IAX2Remote & other);
00127   
00128   
00130   PBoolean operator != (IAX2Remote & other);
00131   
00132   
00133  protected:
00135   PINDEX       sourceCallNumber;    
00136   
00138   PINDEX       destCallNumber;      
00139   
00141   PIPSocket::Address remoteAddress; 
00142   
00144   PINDEX               remotePort;    
00145 
00146 };
00147 
00149 
00158 class IAX2FrameIdValue : public PObject
00159 {
00160   PCLASSINFO(IAX2FrameIdValue, PObject);
00161  public:
00163   IAX2FrameIdValue (PINDEX timeStamp, PINDEX seqVal);
00164 
00166   IAX2FrameIdValue (PINDEX val);
00167 
00169   PINDEX GetTimeStamp() const;
00170 
00172   PINDEX GetSequenceVal() const;
00173 
00177   PINDEX GetPlainSequence() const;
00178 
00180   virtual void PrintOn(ostream & strm) const;
00181 
00184   virtual Comparison Compare(const PObject & obj) const;
00185 
00186  protected:
00187 
00190   PUInt64 value;
00191 };
00192 
00194 
00199 PDECLARE_SORTED_LIST(IAX2PacketIdList, IAX2FrameIdValue)
00200 #ifdef DOC_PLUS_PLUS
00201 class IAX2PacketIdList : public PSortedList
00202 {
00203 #endif
00204   
00207   PBoolean Contains(IAX2FrameIdValue &src);
00208   
00211   PINDEX GetFirstValue();
00212   
00214   void AppendNewFrame(IAX2FullFrame &src);
00215   
00217   virtual void PrintOn(ostream & strm) const;   
00218   
00219  protected:
00225   void RemoveOldContiguousValues();
00226 };
00227 
00229 
00230 class IAX2SequenceNumbers
00231 {
00232  public:
00236   enum IncomingOrder {
00237     InSequence,  
00238     SkippedFrame, 
00239     RepeatedFrame 
00240   };
00241 
00242 
00243 
00245   IAX2SequenceNumbers() 
00246     { ZeroAllValues();   };
00247   
00249   virtual ~IAX2SequenceNumbers() { }
00250   
00252   void ZeroAllValues();
00253   
00255   PINDEX InSeqNo();
00256   
00258   PINDEX OutSeqNo();
00259   
00262   PBoolean IsFirstReplyFrame();
00263 
00266   PBoolean IsSequenceNosZero();
00267 
00269   void SetInSeqNo(PINDEX newVal);
00270   
00272   void SetOutSeqNo(PINDEX newVal);
00273 
00276   void SetInOutSeqNo(PINDEX inVal, PINDEX outVal);
00277   
00280   void SetAckSequenceInfo(IAX2SequenceNumbers & other);
00281   
00283   PBoolean  operator !=(IAX2SequenceNumbers &other);
00284   
00286   PBoolean operator ==(IAX2SequenceNumbers &other);
00287   
00289   void MassageSequenceForSending(IAX2FullFrame &src /*<!src will be transmitted to the remote node */
00290                                  );
00291 
00295   void WrapAroundFrameSequence(IAX2SequenceNumbers & src);
00296   
00300   IncomingOrder IncomingMessageInOrder
00301     (IAX2FullFrame &src /*<!frame to be compared with current data base.*/  );
00302   
00304   void CopyContents(IAX2SequenceNumbers &src);
00305   
00307   PString AsString() const;
00308   
00310   virtual void PrintOn(ostream & strm) const;
00311 
00314   PBoolean IsFirstReply() { return (inSeqNo == 1) && (outSeqNo == 0); }
00315 
00317   void AddWrapAroundValue(PINDEX newOffset);
00318 
00319 
00320  protected:
00321 
00323   enum sequenceDefines {
00324     minSpacing = 3   
00325   };
00326   
00328   PINDEX inSeqNo;  
00329   
00331   PINDEX outSeqNo; 
00332 
00334   PMutex mutex;
00335 
00337   PINDEX lastSentTimeStamp;
00338 
00340   IAX2PacketIdList receivedLog;
00341 };
00342 
00344 
00345 class IAX2Encryption : public PObject 
00346 {
00347   PCLASSINFO(IAX2Encryption, PObject);
00348  public:
00350   IAX2Encryption();
00351 
00353   void SetEncryptionOn (PBoolean newState = PTrue);
00354 
00356   void SetEncryptionKey(PString & newKey);
00357 
00359   void SetChallengeKey(PString & newKey);
00360 
00362   const PString & EncryptionKey() const;
00363 
00365   const PString & ChallengeKey() const;
00366 
00368   PBoolean IsEncrypted() const;
00369 
00370 #if OPAL_PTLIB_SSL_AES
00371 
00372   AES_KEY *AesEncryptKey();
00373 
00375   AES_KEY *AesDecryptKey();
00376 #endif
00377 
00378  protected:
00381   void CalculateAesKeys();
00382 
00384   PString encryptionKey;
00385 
00387   PString challengeKey;
00388 
00390   PBoolean encryptionEnabled;
00391 
00392 #if OPAL_PTLIB_SSL_AES
00393 
00394   AES_KEY aesEncryptKey;
00395 
00397   AES_KEY aesDecryptKey;
00398 #endif
00399 };
00400 
00402 
00403 
00404 #endif // OPAL_IAX2
00405 
00406 #endif // OPAL_IAX2_REMOTE_H
00407 
00408 /* The comment below is magic for those who use emacs to edit this file. */
00409 /* With the comment below, the tab key does auto indent to 4 spaces.     */
00410 
00411 /*
00412  * Local Variables:
00413  * mode:c
00414  * c-basic-offset:2
00415  * End:
00416  */

Generated on Mon Feb 1 00:25:53 2010 for OPAL by  doxygen 1.5.1