本文整理汇总了C++中StellarMessage类的典型用法代码示例。如果您正苦于以下问题:C++ StellarMessage类的具体用法?C++ StellarMessage怎么用?C++ StellarMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StellarMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CLOG
void
Peer::recvPeers(StellarMessage const& msg)
{
for (auto peer : msg.peers())
{
stringstream ip;
ip << (int)peer.ip[0] << "." << (int)peer.ip[1] << "."
<< (int)peer.ip[2] << "." << (int)peer.ip[3];
if (peer.port == 0 || peer.port > UINT16_MAX)
{
CLOG(DEBUG, "Overlay") << "ignoring peer with bad port";
continue;
}
PeerRecord pr{ip.str(), static_cast<unsigned short>(peer.port),
mApp.getClock().now(), peer.numFailures, 1};
if (pr.isPrivateAddress())
{
CLOG(DEBUG, "Overlay") << "ignoring flooded private address";
}
else
{
pr.insertIfNew(mApp.getDatabase());
}
}
}
示例2: LOG
void
Peer::sendHello()
{
LOG(DEBUG) << "Peer::sendHello "
<< "@" << mApp.getConfig().PEER_PORT << " to "
<< mRemoteListeningPort;
StellarMessage msg;
msg.type(HELLO);
msg.hello().protocolVersion = mApp.getConfig().PROTOCOL_VERSION;
msg.hello().versionStr = mApp.getConfig().VERSION_STR;
msg.hello().listeningPort = mApp.getConfig().PEER_PORT;
msg.hello().peerID = mApp.getConfig().PEER_PUBLIC_KEY;
sendMessage(msg);
}
示例3: msgSummary
std::string
msgSummary(StellarMessage const& m)
{
xdr::detail::Printer p(0);
xdr::archive(p, m.type(), nullptr);
return p.buf_.str() + ":" + hexAbbrev(sha256(xdr::xdr_to_msg(m)));
}
示例4: CLOG
void
Peer::recvGetSCPState(StellarMessage const& msg)
{
uint32 seq = msg.getSCPLedgerSeq();
CLOG(TRACE, "Overlay") << "get SCP State " << seq;
mApp.getHerder().sendSCPStateToPeer(seq, shared_from_this());
}
示例5:
void
Peer::recvTransaction(StellarMessage const& msg)
{
TransactionFramePtr transaction = TransactionFrame::makeTransactionFromWire(
mApp.getNetworkID(), msg.transaction());
if (transaction)
{
// add it to our current set
// and make sure it is valid
auto recvRes = mApp.getHerder().recvTransaction(transaction);
if (recvRes == Herder::TX_STATUS_PENDING ||
recvRes == Herder::TX_STATUS_DUPLICATE)
{
// record that this peer sent us this transaction
mApp.getOverlayManager().recvFloodedMsg(msg, shared_from_this());
if (recvRes == Herder::TX_STATUS_PENDING)
{
// if it's a new transaction, broadcast it
mApp.getOverlayManager().broadcastMessage(msg);
}
}
}
}
示例6: shared_from_this
void
Peer::recvGetTxSet(StellarMessage const& msg)
{
auto self = shared_from_this();
if (auto txSet = mApp.getHerder().getTxSet(msg.txSetHash()))
{
StellarMessage newMsg;
newMsg.type(TX_SET);
txSet->toXDR(newMsg.txSet());
self->sendMessage(newMsg);
}
else
{
sendDontHave(TX_SET, msg.txSetHash());
}
}
示例7: switch
void
Peer::recvDontHave(StellarMessage const& msg)
{
switch (msg.dontHave().type)
{
case TX_SET:
mApp.getHerder().doesntHaveTxSet(msg.dontHave().reqHash,
shared_from_this());
break;
case SCP_QUORUMSET:
mApp.getHerder().doesntHaveSCPQuorumSet(msg.dontHave().reqHash,
shared_from_this());
break;
default:
break;
}
}
示例8: sendMessage
void
Peer::recvGetTxSet(StellarMessage const& msg)
{
TxSetFramePtr txSet = mApp.getHerder().fetchTxSet(msg.txSetHash(), false);
if (txSet)
{
StellarMessage newMsg;
newMsg.type(TX_SET);
txSet->toXDR(newMsg.txSet());
sendMessage(newMsg);
}
else
{
sendDontHave(TX_SET, msg.txSetHash());
}
}
示例9: sendSCPQuorumSet
void
Peer::recvGetSCPQuorumSet(StellarMessage const& msg)
{
SCPQuorumSetPtr qSet =
mApp.getHerder().fetchSCPQuorumSet(msg.qSetHash(), false);
if (qSet)
{
sendSCPQuorumSet(qSet);
}
else
{
CLOG(TRACE, "Overlay")
<< "No quorum set: " << hexAbbrev(msg.qSetHash());
sendDontHave(SCP_QUORUMSET, msg.qSetHash());
// do we want to ask other people for it?
}
}
示例10: xdrBytes
void
Peer::sendMessage(StellarMessage const& msg)
{
CLOG(TRACE, "Overlay") << "("
<< binToHex(mApp.getConfig().PEER_PUBLIC_KEY)
.substr(0, 6) << ")send: " << msg.type()
<< " to : " << hexAbbrev(mPeerID);
xdr::msg_ptr xdrBytes(xdr::xdr_to_msg(msg));
this->sendMessage(std::move(xdrBytes));
}
示例11: CLOG
void
Peer::recvSCPMessage(StellarMessage const& msg)
{
SCPEnvelope envelope = msg.envelope();
CLOG(TRACE, "Overlay") << "recvSCPMessage qset: "
<< binToHex(msg.envelope().statement.quorumSetHash)
.substr(0, 6);
mApp.getOverlayManager().recvFloodedMsg(msg, shared_from_this());
auto cb = [msg, this](SCP::EnvelopeState state)
{
if (state == SCP::EnvelopeState::VALID)
{
mApp.getOverlayManager().broadcastMessage(msg);
}
};
mApp.getHerder().recvSCPEnvelope(envelope, cb);
}
示例12: if
void
Peer::recvPeers(StellarMessage const& msg)
{
const uint32 NEW_PEER_WINDOW_SECONDS = 10;
for (auto const& peer : msg.peers())
{
if (peer.port == 0 || peer.port > UINT16_MAX)
{
CLOG(WARNING, "Overlay") << "ignoring received peer with bad port "
<< peer.port;
continue;
}
if (peer.ip.type() == IPv6)
{
CLOG(WARNING, "Overlay") << "ignoring received IPv6 address"
<< " (not yet supported)";
continue;
}
// randomize when we'll try to connect to this peer next if we don't
// know it
auto defaultNextAttempt =
mApp.getClock().now() +
std::chrono::seconds(std::rand() % NEW_PEER_WINDOW_SECONDS);
stringstream ip;
ip << (int)peer.ip.ipv4()[0] << "." << (int)peer.ip.ipv4()[1] << "."
<< (int)peer.ip.ipv4()[2] << "." << (int)peer.ip.ipv4()[3];
// don't use peer.numFailures here as we may have better luck
// (and we don't want to poison our failure count)
PeerRecord pr{ip.str(), static_cast<unsigned short>(peer.port),
defaultNextAttempt, 0};
if (pr.isPrivateAddress())
{
CLOG(WARNING, "Overlay") << "ignoring received private address "
<< pr.toString();
}
else if (pr.isSelfAddressAndPort(getIP(), mApp.getConfig().PEER_PORT))
{
CLOG(WARNING, "Overlay") << "ignoring received self-address "
<< pr.toString();
}
else if (pr.isLocalhost() &&
!mApp.getConfig().ALLOW_LOCALHOST_FOR_TESTING)
{
CLOG(WARNING, "Overlay") << "ignoring received localhost";
}
else
{
pr.insertIfNew(mApp.getDatabase());
}
}
}
示例13: xdrBytes
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));
}
示例14: pr
bool
Peer::recvHello(StellarMessage const& msg)
{
if (msg.hello().peerID == mApp.getConfig().PEER_PUBLIC_KEY)
{
CLOG(DEBUG, "Overlay") << "connecting to self";
drop();
return false;
}
mRemoteOverlayVersion = msg.hello().overlayVersion;
mRemoteVersion = msg.hello().versionStr;
if (msg.hello().listeningPort <= 0 ||
msg.hello().listeningPort > UINT16_MAX)
{
CLOG(DEBUG, "Overlay") << "bad port in recvHello";
drop();
return false;
}
mRemoteListeningPort =
static_cast<unsigned short>(msg.hello().listeningPort);
CLOG(DEBUG, "Overlay") << "recvHello from " << toString();
mState = GOT_HELLO;
mPeerID = msg.hello().peerID;
if (mRole == INITIATOR)
{
PeerRecord pr(getIP(), mRemoteListeningPort, mApp.getClock().now(), 0,
1);
pr.insertIfNew(mApp.getDatabase());
}
return true;
}
示例15: sendMessage
void
Peer::sendPeers()
{
// send top 50 peers we know about
vector<PeerRecord> peerList;
PeerRecord::loadPeerRecords(mApp.getDatabase(), 50, mApp.getClock().now(),
peerList);
StellarMessage newMsg;
newMsg.type(PEERS);
newMsg.peers().reserve(peerList.size());
for (auto const& pr : peerList)
{
if (pr.isPrivateAddress() ||
pr.isSelfAddressAndPort(getIP(), mRemoteListeningPort))
{
continue;
}
PeerAddress pa;
pr.toXdr(pa);
newMsg.peers().push_back(pa);
}
sendMessage(newMsg);
}