libktorrent  2.2.0
udptracker.h
1 /***************************************************************************
2  * Copyright (C) 2005 by Joris Guisson *
3  * joris.guisson@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 #ifndef BTUDPTRACKER_H
21 #define BTUDPTRACKER_H
22 
23 #include <QUrl>
24 #include <QTimer>
25 #include <QByteArray>
26 #include <net/address.h>
27 #include "tracker.h"
28 
29 namespace net
30 {
31  class AddressResolver;
32 }
33 
34 namespace bt
35 {
36 
37  class UDPTrackerSocket;
38 
47  class UDPTracker : public Tracker
48  {
49  Q_OBJECT
50  public:
51  UDPTracker(const QUrl &url,TrackerDataSource* tds,const PeerID & id,int tier);
52  ~UDPTracker() override;
53 
54  void start() override;
55  void stop(WaitJob* wjob = 0) override;
56  void completed() override;
57  Uint32 failureCount() const override {return failures;}
58  void scrape() override;
59 
60  private Q_SLOTS:
61  void onConnTimeout();
62  void connectReceived(Int32 tid,Int64 connection_id);
63  void announceReceived(Int32 tid,const Uint8* buf,Uint32 size);
64  void scrapeReceived(Int32 tid,const Uint8* buf,Uint32 size);
65  void onError(Int32 tid,const QString & error_string);
66  void onResolverResults(net::AddressResolver* ar);
67  void manualUpdate() override;
68 
69  private:
70  void sendConnect();
71  void sendAnnounce();
72  void sendScrape();
73  bool doRequest();
74 
75  enum Event
76  {
77  NONE = 0,
78  COMPLETED = 1,
79  STARTED = 2,
80  STOPPED = 3
81  };
82 
83  enum Todo
84  {
85  NOTHING = 0,
86  SCRAPE_REQUEST = 1,
87  ANNOUNCE_REQUEST = 2
88  };
89 
90  private:
91  net::Address address;
92  Int64 connection_id;
93  Int32 transaction_id;
94  Int32 scrape_transaction_id;
95 
96  Uint32 data_read;
97  int failures;
98  bool resolved;
99  Uint32 todo;
100  Event event;
101  QTimer conn_timer;
102 
103  static UDPTrackerSocket* socket;
104  static Uint32 num_instances;
105  };
106 
107 }
108 
109 #endif
net::AddressResolver
Definition: addressresolver.h:55
net::Address
Definition: address.h:59
bt::WaitJob
Definition: waitjob.h:57
bt::UDPTracker::stop
void stop(WaitJob *wjob=0) override
bt::UDPTracker
Communicates with an UDP tracker.
Definition: udptracker.h:48
bt::TrackerDataSource
Definition: tracker.h:40
bt::Tracker
Definition: tracker.h:55
bt::UDPTracker::failureCount
Uint32 failureCount() const override
Definition: udptracker.h:57
bt::PeerID
Definition: peerid.h:51
bt::UDPTracker::completed
void completed() override
bt::UDPTracker::scrape
void scrape() override
bt::UDPTracker::start
void start() override