mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-07 08:35:16 -04:00
Modifications to Game Launcher to fixup the display of names / status.
Added Date check to DHT Server File, so we don't download each restart. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@378 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
d05ef8d797
commit
7eeb4420fe
10 changed files with 139 additions and 20 deletions
|
@ -35,6 +35,7 @@ class DHTClient
|
|||
public:
|
||||
|
||||
/* initialise from file */
|
||||
virtual bool checkServerFile(std::string filename) = 0;
|
||||
virtual bool loadServers(std::string filename) = 0;
|
||||
virtual bool loadServersFromWeb(std::string storename) = 0;
|
||||
virtual bool loadServers(std::istream&) = 0;
|
||||
|
@ -54,6 +55,7 @@ class DHTClientDummy: public DHTClient
|
|||
public:
|
||||
|
||||
/* initialise from file */
|
||||
virtual bool checkServerFile(std::string filename) { return false; }
|
||||
virtual bool loadServers(std::string filename) { return true; }
|
||||
virtual bool loadServersFromWeb(std::string storename) { return true; }
|
||||
virtual bool loadServers(std::istream&) { return true; }
|
||||
|
|
|
@ -44,6 +44,97 @@ const std::string openDHT_Agent = "RS-HTTP-V0.4";
|
|||
|
||||
#define OPENDHT_DEBUG 1
|
||||
|
||||
bool OpenDHTClient::checkServerFile(std::string filename)
|
||||
{
|
||||
#ifdef OPENDHT_DEBUG
|
||||
std::cerr << "OpenDHTClient::checkServerFile(" << filename << ")" << std::endl;
|
||||
#endif
|
||||
|
||||
/* open the file */
|
||||
std::ifstream file(filename.c_str());
|
||||
|
||||
if (file.fail())
|
||||
{
|
||||
#ifdef OPENDHT_DEBUG
|
||||
std::cerr << "OpenDHTClient::checkServerFile() Open Failed" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/* get the first line */
|
||||
std::string line;
|
||||
getline(file, line);
|
||||
char day[16], month[16];
|
||||
int date;
|
||||
char day2[16], month2[16];
|
||||
int date2;
|
||||
|
||||
if (3 != sscanf(line.c_str(), "%15s %15s %d", day, month, &date))
|
||||
{
|
||||
#ifdef OPENDHT_DEBUG
|
||||
std::cerr << "OpenDHTClient::checkServerFile() failed file TS parse";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef OPENDHT_DEBUG
|
||||
std::cerr << "OpenDHTClient::checkServerFile() file TS month: ";
|
||||
std::cerr << month << " date: " << date << std::endl;
|
||||
#endif
|
||||
|
||||
/* store current timestamp */
|
||||
struct tm result;
|
||||
time_t now = time(NULL);
|
||||
char nowstr[1023];
|
||||
|
||||
asctime_r(gmtime_r(&now, &result), nowstr);
|
||||
|
||||
if (3 != sscanf(nowstr, "%15s %15s %d", day2, month2, &date2))
|
||||
{
|
||||
#ifdef OPENDHT_DEBUG
|
||||
std::cerr << "OpenDHTClient::checkServerFile() failed now TS parse";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef OPENDHT_DEBUG
|
||||
std::cerr << "OpenDHTClient::checkServerFile() current TS month: ";
|
||||
std::cerr << month2 << " date: " << date2 << std::endl;
|
||||
#endif
|
||||
|
||||
/* if month is different */
|
||||
if (0 != strcmp(month, month2))
|
||||
{
|
||||
#ifdef OPENDHT_DEBUG
|
||||
std::cerr << "OpenDHTClient::checkServerFile() different MONTHS fail";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/* if month is different */
|
||||
int delta = abs(date-date2);
|
||||
if (delta > 2)
|
||||
{
|
||||
#ifdef OPENDHT_DEBUG
|
||||
std::cerr << "OpenDHTClient::checkServerFile() fail - large DATE diff: " << delta;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef OPENDHT_DEBUG
|
||||
std::cerr << "OpenDHTClient::checkServerFile() file is up-to-date!";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool OpenDHTClient::loadServers(std::string filename)
|
||||
{
|
||||
/* open the file */
|
||||
|
|
|
@ -55,6 +55,7 @@ virtual bool publishKey(std::string key, std::string value, uint32_t ttl);
|
|||
virtual bool searchKey(std::string key, std::list<std::string> &values);
|
||||
|
||||
/* Fns accessing data */
|
||||
virtual bool checkServerFile(std::string filename);
|
||||
virtual bool loadServers(std::string filename);
|
||||
virtual bool loadServersFromWeb(std::string storefname);
|
||||
virtual bool loadServers(std::istream&);
|
||||
|
|
|
@ -122,7 +122,12 @@ bool OpenDHTMgr::init()
|
|||
}
|
||||
filename += "ODHTservers.txt";
|
||||
|
||||
if (!mClient -> loadServersFromWeb(filename))
|
||||
/* check file date first */
|
||||
if (mClient -> checkServerFile(filename))
|
||||
{
|
||||
return mClient -> loadServers(filename);
|
||||
}
|
||||
else if (!mClient -> loadServersFromWeb(filename))
|
||||
{
|
||||
return mClient -> loadServers(filename);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue