libktorrent  2.2.0
encryptedpacketsocket.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 MSESTREAMSOCKET_H
21 #define MSESTREAMSOCKET_H
22 
23 #include <util/constants.h>
24 #include <net/packetsocket.h>
25 #include <ktorrent_export.h>
26 
27 class QString;
28 
29 using bt::Uint8;
30 using bt::Uint16;
31 using bt::Uint32;
32 
33 namespace bt
34 {
35  class SHA1Hash;
36 }
37 
38 namespace mse
39 {
40  class RC4Encryptor;
41 
42 
43 
44 
50  class KTORRENT_EXPORT EncryptedPacketSocket : public net::PacketSocket
51  {
52  public:
53  EncryptedPacketSocket(int ip_version);
54  EncryptedPacketSocket(int fd,int ip_version);
56  ~EncryptedPacketSocket() override;
57 
64  Uint32 sendData(const Uint8* data,Uint32 len);
65 
72  Uint32 readData(Uint8* buf,Uint32 len);
73 
75  Uint32 bytesAvailable() const;
76 
78  bool encrypted() const {return enc != 0;}
79 
85  void initCrypt(const bt::SHA1Hash & dkey,const bt::SHA1Hash & ekey);
86 
89 
91  void disableCrypt();
92 
94  void close();
95 
97  bool connectTo(const QString & ip,Uint16 port);
98 
100  bool connectTo(const net::Address & addr);
101 
103  QString getRemoteIPAddress() const;
104 
106  bt::Uint16 getRemotePort() const;
107 
110 
116  void reinsert(const Uint8* d,Uint32 size);
117 
119  bool ok() const;
120 
123 
126 
128  bool connecting() const;
129 
131  bool connectSuccesFull() const;
132 
137  static void setTOS(Uint8 t) {tos = t;}
138 
144  void setRemoteAddress(const net::Address & addr);
145 
146  typedef QSharedPointer<EncryptedPacketSocket> Ptr;
147 
148  private:
149  void preProcess(bt::Packet::Ptr packet) override;
150  void postProcess(Uint8* data, Uint32 size) override;
151 
152  private:
153  RC4Encryptor* enc;
154  Uint8* reinserted_data;
155  Uint32 reinserted_data_size;
156  Uint32 reinserted_data_read;
157  bool monitored;
158 
159  static Uint8 tos;
160  };
161 
162 }
163 
164 #endif
mse::EncryptedPacketSocket::readData
Uint32 readData(Uint8 *buf, Uint32 len)
mse::EncryptedPacketSocket::getRemoteAddress
net::Address getRemoteAddress() const
Get the full address.
net::Address
Definition: address.h:59
net::SocketDevice
Definition: socketdevice.h:50
mse::EncryptedPacketSocket::sendData
Uint32 sendData(const Uint8 *data, Uint32 len)
mse::EncryptedPacketSocket::connecting
bool connecting() const
Is this socket connecting to a remote host.
mse::EncryptedPacketSocket::connectTo
bool connectTo(const QString &ip, Uint16 port)
Connect the socket to a remote host.
mse::EncryptedPacketSocket::setTOS
static void setTOS(Uint8 t)
Definition: encryptedpacketsocket.h:137
mse::EncryptedPacketSocket::bytesAvailable
Uint32 bytesAvailable() const
Get the number of bytes available to read.
mse::EncryptedPacketSocket::stopMonitoring
void stopMonitoring()
Stop monitoring this socket.
mse::EncryptedPacketSocket::setRemoteAddress
void setRemoteAddress(const net::Address &addr)
mse::EncryptedPacketSocket::getRemoteIPAddress
QString getRemoteIPAddress() const
Get the IP address of the remote peer.
mse::EncryptedPacketSocket::disableCrypt
void disableCrypt()
Disables encryption. All data will be sent over as plain text.
mse::EncryptedPacketSocket::close
void close()
Close the socket.
net::PacketSocket
Definition: packetsocket.h:63
mse::EncryptedPacketSocket::reinsert
void reinsert(const Uint8 *d, Uint32 size)
mse::EncryptedPacketSocket::setRC4Encryptor
void setRC4Encryptor(RC4Encryptor *enc)
Set the encryptor.
bt::SHA1Hash
Stores a SHA1 hash.
Definition: sha1hash.h:41
mse::EncryptedPacketSocket
Definition: encryptedpacketsocket.h:51
mse::EncryptedPacketSocket::connectTo
bool connectTo(const net::Address &addr)
Connect the socket to a remote host.
mse::EncryptedPacketSocket::ok
bool ok() const
see if the socket is still OK
mse::EncryptedPacketSocket::connectSuccesFull
bool connectSuccesFull() const
See if a connect was success full.
mse::EncryptedPacketSocket::encrypted
bool encrypted() const
Are we using encryption.
Definition: encryptedpacketsocket.h:78
net::SocketReader
Definition: trafficshapedsocket.h:52
mse::RC4Encryptor
Definition: rc4encryptor.h:42
mse::EncryptedPacketSocket::startMonitoring
void startMonitoring(net::SocketReader *rdr)
Start monitoring of this socket by the monitor thread.
mse::EncryptedPacketSocket::initCrypt
void initCrypt(const bt::SHA1Hash &dkey, const bt::SHA1Hash &ekey)
mse::EncryptedPacketSocket::getRemotePort
bt::Uint16 getRemotePort() const
Get the port of the remote peer.