File indexing completed on 2025-01-05 04:37:12
0001 /* 0002 SPDX-FileCopyrightText: 2005 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 #ifndef DHTRPCSERVER_H 0007 #define DHTRPCSERVER_H 0008 0009 #include <QList> 0010 #include <QObject> 0011 #include <dht/rpcserverinterface.h> 0012 #include <net/address.h> 0013 #include <net/socket.h> 0014 #include <util/constants.h> 0015 #include <util/ptrmap.h> 0016 0017 using bt::Uint16; 0018 using bt::Uint32; 0019 using bt::Uint8; 0020 0021 namespace dht 0022 { 0023 class Key; 0024 class DHT; 0025 0026 /** 0027 * @author Joris Guisson 0028 * 0029 * Class to handle incoming and outgoing RPC messages. 0030 */ 0031 class RPCServer : public QObject, public RPCServerInterface 0032 { 0033 Q_OBJECT 0034 public: 0035 RPCServer(DHT *dh_table, Uint16 port, QObject *parent = nullptr); 0036 ~RPCServer() override; 0037 0038 /// Start the server 0039 void start(); 0040 0041 /// Stop the server 0042 void stop(); 0043 0044 /** 0045 * Do a RPC call. 0046 * @param msg The message to send 0047 * @return The call object 0048 */ 0049 RPCCall *doCall(RPCMsg::Ptr msg) override; 0050 0051 /** 0052 * Send a message, this only sends the message, it does not keep any call 0053 * information. This should be used for replies. 0054 * @param msg The message to send 0055 */ 0056 void sendMsg(RPCMsg::Ptr msg); 0057 0058 /** 0059 * Send a message, this only sends the message, it does not keep any call 0060 * information. This should be used for replies. 0061 * @param msg The message to send 0062 */ 0063 void sendMsg(const RPCMsg &msg); 0064 0065 /** 0066 * Ping a node, we don't care about the MTID. 0067 * @param addr The address 0068 */ 0069 void ping(const dht::Key &our_id, const net::Address &addr); 0070 0071 /// Get the number of active calls 0072 Uint32 getNumActiveRPCCalls() const; 0073 0074 private Q_SLOTS: 0075 void callTimeout(RPCCall *call); 0076 0077 private: 0078 class Private; 0079 Private *d; 0080 }; 0081 0082 } 0083 0084 #endif