Browse Source

Merge branch 'master' of ssh://pitanga//home/miguel/softs/twister

miguelfreitas
Miguel Freitas 11 years ago
parent
commit
47292c424e
  1. 2
      libtorrent/include/libtorrent/kademlia/node.hpp
  2. 9
      libtorrent/src/kademlia/dht_tracker.cpp
  3. 64
      libtorrent/src/kademlia/node.cpp
  4. 32
      src/main.cpp
  5. 10
      src/main.h
  6. 10
      src/net.cpp
  7. 4
      src/net.h
  8. 6
      src/rpcrawtransaction.cpp
  9. 2
      src/wallet.cpp

2
libtorrent/include/libtorrent/kademlia/node.hpp

@ -180,10 +180,12 @@ public:
void tick(); void tick();
bool refresh_storage(); bool refresh_storage();
bool save_storage(entry &save) const;
void refresh(node_id const& id, find_data::nodes_callback const& f); void refresh(node_id const& id, find_data::nodes_callback const& f);
void bootstrap(std::vector<udp::endpoint> const& nodes void bootstrap(std::vector<udp::endpoint> const& nodes
, find_data::nodes_callback const& f); , find_data::nodes_callback const& f);
void add_router_node(udp::endpoint router); void add_router_node(udp::endpoint router);
void load_storage(entry const* load);
void unreachable(udp::endpoint const& ep); void unreachable(udp::endpoint const& ep);
void incoming(msg const& m); void incoming(msg const& m);

9
libtorrent/src/kademlia/dht_tracker.cpp

@ -241,6 +241,9 @@ namespace libtorrent { namespace dht
TORRENT_LOG(dht_tracker) << "starting DHT tracker with node id: " << m_dht.nid(); TORRENT_LOG(dht_tracker) << "starting DHT tracker with node id: " << m_dht.nid();
#endif #endif
if (state && state->type() == entry::dictionary_t) {
m_dht.load_storage(state->find_key("storage_table"));
}
} }
dht_tracker::~dht_tracker() {} dht_tracker::~dht_tracker() {}
@ -602,6 +605,12 @@ namespace libtorrent { namespace dht
} }
if (!nodes.list().empty()) if (!nodes.list().empty())
ret["nodes"] = nodes; ret["nodes"] = nodes;
// [MF] save stored keys
entry storate_entry(entry::dictionary_t);
if( m_dht.save_storage(storate_entry) ) {
ret["storage_table"] = storate_entry;
}
} }
ret["node-id"] = m_dht.nid().to_string(); ret["node-id"] = m_dht.nid().to_string();

64
libtorrent/src/kademlia/node.cpp

