From 4ab4d60492169a1d13c622137234f4432f2aae5c Mon Sep 17 00:00:00 2001 From: drbob Date: Tue, 14 Feb 2012 00:45:57 +0000 Subject: [PATCH] Improvements to IntroServer Mode: * Move Dirs to .retroshare// * 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 --- retroshare-nogui/src/introserver.cc | 128 ++++++++++++++++++++++++++-- retroshare-nogui/src/introserver.h | 5 +- 2 files changed, 123 insertions(+), 10 deletions(-) diff --git a/retroshare-nogui/src/introserver.cc b/retroshare-nogui/src/introserver.cc index 4620bccc5..49ca08f5d 100644 --- a/retroshare-nogui/src/introserver.cc +++ b/retroshare-nogui/src/introserver.cc @@ -25,6 +25,8 @@ #include #include +#include + #include "util/folderiterator.h" #include "util/rsdir.h" #include "util/rsstring.h" @@ -46,6 +48,9 @@ #define MAX_PEER_AGE (3600 * 24 * 14) // 2 weeks. //#define MAX_PEER_AGE (600) // 10 minutes - for testing +#define LOBBY_BASENAME "Chat Server" + + RsIntroServer::RsIntroServer() :mStartTS(0) { @@ -58,12 +63,32 @@ RsIntroServer::RsIntroServer() 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->loadPeers(); + + restoreStoredPeers(); } @@ -90,16 +115,25 @@ int RsIntroServer::tick() } - - -int RsIntroServer::setupChatLobbies() +int RsIntroServer::setupChatLobbies(std::string &genericLobbyName) { std::cerr << "RsIntroServer::setupChatLobbies()"; std::cerr << std::endl; - std::string englishLobbyName = "Meeting Place (English)"; - std::string germanLobbyName = "Meeting Place (German)"; - std::string frenchLobbyName = "Meeting Place (French)"; + // get a date/time string. + time_t now = time(NULL); + 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 emptyList; uint32_t lobby_privacy_type = RS_CHAT_LOBBY_PRIVACY_LEVEL_PUBLIC; @@ -111,6 +145,36 @@ int RsIntroServer::setupChatLobbies() 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) { 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 oldIds; + std::list::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 oldIds; + std::list::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() { diff --git a/retroshare-nogui/src/introserver.h b/retroshare-nogui/src/introserver.h index b3a332d6d..13c110e51 100644 --- a/retroshare-nogui/src/introserver.h +++ b/retroshare-nogui/src/introserver.h @@ -47,7 +47,10 @@ int displayPeers(); int addCertificateFile(std::string); 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 cleanOldPeers();