Added support for an Origin header in STUN messages.
For WebRTC there are instances where it may be desirable to provide
information to the STUN/TURN server about the website that initiated
a peer connection. This modification allows an origin string to be
included in the MediaConstraints object provided by the browser, which
is then passed as a STUN header in communications with the server.
A separate change will be submitted to the Chromium project that
uses and is dependent on this change, implementing IETF draft
http://tools.ietf.org/html/draft-johnston-tram-stun-origin-02
Originally a patch from skobalt@gmail.com.
(https://webrtc-codereview.appspot.com/12839005/edit)
R=juberti@webrtc.org
Review URL: https://webrtc-codereview.appspot.com/41409004
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8035 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/webrtc/p2p/base/stunrequest.h b/webrtc/p2p/base/stunrequest.h
index 5fefc2f..6a4bdc0 100644
--- a/webrtc/p2p/base/stunrequest.h
+++ b/webrtc/p2p/base/stunrequest.h
@@ -24,7 +24,7 @@
// Manages a set of STUN requests, sending and resending until we receive a
// response or determine that the request has timed out.
class StunRequestManager {
-public:
+ public:
StunRequestManager(rtc::Thread* thread);
~StunRequestManager();
@@ -46,14 +46,18 @@
bool empty() { return requests_.empty(); }
+ // Set the Origin header for outgoing stun messages.
+ void set_origin(const std::string& origin) { origin_ = origin; }
+
// Raised when there are bytes to be sent.
sigslot::signal3<const void*, size_t, StunRequest*> SignalSendPacket;
-private:
+ private:
typedef std::map<std::string, StunRequest*> RequestMap;
rtc::Thread* thread_;
RequestMap requests_;
+ std::string origin_;
friend class StunRequest;
};
@@ -61,7 +65,7 @@
// Represents an individual request to be sent. The STUN message can either be
// constructed beforehand or built on demand.
class StunRequest : public rtc::MessageHandler {
-public:
+ public:
StunRequest();
StunRequest(StunMessage* request);
virtual ~StunRequest();
@@ -75,6 +79,10 @@
// Returns the transaction ID of this request.
const std::string& id() { return msg_->transaction_id(); }
+ // the origin value
+ const std::string& origin() const { return origin_; }
+ void set_origin(const std::string& origin) { origin_ = origin; }
+
// Returns the STUN type of the request message.
int type();
@@ -84,9 +92,10 @@
// Time elapsed since last send (in ms)
uint32 Elapsed() const;
-protected:
+ protected:
int count_;
bool timeout_;
+ std::string origin_;
// Fills in a request object to be sent. Note that request's transaction ID
// will already be set and cannot be changed.
@@ -98,7 +107,7 @@
virtual void OnTimeout() {}
virtual int GetNextDelay();
-private:
+ private:
void set_manager(StunRequestManager* manager);
// Handles messages for sending and timeout.