1 | |
---|
2 | // Copyright Eóin O'Callaghan 2006 - 2008. |
---|
3 | // Distributed under the Boost Software License, Version 1.0. |
---|
4 | // (See accompanying file LICENSE_1_0.txt or copy at |
---|
5 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
6 | |
---|
7 | #pragma once |
---|
8 | |
---|
9 | #include "stdAfx.hpp" |
---|
10 | #include "Halite.hpp" |
---|
11 | |
---|
12 | #include "halConfig.hpp" |
---|
13 | #include "ProgressDialog.hpp" |
---|
14 | |
---|
15 | namespace hal |
---|
16 | { |
---|
17 | |
---|
18 | bool Config::settingsChanged() |
---|
19 | { |
---|
20 | // thread settings(bind(&BitTConfig::settingsThread, this)); |
---|
21 | return settingsThread(); |
---|
22 | } |
---|
23 | |
---|
24 | bool Config::settingsThread() |
---|
25 | { |
---|
26 | event_log.post(shared_ptr<EventDetail>(new EventMsg(L"Applying BitTorrent session settings."))); |
---|
27 | |
---|
28 | bittorrent().setMapping(mappingType); |
---|
29 | |
---|
30 | event_log.post(shared_ptr<EventDetail>(new EventMsg( |
---|
31 | hal::wform(L"Trying port in range %1% - %2%.") % portFrom % portTo))); |
---|
32 | try |
---|
33 | { |
---|
34 | bool success = bittorrent().listenOn( |
---|
35 | std::make_pair(portFrom, portTo)); |
---|
36 | if (!success) |
---|
37 | { |
---|
38 | hal::event_log.post(boost::shared_ptr<hal::EventDetail>( |
---|
39 | new hal::EventDebug(event_logger::critical, L"settingsThread, Init"))); |
---|
40 | |
---|
41 | return false; |
---|
42 | } |
---|
43 | } |
---|
44 | catch(const std::exception& e) |
---|
45 | { |
---|
46 | hal::event_log.post(boost::shared_ptr<hal::EventDetail>( |
---|
47 | new hal::EventStdException(event_logger::critical, e, L"settingsThread, Init"))); |
---|
48 | |
---|
49 | return false; |
---|
50 | } |
---|
51 | |
---|
52 | event_log.post(shared_ptr<EventDetail>(new EventMsg(hal::wform(L"Opened listen port; %1%.") % bittorrent().isListeningOn()))); |
---|
53 | |
---|
54 | try |
---|
55 | { |
---|
56 | if (enableIPFilter) |
---|
57 | { |
---|
58 | ProgressDialog progDlg(L"Loading IP filters...", bind( |
---|
59 | &bit::ensureIpFilterOn, &bittorrent(), _1)); |
---|
60 | progDlg.DoModal(); |
---|
61 | } |
---|
62 | else |
---|
63 | bittorrent().ensureIpFilterOff(); |
---|
64 | } |
---|
65 | catch(const std::exception& e) |
---|
66 | { |
---|
67 | hal::event_log.post(boost::shared_ptr<hal::EventDetail>( |
---|
68 | new hal::EventStdException(event_logger::critical, e, L"settingsThread, Load IP Filter"))); |
---|
69 | } |
---|
70 | |
---|
71 | try |
---|
72 | { |
---|
73 | if (enablePe) |
---|
74 | { |
---|
75 | bittorrent().ensurePeOn(peEncLevel, peConInPolicy, peConOutPolicy, pePerferRc4); |
---|
76 | } |
---|
77 | else |
---|
78 | bittorrent().ensurePeOff(); |
---|
79 | } |
---|
80 | catch(const std::exception& e) |
---|
81 | { |
---|
82 | hal::event_log.post(boost::shared_ptr<hal::EventDetail>( |
---|
83 | new hal::EventStdException(event_logger::critical, e, L"settingsThread, Protocol Encryption"))); |
---|
84 | } |
---|
85 | |
---|
86 | bittorrent().setSessionHalfOpenLimit(halfConnLimit); |
---|
87 | |
---|
88 | bittorrent().resumeAll(); |
---|
89 | |
---|
90 | bittorrent().setSessionLimits( |
---|
91 | maxConnections, maxUploads); |
---|
92 | bittorrent().setSessionSpeed( |
---|
93 | downRate, upRate); |
---|
94 | |
---|
95 | bittorrent().setTorrentDefaults(torrentMaxConnections, |
---|
96 | torrentMaxUploads, torrentDownRate, |
---|
97 | torrentUpRate); |
---|
98 | |
---|
99 | bittorrent().setDhtSettings(dhtMaxPeersReply, |
---|
100 | dhtSearchBranching, dhtServicePort, |
---|
101 | dhtMaxFailCount); |
---|
102 | |
---|
103 | bittorrent().setTimeouts(peerTimeout, trackerTimeout); |
---|
104 | |
---|
105 | if (enableDHT) |
---|
106 | { |
---|
107 | if (!bittorrent().ensureDhtOn()) |
---|
108 | { |
---|
109 | bittorrent().ensureDhtOff(); |
---|
110 | |
---|
111 | hal::event_log.post(boost::shared_ptr<hal::EventDetail>( |
---|
112 | new hal::EventDebug(event_logger::critical, L"settingsThread, DHT Error"))); |
---|
113 | } |
---|
114 | } |
---|
115 | else |
---|
116 | bittorrent().ensureDhtOff(); |
---|
117 | |
---|
118 | // Settings seem to have applied ok! |
---|
119 | save_to_ini(); |
---|
120 | return true; |
---|
121 | } |
---|
122 | |
---|
123 | Config& config() |
---|
124 | { |
---|
125 | static Config c; |
---|
126 | return c; |
---|
127 | } |
---|
128 | |
---|
129 | } // namespace hal |
---|