line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ex:ts=4:sw=4:sts=4:et |
2
|
|
|
|
|
|
|
package Transmission::Session; |
3
|
|
|
|
|
|
|
# See Transmission::Client for copyright statement. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Transmission::Session - Transmission session |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 DESCRIPTION |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
See "4 Session requests" from |
12
|
|
|
|
|
|
|
L<https://trac.transmissionbt.com/browser/trunk/extras/rpc-spec.txt> |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
This class holds data, regarding the Transmission session. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
937
|
use Moose; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
use Transmission::Types ':all'; |
20
|
|
|
|
|
|
|
use Transmission::Stats; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
BEGIN { |
23
|
|
|
|
|
|
|
with 'Transmission::AttributeRole'; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 stats |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$stats_obj = $self->stats; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Returns a L<Transmission::Stats> object. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=cut |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
has stats => ( |
37
|
|
|
|
|
|
|
is => 'ro', |
38
|
|
|
|
|
|
|
isa => 'Object', |
39
|
|
|
|
|
|
|
lazy => 1, |
40
|
|
|
|
|
|
|
default => sub { |
41
|
|
|
|
|
|
|
Transmission::Stats->new(client => $_[0]->client); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head2 alt_speed_down |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$number = $self->alt_speed_down |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
max global download speed (in K/s) |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 alt_speed_enabled |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
$boolean = $self->alt_speed_enabled |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
true means use the alt speeds |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head2 alt_speed_time_begin |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
$number = $self->alt_speed_time_begin |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
when to turn on alt speeds (units: minutes after midnight) |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 alt_speed_time_enabled |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
$boolean = $self->alt_speed_time_enabled |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
true means the scheduled on/off times are used |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 alt_speed_time_end |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
$number = $self->alt_speed_time_end |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
when to turn off alt speeds (units: same) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 alt_speed_time_day |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
$number = $self->alt_speed_time_day |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
what day(s) to turn on alt speeds (look at tr_sched_day) |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head2 alt_speed_up |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$number = $self->alt_speed_up |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
max global upload speed (in K/s) |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 blocklist_enabled |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
$boolean = $self->blocklist_enabled |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
true means enabled |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 dht_enabled |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
$boolean = $self->dht_enabled |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
true means allow dht in public torrents |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 encryption |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
$string = $self->encryption |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
"required", "preferred", "tolerated" |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 download_dir |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
$string = $self->download_dir |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
default path to download torrents |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=head2 peer_limit_global |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$number = $self->peer_limit_global |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
maximum global number of peers |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head2 peer_limit_per_torrent |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
$number = $self->peer_limit_per_torrent |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
maximum global number of peers |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 pex_enabled |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
$boolean = $self->pex_enabled |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
true means allow pex in public torrents |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 peer_port |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$number = $self->peer_port |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
port number |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head2 peer_port_random_on_start |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
$boolean = $self->peer_port_random_on_start |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
true means pick a random peer port on launch |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 port_forwarding_enabled |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
$boolean = $self->port_forwarding_enabled |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
true means enabled |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head2 seedRatioLimit |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
$double = $self->seedRatioLimit |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
the default seed ratio for torrents to use |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head2 seedRatioLimited |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
$boolean = $self->seedRatioLimited |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
true if seedRatioLimit is honored by default |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 speed_limit_down |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
$number = $self->speed_limit_down |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
max global download speed (in K/s) |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 speed_limit_down_enabled |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
$boolean = $self->speed_limit_down_enabled |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
true means enabled |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 speed_limit_up |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
$number = $self->speed_limit_up |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
max global upload speed (in K/s) |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head2 speed_limit_up_enabled |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
$boolean = $self->speed_limit_up_enabled |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
true means enabled |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=cut |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
BEGIN { |
186
|
|
|
|
|
|
|
my %both = ( |
187
|
|
|
|
|
|
|
'alt-speed-down' => number, |
188
|
|
|
|
|
|
|
'alt-speed-enabled' => boolean, |
189
|
|
|
|
|
|
|
'alt-speed-time-begin' => number, |
190
|
|
|
|
|
|
|
'alt-speed-time-enabled' => boolean, |
191
|
|
|
|
|
|
|
'alt-speed-time-end' => number, |
192
|
|
|
|
|
|
|
'alt-speed-time-day' => number, |
193
|
|
|
|
|
|
|
'alt-speed-up' => number, |
194
|
|
|
|
|
|
|
'blocklist-enabled' => boolean, |
195
|
|
|
|
|
|
|
'dht-enabled' => boolean, |
196
|
|
|
|
|
|
|
'encryption' => string, |
197
|
|
|
|
|
|
|
'download-dir' => string, |
198
|
|
|
|
|
|
|
'peer-limit-global' => number, |
199
|
|
|
|
|
|
|
'peer-limit-per-torrent' => number, |
200
|
|
|
|
|
|
|
'pex-enabled' => boolean, |
201
|
|
|
|
|
|
|
'peer-port' => number, |
202
|
|
|
|
|
|
|
'peer-port-random-on-start' => boolean, |
203
|
|
|
|
|
|
|
'port-forwarding-enabled' => boolean, |
204
|
|
|
|
|
|
|
'seedRatioLimit' => number, |
205
|
|
|
|
|
|
|
'seedRatioLimited' => boolean, |
206
|
|
|
|
|
|
|
'speed-limit-down' => number, |
207
|
|
|
|
|
|
|
'speed-limit-down-enabled' => boolean, |
208
|
|
|
|
|
|
|
'speed-limit-up' => number, |
209
|
|
|
|
|
|
|
'speed-limit-up-enabled' => boolean, |
210
|
|
|
|
|
|
|
); |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
for my $camel (keys %both) { |
213
|
|
|
|
|
|
|
my $name = __PACKAGE__->_camel2Normal($camel); |
214
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute($name => ( |
215
|
|
|
|
|
|
|
is => 'rw', |
216
|
|
|
|
|
|
|
isa => $both{$camel}, |
217
|
|
|
|
|
|
|
coerce => 1, |
218
|
|
|
|
|
|
|
lazy => 1, |
219
|
|
|
|
|
|
|
clearer => "clear_$name", |
220
|
|
|
|
|
|
|
trigger => sub { |
221
|
|
|
|
|
|
|
return if($_[0]->lazy_write); |
222
|
|
|
|
|
|
|
$_[0]->client->rpc('session-set' => $camel => |
223
|
|
|
|
|
|
|
($both{$camel} eq boolean and $_[1]) ? 'true' |
224
|
|
|
|
|
|
|
: ($both{$camel} eq boolean and !$_[1]) ? 'false' |
225
|
|
|
|
|
|
|
: $_[1] |
226
|
|
|
|
|
|
|
); |
227
|
|
|
|
|
|
|
}, |
228
|
|
|
|
|
|
|
default => sub { |
229
|
|
|
|
|
|
|
my $self = shift; |
230
|
|
|
|
|
|
|
my $val = delete $self->_tmp_store->{$name}; |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
if(defined $val) { |
233
|
|
|
|
|
|
|
return $val; |
234
|
|
|
|
|
|
|
} |
235
|
|
|
|
|
|
|
else { |
236
|
|
|
|
|
|
|
$self->_clear_tmp_store; |
237
|
|
|
|
|
|
|
return delete $self->_tmp_store->{$name}; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
}, |
240
|
|
|
|
|
|
|
)); |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
__PACKAGE__->meta->add_attribute(_tmp_store => ( |
244
|
|
|
|
|
|
|
is => 'ro', |
245
|
|
|
|
|
|
|
isa => 'HashRef', |
246
|
|
|
|
|
|
|
lazy => 1, |
247
|
|
|
|
|
|
|
builder => 'read_all', |
248
|
|
|
|
|
|
|
clearer => '_clear_tmp_store', |
249
|
|
|
|
|
|
|
)); |
250
|
|
|
|
|
|
|
|
251
|
|
|
|
|
|
|
__PACKAGE__->meta->add_method(read_all => sub { |
252
|
|
|
|
|
|
|
my $self = shift; |
253
|
|
|
|
|
|
|
my $lazy = $self->lazy_write; |
254
|
|
|
|
|
|
|
my($rpc, %res); |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
$rpc = $self->client->rpc('session-get') or return; |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
$self->lazy_write(1); |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
for my $camel (keys %both) { |
261
|
|
|
|
|
|
|
my $name = __PACKAGE__->_camel2Normal($camel); |
262
|
|
|
|
|
|
|
$res{$name} = $rpc->{$camel}; |
263
|
|
|
|
|
|
|
$self->$name($rpc->{$camel}); |
264
|
|
|
|
|
|
|
} |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
$self->lazy_write($lazy); |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
return \%res; |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
}); |
271
|
|
|
|
|
|
|
} |
272
|
|
|
|
|
|
|
|
273
|
|
|
|
|
|
|
=head1 LICENSE |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=head1 AUTHOR |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
See L<Transmission::Client> |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=cut |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
1; |