OPAL  Version 3.18.8
ice.h
Go to the documentation of this file.
1 /*
2  * ice.h
3  *
4  * Interactive Connectivity Establishment
5  *
6  * Open Phone Abstraction Library (OPAL)
7  *
8  * Copyright (C) 2010 Vox Lucida Pty. Ltd.
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * The Original Code is Open Phone Abstraction Library.
21  *
22  * The Initial Developer of the Original Code is Vox Lucida Pty. Ltd.
23  *
24  * Contributor(s): ______________________________________.
25  */
26 
27 #ifndef OPAL_SIP_ICE_H
28 #define OPAL_SIP_ICE_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 #include <opal_config.h>
35 
36 #if OPAL_ICE
37 
38 #include <opal/mediasession.h>
39 #include <ptclib/pstunsrvr.h>
40 
41 
45 #define OPAL_OPT_ICE_TIMEOUT "ICE-Timeout"
46 
52 #define OPAL_OPT_ICE_LITE "ICE-Lite"
53 
59 #define OPAL_OPT_TRICKLE_ICE "Trickle-ICE"
60 
64 #define OPAL_OPT_NETWORK_COST_ICE "Network-Cost-ICE"
65 
66 
69 class OpalICEMediaTransport : public OpalUDPMediaTransport
70 {
71  PCLASSINFO(OpalICEMediaTransport, OpalUDPMediaTransport);
72  public:
73  OpalICEMediaTransport(const PString & name);
74 
75  virtual bool Open(OpalMediaSession & session, PINDEX count, const PString & localInterface, const OpalTransportAddress & remoteAddress);
76  virtual bool IsEstablished() const;
77  virtual void SetCandidates(const PString & user, const PString & pass, const PNatCandidateList & candidates);
78  virtual bool GetCandidates(PString & user, PString & pass, PNatCandidateList & candidates, bool offering);
79 #if OPAL_STATISTICS
80  virtual void GetStatistics(OpalMediaStatistics & statistics) const;
81 #endif
82 
83 
84  protected:
85  class ICEChannel : public PIndirectChannel
86  {
87  PCLASSINFO(ICEChannel, PIndirectChannel);
88  public:
89  ICEChannel(OpalICEMediaTransport & owner, SubChannels subchannel, PChannel * channel);
90  virtual PBoolean Read(void * buf, PINDEX len);
91  protected:
92  OpalICEMediaTransport & m_owner;
93  SubChannels m_subchannel;
94  };
95  bool InternalHandleICE(SubChannels subchannel, const void * buf, PINDEX len);
96  virtual void InternalRxData(SubChannels subchannel, const PBYTEArray & data);
97  virtual bool InternalOpenPinHole(PUDPSocket & socket);
98  virtual PChannel * AddWrapperChannels(SubChannels subchannel, PChannel * channel);
99  virtual PTimeInterval GetTimeout() const;
100 
101  PString m_localUsername; // ICE username sent to remote
102  PString m_localPassword; // ICE password sent to remote
103  PString m_remoteUsername; // ICE username expected from remote
104  PString m_remotePassword; // ICE password expected from remote
105  PTimeInterval m_iceTimeout;
106  bool m_lite;
107  bool m_trickle;
108  bool m_useNetworkCost;
109 
110  enum CandidateStates
111  {
112  e_CandidateInProgress,
113  e_CandidateWaiting,
114  e_CandidateFrozen,
115  e_CandidateFailed,
116  e_CandidateSucceeded
117  };
118 
119 #if OPAL_STATISTICS
120  typedef OpalCandidateStatistics CandidateStateBase;
121 #else
122  typedef PNatCandidate CandidateStateBase;
123 #endif
124  struct CandidateState : CandidateStateBase
125  {
126  CandidateStates m_state;
127  // Not sure what else might be necessary here. Work in progress!
128 
129  CandidateState(const PNatCandidate & cand)
130  : CandidateStateBase(cand)
131  , m_state(e_CandidateInProgress)
132  {
133  }
134  };
135  typedef std::list<CandidateState> CandidateStateList;
136  typedef std::vector<CandidateStateList> CandidatesArray;
137  friend bool operator!=(const CandidatesArray & left, const CandidatesArray & right);
138 
139  CandidatesArray m_localCandidates;
140  CandidatesArray m_remoteCandidates;
141 
142  enum ICEState
143  {
144  e_Disabled, // Note values and order are important
145  e_Completed,
146  e_Offering,
147  e_OfferAnswered,
148  e_Answering
149  };
150  ICEState m_state;
151  ICEState GetICEState() const;
152 
153  PSTUNServer m_server;
154  PSTUNClient m_client;
155 
156  PNatCandidate m_selectedCandidate;
157 };
158 
159 
160 #endif // OPAL_ICE
161 
162 #endif // OPAL_SIP_ICE_H
virtual bool InternalOpenPinHole(PUDPSocket &socket)
virtual void InternalRxData(SubChannels subchannel, const PBYTEArray &data)
Definition: mediasession.h:647
virtual bool IsEstablished() const
Definition: mediasession.h:621
virtual PTimeInterval GetTimeout() const
Definition: mediasession.h:538
virtual bool Open(OpalMediaSession &session, PINDEX count, const PString &localInterface, const OpalTransportAddress &remoteAddress)
virtual void SetCandidates(const PString &user, const PString &pass, const PNatCandidateList &candidates)
virtual void GetStatistics(OpalMediaStatistics &statistics) const
virtual bool GetCandidates(PString &user, PString &pass, PNatCandidateList &candidates, bool offering)
Definition: mediasession.h:210
Definition: transports.h:151
virtual PChannel * AddWrapperChannels(SubChannels subchannel, PChannel *channel)