CatapultServer  v0.5.0.1 (Elephant)
HeightRequestProcessor.h
Go to the documentation of this file.
1 
21 #pragma once
24 
25 namespace catapult { namespace handlers {
26 
28  template<typename TRequest>
30  public:
32  constexpr HeightRequestInfo() : pRequest(nullptr)
33  {}
34 
35  public:
38 
42 
44  const TRequest* pRequest;
45 
46  public:
48  uint32_t numAvailableBlocks() const {
49  return static_cast<uint32_t>((ChainHeight - NormalizedRequestHeight).unwrap() + 1);
50  }
51  };
52 
54  template<typename TRequest>
56  private:
57  static auto CreateResponsePacket(uint32_t payloadSize) {
58  auto pPacket = ionet::CreateSharedPacket<ionet::Packet>(payloadSize);
59  pPacket->Type = TRequest::Packet_Type;
60  return pPacket;
61  }
62 
63  public:
67  const io::BlockStorageView& storage,
68  const ionet::Packet& packet,
70  bool shouldAllowZeroHeight) {
71  const auto* pRequest = ionet::CoercePacket<TRequest>(&packet);
72  if (!pRequest)
74 
76  info.ChainHeight = storage.chainHeight();
77  CATAPULT_LOG(trace) << "local height = " << info.ChainHeight << ", request height = " << pRequest->Height;
78  if (info.ChainHeight < pRequest->Height || (!shouldAllowZeroHeight && Height(0) == pRequest->Height)) {
81  }
82 
83  info.NormalizedRequestHeight = Height(0) == pRequest->Height ? info.ChainHeight : pRequest->Height;
84  info.pRequest = pRequest;
85  return info;
86  }
87  };
88 }}
HeaderParser.Preproc
Definition: HeaderParser.py:22
HeaderParser.HeaderParser.simpleValidators
simpleValidators
Definition: HeaderParser.py:98
HeaderParser.HeaderParser.processContinuation
def processContinuation(self, line)
Definition: HeaderParser.py:149
CATAPULT_LOG
#define CATAPULT_LOG(SEV)
Writes a log entry to the default logger with SEV severity.
Definition: Logging.h:340
HeaderParser.IndentFix
Definition: HeaderParser.py:65
HeaderParser.HeaderParser.patternExtern
patternExtern
Definition: HeaderParser.py:87
HeaderParser.HeaderParser.errorReporter
errorReporter
Definition: HeaderParser.py:91
HeaderParser.HeaderParser.reportIndents
def reportIndents(self)
Definition: HeaderParser.py:132
HeaderParser.Include.__init__
def __init__(self, line, lineno, include, rest)
Definition: HeaderParser.py:49
HeaderParser.HeaderParser.lineNumber
lineNumber
Definition: HeaderParser.py:93
catapult::ionet::Packet
A packet header with a data payload.
Definition: Packet.h:32
HeaderParser.Include
Definition: HeaderParser.py:48
HeaderParser.HeaderParser.includeError
includeError
Definition: HeaderParser.py:97
catapult::Height
utils::BaseValue< uint64_t, Height_tag > Height
Definition: src/catapult/types.h:85
HeaderParser.HeaderParser.patternEmptyLine
patternEmptyLine
Definition: HeaderParser.py:88
HeaderParser.HeaderParser.path
path
Definition: HeaderParser.py:92
HeaderParser.HeaderParser.fixes
fixes
Definition: HeaderParser.py:100
catapult::handlers::HeightRequestInfo::ChainHeight
Height ChainHeight
Current chain height.
Definition: HeightRequestProcessor.h:37
catapult::io::BlockStorageView
A read only view on top of block storage.
Definition: BlockStorageCache.h:30
HeaderParser.HeaderParser
Definition: HeaderParser.py:84
catapult::handlers::HeightRequestInfo
Information about a height request.
Definition: HeightRequestProcessor.h:29
HeaderParser.HeaderParser.parseFile
def parseFile(self, inputStream)
Definition: HeaderParser.py:162
HeaderParser.Include.lineno
lineno
Definition: HeaderParser.py:52
HeaderParser.Preproc.__init__
def __init__(self, line, lineno, word)
Definition: HeaderParser.py:23
catapult::utils::BaseValue< uint64_t, Height_tag >
HeaderParser.HeaderParser.processPreprocessor
def processPreprocessor(self, line)
Definition: HeaderParser.py:153
HeaderParser.Preproc.type
type
Definition: HeaderParser.py:40
HeaderParser.HeaderParser.patternInclude
patternInclude
Definition: HeaderParser.py:85
HeaderParser.IndentFix.lineno
lineno
Definition: HeaderParser.py:68
HeaderParser.HeaderParser.parseInclude
def parseInclude(self, line)
Definition: HeaderParser.py:209
HeaderParser.HeaderParser.__init__
def __init__(self, errorReporter, path, simpleValidators, fixIndentsInFiles=False)
Definition: HeaderParser.py:90
PacketHandlers.h
HeaderParser.Include.rest
rest
Definition: HeaderParser.py:54
catapult::ionet::ServerPacketHandlerContext::response
const PacketPayload & response() const
Gets the response associated with this context.
Definition: PacketHandlers.cpp:46
Packet_Type
static constexpr auto Packet_Type
Definition: RemoteNodeApi.cpp:33
HeaderParser.Preproc.line
line
Definition: HeaderParser.py:24
HeaderParser.HeaderParser.parseExtern
def parseExtern(self, line)
Definition: HeaderParser.py:218
HeaderParser.Include.__str__
def __str__(self)
Definition: HeaderParser.py:56
HeaderParser.IndentFix.__init__
def __init__(self, mmtype, lineno, line)
Definition: HeaderParser.py:66
HeaderParser.MultilineMacro
Definition: HeaderParser.py:60
HeaderParser.Preproc.__str__
def __str__(self)
Definition: HeaderParser.py:44
forwardsValidation.info
def info(*args)
Definition: forwardsValidation.py:12
catapult::io::BlockStorageView::chainHeight
Height chainHeight() const
Gets the number of blocks.
Definition: BlockStorageCache.cpp:81
HeaderParser.IndentFix.type
type
Definition: HeaderParser.py:67
HeaderParser.HeaderParser.preprocessor
preprocessor
Definition: HeaderParser.py:94
catapult::handlers::HeightRequestProcessor::Process
static HeightRequestInfo< TRequest > Process(const io::BlockStorageView &storage, const ionet::Packet &packet, ionet::ServerPacketHandlerContext &context, bool shouldAllowZeroHeight)
Definition: HeightRequestProcessor.h:66
HeaderParser.PpType
Definition: HeaderParser.py:11
catapult::handlers::HeightRequestInfo::numAvailableBlocks
uint32_t numAvailableBlocks() const
Gets the number of remaining blocks in the chain.
Definition: HeightRequestProcessor.h:48
catapult::handlers::HeightRequestInfo::pRequest
const TRequest * pRequest
Coerced request.
Definition: HeightRequestProcessor.h:44
HeaderParser.Include.line
line
Definition: HeaderParser.py:51
HeaderParser.HeaderParser.patternPreprocessor
patternPreprocessor
Definition: HeaderParser.py:86
catapult::handlers::HeightRequestInfo::NormalizedRequestHeight
Height NormalizedRequestHeight
Definition: HeightRequestProcessor.h:41
HeaderParser.Include.type
type
Definition: HeaderParser.py:50
catapult::handlers::HeightRequestProcessor
Helper for processing height requests.
Definition: HeightRequestProcessor.h:55
catapult::handlers::HeightRequestInfo::HeightRequestInfo
constexpr HeightRequestInfo()
Creates a height request info.
Definition: HeightRequestProcessor.h:32
catapult::ionet::PacketPayload
A packet payload that can be written.
Definition: PacketPayload.h:29
catapult
Definition: AddressExtractionExtension.cpp:28
HeaderParser.fixTabs
def fixTabs(line, count)
Definition: HeaderParser.py:72
HeaderParser.Include.include
include
Definition: HeaderParser.py:53
BlockStorageCache.h
HeaderParser.IndentFix.line
line
Definition: HeaderParser.py:69
HeaderParser.Preproc.lineno
lineno
Definition: HeaderParser.py:25
HeaderParser.HeaderParser.parsePreprocessor
def parsePreprocessor(self, line)
Definition: HeaderParser.py:214
catapult::handlers::HeightRequestProcessor::CreateResponsePacket
static auto CreateResponsePacket(uint32_t payloadSize)
Definition: HeightRequestProcessor.h:57
HeaderParser.HeaderParser.fixIndents
def fixIndents(self, inf, outf)
Definition: HeaderParser.py:110
HeaderParser.HeaderParser.includes
includes
Definition: HeaderParser.py:96
catapult::ionet::ServerPacketHandlerContext
Context passed to a server packet handler function.
Definition: PacketHandlers.h:32