mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-11 07:17:53 +00:00
Merge
This commit is contained in:
commit
5b71538165
14
TODO
14
TODO
@ -1,17 +1,3 @@
|
||||
- Take care of posts using older public key when key is replaced.
|
||||
|
||||
notes: not very difficult, GetTransaction must receive a maximum block number to search the
|
||||
transaction (we get this from post["height"]). another txIndex should be set to speedup lookup
|
||||
(key in db includes the number of the block that changed tx so previous one can be found).
|
||||
pseudocode:
|
||||
getTxIndex( key = "userX" ) => block h contains this tx;
|
||||
while( h > max_h )
|
||||
getTxIndex( "userX_h" ) => block h contains the previous tx
|
||||
=> GetTransation: new parameter maxHeight done!
|
||||
|
||||
- Until old public key is properly used, disable banning torrent peers due to bad piece hashes.
|
||||
note: torrent.cpp line 3286 (function piece_failed), iteration to ban peers is disabled (continue).
|
||||
|
||||
- Count UTF8 chars in acceptSignedPost to proper limit the 140 characters.
|
||||
|
||||
- Encrypt user_data (which contains all DMs)
|
||||
|
@ -98,6 +98,8 @@ private:
|
||||
bool m_done:1;
|
||||
bool m_got_data:1;
|
||||
bool m_justToken:1;
|
||||
|
||||
friend class dht_get_observer;
|
||||
};
|
||||
|
||||
class dht_get_observer : public observer
|
||||
|
@ -93,7 +93,7 @@ namespace libtorrent { namespace dht
|
||||
entry state() const;
|
||||
|
||||
void announce(std::string const& trackerName, sha1_hash const& ih
|
||||
, address addr, int listen_port, bool seed, bool myself
|
||||
, address addr, int listen_port, bool seed, bool myself, int list_peers
|
||||
, boost::function<void(std::vector<tcp::endpoint> const&)> f);
|
||||
|
||||
void putData(std::string const &username, std::string const &resource, bool multi,
|
||||
|
@ -112,6 +112,7 @@ struct torrent_entry
|
||||
{
|
||||
std::string name;
|
||||
std::set<peer_entry> peers;
|
||||
int list_peers; // number of known peers (copied from torrent status)
|
||||
};
|
||||
|
||||
struct dht_storage_item
|
||||
@ -215,7 +216,7 @@ public:
|
||||
#endif
|
||||
|
||||
void announce(std::string const& trackerName, sha1_hash const& info_hash
|
||||
, address addr, int listen_port, bool seed, bool myself
|
||||
, address addr, int listen_port, bool seed, bool myself, int list_peers
|
||||
, boost::function<void(std::vector<tcp::endpoint> const&)> f);
|
||||
|
||||
void putData(std::string const &username, std::string const &resource, bool multi,
|
||||
@ -268,7 +269,7 @@ protected:
|
||||
|
||||
void lookup_peers(sha1_hash const& info_hash, int prefix, entry& reply
|
||||
, bool noseed, bool scrape) const;
|
||||
void add_peer(std::string const& name, sha1_hash const& info_hash, address addr, int port, bool seed);
|
||||
void add_peer(std::string const& name, sha1_hash const& info_hash, address addr, int port, bool seed, int list_peers);
|
||||
|
||||
dht_settings const& m_settings;
|
||||
|
||||
|
@ -125,8 +125,34 @@ void dht_get_observer::reply(msg const& m)
|
||||
values_list.push_back(entry());
|
||||
values_list.back() = *e;
|
||||
}
|
||||
//printf("dht_get::reply from %s:%d with %d entries\n", m.addr.address().to_string().c_str(), m.addr.port(), values_list.size());
|
||||
//printf("dht_get::reply from %s:%d with %d entries\n", m.addr.address().to_string().c_str(), m.addr.port(), values_list.size());
|
||||
static_cast<dht_get*>(m_algorithm.get())->got_data(values_list);
|
||||
} else {
|
||||
// special case for trackers (non-signed content)
|
||||
// pretend it is a normal dht resource to the caller
|
||||
dht_get *dget( static_cast<dht_get*>(m_algorithm.get()) );
|
||||
if( dget->m_targetResource == "tracker" && dget->m_multi ) {
|
||||
int followers = r->dict_find_int_value("followers");
|
||||
if( followers ) {
|
||||
entry::dictionary_type v;
|
||||
v["followers"] = followers;
|
||||
|
||||
entry::dictionary_type target;
|
||||
target["n"] = dget->m_targetUser;
|
||||
target["r"] = dget->m_targetResource;
|
||||
target["t"] = dget->m_multi ? "m" : "s";
|
||||
|
||||
entry::dictionary_type p;
|
||||
p["target"] = target;
|
||||
p["v"] = v;
|
||||
|
||||
entry::dictionary_type e;
|
||||
e["p"] = p;
|
||||
entry::list_type values_list;
|
||||
values_list.push_back(e);
|
||||
dget->got_data(values_list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// look for nodes
|
||||
|
@ -427,10 +427,10 @@ namespace libtorrent { namespace dht
|
||||
}
|
||||
|
||||
void dht_tracker::announce(std::string const& trackerName, sha1_hash const& ih
|
||||
, address addr, int listen_port, bool seed, bool myself
|
||||
, address addr, int listen_port, bool seed, bool myself, int list_peers
|
||||
, boost::function<void(std::vector<tcp::endpoint> const&)> f)
|
||||
{
|
||||
m_dht.announce(trackerName, ih, addr, listen_port, seed, myself, f);
|
||||
m_dht.announce(trackerName, ih, addr, listen_port, seed, myself, list_peers, f);
|
||||
}
|
||||
|
||||
void dht_tracker::putData(std::string const &username, std::string const &resource, bool multi,
|
||||
|
@ -35,6 +35,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
||||
#include <utility>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/function/function1.hpp>
|
||||
//#include <boost/date_time/posix_time/time_formatters_limited.hpp>
|
||||
|
||||
#include "libtorrent/io.hpp"
|
||||
#include "libtorrent/bencode.hpp"
|
||||
@ -400,7 +401,7 @@ void node_impl::add_node(udp::endpoint node)
|
||||
m_rpc.invoke(e, node, o);
|
||||
}
|
||||
|
||||
void node_impl::announce(std::string const& trackerName, sha1_hash const& info_hash, address addr, int listen_port, bool seed, bool myself
|
||||
void node_impl::announce(std::string const& trackerName, sha1_hash const& info_hash, address addr, int listen_port, bool seed, bool myself, int list_peers
|
||||
, boost::function<void(std::vector<tcp::endpoint> const&)> f)
|
||||
{
|
||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||
@ -410,7 +411,7 @@ void node_impl::announce(std::string const& trackerName, sha1_hash const& info_h
|
||||
|
||||
// [MF] is_unspecified() is not always available. never mind.
|
||||
//if( !addr.is_unspecified() ) {
|
||||
add_peer( trackerName, info_hash, addr, listen_port, seed );
|
||||
add_peer( trackerName, info_hash, addr, listen_port, seed, list_peers );
|
||||
//}
|
||||
|
||||
// do not announce other peers, just add them to our local m_map.
|
||||
@ -556,13 +557,18 @@ bool node_impl::refresh_storage() {
|
||||
m_last_refreshed_item = m_storage_table.begin()->first;
|
||||
}
|
||||
|
||||
time_duration sleepToRefresh;
|
||||
if( num_refreshable ) {
|
||||
m_next_storage_refresh = minutes(60) / num_refreshable + time_now();
|
||||
sleepToRefresh = minutes(60) / num_refreshable;
|
||||
} else {
|
||||
m_next_storage_refresh = minutes(10) + time_now();
|
||||
sleepToRefresh = minutes(10);
|
||||
}
|
||||
m_next_storage_refresh = time_now() + sleepToRefresh;
|
||||
|
||||
printf("node dht: next storage refresh in %d seconds\n", (m_next_storage_refresh - time_now())/1000000 );
|
||||
/*
|
||||
printf("node dht: next storage refresh in %s\n",
|
||||
boost::posix_time::to_simple_string(sleepToRefresh).c_str() );
|
||||
*/
|
||||
|
||||
return did_something;
|
||||
}
|
||||
@ -762,6 +768,7 @@ void node_impl::lookup_peers(sha1_hash const& info_hash, int prefix, entry& repl
|
||||
torrent_entry const& v = i->second;
|
||||
|
||||
if (!v.name.empty()) reply["n"] = v.name;
|
||||
reply["followers"] = v.list_peers;
|
||||
|
||||
if (scrape)
|
||||
{
|
||||
@ -803,7 +810,7 @@ void node_impl::lookup_peers(sha1_hash const& info_hash, int prefix, entry& repl
|
||||
return;
|
||||
}
|
||||
|
||||
void node_impl::add_peer(std::string const &name, sha1_hash const& info_hash, address addr, int port, bool seed)
|
||||
void node_impl::add_peer(std::string const &name, sha1_hash const& info_hash, address addr, int port, bool seed, int list_peers)
|
||||
{
|
||||
torrent_entry& v = m_map[info_hash];
|
||||
|
||||
@ -814,6 +821,7 @@ void node_impl::add_peer(std::string const &name, sha1_hash const& info_hash, ad
|
||||
v.name = name;
|
||||
if (v.name.size() > 50) v.name.resize(50);
|
||||
}
|
||||
if (list_peers) v.list_peers = list_peers;
|
||||
|
||||
peer_entry peer;
|
||||
peer.addr = tcp::endpoint(addr, port);
|
||||
@ -1144,7 +1152,7 @@ void node_impl::incoming_request(msg const& m, entry& e)
|
||||
}
|
||||
|
||||
add_peer( msg_keys[3] ? msg_keys[3]->string_value() : std::string(), info_hash,
|
||||
m.addr.address(), port, msg_keys[4] && msg_keys[4]->int_value());
|
||||
m.addr.address(), port, msg_keys[4] && msg_keys[4]->int_value(), 0);
|
||||
|
||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||
++g_announces;
|
||||
|
@ -2073,7 +2073,7 @@ namespace libtorrent
|
||||
p->last_connected && (m_ses.session_time() - p->last_connected) < (4*3600);
|
||||
if( p->connectable && ( p->connection || connect_recently) ) {
|
||||
m_ses.m_dht->announce(name(), m_torrent_file->info_hash()
|
||||
, p->address(), p->port, p->seed, false
|
||||
, p->address(), p->port, p->seed, false, m_policy.num_peers()
|
||||
, boost::bind(&nop));
|
||||
}
|
||||
}
|
||||
@ -2086,8 +2086,8 @@ namespace libtorrent
|
||||
#endif
|
||||
|
||||
boost::weak_ptr<torrent> self(shared_from_this());
|
||||
m_ses.m_dht->announce(name(), m_torrent_file->info_hash()
|
||||
, m_ses.external_address().external_address(address_v4()), port, is_seed(), true
|
||||
m_ses.m_dht->announce(name(), m_torrent_file->info_hash()
|
||||
, m_ses.external_address().external_address(address_v4()), port, is_seed(), true, m_policy.num_peers()
|
||||
, boost::bind(&torrent::on_dht_announce_response_disp, self, _1));
|
||||
}
|
||||
|
||||
@ -3308,9 +3308,6 @@ namespace libtorrent
|
||||
for (std::set<void*>::iterator i = peers.begin()
|
||||
, end(peers.end()); i != end; ++i)
|
||||
{
|
||||
// [MF] FIXME FIXME: BANNING BY FAILED HASH DISABLED - READ TODO!
|
||||
continue;
|
||||
|
||||
policy::peer* p = static_cast<policy::peer*>(*i);
|
||||
if (p == 0) continue;
|
||||
TORRENT_ASSERT(p->in_use);
|
||||
|
@ -606,44 +606,33 @@ std::string createSignature(std::string const &strMessage, std::string const &st
|
||||
}
|
||||
|
||||
|
||||
bool getUserPubKey(std::string const &strUsername, CPubKey &pubkey)
|
||||
bool getUserPubKey(std::string const &strUsername, CPubKey &pubkey, int maxHeight)
|
||||
{
|
||||
{
|
||||
CKeyID keyID;
|
||||
if( pwalletMain->GetKeyIdFromUsername(strUsername, keyID) ) {
|
||||
if( !pwalletMain->GetPubKey(keyID, pubkey) ) {
|
||||
// error? should not have failed.
|
||||
}
|
||||
}
|
||||
CTransaction txOut;
|
||||
uint256 hashBlock;
|
||||
if( !GetTransaction(strUsername, txOut, hashBlock, maxHeight) ) {
|
||||
//printf("getUserPubKey: user unknown '%s'\n", strUsername.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector< std::vector<unsigned char> > vData;
|
||||
if( !txOut.pubKey.ExtractPushData(vData) || vData.size() < 1 ) {
|
||||
printf("getUserPubKey: broken pubkey for user '%s'\n", strUsername.c_str());
|
||||
return false;
|
||||
}
|
||||
pubkey = CPubKey(vData[0]);
|
||||
if( !pubkey.IsValid() ) {
|
||||
CTransaction txOut;
|
||||
uint256 hashBlock;
|
||||
if( !GetTransaction(strUsername, txOut, hashBlock) ) {
|
||||
//printf("getUserPubKey: user unknown '%s'\n", strUsername.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector< std::vector<unsigned char> > vData;
|
||||
if( !txOut.pubKey.ExtractPushData(vData) || vData.size() < 1 ) {
|
||||
printf("getUserPubKey: broken pubkey for user '%s'\n", strUsername.c_str());
|
||||
return false;
|
||||
}
|
||||
pubkey = CPubKey(vData[0]);
|
||||
if( !pubkey.IsValid() ) {
|
||||
printf("getUserPubKey: invalid pubkey for user '%s'\n", strUsername.c_str());
|
||||
return false;
|
||||
}
|
||||
printf("getUserPubKey: invalid pubkey for user '%s'\n", strUsername.c_str());
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool verifySignature(std::string const &strMessage, std::string const &strUsername, std::string const &strSign)
|
||||
bool verifySignature(std::string const &strMessage, std::string const &strUsername, std::string const &strSign, int maxHeight)
|
||||
{
|
||||
CPubKey pubkey;
|
||||
if( !getUserPubKey(strUsername, pubkey) ) {
|
||||
if( !getUserPubKey(strUsername, pubkey, maxHeight) ) {
|
||||
printf("verifySignature: no pubkey for user '%s'\n", strUsername.c_str());
|
||||
return false;
|
||||
}
|
||||
@ -761,7 +750,7 @@ bool acceptSignedPost(char const *data, int data_size, std::string username, int
|
||||
std::pair<char const*, int> postbuf = post->data_section();
|
||||
ret = verifySignature(
|
||||
std::string(postbuf.first,postbuf.second),
|
||||
username, sig);
|
||||
username, sig, height);
|
||||
if( !ret ) {
|
||||
sprintf(errbuf,"bad post signature");
|
||||
} else {
|
||||
@ -771,11 +760,12 @@ bool acceptSignedPost(char const *data, int data_size, std::string username, int
|
||||
if( rt ) {
|
||||
if( flags ) (*flags) |= USERPOST_FLAG_RT;
|
||||
std::string username_rt = rt->dict_find_string_value("n");
|
||||
int height_rt = rt->dict_find_int_value("height",-1);
|
||||
|
||||
std::pair<char const*, int> rtbuf = rt->data_section();
|
||||
ret = verifySignature(
|
||||
std::string(rtbuf.first,rtbuf.second),
|
||||
username_rt, sig_rt);
|
||||
username_rt, sig_rt, height_rt);
|
||||
if( !ret ) {
|
||||
sprintf(errbuf,"bad RT signature");
|
||||
}
|
||||
|
@ -23,10 +23,10 @@ public:
|
||||
void startSessionTorrent(boost::thread_group& threadGroup);
|
||||
void stopSessionTorrent();
|
||||
|
||||
bool getUserPubKey(std::string const &strUsername, CPubKey &pubkey);
|
||||
bool getUserPubKey(std::string const &strUsername, CPubKey &pubkey, int maxHeight = -1);
|
||||
std::string createSignature(std::string const &strMessage, CKeyID &keyID);
|
||||
std::string createSignature(std::string const &strMessage, std::string const &strUsername);
|
||||
bool verifySignature(std::string const &strMessage, std::string const &strUsername, std::string const &strSign);
|
||||
bool verifySignature(std::string const &strMessage, std::string const &strUsername, std::string const &strSign, int maxHeight = -1);
|
||||
|
||||
bool acceptSignedPost(char const *data, int data_size, std::string username, int seq, std::string &errmsg, boost::uint32_t *flags);
|
||||
bool validatePostNumberForUser(std::string const &username, int k);
|
||||
|
Loading…
Reference in New Issue
Block a user