2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef WEBRTC_P2P_BASE_STUNSERVER_H_
12 #define WEBRTC_P2P_BASE_STUNSERVER_H_
14 #include "webrtc/p2p/base/stun.h"
15 #include "webrtc/base/asyncudpsocket.h"
16 #include "webrtc/base/scoped_ptr.h"
20 const int STUN_SERVER_PORT = 3478;
22 class StunServer : public sigslot::has_slots<> {
24 // Creates a STUN server, which will listen on the given socket.
25 explicit StunServer(rtc::AsyncUDPSocket* socket);
26 // Removes the STUN server from the socket and deletes the socket.
30 // Slot for AsyncSocket.PacketRead:
32 rtc::AsyncPacketSocket* socket, const char* buf, size_t size,
33 const rtc::SocketAddress& remote_addr,
34 const rtc::PacketTime& packet_time);
36 // Handlers for the different types of STUN/TURN requests:
37 virtual void OnBindingRequest(StunMessage* msg,
38 const rtc::SocketAddress& addr);
39 void OnAllocateRequest(StunMessage* msg,
40 const rtc::SocketAddress& addr);
41 void OnSharedSecretRequest(StunMessage* msg,
42 const rtc::SocketAddress& addr);
43 void OnSendRequest(StunMessage* msg,
44 const rtc::SocketAddress& addr);
46 // Sends an error response to the given message back to the user.
47 void SendErrorResponse(
48 const StunMessage& msg, const rtc::SocketAddress& addr,
49 int error_code, const char* error_desc);
51 // Sends the given message to the appropriate destination.
52 void SendResponse(const StunMessage& msg,
53 const rtc::SocketAddress& addr);
55 // A helper method to compose a STUN binding response.
56 void GetStunBindReqponse(StunMessage* request,
57 const rtc::SocketAddress& remote_addr,
58 StunMessage* response) const;
61 rtc::scoped_ptr<rtc::AsyncUDPSocket> socket_;
64 } // namespace cricket
66 #endif // WEBRTC_P2P_BASE_STUNSERVER_H_