Commit 71703c8c authored by sergeyu@chromium.org's avatar sergeyu@chromium.org

Properly handle STUN requests and responses from relay servers.

BUG=83242
TEST=Chromoting can connect using relay servers.

Review URL: http://codereview.chromium.org/7529039

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@96072 0039d316-1c4b-4281-b951-d872f2087c98
parent 80772ed5
...@@ -65,6 +65,12 @@ bool P2PSocketHost::GetStunPacketType( ...@@ -65,6 +65,12 @@ bool P2PSocketHost::GetStunPacketType(
} }
} }
// static
bool P2PSocketHost::IsRequestOrResponse(StunMessageType type) {
return type == STUN_BINDING_REQUEST || type == STUN_BINDING_RESPONSE ||
type == STUN_ALLOCATE_REQUEST || type == STUN_ALLOCATE_RESPONSE;
}
// static // static
P2PSocketHost* P2PSocketHost::Create( P2PSocketHost* P2PSocketHost::Create(
IPC::Message::Sender* message_sender, int routing_id, int id, IPC::Message::Sender* message_sender, int routing_id, int id,
......
...@@ -62,6 +62,7 @@ class P2PSocketHost { ...@@ -62,6 +62,7 @@ class P2PSocketHost {
// of success stores type of the message in |type|. // of success stores type of the message in |type|.
static bool GetStunPacketType(const char* data, int data_size, static bool GetStunPacketType(const char* data, int data_size,
StunMessageType* type); StunMessageType* type);
static bool IsRequestOrResponse(StunMessageType type);
IPC::Message::Sender* message_sender_; IPC::Message::Sender* message_sender_;
int routing_id_; int routing_id_;
......
...@@ -138,8 +138,7 @@ void P2PSocketHostTcp::OnPacket(std::vector<char>& data) { ...@@ -138,8 +138,7 @@ void P2PSocketHostTcp::OnPacket(std::vector<char>& data) {
if (!authorized_) { if (!authorized_) {
P2PSocketHost::StunMessageType type; P2PSocketHost::StunMessageType type;
bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); bool stun = GetStunPacketType(&*data.begin(), data.size(), &type);
if (stun && (type == STUN_BINDING_REQUEST || if (stun && IsRequestOrResponse(type)) {
type == STUN_BINDING_RESPONSE)) {
authorized_ = true; authorized_ = true;
} else if (!stun || type == STUN_DATA_INDICATION) { } else if (!stun || type == STUN_DATA_INDICATION) {
LOG(ERROR) << "Received unexpected data packet from " LOG(ERROR) << "Received unexpected data packet from "
......
...@@ -100,8 +100,7 @@ void P2PSocketHostUdp::DidCompleteRead(int result) { ...@@ -100,8 +100,7 @@ void P2PSocketHostUdp::DidCompleteRead(int result) {
if (authorized_peers_.find(recv_address_) == authorized_peers_.end()) { if (authorized_peers_.find(recv_address_) == authorized_peers_.end()) {
P2PSocketHost::StunMessageType type; P2PSocketHost::StunMessageType type;
bool stun = GetStunPacketType(&*data.begin(), data.size(), &type); bool stun = GetStunPacketType(&*data.begin(), data.size(), &type);
if (stun && (type == STUN_BINDING_REQUEST || if (stun && IsRequestOrResponse(type)) {
type == STUN_BINDING_RESPONSE)) {
authorized_peers_.insert(recv_address_); authorized_peers_.insert(recv_address_);
} else if (!stun || type == STUN_DATA_INDICATION) { } else if (!stun || type == STUN_DATA_INDICATION) {
LOG(ERROR) << "Received unexpected data packet from " LOG(ERROR) << "Received unexpected data packet from "
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment