Improvements to IntroServer Mode:

* Move Dirs to .retroshare/<sslid>/
 * Automatically make directories.
 * Create 2 files: key & lobby name, cannot make 3rd file: hyperlink from nogui.
 * chmod NEWCERTS directory to 777
 * delete old peers at startup, reload peers from config file.
 * Add Date to Lobby name.

Improvements not done yet:
 - Remove inactive peers - it is tricky to tell the difference between unconnected and old.
 - Cannot make 3rd file: hyperlink from nogui.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@4937 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2012-02-14 00:45:57 +00:00
parent 363c7d8f41
commit 4ab4d60492
2 changed files with 123 additions and 10 deletions

View File

@ -25,6 +25,8 @@
#include <retroshare/rsmsgs.h> #include <retroshare/rsmsgs.h>
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
#include <retroshare/rsinit.h>
#include "util/folderiterator.h" #include "util/folderiterator.h"
#include "util/rsdir.h" #include "util/rsdir.h"
#include "util/rsstring.h" #include "util/rsstring.h"
@ -46,6 +48,9 @@
#define MAX_PEER_AGE (3600 * 24 * 14) // 2 weeks. #define MAX_PEER_AGE (3600 * 24 * 14) // 2 weeks.
//#define MAX_PEER_AGE (600) // 10 minutes - for testing //#define MAX_PEER_AGE (600) // 10 minutes - for testing
#define LOBBY_BASENAME "Chat Server"
RsIntroServer::RsIntroServer() RsIntroServer::RsIntroServer()
:mStartTS(0) :mStartTS(0)
{ {
@ -58,12 +63,32 @@ RsIntroServer::RsIntroServer()
mMaxPeerAge = MAX_PEER_AGE; mMaxPeerAge = MAX_PEER_AGE;
setupChatLobbies(); std::string sslDir = RsInit::RsConfigDirectory();
std::string certsDir = sslDir + "/NEWCERTS";
std::string peersDir = sslDir + "/STORAGE";
RsDirUtil::checkCreateDirectory(certsDir);
RsDirUtil::checkCreateDirectory(peersDir);
// chmod certsDir -> so WebServer can write to it.
// might be UNIX specific!
chmod(certsDir.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
mPeersFile = peersDir + "/peers.txt";
mCertLoadPath = certsDir;
std::string genericLobbyName;
removeAllPeers();
setupChatLobbies(genericLobbyName);
createConfigFiles(peersDir, genericLobbyName);
mPeersFile = "./STORAGE/peers.txt";
mCertLoadPath = "./NEWCERTS";
mStorePeers = new RsIntroStore(mPeersFile); mStorePeers = new RsIntroStore(mPeersFile);
mStorePeers->loadPeers(); mStorePeers->loadPeers();
restoreStoredPeers();
} }
@ -90,16 +115,25 @@ int RsIntroServer::tick()
} }
int RsIntroServer::setupChatLobbies(std::string &genericLobbyName)
int RsIntroServer::setupChatLobbies()
{ {
std::cerr << "RsIntroServer::setupChatLobbies()"; std::cerr << "RsIntroServer::setupChatLobbies()";
std::cerr << std::endl; std::cerr << std::endl;
std::string englishLobbyName = "Meeting Place (English)"; // get a date/time string.
std::string germanLobbyName = "Meeting Place (German)"; time_t now = time(NULL);
std::string frenchLobbyName = "Meeting Place (French)"; std::string tstr = ctime(&now);
std::string trimmedstr = tstr.substr(0, 16);
genericLobbyName = LOBBY_BASENAME;
std::string englishLobbyName = LOBBY_BASENAME;
std::string germanLobbyName = LOBBY_BASENAME;
std::string frenchLobbyName = LOBBY_BASENAME;
genericLobbyName += " " + trimmedstr;
englishLobbyName += " (EN) " + trimmedstr;
germanLobbyName += " (DE) " + trimmedstr;
frenchLobbyName += " (FR) " + trimmedstr;
std::list<std::string> emptyList; std::list<std::string> emptyList;
uint32_t lobby_privacy_type = RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC; uint32_t lobby_privacy_type = RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC;
@ -111,6 +145,36 @@ int RsIntroServer::setupChatLobbies()
return 1; return 1;
} }
int RsIntroServer::createConfigFiles(std::string peersDir, std::string lobbyName)
{
/* write three files: server key, hyperlink & lobbyname */
std::string serverfile = peersDir + "/serverkey.txt";
//std::string hyperfile = peersDir + "/hyperlink.txt";
std::string lobbyfile = peersDir + "/lobbyname.txt";
std::ofstream fd1(serverfile.c_str());
//std::ofstream fd2(hyperfile.c_str());
std::ofstream fd3(lobbyfile.c_str());
if (fd1)
{
fd1 << rsPeers->GetRetroshareInvite(false);
fd1 << std::endl;
fd1.close();
}
if (fd3)
{
fd3 << lobbyName << std::endl;
fd3.close();
}
return 1;
}
int RsIntroServer::addCertificateFile(std::string filepath) int RsIntroServer::addCertificateFile(std::string filepath)
{ {
std::cerr << "RsIntroServer::addCertificateFile(" << filepath << ")"; std::cerr << "RsIntroServer::addCertificateFile(" << filepath << ")";
@ -310,6 +374,52 @@ int RsIntroServer::cleanOldPeers()
} }
int RsIntroServer::restoreStoredPeers()
{
std::cerr << "RsIntroServer::restoreStoredPeers()";
std::cerr << std::endl;
std::list<std::string> oldIds;
std::list<std::string>::iterator it;
time_t now = time(NULL);
mStorePeers->getPeersBeforeTS(now, oldIds);
for(it = oldIds.begin(); it != oldIds.end(); it++)
{
std::cerr << "RsIntroServer::restoreStoredPeers() Restoring: " << *it;
std::cerr << std::endl;
std::string emptySslId;
rsPeers->addFriend(emptySslId, *it);
}
return 1;
}
int RsIntroServer::removeAllPeers()
{
std::cerr << "RsIntroServer::removeAllPeers()";
std::cerr << std::endl;
std::list<std::string> oldIds;
std::list<std::string>::iterator it;
rsPeers->getGPGAcceptedList(oldIds);
for(it = oldIds.begin(); it != oldIds.end(); it++)
{
std::cerr << "RsIntroServer::removeAllPeers() Removing: " << *it;
std::cerr << std::endl;
rsPeers->removeFriend(*it);
}
return 1;
}
int RsIntroServer::displayPeers() int RsIntroServer::displayPeers()
{ {

View File

@ -47,7 +47,10 @@ int displayPeers();
int addCertificateFile(std::string); int addCertificateFile(std::string);
int addNewUser(std::string certificate); int addNewUser(std::string certificate);
int setupChatLobbies(); int setupChatLobbies(std::string &genericLobbyName);
int createConfigFiles(std::string peersDir, std::string lobbyName);
int restoreStoredPeers();
int removeAllPeers();
int checkForNewCerts(); int checkForNewCerts();
int cleanOldPeers(); int cleanOldPeers();