File indexing completed on 2024-06-02 05:05:28

0001 /*
0002     SPDX-FileCopyrightText: 2010 Joris Guisson <joris.guisson@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef BT_PEERCONNECTOR_H
0008 #define BT_PEERCONNECTOR_H
0009 
0010 #include "connectionlimit.h"
0011 #include <QSharedPointer>
0012 #include <ktorrent_export.h>
0013 #include <net/address.h>
0014 #include <util/constants.h>
0015 #include <util/resourcemanager.h>
0016 
0017 namespace bt
0018 {
0019 class Authenticate;
0020 class PeerManager;
0021 
0022 /**
0023     Class which connects to a peer.
0024 */
0025 class KTORRENT_EXPORT PeerConnector : public Resource
0026 {
0027 public:
0028     enum Method {
0029         TCP_WITH_ENCRYPTION,
0030         TCP_WITHOUT_ENCRYPTION,
0031         UTP_WITH_ENCRYPTION,
0032         UTP_WITHOUT_ENCRYPTION,
0033     };
0034 
0035     PeerConnector(const net::Address &addr, bool local, PeerManager *pman, ConnectionLimit::Token::Ptr token);
0036     ~PeerConnector() override;
0037 
0038     /// Called when an authentication attempt is finished
0039     void authenticationFinished(bt::Authenticate *auth, bool ok);
0040 
0041     /// Start connecting
0042     void start();
0043 
0044     /**
0045      * Set the maximum number of active PeerConnectors allowed
0046      */
0047     static void setMaxActive(Uint32 mc);
0048 
0049     typedef QSharedPointer<PeerConnector> Ptr;
0050     typedef QWeakPointer<PeerConnector> WPtr;
0051 
0052     /// Set a weak pointer to this object
0053     void setWeakPointer(WPtr ptr);
0054 
0055 private:
0056     void acquired() override;
0057 
0058 private:
0059     class Private;
0060     Private *d;
0061 };
0062 
0063 }
0064 
0065 #endif // BT_PEERCONNECTOR_H