Line data Source code
# 1 : // Copyright (c) 2009-2010 Satoshi Nakamoto # 2 : // Copyright (c) 2009-2018 The Bitcoin Core developers # 3 : // Distributed under the MIT software license, see the accompanying # 4 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. # 5 : # 6 : #ifndef BITCOIN_NETMESSAGEMAKER_H # 7 : #define BITCOIN_NETMESSAGEMAKER_H # 8 : # 9 : #include <net.h> # 10 : #include <serialize.h> # 11 : # 12 : class CNetMsgMaker # 13 : { # 14 : public: # 15 52 : explicit CNetMsgMaker(int nVersionIn) : nVersion(nVersionIn){} # 16 : # 17 : template <typename... Args> # 18 : CSerializedNetMsg Make(int nFlags, std::string sCommand, Args&&... args) const # 19 38 : { # 20 38 : CSerializedNetMsg msg; # 21 38 : if (sCommand == NetMsgType::ADDRv2) { # 22 0 : nFlags |= ADDRv2_FORMAT; # 23 0 : } # 24 38 : msg.command = std::move(sCommand); # 25 38 : CVectorWriter{ SER_NETWORK, nFlags | nVersion, msg.data, 0, std::forward<Args>(args)... }; # 26 38 : return msg; # 27 38 : } # 28 : # 29 : template <typename... Args> # 30 : CSerializedNetMsg Make(std::string sCommand, Args&&... args) const # 31 38 : { # 32 38 : return Make(0, std::move(sCommand), std::forward<Args>(args)...); # 33 38 : } # 34 : # 35 : private: # 36 : const int nVersion; # 37 : }; # 38 : # 39 : #endif // BITCOIN_NETMESSAGEMAKER_H