MCPcopy Create free account
hub / github.com/ElementsProject/elements / V1TransportDeserializer

Class V1TransportDeserializer

src/net.h:329–394  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

327};
328
329class V1TransportDeserializer final : public TransportDeserializer
330{
331private:
332 const CChainParams& m_chain_params;
333 const NodeId m_node_id; // Only for logging
334 mutable CHash256 hasher;
335 mutable uint256 data_hash;
336 bool in_data; // parsing header (false) or data (true)
337 CDataStream hdrbuf; // partially received header
338 CMessageHeader hdr; // complete header
339 CDataStream vRecv; // received message data
340 unsigned int nHdrPos;
341 unsigned int nDataPos;
342
343 const uint256& GetMessageHash() const;
344 int readHeader(Span<const uint8_t> msg_bytes);
345 int readData(Span<const uint8_t> msg_bytes);
346
347 void Reset() {
348 vRecv.clear();
349 hdrbuf.clear();
350 hdrbuf.resize(24);
351 in_data = false;
352 nHdrPos = 0;
353 nDataPos = 0;
354 data_hash.SetNull();
355 hasher.Reset();
356 }
357
358public:
359 V1TransportDeserializer(const CChainParams& chain_params, const NodeId node_id, int nTypeIn, int nVersionIn)
360 : m_chain_params(chain_params),
361 m_node_id(node_id),
362 hdrbuf(nTypeIn, nVersionIn),
363 vRecv(nTypeIn, nVersionIn)
364 {
365 Reset();
366 }
367
368 bool IsEmpty() const override
369 {
370 return (nHdrPos == 0);
371 }
372 bool Complete() const override
373 {
374 if (!in_data)
375 return false;
376 return (hdr.nMessageSize == nDataPos);
377 }
378 void SetVersion(int nVersionIn) override
379 {
380 hdrbuf.SetVersion(nVersionIn);
381 vRecv.SetVersion(nVersionIn);
382 }
383 int Read(Span<const uint8_t>& msg_bytes) override
384 {
385 int ret = in_data ? readData(msg_bytes) : readHeader(msg_bytes);
386 if (ret < 0) {

Callers 1

CNodeMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected