libktorrent  2.1.1
authenticatebase.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 BTAUTHENTICATEBASE_H
21 #define BTAUTHENTICATEBASE_H
22 
23 #include <qobject.h>
24 #include <qtimer.h>
25 #include <util/constants.h>
26 #include <mse/encryptedpacketsocket.h>
27 
28 
29 namespace bt
30 {
31  class SHA1Hash;
32  class PeerID;
33 
42  class AuthenticateBase : public QObject
43  {
44  Q_OBJECT
45  public:
46  AuthenticateBase();
47  AuthenticateBase(mse::EncryptedPacketSocket::Ptr s);
48  ~AuthenticateBase() override;
49 
51  void setLocal(bool loc) {local = loc;}
52 
54  bool isLocal() const {return local;}
55 
57  bool isFinished() const {return finished;}
58 
60  Uint32 supportedExtensions() const {return ext_support;}
61 
63  mse::EncryptedPacketSocket::Ptr getSocket() const {return sock;}
64 
66  virtual void onReadyRead();
67 
69  virtual void onReadyWrite();
70 
71  protected:
77  void sendHandshake(const SHA1Hash & info_hash,const PeerID & our_peer_id);
78 
83  virtual void onFinish(bool succes) = 0;
84 
91  virtual void handshakeReceived(bool full) = 0;
92 
96  void makeHandshake(bt::Uint8* buf,const SHA1Hash & info_hash,const PeerID & our_peer_id);
97 
98 
99 
100  protected Q_SLOTS:
101  void onTimeout();
102  void onError(int err);
103 
104  protected:
105  mse::EncryptedPacketSocket::Ptr sock;
106  QTimer timer;
107  bool finished;
108  Uint8 handshake[68];
109  Uint32 bytes_of_handshake_received;
110  Uint32 ext_support;
111  bool local;
112  };
113 
114 }
115 
116 #endif
bt::AuthenticateBase::sendHandshake
void sendHandshake(const SHA1Hash &info_hash, const PeerID &our_peer_id)
bt::AuthenticateBase::onReadyWrite
virtual void onReadyWrite()
We can write to the socket (used to detect a succesfull connection)
bt::AuthenticateBase::isLocal
bool isLocal() const
Is this a local peer.
Definition: authenticatebase.h:72
bt::AuthenticateBase::supportedExtensions
Uint32 supportedExtensions() const
Flags indicating which extensions are supported.
Definition: authenticatebase.h:78
bt::AuthenticateBase::handshakeReceived
virtual void handshakeReceived(bool full)=0
bt::AuthenticateBase::onReadyRead
virtual void onReadyRead()
We can read from the socket.
bt::AuthenticateBase::onFinish
virtual void onFinish(bool succes)=0
bt::SHA1Hash
Stores a SHA1 hash.
Definition: sha1hash.h:41
bt::AuthenticateBase::makeHandshake
void makeHandshake(bt::Uint8 *buf, const SHA1Hash &info_hash, const PeerID &our_peer_id)
bt::AuthenticateBase::setLocal
void setLocal(bool loc)
Set whether this is a local peer.
Definition: authenticatebase.h:69
bt::AuthenticateBase::getSocket
mse::EncryptedPacketSocket::Ptr getSocket() const
get the socket
Definition: authenticatebase.h:81
bt::PeerID
Definition: peerid.h:51
bt::AuthenticateBase::isFinished
bool isFinished() const
See if the authentication is finished.
Definition: authenticatebase.h:75