libktorrent  2.2.0
serverinterface.h
1 /***************************************************************************
2  * Copyright (C) 2009 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 
21 #ifndef BT_SERVERINTERFACE_H
22 #define BT_SERVERINTERFACE_H
23 
24 #include <QObject>
25 #include <QStringList>
26 #include <ktorrent_export.h>
27 #include <util/constants.h>
28 #include <mse/encryptedpacketsocket.h>
29 
30 
31 namespace bt
32 {
33  class SHA1Hash;
34  class PeerManager;
35 
39  class KTORRENT_EXPORT ServerInterface : public QObject
40  {
41  Q_OBJECT
42  public:
43  ServerInterface(QObject* parent = 0);
44  ~ServerInterface() override;
45 
46 
51  virtual bool changePort(Uint16 port) = 0;
52 
54  static void setPort(Uint16 p) {port = p;}
55 
57  static Uint16 getPort() {return port;}
58 
63  static void addPeerManager(PeerManager* pman);
64 
69  static void removePeerManager(PeerManager* pman);
70 
76  static PeerManager* findPeerManager(const SHA1Hash & hash);
77 
86  static bool findInfoHash(const SHA1Hash & skey,SHA1Hash & info_hash);
87 
92  static void enableEncryption(bool allow_unencrypted);
93 
97  static void disableEncryption();
98 
99  static bool isEncryptionEnabled() {return encryption;}
100  static bool unencryptedConnectionsAllowed() {return allow_unencrypted;}
101 
105  static QStringList bindAddresses();
106 
107  static void setUtpEnabled(bool on,bool only_use_utp);
108  static bool isUtpEnabled() {return utp_enabled;}
109  static bool onlyUseUtp() {return only_use_utp;}
110  static void setPrimaryTransportProtocol(TransportProtocol proto);
111  static TransportProtocol primaryTransportProtocol() {return primary_transport_protocol;}
112 
113  protected:
114  void newConnection(mse::EncryptedPacketSocket::Ptr sock);
115 
116  protected:
117  static Uint16 port;
118  static QList<PeerManager*> peer_managers;
119  static bool encryption;
120  static bool allow_unencrypted;
121  static bool utp_enabled;
122  static bool only_use_utp;
123  static TransportProtocol primary_transport_protocol;
124  };
125 
126 }
127 
128 #endif // BT_SERVERINTERFACE_H
bt::PeerManager
Manages all the Peers.
Definition: peermanager.h:67
bt::SHA1Hash
Stores a SHA1 hash.
Definition: sha1hash.h:41