File indexing completed on 2024-06-02 05:05:14
0001 /* 0002 SPDX-FileCopyrightText: 2012 Joris Guisson <joris.guisson@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "errmsg.h" 0008 #include "dht.h" 0009 #include <bcodec/bnode.h> 0010 #include <util/error.h> 0011 #include <util/log.h> 0012 0013 using namespace bt; 0014 0015 namespace dht 0016 { 0017 ErrMsg::ErrMsg() 0018 { 0019 } 0020 0021 ErrMsg::ErrMsg(const QByteArray &mtid, const Key &id, const QString &msg) 0022 : RPCMsg(mtid, NONE, ERR_MSG, id) 0023 , msg(msg) 0024 { 0025 } 0026 0027 ErrMsg::~ErrMsg() 0028 { 0029 } 0030 0031 void ErrMsg::apply(dht::DHT *dh_table) 0032 { 0033 dh_table->error(*this); 0034 } 0035 0036 void ErrMsg::print() 0037 { 0038 Out(SYS_DHT | LOG_NOTICE) << "ERR: " << mtid[0] << " " << msg << endl; 0039 } 0040 0041 void ErrMsg::encode(QByteArray &) const 0042 { 0043 } 0044 0045 void ErrMsg::parse(BDictNode *dict) 0046 { 0047 RPCMsg::parse(dict); 0048 BListNode *ln = dict->getList(ERR_DHT); 0049 if (!ln) 0050 throw bt::Error("Invalid error message"); 0051 0052 msg = ln->getString(1, nullptr); 0053 } 0054 0055 }