removed connecting_to_tracker state
[libtorrent.git] / test / test_natpmp.cpp
blob836752a550d170ceac3c36d30751e3eff0f23327
1 #include "libtorrent/natpmp.hpp"
2 #include "libtorrent/socket.hpp"
3 #include "libtorrent/connection_queue.hpp"
4 #include <boost/bind.hpp>
5 #include <boost/ref.hpp>
6 #include <boost/intrusive_ptr.hpp>
8 using namespace libtorrent;
10 void callback(int mapping, int port, std::string const& err)
12 std::cerr << "mapping: " << mapping << ", port: " << port << ", error: \"" << err << "\"\n";
15 int main(int argc, char* argv[])
17 io_service ios;
18 std::string user_agent = "test agent";
20 if (argc != 3)
22 std::cerr << "usage: " << argv[0] << " tcp-port udp-port" << std::endl;
23 return 1;
26 connection_queue cc(ios);
27 boost::intrusive_ptr<natpmp> natpmp_handler = new natpmp(ios, address_v4(), &callback);
29 deadline_timer timer(ios);
31 int tcp_map = natpmp_handler->add_mapping(natpmp::tcp, atoi(argv[1]), atoi(argv[1]));
32 int udp_map = natpmp_handler->add_mapping(natpmp::udp, atoi(argv[2]), atoi(argv[2]));
34 timer.expires_from_now(seconds(2));
35 timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
36 std::cerr << "mapping ports TCP: " << argv[1]
37 << " UDP: " << argv[2] << std::endl;
39 ios.reset();
40 ios.run();
41 timer.expires_from_now(seconds(2));
42 timer.async_wait(boost::bind(&io_service::stop, boost::ref(ios)));
43 std::cerr << "removing mapping " << tcp_map << std::endl;
44 natpmp_handler->delete_mapping(tcp_map);
46 ios.reset();
47 ios.run();
48 std::cerr << "removing mappings" << std::endl;
49 natpmp_handler->close();
51 ios.reset();
52 ios.run();
53 std::cerr << "closing" << std::endl;