3 Copyright (c) 2008, Arvid Norberg
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
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/session.hpp"
34 #include "libtorrent/session_settings.hpp"
35 #include "libtorrent/hasher.hpp"
36 #include <boost/thread.hpp>
37 #include <boost/tuple/tuple.hpp>
38 #include <boost/filesystem/operations.hpp>
41 #include "setup_transfer.hpp"
43 using boost::filesystem::remove_all
;
47 using namespace libtorrent
;
49 session
ses1(fingerprint("LT", 0, 1, 0, 0), std::make_pair(48100, 49000));
50 session
ses2(fingerprint("LT", 0, 1, 0, 0), std::make_pair(49100, 50000));
51 session
ses3(fingerprint("LT", 0, 1, 0, 0), std::make_pair(50100, 51000));
53 // this is to avoid everything finish from a single peer
54 // immediately. To make the swarm actually connect all
55 // three peers before finishing.
56 float rate_limit
= 180000;
57 ses1
.set_upload_rate_limit(int(rate_limit
));
58 ses2
.set_download_rate_limit(int(rate_limit
));
59 ses3
.set_download_rate_limit(int(rate_limit
));
60 ses2
.set_upload_rate_limit(int(rate_limit
/ 2));
61 ses3
.set_upload_rate_limit(int(rate_limit
/ 2));
63 session_settings settings
;
64 settings
.allow_multiple_connections_per_ip
= true;
65 settings
.ignore_limits_on_local_network
= false;
66 ses1
.set_settings(settings
);
67 ses2
.set_settings(settings
);
68 ses3
.set_settings(settings
);
74 #ifndef TORRENT_DISABLE_ENCRYPTION
76 pes
.out_enc_policy
= pe_settings::forced
;
77 pes
.in_enc_policy
= pe_settings::forced
;
78 ses1
.set_pe_settings(pes
);
79 ses2
.set_pe_settings(pes
);
80 ses3
.set_pe_settings(pes
);
87 boost::tie(tor1
, tor2
, tor3
) = setup_transfer(&ses1
, &ses2
, &ses3
, true, false, false, "_lsd");
89 for (int i
= 0; i
< 30; ++i
)
91 print_alerts(ses1
, "ses1", true);
92 print_alerts(ses2
, "ses2", true);
93 print_alerts(ses3
, "ses3", true);
95 torrent_status st1
= tor1
.status();
96 torrent_status st2
= tor2
.status();
97 torrent_status st3
= tor3
.status();
100 << "\033[33m" << int(st1
.upload_payload_rate
/ 1000.f
) << "kB/s "
101 << st1
.num_peers
<< ": "
102 << "\033[32m" << int(st2
.download_payload_rate
/ 1000.f
) << "kB/s "
103 << "\033[31m" << int(st2
.upload_payload_rate
/ 1000.f
) << "kB/s "
104 << "\033[0m" << int(st2
.progress
* 100) << "% "
105 << st2
.num_peers
<< " - "
106 << "\033[32m" << int(st3
.download_payload_rate
/ 1000.f
) << "kB/s "
107 << "\033[31m" << int(st3
.upload_payload_rate
/ 1000.f
) << "kB/s "
108 << "\033[0m" << int(st3
.progress
* 100) << "% "
112 if (tor2
.is_seed() && tor3
.is_seed()) break;
116 TEST_CHECK(tor2
.is_seed());
117 TEST_CHECK(tor3
.is_seed());
119 if (tor2
.is_seed() && tor3
.is_seed()) std::cerr
<< "done\n";
124 using namespace libtorrent
;
125 using namespace boost::filesystem
;
127 // in case the previous run was terminated
128 try { remove_all("./tmp1_lsd"); } catch (std::exception
&) {}
129 try { remove_all("./tmp2_lsd"); } catch (std::exception
&) {}
130 try { remove_all("./tmp3_lsd"); } catch (std::exception
&) {}
134 remove_all("./tmp1_lsd");
135 remove_all("./tmp2_lsd");
136 remove_all("./tmp3_lsd");