@ -537,6 +537,70 @@ bool node_impl::refresh_storage() {
return did_something; return did_something;
} }
bool node_impl::save_storage(entry &save) const {
bool did_something = false;
if( m_storage_table.size() == 0 )
return did_something;
printf("node dht: saving storage... (storage_table.size = %d)\n", m_storage_table.size());
for (dht_storage_table_t::const_iterator i = m_storage_table.begin(),
iend(m_storage_table.end()); i != iend; ++i )
{
entry save_list(entry::list_t);
dht_storage_list_t const& lsto = i->second;
// save only 's' items? for now save everything
/*if( lsto.size() == 1 )*/ {
for(dht_storage_list_t::const_iterator j = lsto.begin(),
jend(lsto.end()); j != jend; ++j ) {
dht_storage_item const& item = *j;
entry entry_item;
entry_item["p"] = item.p;
entry_item["sig_p"] = item.sig_p;
entry_item["sig_user"] = item.sig_user;
save_list.list().push_back(entry_item);
}
}
if( save_list.list().size() ) {
save[i->first.to_string()] = save_list;
did_something = true;
}
}
return did_something;
}
void node_impl::load_storage(entry const* e) {
if( !e || e->type() != entry::dictionary_t)
return;
printf("node dht: loading storage... (%d node_id keys)\n", e->dict().size());
for (entry::dictionary_type::const_iterator i = e->dict().begin();
i != e->dict().end(); ++i) {
node_id target( i->first );
dht_storage_list_t to_add;
if ( i->second.type() != entry::list_t )
continue;
for (entry::list_type::const_iterator j = i->second.list().begin();
j != i->second.list().end(); ++j) {
dht_storage_item item;
item.p = j->find_key("p")->string();
item.sig_p = j->find_key("sig_p")->string();
item.sig_user = j->find_key("sig_user")->string();
to_add.push_back(item);
}
m_storage_table.insert(std::make_pair(target, to_add));
}
}
time_duration node_impl::connection_timeout() time_duration node_impl::connection_timeout()
{ {
time_duration d = m_rpc.tick(); time_duration d = m_rpc.tick();

32
src/main.cpp

@ -474,16 +474,16 @@ bool CTxMemPool::accept(CValidationState &state, CTransaction &tx, bool fLimitFr
reason.c_str()); reason.c_str());
// is it already in the memory pool? // is it already in the memory pool?
uint256 userhash = tx.GetUsernameHash(); uint256 txhash = tx.GetHash();
{ {
LOCK(cs); LOCK(cs);
if (mapTx.count(userhash)) if (mapTx.count(txhash))
return false; return false;
} }
{ {
// do we already have it? // do we already have it?
if( pblocktree->HaveTxIndex(userhash) && if( pblocktree->HaveTxIndex(tx.GetUsernameHash()) &&
// duplicate should be discarded but replacement is allowed. // duplicate should be discarded but replacement is allowed.
!verifyDuplicateOrReplacementTx(tx, false, true) ) { !verifyDuplicateOrReplacementTx(tx, false, true) ) {
return false; return false;
@ -518,25 +518,25 @@ bool CTxMemPool::accept(CValidationState &state, CTransaction &tx, bool fLimitFr
// Store transaction in memory // Store transaction in memory
{ {
LOCK(cs); LOCK(cs);
addUnchecked(userhash, tx); // adds to mapTx addUnchecked(txhash, tx); // adds to mapTx
} }
///// are we sure this is ok when loading transactions or restoring block txes ///// are we sure this is ok when loading transactions or restoring block txes
SyncWithWallets(userhash, tx, NULL, true); SyncWithWallets(txhash, tx, NULL, true);
printf("CTxMemPool::accept() : accepted %s (poolsz %"PRIszu")\n", printf("CTxMemPool::accept() : accepted %s (poolsz %"PRIszu")\n",
userhash.ToString().c_str(), txhash.ToString().c_str(),
mapTx.size()); mapTx.size());
return true; return true;
} }
bool CTxMemPool::addUnchecked(const uint256& userhash, CTransaction &tx) bool CTxMemPool::addUnchecked(const uint256& txhash, CTransaction &tx)
{ {
// Add to memory pool without checking anything. Don't call this directly, // Add to memory pool without checking anything. Don't call this directly,
// call CTxMemPool::accept to properly check the transaction first. // call CTxMemPool::accept to properly check the transaction first.
{ {
mapTx[userhash] = tx; mapTx[txhash] = tx;
nTransactionsUpdated++; nTransactionsUpdated++;
} }
return true; return true;
@ -548,7 +548,7 @@ bool CTxMemPool::remove(const CTransaction &tx, bool fRecursive)
// Remove transaction from memory pool // Remove transaction from memory pool
if( !tx.IsSpamMessage() ){ if( !tx.IsSpamMessage() ){
LOCK(cs); LOCK(cs);
uint256 hash = tx.GetUsernameHash(); uint256 hash = tx.GetHash();
if (mapTx.count(hash)) if (mapTx.count(hash))
{ {
mapTx.erase(hash); mapTx.erase(hash);
@ -636,12 +636,14 @@ bool GetTransaction(const uint256 &userhash, CTransaction &txOut, uint256 &hashB
{ {
LOCK(cs_main); LOCK(cs_main);
{ {
/* [MF] don't look in mempool anymore - userhash must be written to some block.
LOCK(mempool.cs); LOCK(mempool.cs);
if (mempool.exists(userhash)) if (mempool.exists(userhash)) // and btw mempool is not indexed by userhash anymore!
{ {
txOut = mempool.lookup(userhash); txOut = mempool.lookup(userhash);
return true; return true;
} }
*/
} }
if (fTxIndex) { if (fTxIndex) {
@ -1740,12 +1742,10 @@ CMerkleBlock::CMerkleBlock(const CBlock& block, CBloomFilter& filter)
for (unsigned int i = 0; i < block.vtx.size(); i++) for (unsigned int i = 0; i < block.vtx.size(); i++)
{ {
uint256 hash = block.vtx[i].GetHash(); uint256 hash = block.vtx[i].GetHash();
// [MF] unsure. force 0, use userhash for filter, hash for merkletree if (i == 0 || filter.IsRelevantAndUpdate(block.vtx[i], hash))
// [MF] FIXME: this is most likely broken!
if (i == 0 || filter.IsRelevantAndUpdate(block.vtx[i], block.vtx[i].GetUsernameHash()))
{ {
vMatch.push_back(true); vMatch.push_back(true);
vMatchedTxn.push_back(make_pair(i, block.vtx[i].GetUsernameHash())); vMatchedTxn.push_back(make_pair(i, hash));
} }
else else
vMatch.push_back(false); vMatch.push_back(false);
@ -2388,6 +2388,7 @@ bool static AlreadyHave(const CInv& inv)
* "inv" cmd of the current txs in memory. if recipient decides he * "inv" cmd of the current txs in memory. if recipient decides he
* already has a given tx in txindex (by calling this function), * already has a given tx in txindex (by calling this function),
* he would never ask/receive the key replacement. * he would never ask/receive the key replacement.
* Besides: HaveTxIndex is userhash, mempool is txhash.
*/ */
/* /*
if( !txInMap ) { if( !txInMap ) {
@ -2447,7 +2448,6 @@ void static ProcessGetData(CNode* pfrom)
// Thus, the protocol spec specified allows for us to provide duplicate txn here, // Thus, the protocol spec specified allows for us to provide duplicate txn here,
// however we MUST always provide at least what the remote peer needs // however we MUST always provide at least what the remote peer needs
typedef std::pair<unsigned int, uint256> PairType; typedef std::pair<unsigned int, uint256> PairType;
// [MF] check if vMatchedTxn is userhash
BOOST_FOREACH(PairType& pair, merkleBlock.vMatchedTxn) BOOST_FOREACH(PairType& pair, merkleBlock.vMatchedTxn)
if (!pfrom->setInventoryKnown.count(CInv(MSG_TX, pair.second))) if (!pfrom->setInventoryKnown.count(CInv(MSG_TX, pair.second)))
pfrom->PushMessage("tx", block.vtx[pair.first]); pfrom->PushMessage("tx", block.vtx[pair.first]);
@ -2863,7 +2863,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv)
CTransaction tx; CTransaction tx;
vRecv >> tx; vRecv >> tx;
CInv inv(MSG_TX, tx.GetUsernameHash()); CInv inv(MSG_TX, tx.GetHash());
pfrom->AddInventoryKnown(inv); pfrom->AddInventoryKnown(inv);
// Truncate messages to the size of the tx in them // Truncate messages to the size of the tx in them

10
src/main.h

@ -1007,7 +1007,7 @@ class CTxMemPool
{ {
public: public:
mutable CCriticalSection cs; mutable CCriticalSection cs;
std::map<uint256, CTransaction> mapTx; // [MF] hash is now userhash std::map<uint256, CTransaction> mapTx; // [MF] hash is txhash again
bool accept(CValidationState &state, CTransaction &tx, bool fLimitFree, bool* pfMissingInputs); bool accept(CValidationState &state, CTransaction &tx, bool fLimitFree, bool* pfMissingInputs);
bool addUnchecked(const uint256& userhash, CTransaction &tx); bool addUnchecked(const uint256& userhash, CTransaction &tx);
@ -1021,14 +1021,14 @@ public:
return mapTx.size(); return mapTx.size();
} }
bool exists(uint256 userhash) bool exists(uint256 txhash)
{ {
return (mapTx.count(userhash) != 0); return (mapTx.count(txhash) != 0);
} }
CTransaction& lookup(uint256 userhash) CTransaction& lookup(uint256 txhash)
{ {
return mapTx[userhash]; return mapTx[txhash];
} }
}; };

10
src/net.cpp

@ -1792,17 +1792,17 @@ instance_of_cnetcleanup;
void RelayTransaction(const CTransaction& tx, const uint256& userhash) void RelayTransaction(const CTransaction& tx, const uint256& txhash)
{ {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION); CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(10000); ss.reserve(10000);
ss << tx; ss << tx;
RelayTransaction(tx, userhash, ss); RelayTransaction(tx, txhash, ss);
} }
void RelayTransaction(const CTransaction& tx, const uint256& userhash, const CDataStream& ss) void RelayTransaction(const CTransaction& tx, const uint256& txhash, const CDataStream& ss)
{ {
CInv inv(MSG_TX, userhash); CInv inv(MSG_TX, txhash);
{ {
LOCK(cs_mapRelay); LOCK(cs_mapRelay);
// Expire old relay messages // Expire old relay messages
@ -1824,7 +1824,7 @@ void RelayTransaction(const CTransaction& tx, const uint256& userhash, const CDa
LOCK(pnode->cs_filter); LOCK(pnode->cs_filter);
if (pnode->pfilter) if (pnode->pfilter)
{ {
if (pnode->pfilter->IsRelevantAndUpdate(tx, userhash)) if (pnode->pfilter->IsRelevantAndUpdate(tx, txhash))
pnode->PushInventory(inv); pnode->PushInventory(inv);
} else } else
pnode->PushInventory(inv); pnode->PushInventory(inv);

4
src/net.h

@ -644,7 +644,7 @@ public:
class CTransaction; class CTransaction;
void RelayTransaction(const CTransaction& tx, const uint256& userhash); void RelayTransaction(const CTransaction& tx, const uint256& txhash);
void RelayTransaction(const CTransaction& tx, const uint256& userhash, const CDataStream& ss); void RelayTransaction(const CTransaction& tx, const uint256& txhash, const CDataStream& ss);
#endif #endif

6
src/rpcrawtransaction.cpp

@ -220,16 +220,16 @@ Value sendrawtransaction(const Array& params, bool fHelp)
catch (std::exception &e) { catch (std::exception &e) {
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed"); throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "TX decode failed");
} }
uint256 hashTx = tx.GetUsernameHash(); uint256 hashTx = tx.GetHash();
bool fHave = false; bool fHave = false;
uint256 hashBlock; uint256 hashBlock;
CTransaction tx2; CTransaction tx2;
fHave = GetTransaction(hashTx, tx2, hashBlock); fHave = GetTransaction(tx.GetUsernameHash(), tx2, hashBlock);
// treat replacement as !fHave // treat replacement as !fHave
if( fHave && verifyDuplicateOrReplacementTx(tx, false, true) ) { if( fHave && verifyDuplicateOrReplacementTx(tx, false, true) ) {
printf("verifyDuplicateOrReplacementTx true\n"); printf("sendrawtransaction: is ReplacementTx true\n");
fHave = false; fHave = false;
} }

2
src/wallet.cpp

@ -675,7 +675,7 @@ void CWalletTx::RelayWalletTransaction()
if (!IsSpamMessage()) if (!IsSpamMessage())
{ {
if (GetDepthInMainChain() == 0) { if (GetDepthInMainChain() == 0) {
uint256 hash = GetUsernameHash(); uint256 hash = GetHash();
printf("Relaying wtx %s\n", hash.ToString().c_str()); printf("Relaying wtx %s\n", hash.ToString().c_str());
RelayTransaction((CTransaction)*this, hash); RelayTransaction((CTransaction)*this, hash);
} }

Loading…
Cancel
Save