-
Notifications
You must be signed in to change notification settings - Fork 56
/
alert_types_mod.hpp
2065 lines (1701 loc) · 66.2 KB
/
alert_types_mod.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This is the raw alert_types.hpp with s/const static/static const/
/*
Copyright (c) 2003-2014, Arvid Norberg
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the distribution.
* Neither the name of the author nor the names of its
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef TORRENT_ALERT_TYPES_HPP_INCLUDED
#define TORRENT_ALERT_TYPES_HPP_INCLUDED
#include "libtorrent/alert.hpp"
#include "libtorrent/torrent_handle.hpp"
#include "libtorrent/socket.hpp"
#include "libtorrent/config.hpp"
#include "libtorrent/assert.hpp"
#include "libtorrent/identify_client.hpp"
#include "libtorrent/address.hpp"
#include "libtorrent/stat.hpp"
#include "libtorrent/rss.hpp" // for feed_handle
// lines reserved for future includes
// the type-ids of the alert types
// are derived from the line on which
// they are declared
namespace libtorrent
{
// user defined alerts should use IDs greater than this
static const int user_alert_id = 10000;
// This is a base class for alerts that are associated with a
// specific torrent. It contains a handle to the torrent.
struct TORRENT_EXPORT torrent_alert: alert
{
// internal
torrent_alert(torrent_handle const& h)
: handle(h)
{}
// internal
static const int alert_type = 1;
virtual std::string message() const;
// The torrent_handle pointing to the torrent this
// alert is associated with.
torrent_handle handle;
};
// The peer alert is a base class for alerts that refer to a specific peer. It includes all
// the information to identify the peer. i.e. ``ip`` and ``peer-id``.
struct TORRENT_EXPORT peer_alert: torrent_alert
{
// internal
peer_alert(torrent_handle const& h, tcp::endpoint const& i
, peer_id const& pi)
: torrent_alert(h)
, ip(i)
, pid(pi)
{}
static const int alert_type = 2;
static const int static_category = alert::peer_notification;
virtual int category() const { return static_category; }
virtual std::string message() const;
// The peer's IP address and port.
tcp::endpoint ip;
// the peer ID, if known.
peer_id pid;
};
// This is a base class used for alerts that are associated with a
// specific tracker. It derives from torrent_alert since a tracker
// is also associated with a specific torrent.
struct TORRENT_EXPORT tracker_alert: torrent_alert
{
// internal
tracker_alert(torrent_handle const& h
, std::string const& u)
: torrent_alert(h)
, url(u)
{}
static const int alert_type = 3;
static const int static_category = alert::tracker_notification;
virtual int category() const { return static_category; }
virtual std::string message() const;
// The tracker URL
std::string url;
};
#define TORRENT_DEFINE_ALERT(name) \
static const int alert_type = __LINE__; \
virtual int type() const { return alert_type; } \
virtual std::auto_ptr<alert> clone() const \
{ return std::auto_ptr<alert>(new name(*this)); } \
virtual int category() const { return static_category; } \
virtual char const* what() const { return #name; }
// The ``torrent_added_alert`` is posted once every time a torrent is successfully
// added. It doesn't contain any members of its own, but inherits the torrent handle
// from its base class.
// It's posted when the ``status_notification`` bit is set in the alert_mask.
struct TORRENT_EXPORT torrent_added_alert: torrent_alert
{
// internal
torrent_added_alert(torrent_handle const& h)
: torrent_alert(h)
{}
TORRENT_DEFINE_ALERT(torrent_added_alert);
static const int static_category = alert::status_notification;
virtual std::string message() const;
};
// The ``torrent_removed_alert`` is posted whenever a torrent is removed. Since
// the torrent handle in its baseclass will always be invalid (since the torrent
// is already removed) it has the info hash as a member, to identify it.
// It's posted when the ``status_notification`` bit is set in the alert_mask.
//
// Even though the ``handle`` member doesn't point to an existing torrent anymore,
// it is still useful for comparing to other handles, which may also no
// longer point to existing torrents, but to the same non-existing torrents.
//
// The ``torrent_handle`` acts as a ``weak_ptr``, even though its object no
// longer exists, it can still compare equal to another weak pointer which
// points to the same non-existent object.
struct TORRENT_EXPORT torrent_removed_alert: torrent_alert
{
// internal
torrent_removed_alert(torrent_handle const& h, sha1_hash const& ih)
: torrent_alert(h)
, info_hash(ih)
{}
TORRENT_DEFINE_ALERT(torrent_removed_alert);
static const int static_category = alert::status_notification;
virtual std::string message() const;
sha1_hash info_hash;
};
// This alert is posted when the asynchronous read operation initiated by
// a call to torrent_handle::read_piece() is completed. If the read failed, the torrent
// is paused and an error state is set and the buffer member of the alert
// is 0. If successful, ``buffer`` points to a buffer containing all the data
// of the piece. ``piece`` is the piece index that was read. ``size`` is the
// number of bytes that was read.
//
// If the operation fails, ec will indicat what went wrong.
struct TORRENT_EXPORT read_piece_alert: torrent_alert
{
// internal
read_piece_alert(torrent_handle const& h
, int p, boost::shared_array<char> d, int s)
: torrent_alert(h)
, buffer(d)
, piece(p)
, size(s)
{}
read_piece_alert(torrent_handle h, int p, error_code e)
: torrent_alert(h)
, ec(e)
, piece(p)
, size(0)
{}
TORRENT_DEFINE_ALERT(read_piece_alert);
static const int static_category = alert::storage_notification;
virtual std::string message() const;
virtual bool discardable() const { return false; }
error_code ec;
boost::shared_array<char> buffer;
int piece;
int size;
};
// This is posted whenever an individual file completes its download. i.e.
// All pieces overlapping this file have passed their hash check.
struct TORRENT_EXPORT file_completed_alert: torrent_alert
{
// internal
file_completed_alert(torrent_handle const& h
, int idx)
: torrent_alert(h)
, index(idx)
{}
TORRENT_DEFINE_ALERT(file_completed_alert);
static const int static_category = alert::progress_notification;
virtual std::string message() const;
// refers to the index of the file that completed.
int index;
};
// This is posted as a response to a torrent_handle::rename_file() call, if the rename
// operation succeeds.
struct TORRENT_EXPORT file_renamed_alert: torrent_alert
{
// internal
file_renamed_alert(torrent_handle const& h
, std::string const& n
, int idx)
: torrent_alert(h)
, name(n)
, index(idx)
{}
TORRENT_DEFINE_ALERT(file_renamed_alert);
static const int static_category = alert::storage_notification;
virtual std::string message() const;
virtual bool discardable() const { return false; }
std::string name;
// refers to the index of the file that was renamed,
// ``name`` is the new name of the file.
int index;
};
// This is posted as a response to a torrent_handle::rename_file() call, if the rename
// operation failed.
struct TORRENT_EXPORT file_rename_failed_alert: torrent_alert
{
// internal
file_rename_failed_alert(torrent_handle const& h
, int idx
, error_code ec)
: torrent_alert(h)
, index(idx)
, error(ec)
{}
TORRENT_DEFINE_ALERT(file_rename_failed_alert);
static const int static_category = alert::storage_notification;
virtual std::string message() const;
virtual bool discardable() const { return false; }
// refers to the index of the file that was supposed to be renamed,
// ``error`` is the error code returned from the filesystem.
int index;
error_code error;
};
// This alert is generated when a limit is reached that might have a negative impact on
// upload or download rate performance.
struct TORRENT_EXPORT performance_alert: torrent_alert
{
enum performance_warning_t
{
// This warning means that the number of bytes queued to be written to disk
// exceeds the max disk byte queue setting (``session_settings::max_queued_disk_bytes``).
// This might restrict the download rate, by not queuing up enough write jobs
// to the disk I/O thread. When this alert is posted, peer connections are
// temporarily stopped from downloading, until the queued disk bytes have fallen
// below the limit again. Unless your ``max_queued_disk_bytes`` setting is already
// high, you might want to increase it to get better performance.
outstanding_disk_buffer_limit_reached,
// This is posted when libtorrent would like to send more requests to a peer,
// but it's limited by ``session_settings::max_out_request_queue``. The queue length
// libtorrent is trying to achieve is determined by the download rate and the
// assumed round-trip-time (``session_settings::request_queue_time``). The assumed
// rount-trip-time is not limited to just the network RTT, but also the remote disk
// access time and message handling time. It defaults to 3 seconds. The target number
// of outstanding requests is set to fill the bandwidth-delay product (assumed RTT
// times download rate divided by number of bytes per request). When this alert
// is posted, there is a risk that the number of outstanding requests is too low
// and limits the download rate. You might want to increase the ``max_out_request_queue``
// setting.
outstanding_request_limit_reached,
// This warning is posted when the amount of TCP/IP overhead is greater than the
// upload rate limit. When this happens, the TCP/IP overhead is caused by a much
// faster download rate, triggering TCP ACK packets. These packets eat into the
// rate limit specified to libtorrent. When the overhead traffic is greater than
// the rate limit, libtorrent will not be able to send any actual payload, such
// as piece requests. This means the download rate will suffer, and new requests
// can be sent again. There will be an equilibrium where the download rate, on
// average, is about 20 times the upload rate limit. If you want to maximize the
// download rate, increase the upload rate limit above 5% of your download capacity.
upload_limit_too_low,
// This is the same warning as ``upload_limit_too_low`` but referring to the download
// limit instead of upload. This suggests that your download rate limit is mcuh lower
// than your upload capacity. Your upload rate will suffer. To maximize upload rate,
// make sure your download rate limit is above 5% of your upload capacity.
download_limit_too_low,
// We're stalled on the disk. We want to write to the socket, and we can write
// but our send buffer is empty, waiting to be refilled from the disk.
// This either means the disk is slower than the network connection
// or that our send buffer watermark is too small, because we can
// send it all before the disk gets back to us.
// The number of bytes that we keep outstanding, requested from the disk, is calculated
// as follows::
//
// min(512, max(upload_rate * send_buffer_watermark_factor / 100, send_buffer_watermark))
//
// If you receive this alert, you migth want to either increase your ``send_buffer_watermark``
// or ``send_buffer_watermark_factor``.
send_buffer_watermark_too_low,
// If the half (or more) of all upload slots are set as optimistic unchoke slots, this
// warning is issued. You probably want more regular (rate based) unchoke slots.
too_many_optimistic_unchoke_slots,
// If the disk write queue ever grows larger than half of the cache size, this warning
// is posted. The disk write queue eats into the total disk cache and leaves very little
// left for the actual cache. This causes the disk cache to oscillate in evicting large
// portions of the cache before allowing peers to download any more, onto the disk write
// queue. Either lower ``max_queued_disk_bytes`` or increase ``cache_size``.
too_high_disk_queue_limit,
bittyrant_with_no_uplimit,
// This is generated if outgoing peer connections are failing because of *address in use*
// errors, indicating that ``session_settings::outgoing_ports`` is set and is too small of
// a range. Consider not using the ``outgoing_ports`` setting at all, or widen the range to
// include more ports.
too_few_outgoing_ports,
too_few_file_descriptors,
num_warnings
};
// internal
performance_alert(torrent_handle const& h
, performance_warning_t w)
: torrent_alert(h)
, warning_code(w)
{}
TORRENT_DEFINE_ALERT(performance_alert);
static const int static_category = alert::performance_warning;
virtual std::string message() const;
performance_warning_t warning_code;
};
// Generated whenever a torrent changes its state.
struct TORRENT_EXPORT state_changed_alert: torrent_alert
{
// internal
state_changed_alert(torrent_handle const& h
, torrent_status::state_t st
, torrent_status::state_t prev_st)
: torrent_alert(h)
, state(st)
, prev_state(prev_st)
{}
TORRENT_DEFINE_ALERT(state_changed_alert);
static const int static_category = alert::status_notification;
virtual std::string message() const;
// the new state of the torrent.
torrent_status::state_t state;
// the previous state.
torrent_status::state_t prev_state;
};
// This alert is generated on tracker time outs, premature disconnects, invalid response or
// a HTTP response other than "200 OK". From the alert you can get the handle to the torrent
// the tracker belongs to.
//
// The ``times_in_row`` member says how many times in a row this tracker has failed.
// ``status_code`` is the code returned from the HTTP server. 401 means the tracker needs
// authentication, 404 means not found etc. If the tracker timed out, the code will be set
// to 0.
struct TORRENT_EXPORT tracker_error_alert: tracker_alert
{
// internal
tracker_error_alert(torrent_handle const& h
, int times
, int status
, std::string const& u
, error_code const& e
, std::string const& m)
: tracker_alert(h, u)
, times_in_row(times)
, status_code(status)
, error(e)
, msg(m)
{
TORRENT_ASSERT(!url.empty());
}
TORRENT_DEFINE_ALERT(tracker_error_alert);
static const int static_category = alert::tracker_notification | alert::error_notification;
virtual std::string message() const;
int times_in_row;
int status_code;
error_code error;
std::string msg;
};
// This alert is triggered if the tracker reply contains a warning field. Usually this
// means that the tracker announce was successful, but the tracker has a message to
// the client.
struct TORRENT_EXPORT tracker_warning_alert: tracker_alert
{
// internal
tracker_warning_alert(torrent_handle const& h
, std::string const& u
, std::string const& m)
: tracker_alert(h, u)
, msg(m)
{ TORRENT_ASSERT(!url.empty()); }
TORRENT_DEFINE_ALERT(tracker_warning_alert);
static const int static_category = alert::tracker_notification | alert::error_notification;
virtual std::string message() const;
// contains the warning message from the tracker.
std::string msg;
};
// This alert is generated when a scrape request succeeds.
struct TORRENT_EXPORT scrape_reply_alert: tracker_alert
{
// internal
scrape_reply_alert(torrent_handle const& h
, int incomp
, int comp
, std::string const& u)
: tracker_alert(h, u)
, incomplete(incomp)
, complete(comp)
{ TORRENT_ASSERT(!url.empty()); }
TORRENT_DEFINE_ALERT(scrape_reply_alert);
virtual std::string message() const;
// the data returned in the scrape response. These numbers
// may be -1 if the reponse was malformed.
int incomplete;
int complete;
};
// If a scrape request fails, this alert is generated. This might be due
// to the tracker timing out, refusing connection or returning an http response
// code indicating an error.
struct TORRENT_EXPORT scrape_failed_alert: tracker_alert
{
// internal
scrape_failed_alert(torrent_handle const& h
, std::string const& u
, error_code const& e)
: tracker_alert(h, u)
, msg(convert_from_native(e.message()))
{ TORRENT_ASSERT(!url.empty()); }
scrape_failed_alert(torrent_handle const& h
, std::string const& u
, std::string const& m)
: tracker_alert(h, u)
, msg(m)
{ TORRENT_ASSERT(!url.empty()); }
TORRENT_DEFINE_ALERT(scrape_failed_alert);
static const int static_category = alert::tracker_notification | alert::error_notification;
virtual std::string message() const;
// contains a message describing the error.
std::string msg;
};
// This alert is only for informational purpose. It is generated when a tracker announce
// succeeds. It is generated regardless what kind of tracker was used, be it UDP, HTTP or
// the DHT.
struct TORRENT_EXPORT tracker_reply_alert: tracker_alert
{
// internal
tracker_reply_alert(torrent_handle const& h
, int np
, std::string const& u)
: tracker_alert(h, u)
, num_peers(np)
{ TORRENT_ASSERT(!url.empty()); }
TORRENT_DEFINE_ALERT(tracker_reply_alert);
virtual std::string message() const;
// tells how many peers the tracker returned in this response. This is
// not expected to be more thant the ``num_want`` settings. These are not necessarily
// all new peers, some of them may already be connected.
int num_peers;
};
// This alert is generated each time the DHT receives peers from a node. ``num_peers``
// is the number of peers we received in this packet. Typically these packets are
// received from multiple DHT nodes, and so the alerts are typically generated
// a few at a time.
struct TORRENT_EXPORT dht_reply_alert: tracker_alert
{
// internal
dht_reply_alert(torrent_handle const& h
, int np)
: tracker_alert(h, "")
, num_peers(np)
{}
TORRENT_DEFINE_ALERT(dht_reply_alert);
virtual std::string message() const;
int num_peers;
};
// This alert is generated each time a tracker announce is sent (or attempted to be sent).
// There are no extra data members in this alert. The url can be found in the base class
// however.
struct TORRENT_EXPORT tracker_announce_alert: tracker_alert
{
// internal
tracker_announce_alert(torrent_handle const& h
, std::string const& u, int e)
: tracker_alert(h, u)
, event(e)
{ TORRENT_ASSERT(!url.empty()); }
TORRENT_DEFINE_ALERT(tracker_announce_alert);
virtual std::string message() const;
// specifies what event was sent to the tracker. It is defined as:
//
// 0. None
// 1. Completed
// 2. Started
// 3. Stopped
int event;
};
// This alert is generated when a finished piece fails its hash check. You can get the handle
// to the torrent which got the failed piece and the index of the piece itself from the alert.
struct TORRENT_EXPORT hash_failed_alert: torrent_alert
{
// internal
hash_failed_alert(
torrent_handle const& h
, int index)
: torrent_alert(h)
, piece_index(index)
{ TORRENT_ASSERT(index >= 0);}
TORRENT_DEFINE_ALERT(hash_failed_alert);
static const int static_category = alert::status_notification;
virtual std::string message() const;
int piece_index;
};
// This alert is generated when a peer is banned because it has sent too many corrupt pieces
// to us. ``ip`` is the endpoint to the peer that was banned.
struct TORRENT_EXPORT peer_ban_alert: peer_alert
{
// internal
peer_ban_alert(torrent_handle h, tcp::endpoint const& ep
, peer_id const& peer_id)
: peer_alert(h, ep, peer_id)
{}
TORRENT_DEFINE_ALERT(peer_ban_alert);
virtual std::string message() const;
};
// This alert is generated when a peer is unsnubbed. Essentially when it was snubbed for stalling
// sending data, and now it started sending data again.
struct TORRENT_EXPORT peer_unsnubbed_alert: peer_alert
{
// internal
peer_unsnubbed_alert(torrent_handle h, tcp::endpoint const& ep
, peer_id const& peer_id)
: peer_alert(h, ep, peer_id)
{}
TORRENT_DEFINE_ALERT(peer_unsnubbed_alert);
virtual std::string message() const;
};
// This alert is generated when a peer is snubbed, when it stops sending data when we request
// it.
struct TORRENT_EXPORT peer_snubbed_alert: peer_alert
{
// internal
peer_snubbed_alert(torrent_handle h, tcp::endpoint const& ep
, peer_id const& peer_id)
: peer_alert(h, ep, peer_id)
{}
TORRENT_DEFINE_ALERT(peer_snubbed_alert);
virtual std::string message() const;
};
// This alert is generated when a peer sends invalid data over the peer-peer protocol. The peer
// will be disconnected, but you get its ip address from the alert, to identify it.
struct TORRENT_EXPORT peer_error_alert: peer_alert
{
// internal
peer_error_alert(torrent_handle const& h, tcp::endpoint const& ep
, peer_id const& peer_id, error_code const& e)
: peer_alert(h, ep, peer_id)
, error(e)
{
#ifndef TORRENT_NO_DEPRECATE
msg = convert_from_native(error.message());
#endif
}
TORRENT_DEFINE_ALERT(peer_error_alert);
static const int static_category = alert::peer_notification;
virtual std::string message() const
{
return peer_alert::message() + " peer error: " + convert_from_native(error.message());
}
// tells you what error caused this alert.
error_code error;
#ifndef TORRENT_NO_DEPRECATE
std::string msg;
#endif
};
// This alert is posted every time an outgoing peer connect attempts succeeds.
struct TORRENT_EXPORT peer_connect_alert: peer_alert
{
// internal
peer_connect_alert(torrent_handle h, tcp::endpoint const& ep
, peer_id const& peer_id, int type)
: peer_alert(h, ep, peer_id)
, socket_type(type)
{}
TORRENT_DEFINE_ALERT(peer_connect_alert);
static const int static_category = alert::debug_notification;
virtual std::string message() const;;
int socket_type;
};
// This alert is generated when a peer is disconnected for any reason (other than the ones
// covered by peer_error_alert ).
struct TORRENT_EXPORT peer_disconnected_alert: peer_alert
{
// internal
peer_disconnected_alert(torrent_handle const& h, tcp::endpoint const& ep
, peer_id const& peer_id, error_code const& e)
: peer_alert(h, ep, peer_id)
, error(e)
{
#ifndef TORRENT_NO_DEPRECATE
msg = convert_from_native(error.message());
#endif
}
TORRENT_DEFINE_ALERT(peer_disconnected_alert);
static const int static_category = alert::debug_notification;
virtual std::string message() const;
// tells you what error caused peer to disconnect.
error_code error;
#ifndef TORRENT_NO_DEPRECATE
std::string msg;
#endif
};
// This is a debug alert that is generated by an incoming invalid piece request.
// ``ip`` is the address of the peer and the ``request`` is the actual incoming
// request from the peer. See peer_request for more info.
struct TORRENT_EXPORT invalid_request_alert: peer_alert
{
// internal
invalid_request_alert(torrent_handle const& h, tcp::endpoint const& ep
, peer_id const& peer_id, peer_request const& r)
: peer_alert(h, ep, peer_id)
, request(r)
{}
TORRENT_DEFINE_ALERT(invalid_request_alert);
virtual std::string message() const;
peer_request request;
};
// This alert is generated when a torrent switches from being a downloader to a seed.
// It will only be generated once per torrent. It contains a torrent_handle to the
// torrent in question.
struct TORRENT_EXPORT torrent_finished_alert: torrent_alert
{
// internal
torrent_finished_alert(
const torrent_handle& h)
: torrent_alert(h)
{}
TORRENT_DEFINE_ALERT(torrent_finished_alert);
static const int static_category = alert::status_notification;
virtual std::string message() const
{ return torrent_alert::message() + " torrent finished downloading"; }
};
// this alert is posted every time a piece completes downloading
// and passes the hash check. This alert derives from torrent_alert
// which contains the torrent_handle to the torrent the piece belongs to.
struct TORRENT_EXPORT piece_finished_alert: torrent_alert
{
// internal
piece_finished_alert(
const torrent_handle& h
, int piece_num)
: torrent_alert(h)
, piece_index(piece_num)
{ TORRENT_ASSERT(piece_index >= 0);}
TORRENT_DEFINE_ALERT(piece_finished_alert);
static const int static_category = alert::progress_notification;
virtual std::string message() const;
// the index of the piece that finished
int piece_index;
};
// This alert is generated when a peer rejects or ignores a piece request.
struct TORRENT_EXPORT request_dropped_alert: peer_alert
{
// internal
request_dropped_alert(const torrent_handle& h, tcp::endpoint const& ep
, peer_id const& peer_id, int block_num, int piece_num)
: peer_alert(h, ep, peer_id)
, block_index(block_num)
, piece_index(piece_num)
{ TORRENT_ASSERT(block_index >= 0 && piece_index >= 0);}
TORRENT_DEFINE_ALERT(request_dropped_alert);
static const int static_category = alert::progress_notification
| alert::peer_notification;
virtual std::string message() const;
int block_index;
int piece_index;
};
// This alert is generated when a block request times out.
struct TORRENT_EXPORT block_timeout_alert: peer_alert
{
// internal
block_timeout_alert(const torrent_handle& h, tcp::endpoint const& ep
, peer_id const& peer_id, int block_num, int piece_num)
: peer_alert(h, ep, peer_id)
, block_index(block_num)
, piece_index(piece_num)
{ TORRENT_ASSERT(block_index >= 0 && piece_index >= 0);}
TORRENT_DEFINE_ALERT(block_timeout_alert);
static const int static_category = alert::progress_notification
| alert::peer_notification;
virtual std::string message() const;
int block_index;
int piece_index;
};
// This alert is generated when a block request receives a response.
struct TORRENT_EXPORT block_finished_alert: peer_alert
{
// internal
block_finished_alert(const torrent_handle& h, tcp::endpoint const& ep
, peer_id const& peer_id, int block_num, int piece_num)
: peer_alert(h, ep, peer_id)
, block_index(block_num)
, piece_index(piece_num)
{ TORRENT_ASSERT(block_index >= 0 && piece_index >= 0);}
TORRENT_DEFINE_ALERT(block_finished_alert);
static const int static_category = alert::progress_notification;
virtual std::string message() const;
int block_index;
int piece_index;
};
// This alert is generated when a block request is sent to a peer.
struct TORRENT_EXPORT block_downloading_alert: peer_alert
{
// internal
block_downloading_alert(const torrent_handle& h, tcp::endpoint const& ep
, peer_id const& peer_id, char const* speedmsg, int block_num, int piece_num)
: peer_alert(h, ep, peer_id)
, peer_speedmsg(speedmsg)
, block_index(block_num)
, piece_index(piece_num)
{ TORRENT_ASSERT(block_index >= 0 && piece_index >= 0); }
TORRENT_DEFINE_ALERT(block_downloading_alert);
static const int static_category = alert::progress_notification;
virtual std::string message() const;
char const* peer_speedmsg;
int block_index;
int piece_index;
};
// This alert is generated when a block is received that was not requested or
// whose request timed out.
struct TORRENT_EXPORT unwanted_block_alert: peer_alert
{
// internal
unwanted_block_alert(const torrent_handle& h, tcp::endpoint const& ep
, peer_id const& peer_id, int block_num, int piece_num)
: peer_alert(h, ep, peer_id)
, block_index(block_num)
, piece_index(piece_num)
{ TORRENT_ASSERT(block_index >= 0 && piece_index >= 0);}
TORRENT_DEFINE_ALERT(unwanted_block_alert);
virtual std::string message() const;
int block_index;
int piece_index;
};
// The ``storage_moved_alert`` is generated when all the disk IO has completed and the
// files have been moved, as an effect of a call to ``torrent_handle::move_storage``. This
// is useful to synchronize with the actual disk. The ``path`` member is the new path of
// the storage.
struct TORRENT_EXPORT storage_moved_alert: torrent_alert
{
// internal
storage_moved_alert(torrent_handle const& h, std::string const& p)
: torrent_alert(h)
, path(p)
{}
TORRENT_DEFINE_ALERT(storage_moved_alert);
static const int static_category = alert::storage_notification;
virtual std::string message() const
{
return torrent_alert::message() + " moved storage to: "
+ path;
}
std::string path;
};
// The ``storage_moved_failed_alert`` is generated when an attempt to move the storage,
// via torrent_handle::move_storage(), fails.
struct TORRENT_EXPORT storage_moved_failed_alert: torrent_alert
{
// internal
storage_moved_failed_alert(torrent_handle const& h, error_code const& e)
: torrent_alert(h)
, error(e)
{}
TORRENT_DEFINE_ALERT(storage_moved_failed_alert);
static const int static_category = alert::storage_notification;
virtual std::string message() const
{
return torrent_alert::message() + " storage move failed: "
+ convert_from_native(error.message());
}
error_code error;
};
// This alert is generated when a request to delete the files of a torrent complete.
//
// The ``info_hash`` is the info-hash of the torrent that was just deleted. Most of
// the time the torrent_handle in the ``torrent_alert`` will be invalid by the time
// this alert arrives, since the torrent is being deleted. The ``info_hash`` member
// is hence the main way of identifying which torrent just completed the delete.
//
// This alert is posted in the ``storage_notification`` category, and that bit
// needs to be set in the alert_mask.
struct TORRENT_EXPORT torrent_deleted_alert: torrent_alert
{
// internal
torrent_deleted_alert(torrent_handle const& h, sha1_hash const& ih)
: torrent_alert(h)
{ info_hash = ih; }
TORRENT_DEFINE_ALERT(torrent_deleted_alert);
static const int static_category = alert::storage_notification;
virtual std::string message() const
{ return torrent_alert::message() + " deleted"; }
virtual bool discardable() const { return false; }
sha1_hash info_hash;
};
// This alert is generated when a request to delete the files of a torrent fails.
// Just removing a torrent from the session cannot fail
struct TORRENT_EXPORT torrent_delete_failed_alert: torrent_alert
{
// internal
torrent_delete_failed_alert(torrent_handle const& h, error_code const& e, sha1_hash const& ih)
: torrent_alert(h)
, error(e)
, info_hash(ih)
{
#ifndef TORRENT_NO_DEPRECATE
msg = convert_from_native(error.message());
#endif
}
TORRENT_DEFINE_ALERT(torrent_delete_failed_alert);
static const int static_category = alert::storage_notification
| alert::error_notification;
virtual std::string message() const
{
return torrent_alert::message() + " torrent deletion failed: "
+convert_from_native(error.message());
}
virtual bool discardable() const { return false; }
// tells you why it failed.
error_code error;
// the info hash of the torrent whose files failed to be deleted
sha1_hash info_hash;
#ifndef TORRENT_NO_DEPRECATE
std::string msg;
#endif
};