tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

stunserver_main.cc (1614B)


      1 /*
      2 *  Copyright 2004 The WebRTC Project Authors. All rights reserved.
      3 *
      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.
      9 */
     10 #include <iostream>
     11 #include <memory>
     12 #include <utility>
     13 
     14 #include "api/environment/environment_factory.h"
     15 #include "p2p/test/stun_server.h"
     16 #include "rtc_base/async_udp_socket.h"
     17 #include "rtc_base/checks.h"
     18 #include "rtc_base/socket_address.h"
     19 #include "rtc_base/socket_server.h"
     20 #include "rtc_base/thread.h"
     21 
     22 using ::webrtc::StunServer;
     23 
     24 int main(int argc, char* argv[]) {
     25  if (argc != 2) {
     26    std::cerr << "usage: stunserver address" << std::endl;
     27    return 1;
     28  }
     29 
     30  webrtc::SocketAddress server_addr;
     31  if (!server_addr.FromString(argv[1])) {
     32    std::cerr << "Unable to parse IP address: " << argv[1];
     33    return 1;
     34  }
     35 
     36  webrtc::Thread* pthMain =
     37      webrtc::ThreadManager::Instance()->WrapCurrentThread();
     38  RTC_DCHECK(pthMain);
     39 
     40  std::unique_ptr<webrtc::AsyncUDPSocket> server_socket =
     41      webrtc::AsyncUDPSocket::Create(webrtc::CreateEnvironment(), server_addr,
     42                                     *pthMain->socketserver());
     43  if (!server_socket) {
     44    std::cerr << "Failed to create a UDP socket" << std::endl;
     45    return 1;
     46  }
     47 
     48  StunServer server(std::move(server_socket));
     49 
     50  std::cout << "Listening at " << server_addr.ToString() << std::endl;
     51 
     52  pthMain->Run();
     53 
     54  return 0;
     55 }