mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-09 14:28:22 +00:00
use bitcoin network time reference, dm creation draft
This commit is contained in:
parent
07b165d5f3
commit
4f51727c1b
@ -309,7 +309,7 @@ namespace libtorrent
|
||||
|
||||
void dht_putData(std::string const &username, std::string const &resource, bool multi,
|
||||
entry const &value, std::string const &sig_user,
|
||||
int timeutc, int seq);
|
||||
boost::int64_t timeutc, int seq);
|
||||
|
||||
void dht_getData(std::string const &username, std::string const &resource, bool multi);
|
||||
|
||||
|
@ -96,7 +96,7 @@ namespace libtorrent { namespace dht
|
||||
|
||||
void putData(std::string const &username, std::string const &resource, bool multi,
|
||||
entry const &value, std::string const &sig_user,
|
||||
int timeutc, int seq);
|
||||
boost::int64_t timeutc, int seq);
|
||||
|
||||
void getData(std::string const &username, std::string const &resource, bool multi,
|
||||
boost::function<void(entry::list_type const&)> fdata,
|
||||
|
@ -216,7 +216,7 @@ public:
|
||||
|
||||
void putData(std::string const &username, std::string const &resource, bool multi,
|
||||
entry const &value, std::string const &sig_user,
|
||||
int timeutc, int seq);
|
||||
boost::int64_t timeutc, int seq);
|
||||
|
||||
void getData(std::string const &username, std::string const &resource, bool multi,
|
||||
boost::function<void(entry::list_type const&)> fdata,
|
||||
|
@ -440,7 +440,7 @@ namespace libtorrent
|
||||
// [MF] twister
|
||||
void dht_putData(std::string const &username, std::string const &resource, bool multi,
|
||||
entry const &value, std::string const &sig_user,
|
||||
int timeutc, int seq);
|
||||
boost::int64_t timeutc, int seq);
|
||||
|
||||
void dht_getData(std::string const &username, std::string const &resource, bool multi);
|
||||
|
||||
|
@ -425,7 +425,7 @@ namespace libtorrent { namespace dht
|
||||
|
||||
void dht_tracker::putData(std::string const &username, std::string const &resource, bool multi,
|
||||
entry const &value, std::string const &sig_user,
|
||||
int timeutc, int seq)
|
||||
boost::int64_t timeutc, int seq)
|
||||
{
|
||||
m_dht.putData(username,resource, multi, value, sig_user, timeutc, seq);
|
||||
}
|
||||
|
@ -309,7 +309,7 @@ namespace
|
||||
node_impl& node,
|
||||
std::string const &username, std::string const &resource, bool multi,
|
||||
entry const &value, std::string const &sig_user,
|
||||
int timeutc, int seq)
|
||||
boost::int64_t timeutc, int seq)
|
||||
{
|
||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||
TORRENT_LOG(node) << "sending putData [ username: " << username
|
||||
@ -440,7 +440,7 @@ void node_impl::announce(std::string const& trackerName, sha1_hash const& info_h
|
||||
|
||||
void node_impl::putData(std::string const &username, std::string const &resource, bool multi,
|
||||
entry const &value, std::string const &sig_user,
|
||||
int timeutc, int seq)
|
||||
boost::int64_t timeutc, int seq)
|
||||
{
|
||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||
TORRENT_LOG(node) << "putData [ username: " << info_hash << " res: " << resource << " ]" ;
|
||||
|
@ -853,7 +853,7 @@ namespace libtorrent
|
||||
|
||||
void session::dht_putData(std::string const &username, std::string const &resource, bool multi,
|
||||
entry const &value, std::string const &sig_user,
|
||||
int timeutc, int seq)
|
||||
boost::int64_t timeutc, int seq)
|
||||
{
|
||||
#ifndef TORRENT_DISABLE_DHT
|
||||
TORRENT_ASYNC_CALL7(dht_putData, username, resource, multi, value, sig_user, timeutc, seq);
|
||||
|
@ -5745,7 +5745,7 @@ retry:
|
||||
|
||||
void session_impl::dht_putData(std::string const &username, std::string const &resource, bool multi,
|
||||
entry const &value, std::string const &sig_user,
|
||||
int timeutc, int seq)
|
||||
boost::int64_t timeutc, int seq)
|
||||
{
|
||||
if (m_dht) m_dht->putData(username, resource, multi, value, sig_user, timeutc, seq);
|
||||
}
|
||||
|
@ -468,10 +468,8 @@ std::string createSignature(std::string const &strMessage, std::string const &st
|
||||
return std::string((const char *)&vchSig[0], vchSig.size());
|
||||
}
|
||||
|
||||
|
||||
bool verifySignature(std::string const &strMessage, std::string const &strUsername, std::string const &strSign)
|
||||
bool getUserPubKey(std::string const &strUsername, CPubKey &pubkey)
|
||||
{
|
||||
CPubKey pubkey;
|
||||
{
|
||||
CKeyID keyID;
|
||||
if( pwalletMain->GetKeyIdFromUsername(strUsername, keyID) ) {
|
||||
@ -486,21 +484,32 @@ bool verifySignature(std::string const &strMessage, std::string const &strUserna
|
||||
uint256 hashBlock;
|
||||
uint256 userhash = SerializeHash(strUsername);
|
||||
if( !GetTransaction(userhash, txOut, hashBlock) ) {
|
||||
//printf("verifySignature: user unknown '%s'\n", strUsername.c_str());
|
||||
//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("verifySignature: broken pubkey for user '%s'\n", strUsername.c_str());
|
||||
printf("getUserPubKey: broken pubkey for user '%s'\n", strUsername.c_str());
|
||||
return false;
|
||||
}
|
||||
pubkey = CPubKey(vData[0]);
|
||||
if( !pubkey.IsValid() ) {
|
||||
printf("verifySignature: invalid pubkey for user '%s'\n", strUsername.c_str());
|
||||
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)
|
||||
{
|
||||
CPubKey pubkey;
|
||||
if( !getUserPubKey(strUsername, pubkey) ) {
|
||||
printf("verifySignature: no pubkey for user '%s'\n", strUsername.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<unsigned char> vchSig((const unsigned char*)strSign.data(),
|
||||
(const unsigned char*)strSign.data() + strSign.size());
|
||||
@ -614,14 +623,41 @@ bool validatePostNumberForUser(std::string const &username, int k)
|
||||
"sig_userpost" : signature by userpost.n
|
||||
*/
|
||||
|
||||
bool createSignedUserpost(entry &v, std::string const &username, int k)
|
||||
bool createSignedUserpost(entry &v, std::string const &username, int k,
|
||||
std::string const &msg, // either msg.size() or
|
||||
entry const *rt, entry const *sig_rt, // rt != NULL or
|
||||
entry const *dm, // dm != NULL.
|
||||
std::string const &reply_n, int reply_k
|
||||
)
|
||||
{
|
||||
entry &userpost = v["userpost"];
|
||||
|
||||
//
|
||||
userpost["n"] = username;
|
||||
userpost["k"] = k;
|
||||
userpost["time"] = GetAdjustedTime();
|
||||
userpost["height"] = getBestHeight() - 1; // be conservative
|
||||
|
||||
if( msg.size() ) {
|
||||
//userpost["t"] = "post";
|
||||
userpost["msg"] = msg;
|
||||
} else if ( rt != NULL && sig_rt != NULL ) {
|
||||
//userpost["t"] = "rt";
|
||||
userpost["rt"] = *rt;
|
||||
userpost["sig_rt"] = *sig_rt;
|
||||
} else if ( dm != NULL ) {
|
||||
//userpost["t"] = "dm";
|
||||
userpost["dm"] = *dm;
|
||||
} else {
|
||||
printf("createSignedUserpost: unknown type\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
if( reply_n.size() ) {
|
||||
entry &reply = userpost["reply"];
|
||||
reply["n"]=reply_n;
|
||||
reply["k"]=reply_k;
|
||||
}
|
||||
//
|
||||
|
||||
std::vector<char> buf;
|
||||
@ -635,6 +671,27 @@ bool createSignedUserpost(entry &v, std::string const &username, int k)
|
||||
}
|
||||
}
|
||||
|
||||
bool createDirectMessage(entry &dm, std::string const &to, std::string const &msg)
|
||||
{
|
||||
CPubKey pubkey;
|
||||
if( !getUserPubKey(to, pubkey) ) {
|
||||
printf("createDirectMessage: no pubkey for user '%s'\n", to.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
ecies_secure_t sec;
|
||||
bool encrypted = pubkey.Encrypt(msg, sec);
|
||||
|
||||
if( encrypted ) {
|
||||
dm["key"] = sec.key;
|
||||
dm["mac"] = sec.mac;
|
||||
dm["orig"] = sec.orig;
|
||||
dm["body"] = sec.body;
|
||||
}
|
||||
|
||||
return encrypted;
|
||||
}
|
||||
|
||||
int getBestHeight()
|
||||
{
|
||||
return nBestHeight;
|
||||
@ -698,7 +755,7 @@ Value dhtput(const Array& params, bool fHelp)
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Username must be the same as sig_user for single");
|
||||
|
||||
entry value = entry::string_type(strValue);
|
||||
int timeutc = time(NULL);
|
||||
boost::int64_t timeutc = GetAdjustedTime();
|
||||
|
||||
ses->dht_putData(strUsername, strResource, multi, value, strSigUser, timeutc, seq);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user