14
14
#include < masternode/node.h>
15
15
#include < masternode/sync.h>
16
16
#include < net.h>
17
- #include < net_processing .h>
17
+ #include < net_types .h>
18
18
#include < netmessagemaker.h>
19
19
#include < util/time.h>
20
20
#include < validation.h>
@@ -58,37 +58,33 @@ void CMNAuth::PushMNAUTH(CNode& peer, CConnman& connman, const CBlockIndex* tip)
58
58
connman.PushMessage (&peer, CNetMsgMaker (peer.GetSendVersion ()).Make (NetMsgType::MNAUTH, mnauth));
59
59
}
60
60
61
- void CMNAuth::ProcessMessage (CNode& peer, PeerManager& peerman , CConnman& connman, std::string_view msg_type, CDataStream& vRecv)
61
+ PeerMsgRet CMNAuth::ProcessMessage (CNode& peer, CConnman& connman, std::string_view msg_type, CDataStream& vRecv)
62
62
{
63
63
if (msg_type != NetMsgType::MNAUTH || !::masternodeSync->IsBlockchainSynced ()) {
64
64
// we can't verify MNAUTH messages when we don't have the latest MN list
65
- return ;
65
+ return {} ;
66
66
}
67
67
68
68
CMNAuth mnauth;
69
69
vRecv >> mnauth;
70
70
71
71
// only one MNAUTH allowed
72
72
if (!peer.GetVerifiedProRegTxHash ().IsNull ()) {
73
- peerman.Misbehaving (peer.GetId (), 100 , " duplicate mnauth" );
74
- return ;
73
+ return tl::unexpected{MisbehavingError{100 , " duplicate mnauth" }};
75
74
}
76
75
77
76
if ((~peer.nServices ) & (NODE_NETWORK | NODE_BLOOM)) {
78
77
// either NODE_NETWORK or NODE_BLOOM bit is missing in node's services
79
- peerman.Misbehaving (peer.GetId (), 100 , " mnauth from a node with invalid services" );
80
- return ;
78
+ return tl::unexpected{MisbehavingError{100 , " mnauth from a node with invalid services" }};
81
79
}
82
80
83
81
if (mnauth.proRegTxHash .IsNull ()) {
84
- peerman.Misbehaving (peer.GetId (), 100 , " empty mnauth proRegTxHash" );
85
- return ;
82
+ return tl::unexpected{MisbehavingError{100 , " empty mnauth proRegTxHash" }};
86
83
}
87
84
88
85
if (!mnauth.sig .IsValid ()) {
89
- peerman.Misbehaving (peer.GetId (), 100 , " invalid mnauth signature" );
90
86
LogPrint (BCLog::NET_NETCONN, " CMNAuth::ProcessMessage -- invalid mnauth for protx=%s with sig=%s\n " , mnauth.proRegTxHash .ToString (), mnauth.sig .ToString ());
91
- return ;
87
+ return tl::unexpected{MisbehavingError{ 100 , " invalid mnauth signature " }} ;
92
88
}
93
89
94
90
const auto mnList = deterministicMNManager->GetListAtChainTip ();
@@ -97,8 +93,7 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
97
93
// in case node was unlucky and not up to date, just let it be connected as a regular node, which gives it
98
94
// a chance to get up-to-date and thus realize that it's not a MN anymore. We still give it a
99
95
// low DoS score.
100
- peerman.Misbehaving (peer.GetId (), 10 , " missing mnauth masternode" );
101
- return ;
96
+ return tl::unexpected{MisbehavingError{10 , " missing mnauth masternode" }};
102
97
}
103
98
104
99
uint256 signHash;
@@ -120,8 +115,7 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
120
115
if (!mnauth.sig .VerifyInsecure (dmn->pdmnState ->pubKeyOperator .Get (), signHash)) {
121
116
// Same as above, MN seems to not know its fate yet, so give it a chance to update. If this is a
122
117
// malicious node (DoSing us), it'll get banned soon.
123
- peerman.Misbehaving (peer.GetId (), 10 , " mnauth signature verification failed" );
124
- return ;
118
+ return tl::unexpected{MisbehavingError{10 , " mnauth signature verification failed" }};
125
119
}
126
120
127
121
if (!peer.IsInboundConn ()) {
@@ -130,7 +124,7 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
130
124
LogPrint (BCLog::NET_NETCONN, " CMNAuth::ProcessMessage -- Masternode probe successful for %s, disconnecting. peer=%d\n " ,
131
125
mnauth.proRegTxHash .ToString (), peer.GetId ());
132
126
peer.fDisconnect = true ;
133
- return ;
127
+ return {} ;
134
128
}
135
129
}
136
130
@@ -175,7 +169,7 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
175
169
});
176
170
177
171
if (peer.fDisconnect ) {
178
- return ;
172
+ return {} ;
179
173
}
180
174
181
175
peer.SetVerifiedProRegTxHash (mnauth.proRegTxHash );
@@ -192,6 +186,7 @@ void CMNAuth::ProcessMessage(CNode& peer, PeerManager& peerman, CConnman& connma
192
186
}
193
187
194
188
LogPrint (BCLog::NET_NETCONN, " CMNAuth::%s -- Valid MNAUTH for %s, peer=%d\n " , __func__, mnauth.proRegTxHash .ToString (), peer.GetId ());
189
+ return {};
195
190
}
196
191
197
192
void CMNAuth::NotifyMasternodeListChanged (bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff, CConnman& connman)
0 commit comments