mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 23:45:51 +00:00
Complete initial implementation of transaction relaying.
This commit is contained in:
@@ -38,7 +38,7 @@ bool ConnectionPool::isMessageKnown(PackedMessage::pointer msg)
|
||||
*/
|
||||
|
||||
|
||||
void ConnectionPool::relayMessage(Peer* fromPeer,PackedMessage::pointer msg)
|
||||
void ConnectionPool::relayMessage(Peer* fromPeer, PackedMessage::pointer msg)
|
||||
{
|
||||
BOOST_FOREACH(Peer::pointer peer, mPeers)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ uint32 NetworkOPs::getCurrentLedgerID()
|
||||
return theApp->getMasterLedger().getCurrentLedger()->getLedgerSeq();
|
||||
}
|
||||
|
||||
Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans)
|
||||
Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans, Peer* source)
|
||||
{
|
||||
Transaction::pointer dbtx=Transaction::load(trans->getID());
|
||||
if(dbtx) return dbtx;
|
||||
@@ -57,8 +57,19 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans)
|
||||
if(r==Ledger::TR_SUCCESS)
|
||||
{
|
||||
trans->setStatus(INCLUDED);
|
||||
// WRITEME: send to others
|
||||
theApp->getWallet().applyTransaction(trans);
|
||||
|
||||
newcoin::TMTransaction *tx=new newcoin::TMTransaction();
|
||||
|
||||
Serializer::pointer s(trans->getSigned());
|
||||
tx->set_rawtransaction(&s->getData().front(), s->getLength());
|
||||
tx->set_status(newcoin::tsCURRENT);
|
||||
tx->set_receivetimestamp(getNetworkTime());
|
||||
tx->set_ledgerindexpossible(trans->getLedger());
|
||||
|
||||
PackedMessage::pointer packet(new PackedMessage(PackedMessage::MessagePointer(tx), newcoin::mtTRANSACTION));
|
||||
theApp->getConnectionPool().relayMessage(source, packet);
|
||||
|
||||
return trans;
|
||||
}
|
||||
|
||||
|
||||
17
NetworkOPs.h
17
NetworkOPs.h
@@ -6,22 +6,35 @@
|
||||
|
||||
// Operations that clients may wish to perform against the network
|
||||
|
||||
class Peer;
|
||||
|
||||
class NetworkOPs
|
||||
{
|
||||
enum Fault
|
||||
{
|
||||
{ // exceptions these functions can throw
|
||||
IO_ERROR=1,
|
||||
NO_NETWORK=2,
|
||||
};
|
||||
|
||||
enum OperatingMode
|
||||
{ // how we process transactions or account balance requests
|
||||
FAULTED=0, // we are unable to process requests (not ready or no network)
|
||||
FULL_LOCAL=1, // we are in full local sync
|
||||
PART_LOCAL=2, // we can validate remote data but have to request it
|
||||
REMOTE=3 // we have to trust remote nodes
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
// context information
|
||||
OperatingMode getOperatingMode();
|
||||
|
||||
// network information
|
||||
uint64 getNetworkTime();
|
||||
uint32 getCurrentLedgerID();
|
||||
|
||||
// transaction operations
|
||||
Transaction::pointer processTransaction(Transaction::pointer transaction);
|
||||
Transaction::pointer processTransaction(Transaction::pointer transaction, Peer* source=NULL);
|
||||
Transaction::pointer findTransactionByID(const uint256& transactionID);
|
||||
int findTransactionsBySource(std::list<Transaction::pointer>&, const uint160& sourceAccount,
|
||||
uint32 minSeq, uint32 maxSeq);
|
||||
|
||||
36
Peer.cpp
36
Peer.cpp
@@ -1,11 +1,14 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
//#include <boost/log/trivial.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "Peer.h"
|
||||
#include "KnownNodeList.h"
|
||||
#include "Config.h"
|
||||
#include "Application.h"
|
||||
#include <boost/foreach.hpp>
|
||||
//#include <boost/log/trivial.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <iostream>
|
||||
#include "Conversion.h"
|
||||
|
||||
using namespace std;
|
||||
@@ -279,6 +282,31 @@ void Peer::recvHello(newcoin::TMHello& packet)
|
||||
|
||||
void Peer::recvTransaction(newcoin::TMTransaction& packet)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
std::cerr << "Got transaction from peer" << std::endl;
|
||||
#endif
|
||||
|
||||
std::string rawTx=packet.rawtransaction();
|
||||
std::vector<unsigned char> rTx(rawTx.size());
|
||||
memcpy(&rTx.front(), rawTx.data(), rawTx.size());
|
||||
Transaction::pointer tx(new Transaction(rTx, true));
|
||||
|
||||
if(tx->getStatus()==INVALID)
|
||||
{ // transaction fails basic validity tests
|
||||
#ifdef DEBUG
|
||||
std::cerr << "Transaction from peer fails validity tests" << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
tx=theApp->getOPs().processTransaction(tx, this);
|
||||
|
||||
if(tx->getStatus()!=INCLUDED)
|
||||
{ // transaction wasn't accepted into ledger
|
||||
#ifdef DEBUG
|
||||
std::cerr << "Transaction from peer won't go in ledger" << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void Peer::recvValidation(newcoin::TMValidation& packet)
|
||||
|
||||
3
Peer.h
3
Peer.h
@@ -5,11 +5,12 @@
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
#include "newcoin.pb.h"
|
||||
#include "PackedMessage.h"
|
||||
#include "Ledger.h"
|
||||
#include "Transaction.h"
|
||||
#include "list"
|
||||
#include "NetworkOPs.h"
|
||||
|
||||
class Peer : public boost::enable_shared_from_this<Peer>
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user