mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-22 20:44:56 +00:00
add timeout parameters to dhtget allowing to wait more to collect multiple replies
This commit is contained in:
parent
1ff690e9a0
commit
d1a17dc21f
@ -1264,6 +1264,9 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector<std::stri
|
||||
if (strMethod == "verifychain" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||
if (strMethod == "dhtput" && n > 3) ConvertToValue(params[3]);
|
||||
if (strMethod == "dhtput" && n > 5) ConvertTo<boost::int64_t>(params[5]);
|
||||
if (strMethod == "dhtget" && n > 3) ConvertTo<boost::int64_t>(params[3]);
|
||||
if (strMethod == "dhtget" && n > 4) ConvertTo<boost::int64_t>(params[4]);
|
||||
if (strMethod == "dhtget" && n > 5) ConvertTo<boost::int64_t>(params[5]);
|
||||
if (strMethod == "newpostmsg" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||
if (strMethod == "newpostmsg" && n > 4) ConvertTo<boost::int64_t>(params[4]);
|
||||
if (strMethod == "newdirectmsg" && n > 1) ConvertTo<boost::int64_t>(params[1]);
|
||||
|
@ -1223,9 +1223,9 @@ Value dhtput(const Array& params, bool fHelp)
|
||||
|
||||
Value dhtget(const Array& params, bool fHelp)
|
||||
{
|
||||
if (fHelp || params.size() != 3)
|
||||
if (fHelp || params.size() < 3 || params.size() > 6)
|
||||
throw runtime_error(
|
||||
"dhtget <username> <resource> <s(ingle)/m(ulti)>\n"
|
||||
"dhtget <username> <resource> <s(ingle)/m(ulti)> [timeout_ms] [timeout_multi_ms] [min_multi]\n"
|
||||
"Get resource from dht network");
|
||||
|
||||
if( !ses )
|
||||
@ -1234,9 +1234,19 @@ Value dhtget(const Array& params, bool fHelp)
|
||||
string strUsername = params[0].get_str();
|
||||
string strResource = params[1].get_str();
|
||||
string strMulti = params[2].get_str();
|
||||
|
||||
bool multi = (strMulti == "m");
|
||||
|
||||
time_duration timeToWait = seconds(10);
|
||||
time_duration timeToWaitMulti = milliseconds(100);
|
||||
int minMultiReplies = 3;
|
||||
|
||||
if( params.size() > 3 )
|
||||
timeToWait = milliseconds(params[3].get_int());
|
||||
if( params.size() > 4 )
|
||||
timeToWaitMulti = milliseconds(params[4].get_int());
|
||||
if( params.size() > 5 )
|
||||
minMultiReplies = params[5].get_int();
|
||||
|
||||
alert_manager am(10, alert::dht_notification);
|
||||
sha1_hash ih = dhtTargetHash(strUsername,strResource,strMulti);
|
||||
|
||||
@ -1250,7 +1260,6 @@ Value dhtget(const Array& params, bool fHelp)
|
||||
Array ret;
|
||||
std::set<std::string> uniqueSigPs;
|
||||
|
||||
time_duration timeToWait = seconds(10);
|
||||
int repliesReceived = 0;
|
||||
while( am.wait_for_alert(timeToWait) ) {
|
||||
std::auto_ptr<alert> a(am.get());
|
||||
@ -1279,8 +1288,8 @@ Value dhtget(const Array& params, bool fHelp)
|
||||
}
|
||||
|
||||
if( multi ) {
|
||||
if( repliesReceived++ < 3 && uniqueSigPs.size() ) {
|
||||
timeToWait = milliseconds(100 / repliesReceived);
|
||||
if( repliesReceived++ < minMultiReplies && uniqueSigPs.size() ) {
|
||||
timeToWait = timeToWaitMulti;
|
||||
//printf("dhtget: wait again %d\n", repliesReceived);
|
||||
} else {
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user