CatapultServer  v0.5.0.1 (Elephant)
ZeroMqEntityPublisher.h
Go to the documentation of this file.
1 
21 #pragma once
23 #include "catapult/functions.h"
24 #include <zmq_addon.hpp>
25 
26 namespace catapult {
27  namespace model {
28  struct BlockElement;
29  struct Transaction;
30  struct TransactionElement;
31  struct TransactionInfo;
32  class TransactionRegistry;
33  struct TransactionStatus;
34  }
35 }
36 
37 namespace catapult { namespace zeromq {
38 
40  enum class BlockMarker : uint64_t {
42  Block_Marker = 0x9FF2D8E480CA6A49,
43 
45  Drop_Blocks_Marker = 0x5C20D68AEE25B0B0
46  };
47 
49  enum class TransactionMarker : uint8_t {
51  Transaction_Marker = 0x61, // 'a'
52 
55 
58 
60  Transaction_Status_Marker = 0x73, // 's'
61 
63  Partial_Transaction_Add_Marker = 0x70, // 'p'
64 
67 
69  Cosignature_Marker = 0x63 // 'c'
70  };
71 
74  public:
76  explicit ZeroMqEntityPublisher(unsigned short port, std::unique_ptr<model::NotificationPublisher>&& pNotificationPublisher);
77 
79 
80  public:
82  void publishBlockHeader(const model::BlockElement& blockElement);
83 
85  void publishDropBlocks(Height height);
86 
88  void publishTransaction(TransactionMarker topicMarker, const model::TransactionElement& transactionElement, Height height);
89 
91  void publishTransaction(TransactionMarker topicMarker, const model::TransactionInfo& transactionInfo, Height height);
92 
94  void publishTransactionHash(TransactionMarker topicMarker, const model::TransactionInfo& transactionInfo);
95 
97  void publishTransactionStatus(const model::Transaction& transaction, const Hash256& hash, uint32_t status);
98 
100  void publishCosignature(const model::TransactionInfo& parentTransactionInfo, const Key& signer, const Signature& signature);
101 
102  private:
103  struct WeakTransactionInfo;
105 
106  void publishTransaction(TransactionMarker topicMarker, const WeakTransactionInfo& transactionInfo, Height height);
107  void publish(
108  const std::string& topicName,
109  TransactionMarker topicMarker,
110  const WeakTransactionInfo& transactionInfo,
111  const MessagePayloadBuilder& payloadBuilder);
112 
113  private:
115  std::unique_ptr<model::NotificationPublisher> m_pNotificationPublisher;
116  std::unique_ptr<SynchronizedPublisher> m_pSynchronizedPublisher;
117  };
118 }}
catapult::zeromq::MessageGroup
Definition: ZeroMqEntityPublisher.cpp:35
catapult::zeromq::ZeroMqEntityPublisher::ZeroMqEntityPublisher
ZeroMqEntityPublisher(unsigned short port, std::unique_ptr< model::NotificationPublisher > &&pNotificationPublisher)
Creates a zeromq entity publisher around port and pNotificationPublisher.
Definition: ZeroMqEntityPublisher.cpp:123
catapult::zeromq::ZeroMqEntityPublisher::SynchronizedPublisher::m_pPool
std::unique_ptr< thread::IoThreadPool > m_pPool
Definition: ZeroMqEntityPublisher.cpp:90
NotificationPublisher.h
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
catapult::zeromq::ZeroMqEntityPublisher::WeakTransactionInfo::EntityHash
const Hash256 & EntityHash
Definition: ZeroMqEntityPublisher.cpp:118
catapult::zeromq::ZeroMqEntityPublisher::MessagePayloadBuilder
consumer< zmq::multipart_t & > MessagePayloadBuilder
Definition: ZeroMqEntityPublisher.h:104
catapult::zeromq::ZeroMqEntityPublisher::WeakTransactionInfo::OptionalAddresses
const model::UnresolvedAddressSet * OptionalAddresses
Definition: ZeroMqEntityPublisher.cpp:120
catapult::zeromq::BlockMarker::Drop_Blocks_Marker
A dropped block.
catapult::zeromq::BlockMarker::Block_Marker
A block.
catapult::zeromq::ZeroMqEntityPublisher::m_pNotificationPublisher
std::unique_ptr< model::NotificationPublisher > m_pNotificationPublisher
Definition: ZeroMqEntityPublisher.h:114
catapult::zeromq::ZeroMqEntityPublisher::WeakTransactionInfo::Transaction
const model::Transaction & Transaction
Definition: ZeroMqEntityPublisher.cpp:117
catapult::zeromq::ZeroMqEntityPublisher::SynchronizedPublisher::m_zmqSocket
zmq::socket_t m_zmqSocket
Definition: ZeroMqEntityPublisher.cpp:89
catapult::zeromq::ZeroMqEntityPublisher::SynchronizedPublisher::SynchronizedPublisher
SynchronizedPublisher(unsigned short port)
Definition: ZeroMqEntityPublisher.cpp:61
catapult::zeromq::TransactionMarker::Partial_Transaction_Remove_Marker
A removed partial transaction.
catapult::zeromq::TransactionMarker
TransactionMarker
Markers for publishing transaction related messages.
Definition: ZeroMqEntityPublisher.h:49
catapult::model::BlockElement::EntityHash
Hash256 EntityHash
Entity hash.
Definition: Elements.h:66
catapult::zeromq::MessageGroup::m_messages
std::vector< zmq::multipart_t > m_messages
Definition: ZeroMqEntityPublisher.cpp:56
colorPrint.warning
def warning(*args)
Definition: colorPrint.py:10
catapult::zeromq::ZeroMqEntityPublisher::publishCosignature
void publishCosignature(const model::TransactionInfo &parentTransactionInfo, const Key &signer, const Signature &signature)
Publishes a cosignature composed of transaction info (parentTransactionInfo), signer and signature.
Definition: ZeroMqEntityPublisher.cpp:218
catapult::zeromq::ZeroMqEntityPublisher
A zeromq entity publisher.
Definition: ZeroMqEntityPublisher.h:73
NotificationSubscriber.h
catapult::model::BlockElement::Block
const model::Block & Block
Block entity.
Definition: Elements.h:63
catapult::zeromq::ZeroMqEntityPublisher::publishTransactionHash
void publishTransactionHash(TransactionMarker topicMarker, const model::TransactionInfo &transactionInfo)
Publishes a transaction hash using topicMarker and transactionInfo.
Definition: ZeroMqEntityPublisher.cpp:190
catapult::zeromq::ZeroMqEntityPublisher::publish
void publish(const std::string &topicName, TransactionMarker topicMarker, const WeakTransactionInfo &transactionInfo, const MessagePayloadBuilder &payloadBuilder)
Definition: ZeroMqEntityPublisher.cpp:229
catapult::model::ExtractAddresses
UnresolvedAddressSet ExtractAddresses(const Transaction &transaction, const NotificationPublisher &notificationPublisher)
Extracts all addresses that are involved in transaction using notificationPublisher.
Definition: TransactionUtils.cpp:64
catapult::model::BlockHeader
Binary layout for a block header.
Definition: Block.h:34
catapult::zeromq::ZeroMqEntityPublisher::WeakTransactionInfo
Definition: ZeroMqEntityPublisher.cpp:93
PublisherUtils.h
catapult::model::TransactionStatus
A transaction status.
Definition: TransactionStatus.h:29
catapult::zeromq::TransactionMarker::Unconfirmed_Transaction_Add_Marker
An added unconfirmed transaction.
functions.h
catapult::zeromq::TransactionMarker::Transaction_Marker
A confirmed transaction.
catapult::zeromq::ZeroMqEntityPublisher::WeakTransactionInfo::WeakTransactionInfo
WeakTransactionInfo(const model::TransactionElement &element)
Definition: ZeroMqEntityPublisher.cpp:102
catapult::model::BlockElement::GenerationHash
catapult::GenerationHash GenerationHash
Generation hash of the block.
Definition: Elements.h:69
catapult::zeromq::ZeroMqEntityPublisher::WeakTransactionInfo::WeakTransactionInfo
WeakTransactionInfo(const model::TransactionInfo &transactionInfo)
Definition: ZeroMqEntityPublisher.cpp:95
catapult::zeromq::TransactionMarker::Cosignature_Marker
A detached cosignature.
catapult::zeromq::MessageGroup::flush
void flush(zmq::socket_t &zmqSocket)
Definition: ZeroMqEntityPublisher.cpp:45
catapult::model::TransactionInfo
A transaction and its associated metadata.
Definition: EntityInfo.h:104
catapult::supplier
std::function< T()> supplier
A (stateless) supplier function.
Definition: functions.h:39
catapult::zeromq::MessageGroup::MessageGroup
MessageGroup(const supplier< std::string > &errorMessageGenerator)
Definition: ZeroMqEntityPublisher.cpp:37
Elements.h
catapult::zeromq::ZeroMqEntityPublisher::SynchronizedPublisher::queue
void queue(std::unique_ptr< MessageGroup > &&pMessageGroup)
Definition: ZeroMqEntityPublisher.cpp:79
catapult::thread::CreateIoThreadPool
std::unique_ptr< IoThreadPool > CreateIoThreadPool(size_t numWorkerThreads, const char *name)
Definition: IoThreadPool.cpp:146
catapult::utils::BaseValue< uint64_t, Height_tag >
ZeroMqEntityPublisher.h
catapult::zeromq::TransactionMarker::Transaction_Status_Marker
A transaction status.
catapult::zeromq::BlockMarker
BlockMarker
Markers for publishing block related messages.
Definition: ZeroMqEntityPublisher.h:40
catapult::zeromq::ZeroMqEntityPublisher::m_pSynchronizedPublisher
std::unique_ptr< SynchronizedPublisher > m_pSynchronizedPublisher
Definition: ZeroMqEntityPublisher.h:116
catapult::zeromq::ZeroMqEntityPublisher::publishBlockHeader
void publishBlockHeader(const model::BlockElement &blockElement)
Publishes the block header in blockElement.
Definition: ZeroMqEntityPublisher.cpp:142
TransactionStatus.h
catapult::zeromq::ZeroMqEntityPublisher::SynchronizedPublisher::~SynchronizedPublisher
~SynchronizedPublisher()
Definition: ZeroMqEntityPublisher.cpp:72
IoThreadPool.h
catapult::model::BlockHeader::Height
catapult::Height Height
Height of a block.
Definition: Block.h:41
Address.h
catapult::model::UnresolvedAddressSet
std::unordered_set< UnresolvedAddress, utils::ArrayHasher< UnresolvedAddress > > UnresolvedAddressSet
Unordered set of unresolved addresses.
Definition: ContainerTypes.h:44
catapult::zeromq::TransactionMarker::Partial_Transaction_Add_Marker
An added partial transaction.
catapult::zeromq::MessageGroup::add
void add(zmq::multipart_t &&message)
Definition: ZeroMqEntityPublisher.cpp:41
catapult::zeromq::ZeroMqEntityPublisher::publishTransactionStatus
void publishTransactionStatus(const model::Transaction &transaction, const Hash256 &hash, uint32_t status)
Publishes a transaction status composed of transaction, hash and status.
Definition: ZeroMqEntityPublisher.cpp:210
catapult::model::TransactionElement
Processing element for a transaction composed of a transaction and metadata.
Definition: Elements.h:33
catapult::model::BlockElement
Processing element for a block composed of a block and metadata.
Definition: Elements.h:55
catapult::model::Transaction::Deadline
Timestamp Deadline
Transaction deadline.
Definition: Transaction.h:38
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::Hash256_Size
constexpr size_t Hash256_Size
Definition: src/catapult/types.h:34
catapult::zeromq::ZeroMqEntityPublisher::SynchronizedPublisher
Definition: ZeroMqEntityPublisher.cpp:59
catapult::zeromq::ZeroMqEntityPublisher::WeakTransactionInfo::WeakTransactionInfo
WeakTransactionInfo(const model::Transaction &transaction, const Hash256 &hash)
Definition: ZeroMqEntityPublisher.cpp:109
catapult::zeromq::ZeroMqEntityPublisher::~ZeroMqEntityPublisher
~ZeroMqEntityPublisher()
catapult::zeromq::ZeroMqEntityPublisher::WeakTransactionInfo::MerkleComponentHash
const Hash256 & MerkleComponentHash
Definition: ZeroMqEntityPublisher.cpp:119
catapult::model::BasicEntityType::Transaction
Transaction type.
TransactionUtils.h
catapult::utils::ByteArray< Hash256_Size, Hash256_tag >
catapult::model::EntityInfo::EntityHash
Hash256 EntityHash
Entity hash.
Definition: EntityInfo.h:48
catapult::model::DetachedCosignature
A detached cosignature.
Definition: Cosignature.h:38
catapult::zeromq::CreateTopic
std::vector< uint8_t > CreateTopic(TransactionMarker marker, const UnresolvedAddress &address)
Creates a topic around marker and address.
Definition: PublisherUtils.cpp:25
catapult::zeromq::ZeroMqEntityPublisher::publishTransaction
void publishTransaction(TransactionMarker topicMarker, const model::TransactionElement &transactionElement, Height height)
Publishes a transaction using topicMarker, transactionElement and height.
Definition: ZeroMqEntityPublisher.cpp:176
catapult::consumer
std::function< void(TArgs...)> consumer
A consumer function.
Definition: functions.h:35
catapult::zeromq::TransactionMarker::Unconfirmed_Transaction_Remove_Marker
A removed unconfirmed transaction.
catapult::zeromq::ZeroMqEntityPublisher::SynchronizedPublisher::m_zmqContext
zmq::context_t m_zmqContext
Definition: ZeroMqEntityPublisher.cpp:88
catapult::zeromq::MessageGroup::m_errorMessageGenerator
supplier< std::string > m_errorMessageGenerator
Definition: ZeroMqEntityPublisher.cpp:55
catapult::zeromq::ZeroMqEntityPublisher::publishDropBlocks
void publishDropBlocks(Height height)
Publishes the height after which all blocks were dropped.
Definition: ZeroMqEntityPublisher.cpp:155
catapult::model::Transaction
Binary layout for a transaction.
Definition: Transaction.h:32
Cosignature.h