OPAL  Version 3.18.8
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 
29 #ifndef OPAL_IAX2_REMOTE_H
30 #define OPAL_IAX2_REMOTE_H
31 
32 #ifndef _PTLIB_H
33 #include <ptlib.h>
34 #endif
35 
36 #include <opal_config.h>
37 
38 #if OPAL_IAX2
39 
40 #include <ptlib/sockets.h>
41 #include <ptclib/pssl.h>
42 
43 #ifdef P_USE_PRAGMA
44 #pragma interface
45 #endif
46 
47 class IAX2FullFrame;
48 
49 
52 class IAX2Remote : public PObject
53 {
54  PCLASSINFO(IAX2Remote, PObject);
55 
56  public:
57 
59  IAX2Remote();
60 
61  virtual ~IAX2Remote() { };
62 
65  PINDEX DestCallNumber() { return destCallNumber; }
66 
70  PINDEX SourceCallNumber() { return sourceCallNumber; }
71 
73  virtual void PrintOn(ostream & strm) const;
74 
76  enum {
78  };
79 
81  PIPSocket::Address RemoteAddress() { return remoteAddress; }
82 
86  PString BuildConnectionToken();
87 
89  PString BuildOurConnectionToken();
90 
92  PINDEX RemotePort() { return remotePort; }
93 
95  void Assign(IAX2Remote &);
96 
98  void SetRemoteAddress(PIPSocket::Address &newVal) { remoteAddress = newVal; }
99 
101  void SetRemoteAddress(int newVal) { remoteAddress = newVal; }
102 
104  void SetRemotePort (PINDEX newVal) { remotePort = newVal; }
105 
107  void SetSourceCallNumber(PINDEX newVal) { sourceCallNumber = newVal; }
108 
110  void SetDestCallNumber(PINDEX newVal);
111 
115  PBoolean operator == (IAX2Remote & other);
116 
119  PBoolean operator *= (IAX2Remote & other);
120 
121 
123  PBoolean operator != (IAX2Remote & other);
124 
125 
126  protected:
129 
131  PINDEX destCallNumber;
132 
134  PIPSocket::Address remoteAddress;
135 
137  PINDEX remotePort;
138 
139 };
140 
142 
151 class IAX2FrameIdValue : public PObject
152 {
153  PCLASSINFO(IAX2FrameIdValue, PObject);
154  public:
156  IAX2FrameIdValue (PINDEX timeStamp, PINDEX seqVal);
157 
159  IAX2FrameIdValue (PINDEX val);
160 
162  PINDEX GetTimeStamp() const;
163 
165  PINDEX GetSequenceVal() const;
166 
170  PINDEX GetPlainSequence() const;
171 
173  virtual void PrintOn(ostream & strm) const;
174 
177  virtual Comparison Compare(const PObject & obj) const;
178 
179  protected:
180 
183  PUInt64 value;
184 };
185 
187 
192 PDECLARE_SORTED_LIST(IAX2PacketIdList, IAX2FrameIdValue)
193 #ifdef DOC_PLUS_PLUS
194 class IAX2PacketIdList : public PSortedList
195 {
196 #endif
197 
200  PBoolean Contains(IAX2FrameIdValue &src);
201 
204  PINDEX GetFirstValue();
205 
207  void AppendNewFrame(IAX2FullFrame &src);
208 
210  virtual void PrintOn(ostream & strm) const;
211 
212  protected:
219 };
220 
222 
224 {
225  public:
233  };
234 
235 
236 
239  { ZeroAllValues(); };
240 
242  virtual ~IAX2SequenceNumbers() { }
243 
245  void ZeroAllValues();
246 
248  PINDEX InSeqNo();
249 
251  PINDEX OutSeqNo();
252 
255  PBoolean IsFirstReplyFrame();
256 
259  PBoolean IsSequenceNosZero();
260 
262  void SetInSeqNo(PINDEX newVal);
263 
265  void SetOutSeqNo(PINDEX newVal);
266 
269  void SetInOutSeqNo(PINDEX inVal, PINDEX outVal);
270 
274 
276  PBoolean operator !=(IAX2SequenceNumbers &other);
277 
279  PBoolean operator ==(IAX2SequenceNumbers &other);
280 
282  void MassageSequenceForSending(IAX2FullFrame &src /*<!src will be transmitted to the remote node */
283  );
284 
289 
294  (IAX2FullFrame &src /*<!frame to be compared with current data base.*/ );
295 
298 
300  PString AsString() const;
301 
303  virtual void PrintOn(ostream & strm) const;
304 
307  PBoolean IsFirstReply() { return (inSeqNo == 1) && (outSeqNo == 0); }
308 
310  void AddWrapAroundValue(PINDEX newOffset);
311 
312 
313  protected:
314 
318  };
319 
321  PINDEX inSeqNo;
322 
324  PINDEX outSeqNo;
325 
327  PDECLARE_MUTEX(mutex);
328 
331 
334 };
335 
337 
338 class IAX2Encryption : public PObject
339 {
340  PCLASSINFO(IAX2Encryption, PObject);
341  public:
343  IAX2Encryption();
344 
346  void SetEncryptionOn (PBoolean newState = true);
347 
349  void SetEncryptionKey(PString & newKey);
350 
352  void SetChallengeKey(PString & newKey);
353 
355  const PString & EncryptionKey() const;
356 
358  const PString & ChallengeKey() const;
359 
361  PBoolean IsEncrypted() const;
362 
363 #ifdef P_SSL_AES
364 
365  PAESContext & AesEncryptKey() { return m_aesEncryptKey; }
366 
368  PAESContext & AesDecryptKey() { return m_aesDecryptKey; }
369 #endif
370 
371  protected:
374  void CalculateAesKeys();
375 
377  PString encryptionKey;
378 
380  PString challengeKey;
381 
384 
385 #ifdef P_SSL_AES
386 
387  PAESContext m_aesEncryptKey;
388 
390  PAESContext m_aesDecryptKey;
391 #endif
392 };
393 
395 
396 
397 #endif // OPAL_IAX2
398 
399 #endif // OPAL_IAX2_REMOTE_H
400 
401 /* The comment below is magic for those who use emacs to edit this file.
402  * With the comment below, the tab key does auto indent to 2 spaces.
403  *
404  * Local Variables:
405  * mode:c
406  * c-basic-offset:2
407  * End:
408  */
void SetDestCallNumber(PINDEX newVal)
void CopyContents(IAX2SequenceNumbers &src)
IAX2FrameIdValue(PINDEX timeStamp, PINDEX seqVal)
PINDEX GetSequenceVal() const
Definition: remote.h:223
PBoolean IsSequenceNosZero()
PBoolean encryptionEnabled
Definition: remote.h:383
PBoolean IsEncrypted() const
void SetRemotePort(PINDEX newVal)
Definition: remote.h:104
PBoolean operator!=(IAX2Remote &other)
PString BuildOurConnectionToken()
we have already seen this frame...
Definition: remote.h:232
virtual void PrintOn(ostream &strm) const
Definition: remote.h:317
void SetInOutSeqNo(PINDEX inVal, PINDEX outVal)
Definition: remote.h:52
const PString & EncryptionKey() const
PString BuildConnectionToken()
IncomingOrder
Definition: remote.h:229
PIPSocket::Address remoteAddress
Definition: remote.h:134
void SetSourceCallNumber(PINDEX newVal)
Definition: remote.h:107
PBoolean operator==(IAX2Remote &other)
PString challengeKey
Definition: remote.h:380
PINDEX RemotePort()
Definition: remote.h:92
void SetAckSequenceInfo(IAX2SequenceNumbers &other)
PINDEX DestCallNumber()
Definition: remote.h:65
void RemoveOldContiguousValues()
Definition: frame.h:365
void SetRemoteAddress(PIPSocket::Address &newVal)
Definition: remote.h:98
void Assign(IAX2Remote &)
void CalculateAesKeys()
PINDEX lastSentTimeStamp
Definition: remote.h:330
PINDEX destCallNumber
Definition: remote.h:131
PString AsString() const
IAX2SequenceNumbers()
Definition: remote.h:238
void SetOutSeqNo(PINDEX newVal)
Definition: remote.h:151
there is a missing frame, a VNAK condition
Definition: remote.h:231
Definition: remote.h:77
IAX2PacketIdList receivedLog
Definition: remote.h:333
virtual void PrintOn(ostream &strm) const
PBoolean IsFirstReply()
Definition: remote.h:307
const PString & ChallengeKey() const
PINDEX sourceCallNumber
Definition: remote.h:128
PINDEX outSeqNo
Definition: remote.h:324
PINDEX remotePort
Definition: remote.h:137
Definition: remote.h:338
PIPSocket::Address RemoteAddress()
Definition: remote.h:81
PINDEX SourceCallNumber()
Definition: remote.h:70
virtual Comparison Compare(const PObject &obj) const
PBoolean operator*=(IAX2Remote &other)
sequenceDefines
Definition: remote.h:316
PUInt64 value
Definition: remote.h:183
void SetRemoteAddress(int newVal)
Definition: remote.h:101
void AddWrapAroundValue(PINDEX newOffset)
PBoolean operator!=(IAX2SequenceNumbers &other)
void SetEncryptionOn(PBoolean newState=true)
PBoolean operator==(IAX2SequenceNumbers &other)
void SetChallengeKey(PString &newKey)
PBoolean IsFirstReplyFrame()
virtual ~IAX2SequenceNumbers()
Definition: remote.h:242
void SetInSeqNo(PINDEX newVal)
virtual ~IAX2Remote()
Definition: remote.h:61
perfect sequence number
Definition: remote.h:230
void WrapAroundFrameSequence(IAX2SequenceNumbers &src)
void MassageSequenceForSending(IAX2FullFrame &src)
void SetEncryptionKey(PString &newKey)
PINDEX GetPlainSequence() const
PINDEX inSeqNo
Definition: remote.h:321
PString encryptionKey
Definition: remote.h:377
Definition: remote.h:194
PINDEX GetTimeStamp() const
IncomingOrder IncomingMessageInOrder(IAX2FullFrame &src)
virtual void PrintOn(ostream &strm) const