libktorrent  2.2.0
packet.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 BTPACKET_H
21 #define BTPACKET_H
22 
23 #include <QSharedPointer>
24 #include <util/constants.h>
25 
26 namespace net {
27 class SocketDevice;
28 }
29 
30 
31 namespace bt
32 {
33  class BitSet;
34  class Request;
35  class Chunk;
36  class Peer;
37 
43  class Packet
44  {
45  public:
46  Packet(Uint8 type);
47  Packet(Uint16 port);
48  Packet(Uint32 chunk,Uint8 type);
49  Packet(const BitSet & bs);
50  Packet(const Request & req,Uint8 type);
51  Packet(Uint32 index,Uint32 begin,Uint32 len,Chunk* ch);
52  Packet(Uint8 ext_id,const QByteArray & ext_data); // extension protocol packet
53  ~Packet();
54 
56  Uint8 getType() const {return type;}
57 
58  bool isOK() const;
59 
60  const Uint8* getData() const {return data;}
61  Uint8* getData() {return data;}
62  Uint32 getDataLength() const {return size;}
63 
65  Uint32 isSent() const {return written == size;}
66 
72 
74  bool sending() const {return written > 0;}
75 
81  bool isPiece(const Request & req) const;
82 
89  int send(net::SocketDevice* sock, Uint32 max_to_send);
90 
91  typedef QSharedPointer<Packet> Ptr;
92 
93  private:
94  Uint8* data;
95  Uint32 size;
96  Uint32 written;
97  Uint8 type;
98  };
99 
100 }
101 
102 #endif
bt::Packet::send
int send(net::SocketDevice *sock, Uint32 max_to_send)
bt::Packet::sending
bool sending() const
Are we sending this packet ?
Definition: packet.h:74
bt::BitSet
Simple implementation of a BitSet.
Definition: bitset.h:37
bt::Packet
Definition: packet.h:44
bt::Packet::makeRejectOfPiece
Packet * makeRejectOfPiece()
net::SocketDevice
Definition: socketdevice.h:32
bt::Chunk
Keep track of a piece of the file.
Definition: chunk.h:46
bt::Packet::isPiece
bool isPiece(const Request &req) const
bt::Packet::getType
Uint8 getType() const
Get the packet type.
Definition: packet.h:56
bt::Request
Request of a piece sent to other peers.
Definition: request.h:40
bt::Packet::isSent
Uint32 isSent() const
Is the packet sent ?
Definition: packet.h:65