fixes bug where priorities where lost when force-rechecking.
[libtorrent.git] / test / test_upnp.cpp
blob96dea5e7bfc4dc18cf20166ca7950c40aa1b5d80
1 /*
3 Copyright (c) 2008, Arvid Norberg
4 All rights reserved.
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
10 * Redistributions of source code must retain the above copyright
11 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the distribution.
15 * Neither the name of the author nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
33 #include "libtorrent/upnp.hpp"
34 #include "libtorrent/socket.hpp"
35 #include "libtorrent/connection_queue.hpp"
36 #include <boost/bind.hpp>
37 #include <boost/ref.hpp>
38 #include <boost/intrusive_ptr.hpp>
40 using namespace libtorrent;
42 void callback(int mapping, int port, std::string const& err)
44 std::cerr << "mapping: " << mapping << ", port: " << port << ", error: \"" << err << "\"\n";
47 int main(int argc, char* argv[])
49 libtorrent::io_service ios;
50 std::string user_agent = "test agent";
52 if (argc != 3)
54 std::cerr << "usage: " << argv[0] << " tcp-port udp-port" << std::endl;
55 return 1;
58 connection_queue cc(ios);
59 boost::intrusive_ptr<upnp> upnp_handler = new upnp(ios, cc, address_v4(), user_agent, &callback, true);
60 upnp_handler->discover_device();
62 libtorrent::deadline_timer timer(ios);
63 timer.expires_from_now(seconds(2));
64 timer.async_wait(boost::bind(&libtorrent::io_service::stop, boost::ref(ios)));
66 std::cerr << "broadcasting for UPnP device" << std::endl;
68 ios.reset();
69 ios.run();
71 upnp_handler->add_mapping(upnp::tcp, atoi(argv[1]), atoi(argv[1]));
72 upnp_handler->add_mapping(upnp::udp, atoi(argv[2]), atoi(argv[2]));
73 timer.expires_from_now(seconds(10));
74 timer.async_wait(boost::bind(&libtorrent::io_service::stop, boost::ref(ios)));
75 std::cerr << "mapping ports TCP: " << argv[1]
76 << " UDP: " << argv[2] << std::endl;
78 ios.reset();
79 ios.run();
80 std::cerr << "router: " << upnp_handler->router_model() << std::endl;
81 std::cerr << "removing mappings" << std::endl;
82 upnp_handler->close();
84 ios.reset();
85 ios.run();
86 std::cerr << "closing" << std::endl;