libktorrent  2.1.1
udptrackersocket.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 BTUDPTRACKERSOCKET_H
21 #define BTUDPTRACKERSOCKET_H
22 
23 #include <QObject>
24 #include <QByteArray>
25 #include <util/constants.h>
26 #include <util/bufferpool.h>
27 #include <ktorrent_export.h>
28 
29 #ifdef ERROR
30 #undef ERROR
31 #endif
32 
33 namespace net
34 {
35  class Address;
36 }
37 
38 namespace bt
39 {
40 
46  class KTORRENT_EXPORT UDPTrackerSocket : public QObject
47  {
48  Q_OBJECT
49  public:
51  ~UDPTrackerSocket() override;
52 
53  enum Action
54  {
55  CONNECT = 0,
56  ANNOUNCE = 1,
57  SCRAPE = 2,
58  ERROR = 3
59  };
60 
68  void sendConnect(Int32 tid,const net::Address & addr);
69 
78  void sendAnnounce(Int32 tid,const Uint8* data,const net::Address & addr);
79 
88  void sendScrape(Int32 tid,const Uint8* data,const net::Address & addr);
89 
94  void cancelTransaction(Int32 tid);
95 
96 
102 
107  static void setPort(Uint16 p);
108 
110  static Uint16 getPort();
111 
112  Q_SIGNALS:
118  void connectReceived(Int32 tid,Int64 connection_id);
119 
126  void announceReceived(Int32 tid,const Uint8* buf,Uint32 size);
127 
134  void scrapeReceived(Int32 tid,const Uint8* buf,Uint32 size);
135 
141  void error(Int32 tid,const QString & error_string);
142 
143  private:
144  void handleConnect(bt::Buffer::Ptr buf);
145  void handleAnnounce(bt::Buffer::Ptr buf);
146  void handleError(bt::Buffer::Ptr buf);
147  void handleScrape(bt::Buffer::Ptr buf);
148 
149  private:
150  class Private;
151  Private* d;
152 
153  static Uint16 port;
154  };
155 }
156 
157 #endif
bt::UDPTrackerSocket::setPort
static void setPort(Uint16 p)
net::Address
Definition: address.h:59
bt::UDPTrackerSocket::announceReceived
void announceReceived(Int32 tid, const Uint8 *buf, Uint32 size)
bt::UDPTrackerSocket::sendScrape
void sendScrape(Int32 tid, const Uint8 *data, const net::Address &addr)
bt::UDPTrackerSocket::newTransactionID
Int32 newTransactionID()
bt::UDPTrackerSocket::cancelTransaction
void cancelTransaction(Int32 tid)
bt::UDPTrackerSocket::getPort
static Uint16 getPort()
Get the port in use.
bt::UDPTrackerSocket::sendConnect
void sendConnect(Int32 tid, const net::Address &addr)
bt::UDPTrackerSocket::error
void error(Int32 tid, const QString &error_string)
bt::UDPTrackerSocket
Definition: udptrackersocket.h:47
bt::UDPTrackerSocket::sendAnnounce
void sendAnnounce(Int32 tid, const Uint8 *data, const net::Address &addr)
bt::UDPTrackerSocket::scrapeReceived
void scrapeReceived(Int32 tid, const Uint8 *buf, Uint32 size)
bt::UDPTrackerSocket::connectReceived
void connectReceived(Int32 tid, Int64 connection_id)