File indexing completed on 2025-01-05 04:37:21

0001 /*
0002     SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 #ifndef BTAUTHENTICATE_H
0007 #define BTAUTHENTICATE_H
0008 
0009 #include "authenticatebase.h"
0010 #include <peer/peerconnector.h>
0011 #include <peer/peerid.h>
0012 #include <util/sha1hash.h>
0013 
0014 namespace net
0015 {
0016 class Socks;
0017 }
0018 
0019 namespace bt
0020 {
0021 /**
0022  * @author Joris Guisson
0023  * @brief Authenicate a peer
0024  *
0025  * After we connect to a peer,
0026  * we need to authenticate the peer. This class handles this.
0027  */
0028 class Authenticate : public AuthenticateBase
0029 {
0030     Q_OBJECT
0031 public:
0032     /**
0033      * Connect to a remote host first and authenicate it.
0034      * @param addr Address to connect to
0035      * @param proto Transport protocol to use
0036      * @param info_hash Info hash
0037      * @param peer_id Peer ID
0038      * @param pman PeerManager
0039      */
0040     Authenticate(const net::Address &addr, TransportProtocol proto, const SHA1Hash &info_hash, const PeerID &peer_id, PeerConnector::WPtr pcon);
0041 
0042     ~Authenticate() override;
0043 
0044     const PeerID &getPeerID() const
0045     {
0046         return peer_id;
0047     }
0048 
0049     /// See if the authentication is succesfull
0050     bool isSuccesfull() const
0051     {
0052         return succes;
0053     }
0054 
0055 public Q_SLOTS:
0056     /// Stop the authentication
0057     void stop();
0058 
0059 protected Q_SLOTS:
0060     void onReadyWrite() override;
0061     void onReadyRead() override;
0062 
0063 protected:
0064     void onFinish(bool succes) override;
0065     void handshakeReceived(bool full) override;
0066     virtual void connected();
0067 
0068 protected:
0069     SHA1Hash info_hash;
0070     PeerID our_peer_id, peer_id;
0071     net::Address addr;
0072     bool succes;
0073     PeerConnector::WPtr pcon;
0074     net::Socks *socks;
0075 };
0076 }
0077 
0078 #endif