void Peer::recvMessage(AuthenticatedMessage const& msg) { if (mState >= GOT_HELLO) { if (msg.v0().sequence != mRecvMacSeq) { CLOG(ERROR, "Overlay") << "Unexpected message-auth sequence"; mDropInRecvMessageSeqMeter.Mark(); ++mRecvMacSeq; drop(ERR_AUTH, "unexpected auth sequence"); return; } if (!hmacSha256Verify(msg.v0().mac, mRecvMacKey, xdr::xdr_to_opaque(msg.v0().sequence, msg.v0().message))) { CLOG(ERROR, "Overlay") << "Message-auth check failed"; mDropInRecvMessageMacMeter.Mark(); ++mRecvMacSeq; drop(ERR_AUTH, "unexpected MAC"); return; } ++mRecvMacSeq; } recvMessage(msg.v0().message); }
void Peer::sendMessage(StellarMessage const& msg) { CLOG(TRACE, "Overlay") << "(" << PubKeyUtils::toShortString( mApp.getConfig().NODE_SEED.getPublicKey()) << ") send: " << msg.type() << " to : " << PubKeyUtils::toShortString(mPeerID); AuthenticatedMessage amsg; amsg.v0().message = msg; if (msg.type() != HELLO) { amsg.v0().sequence = mSendMacSeq; amsg.v0().mac = hmacSha256(mSendMacKey, xdr::xdr_to_opaque(mSendMacSeq, msg)); ++mSendMacSeq; } xdr::msg_ptr xdrBytes(xdr::xdr_to_msg(amsg)); this->sendMessage(std::move(xdrBytes)); }
void Peer::sendMessage(StellarMessage const& msg) { CLOG(TRACE, "Overlay") << "(" << mApp.getConfig().toShortString( mApp.getConfig().NODE_SEED.getPublicKey()) << ") send: " << msg.type() << " to : " << mApp.getConfig().toShortString(mPeerID); switch (msg.type()) { case ERROR_MSG: mSendErrorMeter.Mark(); break; case HELLO: case HELLO2: mSendHelloMeter.Mark(); break; case AUTH: mSendAuthMeter.Mark(); break; case DONT_HAVE: mSendDontHaveMeter.Mark(); break; case GET_PEERS: mSendGetPeersMeter.Mark(); break; case PEERS: mSendPeersMeter.Mark(); break; case GET_TX_SET: mSendGetTxSetMeter.Mark(); break; case TX_SET: mSendTxSetMeter.Mark(); break; case TRANSACTION: mSendTransactionMeter.Mark(); break; case GET_SCP_QUORUMSET: mSendGetSCPQuorumSetMeter.Mark(); break; case SCP_QUORUMSET: mSendSCPQuorumSetMeter.Mark(); break; case SCP_MESSAGE: mSendSCPMessageSetMeter.Mark(); break; case GET_SCP_STATE: mSendGetSCPStateMeter.Mark(); break; }; AuthenticatedMessage amsg; amsg.v0().message = msg; if (msg.type() != HELLO && msg.type() != HELLO2 && msg.type() != ERROR_MSG) { amsg.v0().sequence = mSendMacSeq; amsg.v0().mac = hmacSha256(mSendMacKey, xdr::xdr_to_opaque(mSendMacSeq, msg)); ++mSendMacSeq; } xdr::msg_ptr xdrBytes(xdr::xdr_to_msg(amsg)); this->sendMessage(std::move(xdrBytes)); }