MCPcopy Create free account
hub / github.com/bcndev/bytecoin / on_parse_header

Method on_parse_header

src/p2p/P2PProtocolBasic.cpp:113–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113size_t P2PProtocolBasic::on_parse_header(common::CircularBuffer &buffer, BinaryArray &request) {
114 if (buffer.size() < LevinProtocol::HEADER_SIZE())
115 return std::string::npos;
116 request.resize(LevinProtocol::HEADER_SIZE());
117 buffer.read(request.data(), request.size());
118 uint32_t command = 0;
119 LevinProtocol::CommandType command_type = LevinProtocol::REQUEST;
120 size_t size = LevinProtocol::read_command_header(request, &command_type, &command);
121 size_t max_size = p2p::UNKNOWN_COMMAND_MAX_SIZE;
122 if (!handshake_ok()) { // peer_version unknown
123 auto ha = before_handshake_handlers.find({command, command_type});
124 if (ha == before_handshake_handlers.end())
125 throw std::runtime_error("202 Expecting handshake or ping");
126 max_size = ha->second.second;
127 } else {
128 auto ha = after_handshake_handlers.find({command, command_type});
129 if (ha != after_handshake_handlers.end())
130 max_size = ha->second.second;
131 }
132 if (size > max_size)
133 throw std::runtime_error("Command too big cmd=" + common::to_string(command) +
134 " size=" + common::to_string(size) + " max_size=" + common::to_string(max_size));
135 return size;
136}
137
138void P2PProtocolBasic::msg_handshake(p2p::Handshake::Request &&req) {
139 if (!is_incoming()) {

Callers 1

readMethod · 0.80

Calls 5

to_stringFunction · 0.50
sizeMethod · 0.45
readMethod · 0.45
dataMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected