00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifndef TORRENT_UDP_TRACKER_CONNECTION_HPP_INCLUDED
00034 #define TORRENT_UDP_TRACKER_CONNECTION_HPP_INCLUDED
00035
00036 #include <vector>
00037 #include <string>
00038 #include <utility>
00039 #include <ctime>
00040
00041 #ifdef _MSC_VER
00042 #pragma warning(push, 1)
00043 #endif
00044
00045 #include <boost/shared_ptr.hpp>
00046 #include <boost/date_time/posix_time/posix_time.hpp>
00047 #include <boost/cstdint.hpp>
00048
00049 #ifdef _MSC_VER
00050 #pragma warning(pop)
00051 #endif
00052
00053 #include "libtorrent/socket.hpp"
00054 #include "libtorrent/entry.hpp"
00055 #include "libtorrent/session_settings.hpp"
00056 #include "libtorrent/peer_id.hpp"
00057 #include "libtorrent/peer.hpp"
00058 #include "libtorrent/tracker_manager.hpp"
00059 #include "libtorrent/config.hpp"
00060
00061 namespace libtorrent
00062 {
00063 class TORRENT_EXPORT udp_tracker_connection: public tracker_connection
00064 {
00065 friend class tracker_manager;
00066 public:
00067
00068 udp_tracker_connection(
00069 asio::strand& str
00070 , tracker_manager& man
00071 , tracker_request const& req
00072 , std::string const& hostname
00073 , unsigned short port
00074 , address bind_infc
00075 , boost::weak_ptr<request_callback> c
00076 , session_settings const& stn);
00077
00078 private:
00079
00080 enum action_t
00081 {
00082 action_connect,
00083 action_announce,
00084 action_scrape,
00085 action_error
00086 };
00087
00088 boost::intrusive_ptr<udp_tracker_connection> self()
00089 { return boost::intrusive_ptr<udp_tracker_connection>(this); }
00090
00091 void name_lookup(asio::error_code const& error, udp::resolver::iterator i);
00092 void timeout(asio::error_code const& error);
00093
00094 void send_udp_connect();
00095 void connect_response(asio::error_code const& error, std::size_t bytes_transferred);
00096
00097 void send_udp_announce();
00098 void announce_response(asio::error_code const& error, std::size_t bytes_transferred);
00099
00100 void send_udp_scrape();
00101 void scrape_response(asio::error_code const& error, std::size_t bytes_transferred);
00102
00103 virtual void on_timeout();
00104
00105 tracker_manager& m_man;
00106
00107 asio::strand& m_strand;
00108 udp::resolver m_name_lookup;
00109 boost::shared_ptr<datagram_socket> m_socket;
00110 udp::endpoint m_target;
00111 udp::endpoint m_sender;
00112
00113 int m_transaction_id;
00114 boost::int64_t m_connection_id;
00115 session_settings const& m_settings;
00116 int m_attempts;
00117 std::vector<char> m_buffer;
00118 };
00119
00120 }
00121
00122 #endif // TORRENT_UDP_TRACKER_CONNECTION_HPP_INCLUDED
00123