From c88b636295f629f9363b922d763ab837eb343bed Mon Sep 17 00:00:00 2001 From: Lucas Dias Date: Sun, 24 Apr 2022 18:18:02 -0300 Subject: [PATCH] Catch expetion of the deserializeNodes method Signed-off-by: Lucas Dias --- src/network_engine.cpp | 45 +++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/src/network_engine.cpp b/src/network_engine.cpp index b1c65970e..8fac10c63 100644 --- a/src/network_engine.cpp +++ b/src/network_engine.cpp @@ -519,8 +519,15 @@ NetworkEngine::process(std::unique_ptr&& msg, const SockAddr& fro throw DhtProtocolException {DhtProtocolException::UNKNOWN_TID, "Can't find socket", msg->id}; node->received(now, {}); onNewNode(node, 2); - deserializeNodes(*msg, from); - rsocket->on_receive(node, std::move(*msg)); + try { + deserializeNodes(*msg, from); + rsocket->on_receive(node, std::move(*msg)); + } catch (DhtProtocolException &ex) { + if (logIncoming_) + if (logger_) + logger_->ERR("Exception in deserializeNodes: %s, code: %u", ex.getMsg(), ex.getCode()); + return; + } } else if (msg->type == MessageType::Error or msg->type == MessageType::Reply) { auto rsocket = node->getSocket(msg->tid); @@ -576,26 +583,32 @@ NetworkEngine::process(std::unique_ptr&& msg, const SockAddr& fro } case MessageType::Reply: if (req) { /* request reply */ + auto& r = *req; + if (r.getType() == MessageType::AnnounceValue + or r.getType() == MessageType::Listen + or r.getType() == MessageType::Refresh) { + r.node->authSuccess(); + } + r.reply_time = scheduler.time(); try { - deserializeNodes(*msg, from); - auto& r = *req; - if (r.getType() == MessageType::AnnounceValue - or r.getType() == MessageType::Listen - or r.getType() == MessageType::Refresh) { - r.node->authSuccess(); - } - r.reply_time = scheduler.time(); + deserializeNodes(*msg, from); r.setDone(std::move(*msg)); - } catch (...) { - req->node->authError(); - } + } catch (DhtProtocolException &ex) { + if (logIncoming_) + if (logger_) + logger_->ERR("Exception in deserializeNodes: %s, code: %u", ex.getMsg(), ex.getCode()); + return; + } break; } else { /* request socket data */ - try { + try { deserializeNodes(*msg, from); rsocket->on_receive(node, std::move(*msg)); - } catch(DhtProtocolException &ex) { - node->authError(); + } catch (DhtProtocolException &ex) { + if (logIncoming_) + if (logger_) + logger_->ERR("Exception in deserializeNodes: %s, code: %u", ex.getMsg(), ex.getCode()); + return; } } break;