merged before commit

This commit is contained in:
csoler 2015-08-15 10:10:23 -04:00
commit d09b636cda
3 changed files with 298 additions and 252 deletions

View File

@ -59,7 +59,7 @@
const uint8_t RsTokenService::GXS_REQUEST_V2_STATUS_FINISHED_INCOMPLETE = 3;
const uint8_t RsTokenService::GXS_REQUEST_V2_STATUS_COMPLETE = 4;
const uint8_t RsTokenService::GXS_REQUEST_V2_STATUS_DONE = 5; // ONCE ALL DATA RETRIEVED.
const uint8_t RsTokenService::GXS_REQUEST_V2_STATUS_CANCELLED = 6;
/***********
* #define DATA_DEBUG 1
@ -367,13 +367,19 @@ uint32_t RsGxsDataAccess::requestStatus(uint32_t token)
return status;
}
bool RsGxsDataAccess::cancelRequest(const uint32_t& token)
{
return clearRequest(token);
RsStackMutex stack(mDataMutex); /****** LOCKED *****/
GxsRequest* req = locked_retrieveRequest(token);
if (!req)
{
return false;
}
req->status = GXS_REQUEST_V2_STATUS_CANCELLED;
return true;
}
bool RsGxsDataAccess::clearRequest(const uint32_t& token)
@ -389,7 +395,7 @@ bool RsGxsDataAccess::clearRequest(const uint32_t& token)
}
delete it->second;
mRequests.erase(it->first);
mRequests.erase(it);
return true;
}
@ -707,7 +713,6 @@ bool RsGxsDataAccess::getGroupList(const uint32_t& token, std::list<RsGxsGroupId
return true;
}
GxsRequest* RsGxsDataAccess::locked_retrieveRequest(const uint32_t& token)
{
@ -722,15 +727,84 @@ GxsRequest* RsGxsDataAccess::locked_retrieveRequest(const uint32_t& token)
void RsGxsDataAccess::processRequests()
{
std::list<uint32_t> toClear;
std::list<uint32_t>::iterator cit;
time_t now = time(NULL);
std::map<uint32_t, GxsRequest*>::iterator it;
{
RsStackMutex stack(mDataMutex); /******* LOCKED *******/
std::map<uint32_t, GxsRequest*>::iterator it;
// process status of the requests
for (it = mRequests.begin(); it != mRequests.end(); ++it)
{
GxsRequest* req = it->second;
switch (req->status)
{
case GXS_REQUEST_V2_STATUS_PENDING:
// process request later
break;
case GXS_REQUEST_V2_STATUS_PARTIAL:
// should not happen
req->status = GXS_REQUEST_V2_STATUS_COMPLETE;
break;
case GXS_REQUEST_V2_STATUS_DONE:
#ifdef DATA_DEBUG
std::cerr << "RsGxsDataAccess::processrequests() Clearing Done Request Token: " << req->token;
std::cerr << std::endl;
#endif
toClear.push_back(req->token);
break;
case GXS_REQUEST_V2_STATUS_CANCELLED:
#ifdef DATA_DEBUG
std::cerr << "RsGxsDataAccess::processrequests() Clearing Cancelled Request Token: " << req->token;
std::cerr << std::endl;
#endif
toClear.push_back(req->token);
break;
default:
if (now - req->reqTime > MAX_REQUEST_AGE)
{
#ifdef DATA_DEBUG
std::cerr << "RsGxsDataAccess::processrequests() Clearing Old Request Token: " << req->token;
std::cerr << std::endl;
#endif
toClear.push_back(req->token);
}
}
}
} // END OF MUTEX.
// clear requests
std::list<uint32_t>::iterator cit;
for (cit = toClear.begin(); cit != toClear.end(); ++cit)
{
clearRequest(*cit);
}
// process requests
while (true)
{
GxsRequest* req = NULL;
{
RsStackMutex stack(mDataMutex); /******* LOCKED *******/
// get the first pending request
for (it = mRequests.begin(); it != mRequests.end(); ++it)
{
GxsRequest* reqCheck = it->second;
if (reqCheck->status == GXS_REQUEST_V2_STATUS_PENDING)
{
req = reqCheck;
req->status = GXS_REQUEST_V2_STATUS_PARTIAL;
break;
}
}
} // END OF MUTEX.
if (!req) {
break;
}
GroupMetaReq* gmr;
GroupDataReq* gdr;
@ -739,101 +813,69 @@ void RsGxsDataAccess::processRequests()
MsgMetaReq* mmr;
MsgDataReq* mdr;
MsgIdReq* mir;
MsgRelatedInfoReq* mri;
GroupStatisticRequest* gsr;
ServiceStatisticRequest* ssr;
MsgRelatedInfoReq* mri;
GroupStatisticRequest* gsr;
ServiceStatisticRequest* ssr;
for(it = mRequests.begin(); it != mRequests.end(); ++it)
#ifdef DATA_DEBUG
std::cerr << "RsGxsDataAccess::processRequests() Processing Token: " << req->token << " Status: "
<< req->status << " ReqType: " << req->reqType << " Age: "
<< now - req->reqTime << std::endl;
#endif
/* PROCESS REQUEST! */
bool ok = false;
if((gmr = dynamic_cast<GroupMetaReq*>(req)) != NULL)
{
GxsRequest* req = it->second;
if (req->status == GXS_REQUEST_V2_STATUS_PENDING)
{
#ifdef DATA_DEBUG
std::cerr << "RsGxsDataAccess::processRequests() Processing Token: " << req->token << " Status: "
<< req->status << " ReqType: " << req->reqType << " Age: "
<< now - req->reqTime << std::endl;
#endif
req->status = GXS_REQUEST_V2_STATUS_PARTIAL;
/* PROCESS REQUEST! */
if((gmr = dynamic_cast<GroupMetaReq*>(req)) != NULL)
{
getGroupSummary(gmr);
}
else if((gdr = dynamic_cast<GroupDataReq*>(req)) != NULL)
{
getGroupData(gdr);
}
else if((gir = dynamic_cast<GroupIdReq*>(req)) != NULL)
{
getGroupList(gir);
}
else if((mmr = dynamic_cast<MsgMetaReq*>(req)) != NULL)
{
getMsgSummary(mmr);
}
else if((mdr = dynamic_cast<MsgDataReq*>(req)) != NULL)
{
getMsgData(mdr);
}
else if((mir = dynamic_cast<MsgIdReq*>(req)) != NULL)
{
getMsgList(mir);
}
else if((mri = dynamic_cast<MsgRelatedInfoReq*>(req)) != NULL)
{
getMsgRelatedInfo(mri);
}
else if((gsr = dynamic_cast<GroupStatisticRequest*>(req)) != NULL)
{
getGroupStatistic(gsr);
}
else if((ssr = dynamic_cast<ServiceStatisticRequest*>(req)) != NULL)
{
getServiceStatistic(ssr);
}
else
{
std::cerr << "RsGxsDataAccess::processRequests() Failed to process request, token: "
<< req->token << std::endl;
req->status = GXS_REQUEST_V2_STATUS_FAILED;
}
}
else if (req->status == GXS_REQUEST_V2_STATUS_PARTIAL)
{
req->status = GXS_REQUEST_V2_STATUS_COMPLETE;
}
else if (req->status == GXS_REQUEST_V2_STATUS_DONE)
{
#ifdef DATA_DEBUG
std::cerr << "RsGxsDataAccess::processrequests() Clearing Done Request Token: "
<< req->token;
std::cerr << std::endl;
#endif
toClear.push_back(req->token);
}
else if (now - req->reqTime > MAX_REQUEST_AGE)
{
#ifdef DATA_DEBUG
std::cerr << "RsGxsDataAccess::processrequests() Clearing Old Request Token: " << req->token;
std::cerr << std::endl;
#endif
toClear.push_back(req->token);
}
ok = getGroupSummary(gmr);
}
else if((gdr = dynamic_cast<GroupDataReq*>(req)) != NULL)
{
ok = getGroupData(gdr);
}
else if((gir = dynamic_cast<GroupIdReq*>(req)) != NULL)
{
ok = getGroupList(gir);
}
else if((mmr = dynamic_cast<MsgMetaReq*>(req)) != NULL)
{
ok = getMsgSummary(mmr);
}
else if((mdr = dynamic_cast<MsgDataReq*>(req)) != NULL)
{
ok = getMsgData(mdr);
}
else if((mir = dynamic_cast<MsgIdReq*>(req)) != NULL)
{
ok = getMsgList(mir);
}
else if((mri = dynamic_cast<MsgRelatedInfoReq*>(req)) != NULL)
{
ok = getMsgRelatedInfo(mri);
}
else if((gsr = dynamic_cast<GroupStatisticRequest*>(req)) != NULL)
{
ok = getGroupStatistic(gsr);
}
else if((ssr = dynamic_cast<ServiceStatisticRequest*>(req)) != NULL)
{
ok = getServiceStatistic(ssr);
}
else
{
std::cerr << "RsGxsDataAccess::processRequests() Failed to process request, token: "
<< req->token << std::endl;
}
} // END OF MUTEX.
for(cit = toClear.begin(); cit != toClear.end(); ++cit)
{
clearRequest(*cit);
{
RsStackMutex stack(mDataMutex); /******* LOCKED *******/
if (req->status == GXS_REQUEST_V2_STATUS_PARTIAL)
{
req->status = ok ? GXS_REQUEST_V2_STATUS_COMPLETE : GXS_REQUEST_V2_STATUS_FAILED;
}
} // END OF MUTEX.
}
return;
}
bool RsGxsDataAccess::getGroupStatistic(const uint32_t &token, GxsGroupStatistic &grpStatistic)
@ -1719,7 +1761,7 @@ bool RsGxsDataAccess::checkRequestStatus(const uint32_t& token,
GxsRequest* req = locked_retrieveRequest(token);
if(req == NULL)
if (req == NULL || req->status == GXS_REQUEST_V2_STATUS_CANCELLED)
return false;
anstype = req->ansType;

View File

@ -121,6 +121,7 @@ public:
static const uint8_t GXS_REQUEST_V2_STATUS_FINISHED_INCOMPLETE;
static const uint8_t GXS_REQUEST_V2_STATUS_COMPLETE;
static const uint8_t GXS_REQUEST_V2_STATUS_DONE; // ONCE ALL DATA RETRIEVED.
static const uint8_t GXS_REQUEST_V2_STATUS_CANCELLED;
public:

View File

@ -511,175 +511,178 @@ behind a firewall or a VPN.</string>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>IP blacklist</string>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QTableWidget" name="filteredIpsTable">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This list gets automatically filled with information gathered at multiple sources: masquerading peers reported by the DHT, IP ranges entered by you, and IP ranges reported by your friends. Default settings should protect you against large scale traffic relaying.&lt;/p&gt;&lt;p&gt;Automatically guessing masquerading IPs can put your friends IPs in the blacklist. In this case, use the context menu to whitelist them.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>IP range</string>
<widget class="QWidget" name="tabWidgetPage1" native="true">
<attribute name="title">
<string>IP blacklist</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QTableWidget" name="filteredIpsTable">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</column>
<column>
<property name="text">
<string>Status</string>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This list gets automatically filled with information gathered at multiple sources: masquerading peers reported by the DHT, IP ranges entered by you, and IP ranges reported by your friends. Default settings should protect you against large scale traffic relaying.&lt;/p&gt;&lt;p&gt;Automatically guessing masquerading IPs can put your friends IPs in the blacklist. In this case, use the context menu to whitelist them.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</column>
<column>
<property name="text">
<string>Origin</string>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
</column>
<column>
<property name="text">
<string>Reason</string>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
</column>
<column>
<property name="text">
<string>Comment</string>
<property name="sortingEnabled">
<bool>false</bool>
</property>
</column>
</widget>
</item>
<item>
<widget class="QCheckBox" name="includeFromFriends_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is very drastic, be careful. Since masquerading IPs might be actual real IPs, this option might cause disconnection, and will probably force you to add your friends' IPs into the whitelist.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Ban every IP reported by your friends</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="includeFromDHT_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Another drastic option. If you use it, be prepared to add your friends' IPs into the whitelist when needed.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Ban every masquerading IP reported by your DHT</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QCheckBox" name="groupIPRanges_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If used alone, this option protects you quite well from large scale IP masquerading.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>Automatically ban ranges of DHT masquerading IPs starting at</string>
<string>IP range</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="groupIPRanges_SB">
<property name="suffix">
<string> IPs</string>
</column>
<column>
<property name="text">
<string>Status</string>
</property>
<property name="minimum">
<number>2</number>
</column>
<column>
<property name="text">
<string>Origin</string>
</property>
<property name="maximum">
<number>255</number>
</column>
<column>
<property name="text">
<string>Reason</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</column>
<column>
<property name="text">
<string>Comment</string>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>IP whitelist</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_9">
<item>
<widget class="QTableWidget" name="whiteListIpsTable">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;White listed IPs are gathered from the following sources: IPs coming inside a manually exchanged certificate, IP ranges entered by you in this window, or in the security feed items.&lt;/p&gt;&lt;p&gt;The default behavior for Retroshare is to (1) always allow connection to peers with IP in the whitelist, even if that IP is also blacklisted; (2) optionally require IPs to be in the whitelist. You can change this behavior for each peer in the &amp;quot;Details&amp;quot; window of each Retroshare node. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>IP range</string>
</column>
</widget>
</item>
<item>
<widget class="QCheckBox" name="includeFromFriends_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is very drastic, be careful. Since masquerading IPs might be actual real IPs, this option might cause disconnection, and will probably force you to add your friends' IPs into the whitelist.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</column>
<column>
<property name="text">
<string>Status</string>
<string>Ban every IP reported by your friends</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="includeFromDHT_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Another drastic option. If you use it, be prepared to add your friends' IPs into the whitelist when needed.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</column>
<column>
<property name="text">
<string>Origin</string>
<string>Ban every masquerading IP reported by your DHT</string>
</property>
</column>
<column>
<property name="text">
<string>Reason</string>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item>
<widget class="QCheckBox" name="groupIPRanges_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If used alone, this option protects you quite well from large scale IP masquerading.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>Automatically ban ranges of DHT masquerading IPs starting at</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="groupIPRanges_SB">
<property name="suffix">
<string> IPs</string>
</property>
<property name="minimum">
<number>2</number>
</property>
<property name="maximum">
<number>255</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_3">
<attribute name="title">
<string>IP whitelist</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QTableWidget" name="whiteListIpsTable">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
</column>
<column>
<property name="text">
<string>Comment</string>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;White listed IPs are gathered from the following sources: IPs coming inside a manually exchanged certificate, IP ranges entered by you in this window, or in the security feed items.&lt;/p&gt;&lt;p&gt;The default behavior for Retroshare is to (1) always allow connection to peers with IP in the whitelist, even if that IP is also blacklisted; (2) optionally require IPs to be in the whitelist. You can change this behavior for each peer in the &amp;quot;Details&amp;quot; window of each Retroshare node. &lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</column>
</widget>
</item>
</layout>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="sortingEnabled">
<bool>false</bool>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>IP range</string>
</property>
</column>
<column>
<property name="text">
<string>Status</string>
</property>
</column>
<column>
<property name="text">
<string>Origin</string>
</property>
</column>
<column>
<property name="text">
<string>Reason</string>
</property>
</column>
<column>
<property name="text">
<string>Comment</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
<item>