mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-09-11 22:02:06 +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,
|
void dht_putData(std::string const &username, std::string const &resource, bool multi,
|
||||||
entry const &value, std::string const &sig_user,
|
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);
|
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,
|
void putData(std::string const &username, std::string const &resource, bool multi,
|
||||||
entry const &value, std::string const &sig_user,
|
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,
|
void getData(std::string const &username, std::string const &resource, bool multi,
|
||||||
boost::function<void(entry::list_type const&)> fdata,
|
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,
|
void putData(std::string const &username, std::string const &resource, bool multi,
|
||||||
entry const &value, std::string const &sig_user,
|
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,
|
void getData(std::string const &username, std::string const &resource, bool multi,
|
||||||
boost::function<void(entry::list_type const&)> fdata,
|
boost::function<void(entry::list_type const&)> fdata,
|
||||||
|
@ -440,7 +440,7 @@ namespace libtorrent
|
|||||||
// [MF] twister
|
// [MF] twister
|
||||||
void dht_putData(std::string const &username, std::string const &resource, bool multi,
|
void dht_putData(std::string const &username, std::string const &resource, bool multi,
|
||||||
entry const &value, std::string const &sig_user,
|
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);
|
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,
|
void dht_tracker::putData(std::string const &username, std::string const &resource, bool multi,
|
||||||
entry const &value, std::string const &sig_user,
|
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);
|
m_dht.putData(username,resource, multi, value, sig_user, timeutc, seq);
|
||||||
}
|
}
|
||||||
|
@ -309,7 +309,7 @@ namespace
|
|||||||
node_impl& node,
|
node_impl& node,
|
||||||
std::string const &username, std::string const &resource, bool multi,
|
std::string const &username, std::string const &resource, bool multi,
|
||||||
entry const &value, std::string const &sig_user,
|
entry const &value, std::string const &sig_user,
|
||||||
int timeutc, int seq)
|
boost::int64_t timeutc, int seq)
|
||||||
{
|
{
|
||||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
TORRENT_LOG(node) << "sending putData [ username: " << username
|
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,
|
void node_impl::putData(std::string const &username, std::string const &resource, bool multi,
|
||||||
entry const &value, std::string const &sig_user,
|
entry const &value, std::string const &sig_user,
|
||||||
int timeutc, int seq)
|
boost::int64_t timeutc, int seq)
|
||||||
{
|
{
|
||||||
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
#ifdef TORRENT_DHT_VERBOSE_LOGGING
|
||||||
TORRENT_LOG(node) << "putData [ username: " << info_hash << " res: " << resource << " ]" ;
|
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,
|
void session::dht_putData(std::string const &username, std::string const &resource, bool multi,
|
||||||
entry const &value, std::string const &sig_user,
|
entry const &value, std::string const &sig_user,
|
||||||
int timeutc, int seq)
|
boost::int64_t timeutc, int seq)
|
||||||
{
|
{
|
||||||
#ifndef TORRENT_DISABLE_DHT
|
#ifndef TORRENT_DISABLE_DHT
|
||||||
TORRENT_ASYNC_CALL7(dht_putData, username, resource, multi, value, sig_user, timeutc, seq);
|
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,
|
void session_impl::dht_putData(std::string const &username, std::string const &resource, bool multi,
|
||||||
entry const &value, std::string const &sig_user,
|
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);
|
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());
|
return std::string((const char *)&vchSig[0], vchSig.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool getUserPubKey(std::string const &strUsername, CPubKey &pubkey)
|
||||||
bool verifySignature(std::string const &strMessage, std::string const &strUsername, std::string const &strSign)
|
|
||||||
{
|
{
|
||||||
CPubKey pubkey;
|
|
||||||
{
|
{
|
||||||
CKeyID keyID;
|
CKeyID keyID;
|
||||||
if( pwalletMain->GetKeyIdFromUsername(strUsername, keyID) ) {
|
if( pwalletMain->GetKeyIdFromUsername(strUsername, keyID) ) {
|
||||||
@ -486,21 +484,32 @@ bool verifySignature(std::string const &strMessage, std::string const &strUserna
|
|||||||
uint256 hashBlock;
|
uint256 hashBlock;
|
||||||
uint256 userhash = SerializeHash(strUsername);
|
uint256 userhash = SerializeHash(strUsername);
|
||||||
if( !GetTransaction(userhash, txOut, hashBlock) ) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector< std::vector<unsigned char> > vData;
|
std::vector< std::vector<unsigned char> > vData;
|
||||||
if( !txOut.pubKey.ExtractPushData(vData) || vData.size() < 1 ) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
pubkey = CPubKey(vData[0]);
|
pubkey = CPubKey(vData[0]);
|
||||||
if( !pubkey.IsValid() ) {
|
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 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(),
|
vector<unsigned char> vchSig((const unsigned char*)strSign.data(),
|
||||||
(const unsigned char*)strSign.data() + strSign.size());
|
(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
|
"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"];
|
entry &userpost = v["userpost"];
|
||||||
|
|
||||||
//
|
//
|
||||||
userpost["n"] = username;
|
userpost["n"] = username;
|
||||||
userpost["k"] = k;
|
userpost["k"] = k;
|
||||||
|
userpost["time"] = GetAdjustedTime();
|
||||||
userpost["height"] = getBestHeight() - 1; // be conservative
|
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;
|
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()
|
int getBestHeight()
|
||||||
{
|
{
|
||||||
return nBestHeight;
|
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");
|
throw JSONRPCError(RPC_WALLET_ERROR, "Username must be the same as sig_user for single");
|
||||||
|
|
||||||
entry value = entry::string_type(strValue);
|
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);
|
ses->dht_putData(strUsername, strResource, multi, value, strSigUser, timeutc, seq);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user