OPAL  Version 3.10.10
remote.h
Go to the documentation of this file.
1 /*
2  *
3  *
4  * Inter Asterisk Exchange 2
5  *
6  * A class to describe the node we are talking to.
7  *
8  * Open Phone Abstraction Library (OPAL)
9  *
10  * Copyright (c) 2005 Indranet Technologies Ltd.
11  *
12  * The contents of this file are subject to the Mozilla Public License
13  * Version 1.0 (the "License"); you may not use this file except in
14  * compliance with the License. You may obtain a copy of the License at
15  * http://www.mozilla.org/MPL/
16  *
17  * Software distributed under the License is distributed on an "AS IS"
18  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19  * the License for the specific language governing rights and limitations
20  * under the License.
21  *
22  * The Original Code is Open Phone Abstraction Library.
23  *
24  * The Initial Developer of the Original Code is Indranet Technologies Ltd.
25  *
26  * The author of this code is Derek J Smithies
27  *
28  * $Revision: 24606 $
29  * $Author: dereksmithies $
30  * $Date: 2010-07-28 22:51:05 -0500 (Wed, 28 Jul 2010) $
31  */
32 
33 #ifndef OPAL_IAX2_REMOTE_H
34 #define OPAL_IAX2_REMOTE_H
35 
36 #ifndef _PTLIB_H
37 #include <ptlib.h>
38 #endif
39 
40 #include <opal/buildopts.h>
41 
42 #if OPAL_IAX2
43 
44 #include <ptlib/sockets.h>
45 
46 #if OPAL_PTLIB_SSL_AES
47 #include <openssl/aes.h>
48 #endif
49 
50 #ifdef P_USE_PRAGMA
51 #pragma interface
52 #endif
53 
54 class IAX2FullFrame;
55 
56 
59 class IAX2Remote : public PObject
60 {
61  PCLASSINFO(IAX2Remote, PObject);
62 
63  public:
64 
66  IAX2Remote();
67 
68  virtual ~IAX2Remote() { };
69 
72  PINDEX DestCallNumber() { return destCallNumber; }
73 
77  PINDEX SourceCallNumber() { return sourceCallNumber; }
78 
80  virtual void PrintOn(ostream & strm) const;
81 
83  enum {
85  };
86 
88  PIPSocket::Address RemoteAddress() { return remoteAddress; }
89 
93  PString BuildConnectionToken();
94 
96  PString BuildOurConnectionToken();
97 
99  PINDEX RemotePort() { return remotePort; }
100 
102  void Assign(IAX2Remote &);
103 
105  void SetRemoteAddress(PIPSocket::Address &newVal) { remoteAddress = newVal; }
106 
108  void SetRemoteAddress(int newVal) { remoteAddress = newVal; }
109 
111  void SetRemotePort (PINDEX newVal) { remotePort = newVal; }
112 
114  void SetSourceCallNumber(PINDEX newVal) { sourceCallNumber = newVal; }
115 
117  void SetDestCallNumber(PINDEX newVal);
118 
122  PBoolean operator == (IAX2Remote & other);
123 
126  PBoolean operator *= (IAX2Remote & other);
127 
128 
130  PBoolean operator != (IAX2Remote & other);
131 
132 
133  protected:
136 
138  PINDEX destCallNumber;
139 
141  PIPSocket::Address remoteAddress;
142 
144  PINDEX remotePort;
145 
146 };
147 
149 
158 class IAX2FrameIdValue : public PObject
159 {
160  PCLASSINFO(IAX2FrameIdValue, PObject);
161  public:
163  IAX2FrameIdValue (PINDEX timeStamp, PINDEX seqVal);
164 
166  IAX2FrameIdValue (PINDEX val);
167 
169  PINDEX GetTimeStamp() const;
170 
172  PINDEX GetSequenceVal() const;
173 
177  PINDEX GetPlainSequence() const;
178 
180  virtual void PrintOn(ostream & strm) const;
181 
184  virtual Comparison Compare(const PObject & obj) const;
185 
186  protected:
187 
190  PUInt64 value;
191 };
192 
194 
199 PDECLARE_SORTED_LIST(IAX2PacketIdList, IAX2FrameIdValue)
200 #ifdef DOC_PLUS_PLUS
201 class IAX2PacketIdList : public PSortedList
202 {
203 #endif
204 
207  PBoolean Contains(IAX2FrameIdValue &src);
208 
211  PINDEX GetFirstValue();
212 
214  void AppendNewFrame(IAX2FullFrame &src);
215 
217  virtual void PrintOn(ostream & strm) const;
218 
219  protected:
225  void RemoveOldContiguousValues();
226 };
227 
229 
231 {
232  public:
239  RepeatedFrame
240  };
241 
242 
243 
246  { ZeroAllValues(); };
247 
249  virtual ~IAX2SequenceNumbers() { }
250 
252  void ZeroAllValues();
253 
255  PINDEX InSeqNo();
256 
258  PINDEX OutSeqNo();
259 
262  PBoolean IsFirstReplyFrame();
263 
266  PBoolean IsSequenceNosZero();
267 
269  void SetInSeqNo(PINDEX newVal);
270 
272  void SetOutSeqNo(PINDEX newVal);
273 
276  void SetInOutSeqNo(PINDEX inVal, PINDEX outVal);
277 
280  void SetAckSequenceInfo(IAX2SequenceNumbers & other);
281 
283  PBoolean operator !=(IAX2SequenceNumbers &other);
284 
286  PBoolean operator ==(IAX2SequenceNumbers &other);
287 
289  void MassageSequenceForSending(IAX2FullFrame &src /*<!src will be transmitted to the remote node */
290  );
291 
295  void WrapAroundFrameSequence(IAX2SequenceNumbers & src);
296 
300  IncomingOrder IncomingMessageInOrder
301  (IAX2FullFrame &src /*<!frame to be compared with current data base.*/ );
302 
304  void CopyContents(IAX2SequenceNumbers &src);
305 
307  PString AsString() const;
308 
310  virtual void PrintOn(ostream & strm) const;
311 
314  PBoolean IsFirstReply() { return (inSeqNo == 1) && (outSeqNo == 0); }
315 
317  void AddWrapAroundValue(PINDEX newOffset);
318 
319 
320  protected:
321 
324  minSpacing = 3
325  };
326 
328  PINDEX inSeqNo;
329 
331  PINDEX outSeqNo;
332 
334  PMutex mutex;
335 
338 
341 };
342 
344 
345 class IAX2Encryption : public PObject
346 {
347  PCLASSINFO(IAX2Encryption, PObject);
348  public:
350  IAX2Encryption();
351 
353  void SetEncryptionOn (PBoolean newState = true);
354 
356  void SetEncryptionKey(PString & newKey);
357 
359  void SetChallengeKey(PString & newKey);
360 
362  const PString & EncryptionKey() const;
363 
365  const PString & ChallengeKey() const;
366 
368  PBoolean IsEncrypted() const;
369 
370 #if OPAL_PTLIB_SSL_AES
371 
372  AES_KEY *AesEncryptKey();
373 
375  AES_KEY *AesDecryptKey();
376 #endif
377 
378  protected:
381  void CalculateAesKeys();
382 
384  PString encryptionKey;
385 
387  PString challengeKey;
388 
391 
392 #if OPAL_PTLIB_SSL_AES
393 
394  AES_KEY aesEncryptKey;
395 
397  AES_KEY aesDecryptKey;
398 #endif
399 };
400 
402 
403 
404 #endif // OPAL_IAX2
405 
406 #endif // OPAL_IAX2_REMOTE_H
407 
408 /* The comment below is magic for those who use emacs to edit this file.
409  * With the comment below, the tab key does auto indent to 2 spaces.
410  *
411  * Local Variables:
412  * mode:c
413  * c-basic-offset:2
414  * End:
415  */
void SetDestCallNumber(PINDEX newVal)
Definition: remote.h:230
PBoolean encryptionEnabled
Definition: remote.h:390
void SetRemotePort(PINDEX newVal)
Definition: remote.h:111
PBoolean operator!=(IAX2Remote &other)
PString BuildOurConnectionToken()
Definition: remote.h:59
PString BuildConnectionToken()
IncomingOrder
Definition: remote.h:236
PIPSocket::Address remoteAddress
Definition: remote.h:141
PMutex mutex
Definition: remote.h:334
void SetSourceCallNumber(PINDEX newVal)
Definition: remote.h:114
PBoolean operator==(IAX2Remote &other)
PString challengeKey
Definition: remote.h:387
PINDEX RemotePort()
Definition: remote.h:99
PINDEX DestCallNumber()
Definition: remote.h:72
Definition: frame.h:369
void SetRemoteAddress(PIPSocket::Address &newVal)
Definition: remote.h:105
void Assign(IAX2Remote &)
PINDEX lastSentTimeStamp
Definition: remote.h:337
PINDEX destCallNumber
Definition: remote.h:138
IAX2SequenceNumbers()
Definition: remote.h:245
Definition: remote.h:158
there is a missing frame, a VNAK condition
Definition: remote.h:238
IAX2PacketIdList receivedLog
Definition: remote.h:340
PBoolean IsFirstReply()
Definition: remote.h:314
PINDEX sourceCallNumber
Definition: remote.h:135
PINDEX outSeqNo
Definition: remote.h:331
PINDEX remotePort
Definition: remote.h:144
Definition: remote.h:345
PIPSocket::Address RemoteAddress()
Definition: remote.h:88
PINDEX SourceCallNumber()
Definition: remote.h:77
PBoolean operator*=(IAX2Remote &other)
sequenceDefines
Definition: remote.h:323
Definition: remote.h:84
PUInt64 value
Definition: remote.h:190
void SetRemoteAddress(int newVal)
Definition: remote.h:108
virtual ~IAX2SequenceNumbers()
Definition: remote.h:249
virtual ~IAX2Remote()
Definition: remote.h:68
perfect sequence number
Definition: remote.h:237
virtual void PrintOn(ostream &strm) const
PINDEX inSeqNo
Definition: remote.h:328
PString encryptionKey
Definition: remote.h:384
Definition: remote.h:201