alert_types.hpp
Upload User: xiaoan1112
Upload Date: 2016-09-19
Package Size: 1631k
Code Size: 34k
Category:

P2P

Development Platform:

Visual C++

  1. /*
  2. Copyright (c) 2003, Arvid Norberg
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions
  6. are met:
  7.     * Redistributions of source code must retain the above copyright
  8.       notice, this list of conditions and the following disclaimer.
  9.     * Redistributions in binary form must reproduce the above copyright
  10.       notice, this list of conditions and the following disclaimer in
  11.       the documentation and/or other materials provided with the distribution.
  12.     * Neither the name of the author nor the names of its
  13.       contributors may be used to endorse or promote products derived
  14.       from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  19. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. #ifndef TORRENT_ALERT_TYPES_HPP_INCLUDED
  28. #define TORRENT_ALERT_TYPES_HPP_INCLUDED
  29. #include "libtorrent/alert.hpp"
  30. #include "libtorrent/torrent_handle.hpp"
  31. #include "libtorrent/socket.hpp"
  32. #include "libtorrent/peer_connection.hpp"
  33. #include "libtorrent/config.hpp"
  34. #include "libtorrent/assert.hpp"
  35. #include "libtorrent/identify_client.hpp"
  36. #include <boost/lexical_cast.hpp>
  37. namespace libtorrent
  38. {
  39. struct TORRENT_EXPORT torrent_alert: alert
  40. {
  41. torrent_alert(torrent_handle const& h)
  42. : handle(h)
  43. {}
  44. virtual std::string message() const
  45. { return handle.is_valid()?handle.name():" - "; }
  46. torrent_handle handle;
  47. };
  48. struct TORRENT_EXPORT peer_alert: torrent_alert
  49. {
  50. peer_alert(torrent_handle const& h, tcp::endpoint const& ip_
  51. , peer_id const& pid_)
  52. : torrent_alert(h)
  53. , ip(ip_)
  54. , pid(pid_)
  55. {}
  56. const static int static_category = alert::peer_notification;
  57. virtual int category() const { return static_category; }
  58. virtual std::string message() const
  59. {
  60. error_code ec;
  61. return torrent_alert::message() + " peer (" + ip.address().to_string(ec)
  62. + ", " + identify_client(pid) + ")";
  63. }
  64. tcp::endpoint ip;
  65. peer_id pid;
  66. };
  67. struct TORRENT_EXPORT tracker_alert: torrent_alert
  68. {
  69. tracker_alert(torrent_handle const& h
  70. , std::string const& url_)
  71. : torrent_alert(h)
  72. , url(url_)
  73. {}
  74. const static int static_category = alert::tracker_notification;
  75. virtual int category() const { return static_category; }
  76. virtual std::string message() const
  77. {
  78. return torrent_alert::message() + " (" + url + ")";
  79. }
  80. std::string url;
  81. };
  82. struct TORRENT_EXPORT file_renamed_alert: torrent_alert
  83. {
  84. file_renamed_alert(torrent_handle const& h
  85. , std::string const& name_
  86. , int index_)
  87. : torrent_alert(h)
  88. , name(name_)
  89. , index(index_)
  90. {}
  91. virtual std::auto_ptr<alert> clone() const
  92. { return std::auto_ptr<alert>(new file_renamed_alert(*this)); }
  93. const static int static_category = alert::storage_notification;
  94. virtual int category() const { return static_category; }
  95. virtual char const* what() const { return "file renamed"; }
  96. virtual std::string message() const
  97. {
  98. std::stringstream ret;
  99. ret << torrent_alert::message() << ": file "
  100. << index << " renamed to " << name;
  101. return ret.str();
  102. }
  103. std::string name;
  104. int index;
  105. };
  106. struct TORRENT_EXPORT file_rename_failed_alert: torrent_alert
  107. {
  108. file_rename_failed_alert(torrent_handle const& h
  109. , std::string const& msg_
  110. , int index_)
  111. : torrent_alert(h)
  112. , msg(msg_)
  113. , index(index_)
  114. {}
  115. virtual std::auto_ptr<alert> clone() const
  116. { return std::auto_ptr<alert>(new file_rename_failed_alert(*this)); }
  117. virtual char const* what() const { return "file rename failed"; }
  118. virtual std::string message() const
  119. {
  120. std::stringstream ret;
  121. ret << torrent_alert::message() << ": failed to rename file "
  122. << index << ": " << msg;
  123. return ret.str();
  124. }
  125. const static int static_category = alert::storage_notification;
  126. virtual int category() const { return static_category; }
  127. std::string msg;
  128. int index;
  129. };
  130. struct TORRENT_EXPORT performance_alert: torrent_alert
  131. {
  132. enum performance_warning_t
  133. {
  134. outstanding_disk_buffer_limit_reached,
  135. outstanding_request_limit_reached
  136. };
  137. performance_alert(torrent_handle const& h
  138. , performance_warning_t w)
  139. : torrent_alert(h)
  140. , warning_code(w)
  141. {}
  142. virtual std::auto_ptr<alert> clone() const
  143. { return std::auto_ptr<alert>(new performance_alert(*this)); }
  144. virtual char const* what() const { return "performance warning"; }
  145. virtual std::string message() const
  146. {
  147. static char const* warning_str[] =
  148. {
  149. "max outstanding disk writes reached",
  150. "max outstanding piece requests reached",
  151. };
  152. return torrent_alert::message() + ": performance warning: "
  153. + warning_str[warning_code];
  154. }
  155. const static int static_category = alert::performance_warning;
  156. virtual int category() const { return static_category; }
  157. performance_warning_t warning_code;
  158. };
  159. struct TORRENT_EXPORT state_changed_alert: torrent_alert
  160. {
  161. state_changed_alert(torrent_handle const& h
  162. , torrent_status::state_t const& state_)
  163. : torrent_alert(h)
  164. , state(state_)
  165. {}
  166. virtual std::auto_ptr<alert> clone() const
  167. { return std::auto_ptr<alert>(new state_changed_alert(*this)); }
  168. virtual char const* what() const { return "torrent state changed"; }
  169. virtual std::string message() const
  170. {
  171. static char const* state_str[] =
  172. {"checking (q)", "checking", "dl metadata"
  173. , "downloading", "finished", "seeding", "allocating"};
  174. return torrent_alert::message() + ": state changed to: "
  175. + state_str[state];
  176. }
  177. const static int static_category = alert::status_notification;
  178. virtual int category() const { return static_category; }
  179. torrent_status::state_t state;
  180. };
  181. struct TORRENT_EXPORT tracker_error_alert: tracker_alert
  182. {
  183. tracker_error_alert(torrent_handle const& h
  184. , int times
  185. , int status
  186. , std::string const& url
  187. , std::string const& msg_)
  188. : tracker_alert(h, url)
  189. , times_in_row(times)
  190. , status_code(status)
  191. , msg(msg_)
  192. { TORRENT_ASSERT(!url.empty()); }
  193. virtual std::auto_ptr<alert> clone() const
  194. { return std::auto_ptr<alert>(new tracker_error_alert(*this)); }
  195. const static int static_category = alert::tracker_notification | alert::error_notification;
  196. virtual int category() const { return static_category; }
  197. virtual char const* what() const { return "tracker error"; }
  198. virtual std::string message() const
  199. {
  200. std::stringstream ret;
  201. ret << tracker_alert::message() << " (" << status_code << ") "
  202. << msg << " (" << times_in_row << ")";
  203. return ret.str();
  204. }
  205. int times_in_row;
  206. int status_code;
  207. std::string msg;
  208. };
  209. struct TORRENT_EXPORT tracker_warning_alert: tracker_alert
  210. {
  211. tracker_warning_alert(torrent_handle const& h
  212. , std::string const& url
  213. , std::string const& msg_)
  214. : tracker_alert(h, url)
  215. , msg(msg_)
  216. { TORRENT_ASSERT(!url.empty()); }
  217. std::string msg;
  218. virtual std::auto_ptr<alert> clone() const
  219. { return std::auto_ptr<alert>(new tracker_warning_alert(*this)); }
  220. const static int static_category = alert::tracker_notification | alert::error_notification;
  221. virtual int category() const { return static_category; }
  222. virtual char const* what() const { return "tracker warning"; }
  223. virtual std::string message() const
  224. {
  225. return tracker_alert::message() + " warning: " + msg;
  226. }
  227. };
  228. struct TORRENT_EXPORT scrape_reply_alert: tracker_alert
  229. {
  230. scrape_reply_alert(torrent_handle const& h
  231. , int incomplete_
  232. , int complete_
  233. , std::string const& url)
  234. : tracker_alert(h, url)
  235. , incomplete(incomplete_)
  236. , complete(complete_)
  237. { TORRENT_ASSERT(!url.empty()); }
  238. int incomplete;
  239. int complete;
  240. virtual std::auto_ptr<alert> clone() const
  241. { return std::auto_ptr<alert>(new scrape_reply_alert(*this)); }
  242. virtual char const* what() const { return "tracker scrape reply"; }
  243. virtual std::string message() const
  244. {
  245. std::stringstream ret;
  246. ret << tracker_alert::message() << " scrape reply: " << incomplete
  247. << " " << complete;
  248. return ret.str();
  249. }
  250. };
  251. struct TORRENT_EXPORT scrape_failed_alert: tracker_alert
  252. {
  253. scrape_failed_alert(torrent_handle const& h
  254. , std::string const& url
  255. , std::string const& msg_)
  256. : tracker_alert(h, url)
  257. , msg(msg_)
  258. { TORRENT_ASSERT(!url.empty()); }
  259. std::string msg;
  260. virtual std::auto_ptr<alert> clone() const
  261. { return std::auto_ptr<alert>(new scrape_failed_alert(*this)); }
  262. const static int static_category = alert::tracker_notification | alert::error_notification;
  263. virtual int category() const { return static_category; }
  264. virtual char const* what() const { return "tracker scrape failed"; }
  265. virtual std::string message() const
  266. {
  267. return tracker_alert::message() + " scrape failed: " + msg;
  268. }
  269. };
  270. struct TORRENT_EXPORT tracker_reply_alert: tracker_alert
  271. {
  272. tracker_reply_alert(torrent_handle const& h
  273. , int np
  274. , std::string const& url)
  275. : tracker_alert(h, url)
  276. , num_peers(np)
  277. { TORRENT_ASSERT(!url.empty()); }
  278. int num_peers;
  279. virtual std::auto_ptr<alert> clone() const
  280. { return std::auto_ptr<alert>(new tracker_reply_alert(*this)); }
  281. virtual char const* what() const { return "tracker reply"; }
  282. virtual std::string message() const
  283. {
  284. std::stringstream ret;
  285. ret << tracker_alert::message() << " received peers: "
  286. << num_peers;
  287. return ret.str();
  288. }
  289. };
  290. struct TORRENT_EXPORT dht_reply_alert: tracker_alert
  291. {
  292. dht_reply_alert(torrent_handle const& h
  293. , int np)
  294. : tracker_alert(h, "")
  295. , num_peers(np)
  296. {}
  297. int num_peers;
  298. virtual std::auto_ptr<alert> clone() const
  299. { return std::auto_ptr<alert>(new dht_reply_alert(*this)); }
  300. virtual char const* what() const { return "DHT reply"; }
  301. virtual std::string message() const
  302. {
  303. std::stringstream ret;
  304. ret << torrent_alert::message() << " received DHT peers: "
  305. << num_peers;
  306. return ret.str();
  307. }
  308. };
  309. struct TORRENT_EXPORT tracker_announce_alert: tracker_alert
  310. {
  311. tracker_announce_alert(torrent_handle const& h
  312. , std::string const& url, int event_)
  313. : tracker_alert(h, url)
  314. , event(event_)
  315. { TORRENT_ASSERT(!url.empty()); }
  316. int event;
  317. virtual std::auto_ptr<alert> clone() const
  318. { return std::auto_ptr<alert>(new tracker_announce_alert(*this)); }
  319. virtual char const* what() const { return "tracker announce sent"; }
  320. virtual std::string message() const
  321. {
  322. const static char* event_str[] = {"none", "completed", "started", "stopped"};
  323. return tracker_alert::message() + " sending announce (" + event_str[event] + ")";
  324. }
  325. };
  326. struct TORRENT_EXPORT hash_failed_alert: torrent_alert
  327. {
  328. hash_failed_alert(
  329. torrent_handle const& h
  330. , int index)
  331. : torrent_alert(h)
  332. , piece_index(index)
  333. { TORRENT_ASSERT(index >= 0);}
  334. virtual std::auto_ptr<alert> clone() const
  335. { return std::auto_ptr<alert>(new hash_failed_alert(*this)); }
  336. virtual char const* what() const { return "piece hash failed"; }
  337. const static int static_category = alert::status_notification;
  338. virtual int category() const { return static_category; }
  339. virtual std::string message() const
  340. {
  341. std::stringstream ret;
  342. ret << torrent_alert::message() << " hash for piece "
  343. << piece_index << " failed";
  344. return ret.str();
  345. }
  346. int piece_index;
  347. };
  348. struct TORRENT_EXPORT peer_ban_alert: peer_alert
  349. {
  350. peer_ban_alert(torrent_handle h, tcp::endpoint const& ip
  351. , peer_id const& pid)
  352. : peer_alert(h, ip, pid)
  353. {}
  354. virtual std::auto_ptr<alert> clone() const
  355. { return std::auto_ptr<alert>(new peer_ban_alert(*this)); }
  356. virtual char const* what() const { return "peer banned"; }
  357. virtual std::string message() const
  358. {
  359. error_code ec;
  360. return peer_alert::message() + " banned peer";
  361. }
  362. };
  363. struct TORRENT_EXPORT peer_unsnubbed_alert: peer_alert
  364. {
  365. peer_unsnubbed_alert(torrent_handle h, tcp::endpoint const& ip
  366. , peer_id const& pid)
  367. : peer_alert(h, ip, pid)
  368. {}
  369. virtual std::auto_ptr<alert> clone() const
  370. { return std::auto_ptr<alert>(new peer_unsnubbed_alert(*this)); }
  371. virtual char const* what() const { return "peer unsnubbed"; }
  372. virtual std::string message() const
  373. {
  374. return peer_alert::message() + " peer unsnubbed";
  375. }
  376. };
  377. struct TORRENT_EXPORT peer_snubbed_alert: peer_alert
  378. {
  379. peer_snubbed_alert(torrent_handle h, tcp::endpoint const& ip
  380. , peer_id const& pid)
  381. : peer_alert(h, ip, pid)
  382. {}
  383. virtual std::auto_ptr<alert> clone() const
  384. { return std::auto_ptr<alert>(new peer_snubbed_alert(*this)); }
  385. virtual char const* what() const { return "peer snubbed"; }
  386. virtual std::string message() const
  387. {
  388. return peer_alert::message() + " peer snubbed";
  389. }
  390. };
  391. struct TORRENT_EXPORT peer_error_alert: peer_alert
  392. {
  393. peer_error_alert(torrent_handle const& h, tcp::endpoint const& ip
  394. , peer_id const& pid, std::string const& msg_)
  395. : peer_alert(h, ip, pid)
  396. , msg(msg_)
  397. {}
  398. virtual std::auto_ptr<alert> clone() const
  399. { return std::auto_ptr<alert>(new peer_error_alert(*this)); }
  400. virtual char const* what() const { return "peer error"; }
  401. const static int static_category = alert::peer_notification;
  402. virtual int category() const { return static_category; }
  403. virtual std::string message() const
  404. {
  405. error_code ec;
  406. return peer_alert::message() + " peer error: " + msg;
  407. }
  408. std::string msg;
  409. };
  410. struct TORRENT_EXPORT peer_connect_alert: peer_alert
  411. {
  412. peer_connect_alert(torrent_handle h, tcp::endpoint const& ip
  413. , peer_id const& pid)
  414. : peer_alert(h, ip, pid)
  415. {}
  416. virtual std::auto_ptr<alert> clone() const
  417. { return std::auto_ptr<alert>(new peer_connect_alert(*this)); }
  418. virtual char const* what() const { return "connecting to peer"; }
  419. const static int static_category = alert::debug_notification;
  420. virtual int category() const { return static_category; }
  421. virtual std::string message() const
  422. {
  423. return peer_alert::message() + " connecting to peer";
  424. }
  425. };
  426. struct TORRENT_EXPORT peer_disconnected_alert: peer_alert
  427. {
  428. peer_disconnected_alert(torrent_handle const& h, tcp::endpoint const& ip
  429. , peer_id const& pid, std::string const& msg_)
  430. : peer_alert(h, ip, pid)
  431. , msg(msg_)
  432. {}
  433. virtual std::auto_ptr<alert> clone() const
  434. { return std::auto_ptr<alert>(new peer_disconnected_alert(*this)); }
  435. virtual char const* what() const { return "peer disconnected"; }
  436. const static int static_category = alert::debug_notification;
  437. virtual int category() const { return static_category; }
  438. virtual std::string message() const
  439. {
  440. return peer_alert::message() + " disconnecting: " + msg;
  441. }
  442. std::string msg;
  443. };
  444. struct TORRENT_EXPORT invalid_request_alert: peer_alert
  445. {
  446. invalid_request_alert(torrent_handle const& h, tcp::endpoint const& ip
  447. , peer_id const& pid, peer_request const& r)
  448. : peer_alert(h, ip, pid)
  449. , request(r)
  450. {}
  451. virtual std::auto_ptr<alert> clone() const
  452. { return std::auto_ptr<alert>(new invalid_request_alert(*this)); }
  453. virtual char const* what() const { return "invalid piece request"; }
  454. virtual std::string message() const
  455. {
  456. std::stringstream ret;
  457. ret << peer_alert::message() << " peer sent an invalid piece request "
  458. "( piece: " << request.piece << " start: " << request.start
  459. << " len: " << request.length << ")";
  460. return ret.str();
  461. }
  462. peer_request request;
  463. };
  464. struct TORRENT_EXPORT torrent_finished_alert: torrent_alert
  465. {
  466. torrent_finished_alert(
  467. const torrent_handle& h)
  468. : torrent_alert(h)
  469. {}
  470. virtual std::auto_ptr<alert> clone() const
  471. { return std::auto_ptr<alert>(new torrent_finished_alert(*this)); }
  472. virtual char const* what() const { return "torrent finished"; }
  473. const static int static_category = alert::status_notification;
  474. virtual int category() const { return static_category; }
  475. virtual std::string message() const
  476. {
  477. return torrent_alert::message() + " torrent finished downloading";
  478. }
  479. };
  480. struct TORRENT_EXPORT piece_finished_alert: torrent_alert
  481. {
  482. piece_finished_alert(
  483. const torrent_handle& h
  484. , int piece_num)
  485. : torrent_alert(h)
  486. , piece_index(piece_num)
  487. { TORRENT_ASSERT(piece_index >= 0);}
  488. int piece_index;
  489. virtual std::auto_ptr<alert> clone() const
  490. { return std::auto_ptr<alert>(new piece_finished_alert(*this)); }
  491. virtual char const* what() const { return "piece finished downloading"; }
  492. const static int static_category = alert::progress_notification;
  493. virtual int category() const { return static_category; }
  494. virtual std::string message() const
  495. {
  496. std::stringstream ret;
  497. ret << torrent_alert::message() << " piece " << piece_index
  498. << " finished downloading";
  499. return ret.str();
  500. }
  501. };
  502. struct TORRENT_EXPORT request_dropped_alert: peer_alert
  503. {
  504. request_dropped_alert(const torrent_handle& h, tcp::endpoint const& ip
  505. , peer_id const& pid, int block_num, int piece_num)
  506. : peer_alert(h, ip, pid)
  507. , block_index(block_num)
  508. , piece_index(piece_num)
  509. { TORRENT_ASSERT(block_index >= 0 && piece_index >= 0);}
  510. int block_index;
  511. int piece_index;
  512. virtual std::auto_ptr<alert> clone() const
  513. { return std::auto_ptr<alert>(new request_dropped_alert(*this)); }
  514. virtual char const* what() const { return "block request dropped"; }
  515. const static int static_category = alert::progress_notification
  516. | alert::peer_notification;
  517. virtual int category() const { return static_category; }
  518. virtual std::string message() const
  519. {
  520. std::stringstream ret;
  521. ret << peer_alert::message() << " peer dropped block ( piece: "
  522. << piece_index << " block: " << block_index << ")";
  523. return ret.str();
  524. }
  525. };
  526. struct TORRENT_EXPORT block_timeout_alert: peer_alert
  527. {
  528. block_timeout_alert(const torrent_handle& h, tcp::endpoint const& ip
  529. , peer_id const& pid, int block_num, int piece_num)
  530. : peer_alert(h, ip, pid)
  531. , block_index(block_num)
  532. , piece_index(piece_num)
  533. { TORRENT_ASSERT(block_index >= 0 && piece_index >= 0);}
  534. int block_index;
  535. int piece_index;
  536. virtual std::auto_ptr<alert> clone() const
  537. { return std::auto_ptr<alert>(new block_timeout_alert(*this)); }
  538. virtual char const* what() const { return "block timed out"; }
  539. const static int static_category = alert::progress_notification
  540. | alert::peer_notification;
  541. virtual int category() const { return static_category; }
  542. virtual std::string message() const
  543. {
  544. std::stringstream ret;
  545. ret << peer_alert::message() << " peer timed out request ( piece: "
  546. << piece_index << " block: " << block_index << ")";
  547. return ret.str();
  548. }
  549. };
  550. struct TORRENT_EXPORT block_finished_alert: peer_alert
  551. {
  552. block_finished_alert(const torrent_handle& h, tcp::endpoint const& ip
  553. , peer_id const& pid, int block_num, int piece_num)
  554. : peer_alert(h, ip, pid)
  555. , block_index(block_num)
  556. , piece_index(piece_num)
  557. { TORRENT_ASSERT(block_index >= 0 && piece_index >= 0);}
  558. int block_index;
  559. int piece_index;
  560. virtual std::auto_ptr<alert> clone() const
  561. { return std::auto_ptr<alert>(new block_finished_alert(*this)); }
  562. virtual char const* what() const { return "block finished downloading"; }
  563. const static int static_category = alert::progress_notification;
  564. virtual int category() const { return static_category; }
  565. virtual std::string message() const
  566. {
  567. std::stringstream ret;
  568. ret << peer_alert::message() << " block finished downloading ( piece: "
  569. << piece_index << " block: " << block_index << ")";
  570. return ret.str();
  571. }
  572. };
  573. struct TORRENT_EXPORT block_downloading_alert: peer_alert
  574. {
  575. block_downloading_alert(const torrent_handle& h, tcp::endpoint const& ip
  576. , peer_id const& pid, char const* speedmsg, int block_num, int piece_num)
  577. : peer_alert(h, ip, pid)
  578. , peer_speedmsg(speedmsg)
  579. , block_index(block_num)
  580. , piece_index(piece_num)
  581. { TORRENT_ASSERT(block_index >= 0 && piece_index >= 0);}
  582. char const* peer_speedmsg;
  583. int block_index;
  584. int piece_index;
  585. virtual std::auto_ptr<alert> clone() const
  586. { return std::auto_ptr<alert>(new block_downloading_alert(*this)); }
  587. virtual char const* what() const { return "block requested"; }
  588. const static int static_category = alert::progress_notification;
  589. virtual int category() const { return static_category; }
  590. virtual std::string message() const
  591. {
  592. std::stringstream ret;
  593. ret << peer_alert::message() << " requested block ( piece: "
  594. << piece_index << " block: " << block_index << ") " << peer_speedmsg;
  595. return ret.str();
  596. }
  597. };
  598. struct TORRENT_EXPORT unwanted_block_alert: peer_alert
  599. {
  600. unwanted_block_alert(const torrent_handle& h, tcp::endpoint const& ip
  601. , peer_id const& pid, int block_num, int piece_num)
  602. : peer_alert(h, ip, pid)
  603. , block_index(block_num)
  604. , piece_index(piece_num)
  605. { TORRENT_ASSERT(block_index >= 0 && piece_index >= 0);}
  606. int block_index;
  607. int piece_index;
  608. virtual std::auto_ptr<alert> clone() const
  609. { return std::auto_ptr<alert>(new unwanted_block_alert(*this)); }
  610. virtual char const* what() const { return "unwanted block received"; }
  611. virtual std::string message() const
  612. {
  613. std::stringstream ret;
  614. ret << peer_alert::message() << " received block not in download queue ( piece: "
  615. << piece_index << " block: " << block_index << ")";
  616. return ret.str();
  617. }
  618. };
  619. struct TORRENT_EXPORT storage_moved_alert: torrent_alert
  620. {
  621. storage_moved_alert(torrent_handle const& h, std::string const& path_)
  622. : torrent_alert(h)
  623. , path(path_)
  624. {}
  625. std::string path;
  626. virtual std::auto_ptr<alert> clone() const
  627. { return std::auto_ptr<alert>(new storage_moved_alert(*this)); }
  628. virtual char const* what() const { return "storage moved"; }
  629. const static int static_category = alert::storage_notification;
  630. virtual int category() const { return static_category; }
  631. virtual std::string message() const
  632. {
  633. return torrent_alert::message() + " moved storage to: "
  634. + path;
  635. }
  636. };
  637. struct TORRENT_EXPORT torrent_deleted_alert: torrent_alert
  638. {
  639. torrent_deleted_alert(torrent_handle const& h)
  640. : torrent_alert(h)
  641. {}
  642. virtual std::auto_ptr<alert> clone() const
  643. { return std::auto_ptr<alert>(new torrent_deleted_alert(*this)); }
  644. virtual char const* what() const { return "torrent deleted"; }
  645. const static int static_category = alert::storage_notification;
  646. virtual int category() const { return static_category; }
  647. virtual std::string message() const
  648. {
  649. return torrent_alert::message() + " deleted";
  650. }
  651. };
  652. struct TORRENT_EXPORT torrent_delete_failed_alert: torrent_alert
  653. {
  654. torrent_delete_failed_alert(torrent_handle const& h, std::string msg_)
  655. : torrent_alert(h)
  656. , msg(msg_)
  657. {}
  658. std::string msg;
  659. virtual std::auto_ptr<alert> clone() const
  660. { return std::auto_ptr<alert>(new torrent_delete_failed_alert(*this)); }
  661. virtual char const* what() const { return "torrent delete failed"; }
  662. const static int static_category = alert::storage_notification
  663. | alert::error_notification;
  664. virtual int category() const { return static_category; }
  665. virtual std::string message() const
  666. {
  667. return torrent_alert::message() + " torrent deletion failed: "
  668. + msg;
  669. }
  670. };
  671. struct TORRENT_EXPORT save_resume_data_alert: torrent_alert
  672. {
  673. save_resume_data_alert(boost::shared_ptr<entry> const& rd
  674. , torrent_handle const& h)
  675. : torrent_alert(h)
  676. , resume_data(rd)
  677. {}
  678. boost::shared_ptr<entry> resume_data;
  679. virtual std::auto_ptr<alert> clone() const
  680. { return std::auto_ptr<alert>(new save_resume_data_alert(*this)); }
  681. virtual char const* what() const { return "save resume data complete"; }
  682. const static int static_category = alert::storage_notification;
  683. virtual int category() const { return static_category; }
  684. virtual std::string message() const
  685. {
  686. return torrent_alert::message() + " resume data generated";
  687. }
  688. };
  689. struct TORRENT_EXPORT save_resume_data_failed_alert: torrent_alert
  690. {
  691. save_resume_data_failed_alert(torrent_handle const& h
  692. , std::string const& msg_)
  693. : torrent_alert(h)
  694. , msg(msg_)
  695. {}
  696. std::string msg;
  697. virtual std::auto_ptr<alert> clone() const
  698. { return std::auto_ptr<alert>(new save_resume_data_failed_alert(*this)); }
  699. virtual char const* what() const { return "save resume data failed"; }
  700. const static int static_category = alert::storage_notification
  701. | alert::error_notification;
  702. virtual int category() const { return static_category; }
  703. virtual std::string message() const
  704. {
  705. return torrent_alert::message() + " resume data was not generated: "
  706. + msg;
  707. }
  708. };
  709. struct TORRENT_EXPORT torrent_paused_alert: torrent_alert
  710. {
  711. torrent_paused_alert(torrent_handle const& h)
  712. : torrent_alert(h)
  713. {}
  714. virtual std::auto_ptr<alert> clone() const
  715. { return std::auto_ptr<alert>(new torrent_paused_alert(*this)); }
  716. virtual char const* what() const { return "torrent paused"; }
  717. const static int static_category = alert::status_notification;
  718. virtual int category() const { return static_category; }
  719. virtual std::string message() const
  720. {
  721. return torrent_alert::message() + " paused";
  722. }
  723. };
  724. struct TORRENT_EXPORT torrent_resumed_alert: torrent_alert
  725. {
  726. torrent_resumed_alert(torrent_handle const& h)
  727. : torrent_alert(h) {}
  728. virtual std::auto_ptr<alert> clone() const
  729. { return std::auto_ptr<alert>(new torrent_resumed_alert(*this)); }
  730. virtual char const* what() const { return "torrent resumed"; }
  731. const static int static_category = alert::status_notification;
  732. virtual int category() const { return static_category; }
  733. virtual std::string message() const
  734. {
  735. return torrent_alert::message() + " resumed";
  736. }
  737. };
  738. struct TORRENT_EXPORT torrent_checked_alert: torrent_alert
  739. {
  740. torrent_checked_alert(torrent_handle const& h)
  741. : torrent_alert(h)
  742. {}
  743. virtual std::auto_ptr<alert> clone() const
  744. { return std::auto_ptr<alert>(new torrent_checked_alert(*this)); }
  745. virtual char const* what() const { return "torrent checked"; }
  746. const static int static_category = alert::status_notification;
  747. virtual int category() const { return static_category; }
  748. virtual std::string message() const
  749. {
  750. return torrent_alert::message() + " checked";
  751. }
  752.   };
  753. struct TORRENT_EXPORT url_seed_alert: torrent_alert
  754. {
  755. url_seed_alert(
  756. torrent_handle const& h
  757. , const std::string& url_
  758. , const std::string& msg_)
  759. : torrent_alert(h)
  760. , url(url_)
  761. , msg(msg_)
  762. {}
  763. virtual std::auto_ptr<alert> clone() const
  764. { return std::auto_ptr<alert>(new url_seed_alert(*this)); }
  765. virtual char const* what() const { return "web seed error"; }
  766. const static int static_category = alert::peer_notification | alert::error_notification;
  767. virtual int category() const { return static_category; }
  768. virtual std::string message() const
  769. {
  770. return torrent_alert::message() + " url seed ("
  771. + url + ") failed: " + msg;
  772. }
  773. std::string url;
  774. std::string msg;
  775. };
  776. struct TORRENT_EXPORT file_error_alert: torrent_alert
  777. {
  778. file_error_alert(
  779. std::string const& f
  780. , const torrent_handle& h
  781. , const std::string& msg_)
  782. : torrent_alert(h)
  783. , file(f)
  784. , msg(msg_)
  785. {}
  786. std::string file;
  787. std::string msg;
  788. virtual std::auto_ptr<alert> clone() const
  789. { return std::auto_ptr<alert>(new file_error_alert(*this)); }
  790. virtual char const* what() const { return "file error"; }
  791. const static int static_category = alert::status_notification
  792. | alert::error_notification
  793. | alert::storage_notification;
  794. virtual int category() const { return static_category; }
  795. virtual std::string message() const
  796. {
  797. return torrent_alert::message() + " file (" + file + ") error: "
  798. + msg;
  799. }
  800. };
  801. struct TORRENT_EXPORT metadata_failed_alert: torrent_alert
  802. {
  803. metadata_failed_alert(const torrent_handle& h)
  804. : torrent_alert(h)
  805. {}
  806. virtual std::auto_ptr<alert> clone() const
  807. { return std::auto_ptr<alert>(new metadata_failed_alert(*this)); }
  808. virtual char const* what() const { return "metadata failed"; }
  809. const static int static_category = alert::error_notification;
  810. virtual int category() const { return static_category; }
  811. virtual std::string message() const
  812. {
  813. return torrent_alert::message() + " invalid metadata received";
  814. }
  815. };
  816. struct TORRENT_EXPORT metadata_received_alert: torrent_alert
  817. {
  818. metadata_received_alert(
  819. const torrent_handle& h)
  820. : torrent_alert(h)
  821. {}
  822. virtual std::auto_ptr<alert> clone() const
  823. { return std::auto_ptr<alert>(new metadata_received_alert(*this)); }
  824. virtual char const* what() const { return "metadata received"; }
  825. const static int static_category = alert::status_notification;
  826. virtual int category() const { return static_category; }
  827. virtual std::string message() const
  828. {
  829. return torrent_alert::message() + " metadata successfully received";
  830. }
  831. };
  832. struct TORRENT_EXPORT udp_error_alert: alert
  833. {
  834. udp_error_alert(
  835. udp::endpoint const& ep
  836. , error_code const& ec)
  837. : endpoint(ep)
  838. , error(ec)
  839. {}
  840. udp::endpoint endpoint;
  841. error_code error;
  842. virtual std::auto_ptr<alert> clone() const
  843. { return std::auto_ptr<alert>(new udp_error_alert(*this)); }
  844. virtual char const* what() const { return "udp error"; }
  845. const static int static_category = alert::error_notification;
  846. virtual int category() const { return static_category; }
  847. virtual std::string message() const
  848. {
  849. error_code ec;
  850. return "UDP error: " + error.message() + " from: " + endpoint.address().to_string(ec);
  851. }
  852. };
  853. struct TORRENT_EXPORT external_ip_alert: alert
  854. {
  855. external_ip_alert(address const& ip)
  856. : external_address(ip)
  857. {}
  858. address external_address;
  859. virtual std::auto_ptr<alert> clone() const
  860. { return std::auto_ptr<alert>(new external_ip_alert(*this)); }
  861. virtual char const* what() const { return "external IP received"; }
  862. const static int static_category = alert::status_notification;
  863. virtual int category() const { return static_category; }
  864. virtual std::string message() const
  865. {
  866. error_code ec;
  867. return "external IP received: " + external_address.to_string(ec);
  868. }
  869. };
  870. struct TORRENT_EXPORT listen_failed_alert: alert
  871. {
  872. listen_failed_alert(
  873. tcp::endpoint const& ep
  874. , error_code const& ec)
  875. : endpoint(ep)
  876. , error(ec)
  877. {}
  878. tcp::endpoint endpoint;
  879. error_code error;
  880. virtual std::auto_ptr<alert> clone() const
  881. { return std::auto_ptr<alert>(new listen_failed_alert(*this)); }
  882. virtual char const* what() const { return "listen failed"; }
  883. const static int static_category = alert::status_notification | alert::error_notification;
  884. virtual int category() const { return static_category; }
  885. virtual std::string message() const
  886. {
  887. error_code ec;
  888. std::stringstream ret;
  889. ret << "listening on " << endpoint
  890. << " failed: " << error.message();
  891. return ret.str();
  892. }
  893. };
  894. struct TORRENT_EXPORT listen_succeeded_alert: alert
  895. {
  896. listen_succeeded_alert(tcp::endpoint const& ep)
  897. : endpoint(ep)
  898. {}
  899. tcp::endpoint endpoint;
  900. virtual std::auto_ptr<alert> clone() const
  901. { return std::auto_ptr<alert>(new listen_succeeded_alert(*this)); }
  902. virtual char const* what() const { return "listen succeeded"; }
  903. const static int static_category = alert::status_notification;
  904. virtual int category() const { return static_category; }
  905. virtual std::string message() const
  906. {
  907. error_code ec;
  908. std::stringstream ret;
  909. ret << "successfully listening on " << endpoint;
  910. return ret.str();
  911. }
  912. };
  913. struct TORRENT_EXPORT portmap_error_alert: alert
  914. {
  915. portmap_error_alert(int i, int t, const std::string& msg_)
  916. :  mapping(i), type(t), msg(msg_)
  917. {}
  918. int mapping;
  919. int type;
  920. std::string msg;
  921. virtual std::auto_ptr<alert> clone() const
  922. { return std::auto_ptr<alert>(new portmap_error_alert(*this)); }
  923. virtual char const* what() const { return "port map error"; }
  924. const static int static_category = alert::port_mapping_notification
  925. | alert::error_notification;
  926. virtual int category() const { return static_category; }
  927. virtual std::string message() const
  928. {
  929. static char const* type_str[] = {"NAT-PMP", "UPnP"};
  930. return std::string("could not map port using ") + type_str[type]
  931. + ": " + msg;
  932. }
  933. };
  934. struct TORRENT_EXPORT portmap_alert: alert
  935. {
  936. portmap_alert(int i, int port, int t)
  937. : mapping(i), external_port(port), type(t)
  938. {}
  939. int mapping;
  940. int external_port;
  941. int type;
  942. virtual std::auto_ptr<alert> clone() const
  943. { return std::auto_ptr<alert>(new portmap_alert(*this)); }
  944. virtual char const* what() const { return "port map succeeded"; }
  945. const static int static_category = alert::port_mapping_notification;
  946. virtual int category() const { return static_category; }
  947. virtual std::string message() const
  948. {
  949. static char const* type_str[] = {"NAT-PMP", "UPnP"};
  950. std::stringstream ret;
  951. ret << "successfully mapped port using " << type_str[type]
  952. << ". external port: " << external_port;
  953. return ret.str();
  954. }
  955. };
  956. struct TORRENT_EXPORT fastresume_rejected_alert: torrent_alert
  957. {
  958. fastresume_rejected_alert(torrent_handle const& h
  959. , std::string const& msg_)
  960. : torrent_alert(h)
  961. , msg(msg_)
  962. {}
  963. std::string msg;
  964. virtual std::auto_ptr<alert> clone() const
  965. { return std::auto_ptr<alert>(new fastresume_rejected_alert(*this)); }
  966. virtual char const* what() const { return "resume data rejected"; }
  967. const static int static_category = alert::status_notification
  968. | alert::error_notification;
  969. virtual int category() const { return static_category; }
  970. virtual std::string message() const
  971. {
  972. return torrent_alert::message() + " fast resume rejected: " + msg;
  973. }
  974. };
  975. struct TORRENT_EXPORT peer_blocked_alert: alert
  976. {
  977. peer_blocked_alert(address const& ip_)
  978. : ip(ip_)
  979. {}
  980. address ip;
  981. virtual std::auto_ptr<alert> clone() const
  982. { return std::auto_ptr<alert>(new peer_blocked_alert(*this)); }
  983. virtual char const* what() const { return "peer blocked"; }
  984. const static int static_category = alert::ip_block_notification;
  985. virtual int category() const { return static_category; }
  986. virtual std::string message() const
  987. {
  988. error_code ec;
  989. return "blocked peer: " + ip.to_string(ec);
  990. }
  991. };
  992. }
  993. #endif