Commit of the new UDP Connection methods and

the rewrite of the retroshare core networking stack.

This check-in commits the changes to the rsserver code.
Major changes to use the new networking code. Added
p3peers.h as a new interface for peer/neighbour management.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@314 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2008-01-25 07:58:29 +00:00
parent 7c2d5611bd
commit fd8adceb7e
13 changed files with 1039 additions and 701 deletions

View File

@ -2,14 +2,18 @@
RS_TOP_DIR = .. RS_TOP_DIR = ..
include ../make.opt include ../make.opt
OBJ = pqistrings.o \ OBJ = p3face-file.o \
p3face-people.o p3face-file.o \ p3face-msgs.o \
p3face-msgs.o p3face-server.o \ p3face-server.o \
p3face-config.o \ p3face-config.o \
p3face-network.o \
p3face-startup.o \ p3face-startup.o \
rstypes.o \ rstypes.o \
rsiface.o rsiface.o \
p3peers.o
# pqistrings.o \
# p3face-people.o
# p3face-network.o \
TESTS = TESTS =

View File

@ -106,7 +106,7 @@ int RsServer::ConfigSetIncomingDir( std::string dir )
} }
#ifdef MOVE_TO_RS_NETWORK #if 0
int RsServer::ConfigSetLocalAddr( std::string ipAddr, int port ) int RsServer::ConfigSetLocalAddr( std::string ipAddr, int port )
{ {
@ -182,7 +182,6 @@ int RsServer::ConfigSetExtAddr( std::string ipAddr, int port )
return 1; return 1;
} }
#endif /* MOVE_TO_RS_NETWORK */
int RsServer::ConfigSetLanConfig( bool firewalled, bool forwarded ) int RsServer::ConfigSetLanConfig( bool firewalled, bool forwarded )
@ -239,6 +238,7 @@ int RsServer::ConfigSetExtName( std::string addr )
return 1; return 1;
} }
#endif /* 0 */
int RsServer::ConfigSetDataRates( int total, int indiv ) /* in kbrates */ int RsServer::ConfigSetDataRates( int total, int indiv ) /* in kbrates */
{ {
@ -283,42 +283,26 @@ int RsServer::UpdateAllConfig()
RsConfig &config = iface.mConfig; RsConfig &config = iface.mConfig;
cert *own = sslr -> getOwnCert(); config.ownId = mAuthMgr->OwnId();
config.ownName = mAuthMgr->getName(config.ownId);
/* set the id. */ peerConnectState pstate;
{ mConnMgr->getOwnNetStatus(pstate);
RsCertId rid = intGetCertId(own);
std::ostringstream out;
out << rid;
config.ownId = out.str();
}
config.ownName = own->Name();
/* shared dirs */ /* shared dirs */
std::list<std::string> &dirs = server -> getSearchDirectories(); std::list<std::string> &dirs = server -> getSearchDirectories();
config.sharedDirList = dirs; config.sharedDirList = dirs;
config.incomingDir = server->getSaveDir(); config.incomingDir = server->getSaveDir();
/* ports */ /* ports */
config.localAddr = inet_ntoa(own -> localaddr.sin_addr); config.localAddr = inet_ntoa(pstate.localaddr.sin_addr);
config.localPort = ntohs(own -> localaddr.sin_port); config.localPort = ntohs(pstate.localaddr.sin_port);
config.firewalled = own -> Firewalled(); config.firewalled = true;
config.forwardPort = own -> Forwarded(); config.forwardPort = true;
if (own -> Firewalled() && !own -> Forwarded()) config.extAddr = inet_ntoa(pstate.serveraddr.sin_addr);
{ config.extPort = ntohs(pstate.serveraddr.sin_port);
config.extAddr = "0.0.0.0";
config.extPort = 0;
config.extName = "<Incoming Not Possible>";
}
else
{
config.extAddr = inet_ntoa(own -> serveraddr.sin_addr);
config.extPort = ntohs(own -> serveraddr.sin_port);
config.extName = "<Coming Soon!>";
}
/* data rates */ /* data rates */
config.maxDataRate = (int) pqih -> getMaxRate(true); /* kb */ config.maxDataRate = (int) pqih -> getMaxRate(true); /* kb */
@ -326,7 +310,11 @@ int RsServer::UpdateAllConfig()
config.promptAtBoot = true; /* popup the password prompt */ config.promptAtBoot = true; /* popup the password prompt */
/* update DHT/UPnP config */ /* update DHT/UPnP config */
UpdateNetworkConfig(config);
config.uPnPState = mConnMgr->getUPnPState();
config.uPnPActive = mConnMgr->getUPnPEnabled();
config.DHTPeers = 20;
config.DHTActive = mConnMgr->getDHTEnabled();;
/* Notify of Changes */ /* Notify of Changes */
iface.setChanged(RsIface::Config); iface.setChanged(RsIface::Config);
@ -341,28 +329,5 @@ int RsServer::UpdateAllConfig()
} }
int RsServer::ConfigSave()
{
/* fill the rsiface class */
RsIface &iface = getIface();
/* lock Mutexes */
lockRsCore(); /* LOCK */
iface.lockData(); /* LOCK */
// call save all the other parts.
server -> save_config();
ad -> save_configuration();
pqih -> save_config();
sslr -> saveCertificates();
/* unlock Mutexes */
iface.unlockData(); /* UNLOCK */
unlockRsCore(); /* UNLOCK */
return 1;
}

View File

@ -42,12 +42,7 @@ const int p3facefilezone = 11452;
static const int FileMaxAge = 1800; /* Reload Data after 30 minutes */ static const int FileMaxAge = 1800; /* Reload Data after 30 minutes */
/* add in an extension if necessary */ //int ensureExtension(std::string &name, std::string def_ext);
int ensureExtension(std::string &name, std::string def_ext)
{
return 1;
}
/****************************************/ /****************************************/
/****************************************/ /****************************************/
@ -91,27 +86,8 @@ int RsServer::UpdateAllTransfers()
{ {
FileTransferInfo ti; FileTransferInfo ti;
/* set it up */
certsign sign;
cert *c = NULL;
if (!convert_to_certsign((*it)->PeerId(), sign))
{
std::cerr << "CERTSIGN error!" << std::endl;
}
/* look it up */
c = getSSLRoot() -> findcertsign(sign);
if (c == NULL)
{
std::cerr << "CERTSIGN error! 2" << std::endl;
ti.source = "Unknown";
}
else
{
ti.source = c -> Name();
}
ti.id = (*it)->PeerId(); ti.id = (*it)->PeerId();
ti.source = mAuthMgr->getName(ti.id);
ti.peerIds = (*it) -> allPeerIds.ids; ti.peerIds = (*it) -> allPeerIds.ids;
ti.fname = (*it) -> file.name; ti.fname = (*it) -> file.name;

View File

@ -377,11 +377,7 @@ int RsServer::UpdateAllChannels()
void RsServer::initRsChatInfo(RsChatItem *c, ChatInfo &i) void RsServer::initRsChatInfo(RsChatItem *c, ChatInfo &i)
{ {
i.rsid = c -> PeerId(); i.rsid = c -> PeerId();
cert *peer = intFindCert(c->PeerId()); i.name = mAuthMgr->getName(i.rsid);
if (peer)
i.name = peer -> Name();
else
i.name = "Unknown";
i.msg = c -> message; i.msg = c -> message;
if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE) if (c -> chatFlags & RS_CHAT_FLAG_PRIVATE)
@ -514,7 +510,7 @@ void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
/* translate flags, if we sent it... outgoing */ /* translate flags, if we sent it... outgoing */
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING) if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|| (msg->PeerId() == sslr->getOwnCert()->PeerId())) || (msg->PeerId() == mAuthMgr->OwnId()))
{ {
mi.msgflags |= RS_MSG_OUTGOING; mi.msgflags |= RS_MSG_OUTGOING;
} }
@ -529,11 +525,7 @@ void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
} }
mi.id = msg->PeerId(); mi.id = msg->PeerId();
cert *c = intFindCert(mi.id); mi.srcname = mAuthMgr->getName(mi.id);
if (c)
mi.srcname = c->Name();
else
mi.srcname = "Unknown";
std::list<std::string>::iterator pit; std::list<std::string>::iterator pit;
@ -542,11 +534,7 @@ void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
{ {
PersonInfo pi; PersonInfo pi;
pi.id = (*pit); pi.id = (*pit);
cert *peer = intFindCert(pi.id); pi.name = mAuthMgr->getName(pi.id);
if (peer)
pi.name = peer->Name();
else
pi.name = "Unknown";
mi.msgto.push_back(pi); mi.msgto.push_back(pi);
} }
@ -555,11 +543,7 @@ void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
{ {
PersonInfo pi; PersonInfo pi;
pi.id = (*pit); pi.id = (*pit);
cert *peer = intFindCert(pi.id); pi.name = mAuthMgr->getName(pi.id);
if (peer)
pi.name = peer->Name();
else
pi.name = "Unknown";
mi.msgcc.push_back(pi); mi.msgcc.push_back(pi);
} }
@ -568,11 +552,7 @@ void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
{ {
PersonInfo pi; PersonInfo pi;
pi.id = (*pit); pi.id = (*pit);
cert *peer = intFindCert(pi.id); pi.name = mAuthMgr->getName(pi.id);
if (peer)
pi.name = peer->Name();
else
pi.name = "Unknown";
mi.msgbcc.push_back(pi); mi.msgbcc.push_back(pi);
} }
@ -607,7 +587,7 @@ void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
int RsServer::ClearInChat() int RsServer::ClearInChat()
{ {
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
#if 0
std::list<cert *>::iterator it; std::list<cert *>::iterator it;
std::list<cert *> &certs = sslr -> getCertList(); std::list<cert *> &certs = sslr -> getCertList();
@ -617,7 +597,7 @@ int RsServer::ClearInChat()
} }
sslr->IndicateCertsChanged(); sslr->IndicateCertsChanged();
#endif
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
return 1; return 1;
@ -630,6 +610,7 @@ int RsServer::SetInChat(std::string id, bool in) /* friend : cha
/* so we send this.... */ /* so we send this.... */
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
#if 0
RsCertId rsid(id); RsCertId rsid(id);
cert *c = intFindCert(rsid); cert *c = intFindCert(rsid);
@ -643,10 +624,11 @@ int RsServer::SetInChat(std::string id, bool in) /* friend : cha
{ {
std::cerr << "FAILED TO Set InChat(" << id << ") to " << (in ? "True" : "False") << std::endl; std::cerr << "FAILED TO Set InChat(" << id << ") to " << (in ? "True" : "False") << std::endl;
} }
#endif
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
UpdateAllCerts(); //UpdateAllCerts();
return 1; return 1;
} }
@ -655,6 +637,7 @@ int RsServer::ClearInMsg()
{ {
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
#if 0
std::list<cert *>::iterator it; std::list<cert *>::iterator it;
std::list<cert *> &certs = sslr -> getCertList(); std::list<cert *> &certs = sslr -> getCertList();
@ -663,6 +646,7 @@ int RsServer::ClearInMsg()
(*it)->InMessage(false); (*it)->InMessage(false);
} }
sslr->IndicateCertsChanged(); sslr->IndicateCertsChanged();
#endif
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
@ -675,6 +659,7 @@ int RsServer::SetInMsg(std::string id, bool in) /* friend : msgs
/* so we send this.... */ /* so we send this.... */
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
#if 0
RsCertId rsid(id); RsCertId rsid(id);
cert *c = intFindCert(rsid); cert *c = intFindCert(rsid);
@ -689,9 +674,12 @@ int RsServer::SetInMsg(std::string id, bool in) /* friend : msgs
std::cerr << "FAILED to Set InMsg(" << id << ") to " << (in ? "True" : "False") << std::endl; std::cerr << "FAILED to Set InMsg(" << id << ") to " << (in ? "True" : "False") << std::endl;
} }
#endif
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
UpdateAllCerts(); //UpdateAllCerts();
return 1; return 1;
} }

View File

@ -119,40 +119,21 @@ int RsServer::FriendStatus(std::string uid, bool accept)
RsCertId id(uid); RsCertId id(uid);
cert *c = intFindCert(id); std::cerr << "RsServer::FriendStatus() " << uid << " accept: " << accept << std::endl;
std::string errstr;
int err = 0;
if ((c == NULL) || (c == sslr -> getOwnCert()))
{
if (accept) if (accept)
{ {
pqih -> cert_accept(c); mConnMgr->addFriend(uid);
pqih -> cert_auto(c, true);
} }
else else
{ {
pqih -> cert_auto(c, false); mConnMgr->removeFriend(uid);
pqih -> cert_deny(c);
}
}
else
{
/* error */
err = 1;
} }
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
if (err)
{
/* notify */
}
else
{
/* call the repopulate fn */ /* call the repopulate fn */
UpdateAllCerts(); UpdateAllCerts();
return 1;
}
return err;
} }
@ -161,34 +142,15 @@ int RsServer::FriendRemove(std::string uid)
{ {
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
RsCertId id(uid); std::cerr << "RsServer::FriendRemove() " << uid << std::endl;
cert * c = intFindCert(id); mConnMgr->removeFriend(uid);
int err = 0;
if ((c == NULL) || (c == sslr -> getOwnCert()))
{
std::cerr << "RsServer::FriendRemove() Failed ... Bad Cert or Own." << std::endl;
err = 1;
}
else
{
std::cerr << "RsServer::FriendRemove() " << c -> Name() << std::endl;
pqih -> cert_deny(c);
err = sslr -> removeCertificate(c);
}
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
if (err)
{
/* notify */
}
else
{
/* call the repopulate fn */ /* call the repopulate fn */
UpdateAllCerts(); UpdateAllCerts();
} return 1;
return err;
} }
@ -199,26 +161,13 @@ int RsServer::FriendConnectAttempt(std::string uid)
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
RsCertId id(uid); err = mConnMgr->connectFriend(uid);
cert *c = intFindCert(id);
c -> nc_timestamp = 0;
// set Firewall to off -> so we
// will definitely have connect attempt.
c -> Firewalled(false);
c -> WillConnect(true);
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
if (err)
{
/* notify */
}
else
{
/* call the repopulate fn */ /* call the repopulate fn */
UpdateAllCerts(); UpdateAllCerts();
}
return err; return err;
} }
@ -226,25 +175,7 @@ int RsServer::FriendSignCert(std::string uid)
{ {
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
RsCertId id(uid); int ret = mConnMgr->signCertificate(uid);
/* get the current cert, check that its
* in the allowed group.
*/
/* ask sslroot to sign certificate
*/
int ret = 1;
cert *c = intFindCert(id);
if ((c == NULL) || (c == sslr -> getOwnCert()))
{
ret = 0;
}
if (ret)
{
ret = sslr -> signCertificate(c);
}
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
@ -260,17 +191,8 @@ int RsServer::FriendTrustSignature(std::string uid, bool trust)
{ {
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
RsCertId id(uid);
int ret = -1; int ret = -1;
cert *c = intFindCert(id); ret = mConnMgr -> trustCertificate(uid, trust);
if ((c == NULL) || (c == sslr -> getOwnCert()))
{
return -1;
}
ret = sslr -> trustCertificate(c, !(c -> Trusted()));
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
@ -329,17 +251,9 @@ int RsServer::FriendSetLocalAddress(std::string uid,
struct sockaddr_in addr; struct sockaddr_in addr;
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
RsCertId id(uid);
int ret = 1; int ret = 1;
cert *c = intFindCert(id);
if ((c == NULL) || (c == sslr -> getOwnCert()))
{
pqioutput(PQL_ALERT, fltksrvrzone, "NULL/Own cert!");
ret = 0;
}
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/ /********************************** WINDOWS/UNIX SPECIFIC PART *******************/
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS
if (ret && (0 != inet_aton(addr_str.c_str(), &(addr.sin_addr)))) if (ret && (0 != inet_aton(addr_str.c_str(), &(addr.sin_addr))))
@ -349,11 +263,11 @@ int RsServer::FriendSetLocalAddress(std::string uid,
#endif #endif
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/ /********************************** WINDOWS/UNIX SPECIFIC PART *******************/
{ {
// get the server address. addr.sin_family = AF_INET;
c -> localaddr.sin_addr = addr.sin_addr; addr.sin_port = htons(port);
c -> localaddr.sin_port = htons(port);
/* tell SSL */ mConnMgr->setPeerLocalAddress(uid, addr);
getSSLRoot() -> IndicateCertsChanged();
ret = 1; ret = 1;
} }
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
@ -378,16 +292,9 @@ int RsServer::FriendSetExtAddress(std::string uid,
struct sockaddr_in addr; struct sockaddr_in addr;
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
RsCertId id(uid);
int ret = 1; int ret = 1;
cert *c = intFindCert(id);
if ((c == NULL) || (c == sslr -> getOwnCert()))
{
pqioutput(PQL_ALERT, fltksrvrzone, "NULL/Own cert!");
ret = 0;
}
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/ /********************************** WINDOWS/UNIX SPECIFIC PART *******************/
#ifndef WINDOWS_SYS #ifndef WINDOWS_SYS
@ -399,10 +306,10 @@ int RsServer::FriendSetExtAddress(std::string uid,
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/ /********************************** WINDOWS/UNIX SPECIFIC PART *******************/
{ {
// get the server address. // get the server address.
c -> serveraddr.sin_addr = addr.sin_addr; addr.sin_family = AF_INET;
c -> serveraddr.sin_port = htons(port); addr.sin_port = htons(port);
/* tell SSL */
getSSLRoot() -> IndicateCertsChanged(); mConnMgr->setPeerExtAddress(uid, addr);
ret = 1; ret = 1;
} }
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
@ -428,33 +335,8 @@ int RsServer::FriendSetDNSAddress(std::string uid, std::string addr_str)
int ret = 1; int ret = 1;
cert *c = intFindCert(id);
if ((c == NULL) || (c == sslr -> getOwnCert()))
{
pqioutput(PQL_ALERT, fltksrvrzone, "NULL/Own cert!");
ret = 0;
}
if (ret)
{
// get the server address.
c -> dynDNSaddr = addr_str;
/* tell SSL */
getSSLRoot() -> IndicateCertsChanged();
ret = 1;
}
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
if (ret)
{
/* notify */
UpdateAllCerts();
}
else
{
/* error message? */
intNotifyCertError(id, "Failed to Change Cert Address");
}
return ret; return ret;
} }
@ -467,30 +349,9 @@ int RsServer::FriendSaveCertificate(std::string uid, std::string fname)
int ret = 1; int ret = 1;
cert *c = intFindCert(id);
if (c == NULL)
{
pqioutput(PQL_ALERT, p3facepersonzone, "FriendSaveCertificate: Invalid cert!");
ret = 0;
}
if (ret)
{
ensureExtension(fname, "pqi"); ensureExtension(fname, "pqi");
if (c -> certificate == NULL) mConnMgr->saveCertificate(uid, fname);
{
std::ostringstream out;
out << "File Export (" << fname;
out << ") Failed -> Certificate == NULL!" << std::endl;
pqioutput(PQL_DEBUG_BASIC, p3facepersonzone, out.str());
ret = 0;
}
else
{
ret = sslr -> savecertificate(c, fname.c_str());
}
}
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
@ -526,7 +387,6 @@ int RsServer::UpdateAllCerts()
NotifyBase &cb = getNotify(); NotifyBase &cb = getNotify();
cb.notifyListPreChange(NOTIFY_LIST_FRIENDS, NOTIFY_TYPE_MOD); cb.notifyListPreChange(NOTIFY_LIST_FRIENDS, NOTIFY_TYPE_MOD);
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
@ -536,34 +396,27 @@ int RsServer::UpdateAllCerts()
int i; int i;
int ret = 1; int ret = 1;
//Fl_Funky_Browser *cb = ui -> cert_list; std::list<std::string> peers;
// Get the Current Cert, by getting current item std::list<std::string>::iterator it;
// and extracting ref.
mConnMgr->getFriendList(peers);
// only do if
if ((sslr -> CertsChanged()) ||
(sslr -> CertsMajorChanged()))
{
// clear the data. // clear the data.
std::map<RsChanId, NeighbourInfo> &frnds = iface.mFriendMap; std::map<RsChanId, NeighbourInfo> &frnds = iface.mFriendMap;
frnds.clear(); frnds.clear();
std::list<cert *>::iterator it; for(it = peers.begin(); it != peers.end(); it++)
std::list<cert *> &certs = sslr -> getCertList(); {
peerConnectState state;
mConnMgr->setFriendNetStatus(*it, state);
std::string emptystr(""); std::string emptystr("");
for(it = certs.begin(), i = 0;
it != certs.end(); it++, i++)
{
cert *c = (*it);
NeighbourInfo ni; NeighbourInfo ni;
initRsNI(c, ni); /* same as for neighbour */ initRsNI(state, ni); /* same as for neighbour */
frnds[ni.id] = ni; frnds[ni.id] = ni;
}
/* let the GUI know */ /* let the GUI know */
iface.setChanged(RsIface::Friend); iface.setChanged(RsIface::Friend);
@ -638,9 +491,6 @@ void RsServer::intNotifyChangeCert(RsCertId &id)
*/ */
/**************************** NEIGHBOUR FNS ******************* /**************************** NEIGHBOUR FNS *******************
* *
* *
@ -654,9 +504,11 @@ std::string RsServer::NeighGetInvite()
{ {
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
cert *own = sslr -> getOwnCert(); peerConnectState state;
std::string name = own -> Name(); mConnMgr->getOwnNetStatus(state);
std::string certstr = sslr -> saveCertAsString(own);
std::string name = state.name;
std::string certstr = mConnMgr -> getCertificateAsString(state.id);
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
@ -692,27 +544,7 @@ int RsServer::NeighLoadPEMString(std::string pem, std::string &id)
{ {
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
int ret = 1; id = mConnMgr -> loadCertificateAsString(pem);
std::ostringstream out;
cert *nc;
nc = sslr -> loadCertFromString(pem);
if (nc == NULL)
{
out << "Stringe Import (" << pem;
out << ") Failed!" << std::endl;
pqioutput(PQL_DEBUG_BASIC, fltksrvrzone, out.str());
ret = 0;
}
else if (0 > sslr -> addCollectedCertificate(nc))
{
out << "Imported Certificate....but no";
out << " need for addition - As it exists!";
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, fltksrvrzone, out.str());
//ret = 0; want this case to set id (as is valid!)
}
/* ensure it gets to p3disc */ /* ensure it gets to p3disc */
if (ad) if (ad)
@ -722,17 +554,12 @@ int RsServer::NeighLoadPEMString(std::string pem, std::string &id)
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
if (ret) if (id != "")
{ {
UpdateAllNetwork(); UpdateAllNetwork();
return 1;
/* set the id. */
RsCertId rid = intGetCertId(nc);
std::ostringstream out;
out << rid;
id = out.str();
} }
return ret; return 0;
} }
@ -742,27 +569,9 @@ int RsServer::NeighLoadCertificate(std::string fname, std::string &id)
int ret = 1; int ret = 1;
std::ostringstream out; lockRsCore(); /* LOCK */
std::string nullhash(""); // empty hash - as signature not correct.
cert *nc; id = mConnMgr -> loadCertificateFromFile(fname);
nc = sslr -> loadcertificate(fname.c_str(), nullhash);
if (nc == NULL)
{
out << "File Import (" << fname;
out << ") Failed!" << std::endl;
pqioutput(PQL_DEBUG_BASIC, fltksrvrzone, out.str());
ret = 0;
}
else if (0 > sslr -> addCollectedCertificate(nc))
{
out << "Imported Certificate....but no";
out << " need for addition - As it exists!";
out << std::endl;
pqioutput(PQL_DEBUG_BASIC, fltksrvrzone, out.str());
//ret = 0; want this case to set id (as is valid!)
}
/* ensure it gets to p3disc */ /* ensure it gets to p3disc */
if (ad) if (ad)
@ -772,17 +581,12 @@ int RsServer::NeighLoadCertificate(std::string fname, std::string &id)
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
if (ret) if (id != "")
{ {
UpdateAllNetwork(); UpdateAllNetwork();
return 1;
/* set the id. */
RsCertId rid = intGetCertId(nc);
std::ostringstream out;
out << rid;
id = out.str();
} }
return ret; return 0;
} }
@ -791,45 +595,8 @@ int RsServer::NeighAuthFriend(std::string uid, RsAuthId code)
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
RsCertId id(uid); RsCertId id(uid);
int ret = 1; int ret = mConnMgr -> AuthNeighbour(uid, code);
cert *c = intFindCert(id);
if ((c == NULL) || (c->certificate == NULL))
{
ret = 0;
}
else
{
std::string real_code = getXPGPAuthCode(c->certificate);
if (code == real_code) {
ret = 1;
} else {
ret = 0;
}
}
/* if correct -> sign */
if (ret)
{
if (0 < validateCertificateIsSignedByKey(c->certificate,
sslr -> getOwnCert() -> certificate))
{
std::cerr << "RsServer::cert_add_neighbour() Signed Already";
std::cerr << std::endl;
ret = 0;
}
else
{
/* if not signed already */
std::cerr << "RsServer::cert_add_neighbour() Signing Cert";
std::cerr << std::endl;
/* sign certificate */
sslr -> signCertificate(c);
}
}
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
if (ret) if (ret)
@ -845,46 +612,7 @@ int RsServer::NeighAddFriend(std::string uid)
{ {
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
int ret = 1; int ret = mConnMgr -> AddNeighbour(uid);
RsCertId id(uid);
cert *c = intFindCert(id);
if ((c == NULL) || (c->certificate == NULL)
|| (c == sslr -> getOwnCert()))
{
std::cerr << "RsServer::NeighAddFriend() Invalid Cert";
std::cerr << std::endl;
ret = 0;
}
else
{
/* check authentication */
sslr -> checkAuthCertificate(c);
if (c->trustLvl < TRUST_SIGN_AUTHEN)
{
/* do nothing */
std::cerr << "RsServer::cert_add_neighbour() Not Authed";
std::cerr << std::endl;
std::cerr << "RsServer::cert_add_neighbour() Do Nothing";
std::cerr << std::endl;
ret = 0;
}
else
{
std::cerr << "RsServer::cert_add_neighbour() Adding Cert";
std::cerr << std::endl;
/* add */
sslr -> addUntrustedCertificate(c);
std::cerr << "RsServer::cert_add_neighbour() Auto Connecting";
std::cerr << std::endl;
/* auto connect */
pqih -> cert_auto(c, true);
/* XXX: Update the Neighbour/Friends Maps */
}
}
unlockRsCore(); /* UNLOCK */ unlockRsCore(); /* UNLOCK */
@ -897,39 +625,6 @@ int RsServer::NeighAddFriend(std::string uid)
return (ret); return (ret);
} }
#if 0
std::list<std::string> RsServer::NeighGetSigners(std::string uid)
{
lockRsCore(); /* LOCK */
RsCertId id(uid);
std::list<std::string> signers;
int ret = 1;
cert *c = intFindCert(id);
if ((c == NULL) || (c->certificate == NULL))
{
ret = 0;
}
/* if valid, get signers */
if (ret)
{
signers = getXPGPsigners(c->certificate);
}
unlockRsCore(); /* UNLOCK */
return signers;
}
#endif
int RsServer::NeighGetSigners(std::string uid, char *out, int len) int RsServer::NeighGetSigners(std::string uid, char *out, int len)
{ {
lockRsCore(); /* LOCK */ lockRsCore(); /* LOCK */
@ -982,21 +677,29 @@ int RsServer::UpdateAllNetwork()
int ret = 1; int ret = 1;
int i; int i;
std::list<std::string> peers;
std::list<std::string>::iterator it;
mConnMgr->getOthersList(peers);
// clear the data. // clear the data.
std::map<RsChanId, NeighbourInfo> &neighs = iface.mNeighbourMap; std::map<RsChanId, NeighbourInfo> &neighs = iface.mNeighbourMap;
neighs.clear(); neighs.clear();
std::list<cert *>::iterator it; for(it = peers.begin(); it != peers.end(); it++)
std::list<cert *> &certs = ad -> getDiscovered();
for(it = certs.begin(), i = 0; it != certs.end(); it++, i++)
{ {
peerConnectState state;
mConnMgr->getOthersNetStatus(*it, state);
NeighbourInfo ni; NeighbourInfo ni;
cert *c = (*it);
initRsNI(c, ni); initRsNI(state, ni); /* same as for neighbour */
neighs[ni.id] = ni; neighs[ni.id] = ni;
/* let the GUI know */
iface.setChanged(RsIface::Friend);
} }
/* let the GUI know */ /* let the GUI know */

View File

@ -45,6 +45,7 @@ RsServer::~RsServer()
----> MUST BE LOCKED! ----> MUST BE LOCKED!
*/ */
#if 0
cert *RsServer::intFindCert(RsCertId id) cert *RsServer::intFindCert(RsCertId id)
{ {
certsign cs; certsign cs;
@ -59,6 +60,7 @@ RsCertId RsServer::intGetCertId(cert *c)
RsCertId id = convert_to_str(cs); RsCertId id = convert_to_str(cs);
return id; return id;
} }
#endif
#ifdef WINDOWS_SYS #ifdef WINDOWS_SYS
#include <time.h> #include <time.h>
@ -122,9 +124,14 @@ void RsServer::run()
/******************************** RUN SERVER *****************/ /******************************** RUN SERVER *****************/
lockRsCore(); lockRsCore();
// std::cerr << "RsServer::run() Lock() -> Run()" << std::endl; // std::cerr << "RsServer::run() Lock() -> Run()" << std::endl;
int moreToTick = server -> tick(); int moreToTick = server -> tick();
unlockRsCore(); unlockRsCore();
/* tick the connection Manager */
mConnMgr->tick();
/******************************** RUN SERVER *****************/ /******************************** RUN SERVER *****************/
/* adjust tick rate depending on whether there is more. /* adjust tick rate depending on whether there is more.
@ -184,9 +191,9 @@ void RsServer::run()
// These two have been completed! // These two have been completed!
//std::cerr << "RsServer::run() UpdateAllCerts()" << std::endl; //std::cerr << "RsServer::run() UpdateAllCerts()" << std::endl;
UpdateAllCerts(); //UpdateAllCerts();
//std::cerr << "RsServer::run() UpdateAllNetwork()" << std::endl; //std::cerr << "RsServer::run() UpdateAllNetwork()" << std::endl;
UpdateAllNetwork(); //UpdateAllNetwork();
// currently Dummy Functions. // currently Dummy Functions.
//std::cerr << "RsServer::run() UpdateAllTransfers()" << std::endl; //std::cerr << "RsServer::run() UpdateAllTransfers()" << std::endl;
@ -210,7 +217,7 @@ void RsServer::run()
//std::cerr << "RsServer::run() CheckDHT()" << std::endl; //std::cerr << "RsServer::run() CheckDHT()" << std::endl;
CheckNetworking(); //CheckNetworking();
} }
@ -222,7 +229,7 @@ void RsServer::run()
// save the config every 5 minutes. // save the config every 5 minutes.
if (min % 5 == 1) if (min % 5 == 1)
{ {
ConfigSave(); //ConfigSave();
#ifdef PQI_USE_CHANNELS #ifdef PQI_USE_CHANNELS
/* hack to update for now /* hack to update for now
* Only occassionally - cos disabled * Only occassionally - cos disabled

View File

@ -27,12 +27,19 @@
#include <unistd.h> #include <unistd.h>
//#include <getopt.h> //#include <getopt.h>
#include "dbase/cachestrapper.h"
#include "server/filedexserver.h" #include "server/filedexserver.h"
#include "pqi/pqipersongrp.h" #include "pqi/pqipersongrp.h"
#include "pqi/pqisslpersongrp.h"
#include "pqi/pqiloopback.h" #include "pqi/pqiloopback.h"
#include "pqi/p3cfgmgr.h"
#include "util/rsdir.h" #include "util/rsdir.h"
#include "services/p3disc.h" #include "upnp/upnphandler.h"
#include "dht/opendhtmgr.h"
// Removed temporarily...
//#include "services/p3disc.h"
#include "services/p3msgservice.h" #include "services/p3msgservice.h"
#include "services/p3chatservice.h" #include "services/p3chatservice.h"
#include "services/p3gamelauncher.h" #include "services/p3gamelauncher.h"
@ -41,20 +48,23 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
// Includes for directory creation.
//#include <sys/types.h>
//#include <sys/stat.h>
//#include <unistd.h>
// Conflicts with FLTK def - hope they are the same.
//#include <dirent.h>
// for blocking signals // for blocking signals
#include <signal.h> #include <signal.h>
#include "pqi/pqidebug.h" #include "pqi/pqidebug.h"
#include "rsserver/p3face.h" #include "rsserver/p3face.h"
#include "rsserver/p3peers.h"
#include "rsiface/rsgame.h" #include "rsiface/rsgame.h"
/**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP)
#include "pqi/authxpgp.h"
#else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
#endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
const int p3facestartupzone = 47238; const int p3facestartupzone = 47238;
// initial configuration bootstrapping... // initial configuration bootstrapping...
@ -364,10 +374,10 @@ int InitRetroShare(int argcIgnored, char **argvIgnored, RsInit *config)
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP) #if defined(PQI_USE_XPGP)
/* do a null init to allow the SSL libray to startup! */ /* do a null init to allow the SSL libray to startup! */
getSSLRoot() -> initssl(NULL, NULL, NULL); getAuthMgr() -> InitAuth(NULL, NULL, NULL);
#else /* X509 Certificates */ #else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
getSSLRoot() -> initssl(NULL, NULL, NULL, NULL); getAuthMgr() -> InitAuth(NULL, NULL, NULL, NULL);
#endif /* X509 Certificates */ #endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
@ -393,16 +403,21 @@ int InitRetroShare(int argcIgnored, char **argvIgnored, RsInit *config)
int RsServer::StartupRetroShare(RsInit *config) int RsServer::StartupRetroShare(RsInit *config)
{ {
// ssl root is setup already.... by welcome_window. /**************************************************************************/
// this means that the cert/key + cacerts have been loaded. /* STARTUP procedure */
sslr = getSSLRoot(); /**************************************************************************/
/**************************************************************************/
/* (1) Load up own certificate (DONE ALREADY) - just CHECK */
/**************************************************************************/
mAuthMgr = getAuthMgr();
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP) #if defined(PQI_USE_XPGP)
if (1 != sslr -> initssl(NULL, NULL, NULL)) if (1 != mAuthMgr -> InitAuth(NULL, NULL, NULL))
#else /* X509 Certificates */ #else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
if (1 != sslr -> initssl(NULL, NULL, NULL, NULL)) if (1 != mAuthMgr -> InitAuth(NULL, NULL, NULL, NULL))
#endif /* X509 Certificates */ #endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
{ {
@ -412,6 +427,12 @@ int RsServer::StartupRetroShare(RsInit *config)
exit(1); exit(1);
} }
std::string ownId = mAuthMgr->OwnId();
/**************************************************************************/
/* Any Initial Configuration (Commandline Options) */
/**************************************************************************/
/* set the debugging to crashMode */ /* set the debugging to crashMode */
if ((!config->haveLogFile) && (!config->outStderr)) if ((!config->haveLogFile) && (!config->outStderr))
{ {
@ -420,19 +441,78 @@ int RsServer::StartupRetroShare(RsInit *config)
setDebugCrashMode(crashfile.c_str()); setDebugCrashMode(crashfile.c_str());
} }
unsigned long flags = 0;
if (config->udpListenerOnly)
{
flags |= PQIPERSON_NO_LISTENER;
}
/**************************************************************************/
// set the directories for full configuration load. // set the directories for full configuration load.
sslr -> setConfigDirs(config->basedir.c_str(), configCertDir.c_str()); mAuthMgr -> setConfigDirectories(config->basedir.c_str(), configCertDir.c_str());
sslr -> loadCertificates(configConfFile.c_str()); //sslr -> loadCertificates(configConfFile.c_str());
sslr -> checkNetAddress();
// Create Classes. // Create Classes.
// filedex server. // filedex server.
server = new filedexserver(); server = new filedexserver();
server->setConfigDir(config->basedir.c_str()); server->setConfigDir(config->basedir.c_str());
server->setFileCallback(&(getNotify()));
/**************************************************************************/
/* setup classes / structures */
/**************************************************************************/
uint32_t queryPeriod = 60; /* query every 1 minutes -> change later to 600+ */
mConnMgr = new p3ConnectMgr(mAuthMgr);
p3UpnpMgr *mUpnpMgr = new upnphandler();
p3DhtMgr *mDhtMgr = new OpenDHTMgr(ownId, mConnMgr);
CacheStrapper *mCacheStrapper = new CacheStrapper(ownId, queryPeriod);
p3ConfigMgr *mConfigMgr = new p3ConfigMgr(config->basedir, "rs-v0.4.cfg", "rs-v0.4.sgn");
SecurityPolicy *none = secpolicy_create(); SecurityPolicy *none = secpolicy_create();
//pqih = new pqisslpersongrp(none, flags);
pqih = new pqipersongrpDummy(none, flags);
// Setup Peer Interface.
rsPeers = new p3Peers(mConnMgr, mAuthMgr);
/**************************************************************************/
mConnMgr->setDhtMgr(mDhtMgr);
mConnMgr->setUpnpMgr(mUpnpMgr);
/**************************************************************************/
mConnMgr->addMonitor(pqih);
mConnMgr->addMonitor(mCacheStrapper);
/**************************************************************************/
mConfigMgr->addConfiguration(CONFIG_TYPE_FSERVER, server); //"server.cfg");
mConfigMgr->addConfiguration(CONFIG_TYPE_PEERS, mConnMgr);
/**************************************************************************/
server->setSearchInterface(pqih, mAuthMgr, mConnMgr);
/**************************************************************************/
/* (2) Load configuration files */
/**************************************************************************/
mConfigMgr->loadConfiguration();
/**************************************************************************/
/* trigger generalConfig loading for classes that require it */
/**************************************************************************/
/**************************************************************************/
/* Force Any Configuration before Startup (After Load) */
/**************************************************************************/
if (config->forceLocalAddr) if (config->forceLocalAddr)
{ {
@ -444,13 +524,10 @@ int RsServer::StartupRetroShare(RsInit *config)
// universal // universal
laddr.sin_addr.s_addr = inet_addr(config->inet); laddr.sin_addr.s_addr = inet_addr(config->inet);
cert *own = sslr -> getOwnCert(); mConnMgr->setLocalAddress(ownId, laddr);
if (own != NULL)
{
own -> localaddr = laddr;
}
} }
#if 0
/* must load the trusted_peer before setting up the pqipersongrp */ /* must load the trusted_peer before setting up the pqipersongrp */
if (config->firsttime_run) if (config->firsttime_run)
{ {
@ -461,16 +538,45 @@ int RsServer::StartupRetroShare(RsInit *config)
sslr -> loadInitialTrustedPeer(config->load_trustedpeer_file); sslr -> loadInitialTrustedPeer(config->load_trustedpeer_file);
} }
} }
#endif
unsigned long flags = 0; mConnMgr -> checkNetAddress();
if (config->udpListenerOnly)
{ /**************************************************************************/
flags |= PQIPERSON_NO_SSLLISTENER; /* startup (stuff dependent on Ids/peers is after this point) */
} /**************************************************************************/
/**************************************************************************/
/* load caches and secondary data */
/**************************************************************************/
/**************************************************************************/
/* Force Any Last Configuration Options */
/**************************************************************************/
/****************** setup new stuff ***************/
pqih = new pqipersongrp(none, sslr, flags);
pqih->load_config(); pqih->load_config();
server->setSearchInterface(pqih, sslr);
/* must be after server->setSearchInterface() */
server->setFileCallback(ownId, mCacheStrapper, &(getNotify()));
#ifdef PQI_USE_CHANNELS #ifdef PQI_USE_CHANNELS
server->setP3Channel(pqih->getP3Channel()); server->setP3Channel(pqih->getP3Channel());
@ -478,11 +584,10 @@ int RsServer::StartupRetroShare(RsInit *config)
// create loopback device, and add to pqisslgrp. // create loopback device, and add to pqisslgrp.
std::string ownPeerId = sslr->getOwnCert()->PeerId();
SearchModule *mod = new SearchModule(); SearchModule *mod = new SearchModule();
pqiloopback *ploop = new pqiloopback(ownPeerId); pqiloopback *ploop = new pqiloopback(ownId);
mod -> peerid = ownPeerId; mod -> peerid = ownId;
mod -> pqi = ploop; mod -> pqi = ploop;
mod -> sp = secpolicy_create(); mod -> sp = secpolicy_create();
@ -492,15 +597,15 @@ int RsServer::StartupRetroShare(RsInit *config)
// Load from config will overwrite... // Load from config will overwrite...
server->setSaveDir(config->homePath.c_str()); server->setSaveDir(config->homePath.c_str());
server->load_config(); //server->load_config();
/* create Services */ /* create Services */
ad = new p3disc(sslr); //ad = new p3disc(sslr); // XXX
msgSrv = new p3MsgService(); msgSrv = new p3MsgService(mConnMgr);
chatSrv = new p3ChatService(); chatSrv = new p3ChatService(mConnMgr);
p3GameLauncher *gameLauncher = new p3GameLauncher(); p3GameLauncher *gameLauncher = new p3GameLauncher();
pqih -> addService(ad); //pqih -> addService(ad);
pqih -> addService(msgSrv); pqih -> addService(msgSrv);
pqih -> addService(chatSrv); pqih -> addService(chatSrv);
pqih -> addService(gameLauncher); pqih -> addService(gameLauncher);
@ -520,10 +625,10 @@ int RsServer::StartupRetroShare(RsInit *config)
helppage += configHelpName; helppage += configHelpName;
/* for DHT/UPnP stuff */ /* for DHT/UPnP stuff */
InitNetworking(config->basedir + "/kadc.ini"); //InitNetworking(config->basedir + "/kadc.ini");
/* Startup this thread! */ /* Startup this thread! */
pthread_t coreId = createThread(*this); createThread(*this);
return 1; return 1;
} }
@ -553,16 +658,16 @@ int LoadCertificates(RsInit *config, bool autoLoginNT)
std::string ca_loc = config->basedir + config->dirSeperator; std::string ca_loc = config->basedir + config->dirSeperator;
ca_loc += configCaFile; ca_loc += configCaFile;
sslroot *sr = getSSLRoot(); p3AuthMgr *authMgr = getAuthMgr();
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP) #if defined(PQI_USE_XPGP)
if (0 < sr -> initssl(config->load_cert.c_str(), if (0 < authMgr -> InitAuth(config->load_cert.c_str(),
config->load_key.c_str(), config->load_key.c_str(),
config->passwd.c_str())) config->passwd.c_str()))
#else /* X509 Certificates */ #else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/ /**************** PQI_USE_XPGP ******************/
if (0 < sr -> initssl(config->load_cert.c_str(), if (0 < authMgr -> InitAuth(config->load_cert.c_str(),
config->load_key.c_str(), config->load_key.c_str(),
ca_loc.c_str(), ca_loc.c_str(),
config->passwd.c_str())) config->passwd.c_str()))

View File

@ -27,16 +27,21 @@
*/ */
#include "server/filedexserver.h" #include "server/filedexserver.h"
//#include "pqi/pqissl.h"
#include "pqi/p3connmgr.h"
#include "pqi/pqipersongrp.h" #include "pqi/pqipersongrp.h"
#include "pqi/pqissl.h"
#include "rsiface/rsiface.h" #include "rsiface/rsiface.h"
#include "rsiface/rstypes.h" #include "rsiface/rstypes.h"
#include "util/rsthreads.h" #include "util/rsthreads.h"
#include "services/p3disc.h" class p3disc;
#include "services/p3msgservice.h" class p3MsgService;
class p3ChatService;
#include "services/p3chatservice.h" #include "services/p3chatservice.h"
#include "services/p3msgservice.h"
/* The Main Interface Class - for controlling the server */ /* The Main Interface Class - for controlling the server */
@ -105,55 +110,14 @@ void unlockRsCore()
/* General Internal Helper Functions /* General Internal Helper Functions
(Must be Locked) (Must be Locked)
*/ */
#if 0
cert *intFindCert(RsCertId id); cert *intFindCert(RsCertId id);
RsCertId intGetCertId(cert *c); RsCertId intGetCertId(cert *c);
#endif
/****************************************/ /****************************************/
/* p3face-people Operations */ /* p3face-people Operations */
public:
// All Public Fns, must use td::string instead of RsCertId.
// cos of windows interfacing errors...
virtual std::string NeighGetInvite();
virtual int NeighLoadPEMString(std::string pem, std::string &id);
virtual int NeighLoadCertificate(std::string fname, std::string &id);
virtual int NeighAuthFriend(std::string id, RsAuthId code);
virtual int NeighAddFriend(std::string id);
virtual int NeighGetSigners(std::string uid, char *out, int len);
/* Friend Operations */
virtual int FriendStatus(std::string id, bool accept);
virtual int FriendRemove(std::string id);
virtual int FriendConnectAttempt(std::string id);
virtual int FriendSignCert(std::string id);
virtual int FriendTrustSignature(std::string id, bool trust);
//virtual int FriendSetAddress(std::string, std::string &addr, unsigned short port);
virtual int FriendSaveCertificate(std::string id, std::string fname);
virtual int FriendSetBandwidth(std::string id, float outkB, float inkB);
virtual int FriendSetLocalAddress(std::string id, std::string addr, unsigned short port);
virtual int FriendSetExtAddress(std::string id, std::string addr, unsigned short port);
virtual int FriendSetDNSAddress(std::string id, std::string addr);
virtual int FriendSetFirewall(std::string id, bool firewalled, bool forwarded);
private:
void intNotifyCertError(RsCertId &id, std::string errstr);
void intNotifyChangeCert(RsCertId &id);
/* Internal Update Iface Fns */
int UpdateAllCerts();
int UpdateAllNetwork();
void initRsNI(cert *c, NeighbourInfo &ni); /* translate to Ext */
int ensureExtension(std::string &name, std::string def_ext);
/****************************************/ /****************************************/
/****************************************/ /****************************************/
/* p3face-file Operations */ /* p3face-file Operations */
@ -256,24 +220,24 @@ void initRsMI(RsMsgItem *msg, MessageInfo &mi);
public: public:
/****************************************/ /****************************************/
/* RsIface Networking */ /* RsIface Networking */
virtual int NetworkDHTActive(bool active); //virtual int NetworkDHTActive(bool active);
virtual int NetworkUPnPActive(bool active); //virtual int NetworkUPnPActive(bool active);
virtual int NetworkDHTStatus(); //virtual int NetworkDHTStatus();
virtual int NetworkUPnPStatus(); //virtual int NetworkUPnPStatus();
private: private:
/* internal */ /* internal */
int InitNetworking(std::string); //int InitNetworking(std::string);
int CheckNetworking(); //int CheckNetworking();
int InitDHT(std::string); //int InitDHT(std::string);
int CheckDHT(); //int CheckDHT();
int InitUPnP(); //int InitUPnP();
int CheckUPnP(); //int CheckUPnP();
int UpdateNetworkConfig(RsConfig &config); //int UpdateNetworkConfig(RsConfig &config);
int SetExternalPorts(); //int SetExternalPorts();
public: public:
@ -284,14 +248,14 @@ virtual int ConfigAddSharedDir( std::string dir );
virtual int ConfigRemoveSharedDir( std::string dir ); virtual int ConfigRemoveSharedDir( std::string dir );
virtual int ConfigSetIncomingDir( std::string dir ); virtual int ConfigSetIncomingDir( std::string dir );
virtual int ConfigSetLocalAddr( std::string ipAddr, int port ); //virtual int ConfigSetLocalAddr( std::string ipAddr, int port );
virtual int ConfigSetExtAddr( std::string ipAddr, int port ); //virtual int ConfigSetExtAddr( std::string ipAddr, int port );
virtual int ConfigSetExtName( std::string addr ); //virtual int ConfigSetExtName( std::string addr );
virtual int ConfigSetLanConfig( bool fire, bool forw ); //virtual int ConfigSetLanConfig( bool fire, bool forw );
virtual int ConfigSetDataRates( int total, int indiv ); virtual int ConfigSetDataRates( int total, int indiv );
virtual int ConfigSetBootPrompt( bool on ); virtual int ConfigSetBootPrompt( bool on );
virtual int ConfigSave( ); //virtual int ConfigSave( );
private: private:
int UpdateAllConfig(); int UpdateAllConfig();
@ -304,8 +268,13 @@ int UpdateAllConfig();
// The real Server Parts. // The real Server Parts.
filedexserver *server; filedexserver *server;
p3ConnectMgr *mConnMgr;
p3AuthMgr *mAuthMgr;
pqipersongrp *pqih; pqipersongrp *pqih;
sslroot *sslr;
//sslroot *sslr;
/* services */ /* services */
p3disc *ad; p3disc *ad;

View File

@ -0,0 +1,635 @@
/*
* libretroshare/src/rsserver: p3peers.cc
*
* RetroShare C++ Interface.
*
* Copyright 2004-2008 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include "rsserver/p3peers.h"
#include "pqi/p3connmgr.h"
#include "pqi/p3authmgr.h"
#include <iostream>
#include <sstream>
RsPeers *rsPeers = NULL;
static uint32_t RsPeerTranslateTrust(uint32_t trustLvl);
int ensureExtension(std::string &name, std::string def_ext);
std::string RsPeerTrustString(uint32_t trustLvl)
{
std::string str;
if (trustLvl == RS_TRUST_LVL_GOOD)
{
str = "Good";
}
else if (trustLvl == RS_TRUST_LVL_MARGINAL)
{
str = "Marginal";
}
else
{
str = "No Trust";
}
return str;
}
std::string RsPeerStateString(uint32_t state)
{
std::string str;
if (state & RS_PEER_STATE_CONNECTED)
{
str = "Connected";
}
else if (state & RS_PEER_STATE_ONLINE)
{
str = "Available";
}
else if (state & RS_PEER_STATE_FRIEND)
{
str = "Offline";
}
else
{
str = "Neighbour";
}
return str;
}
std::string RsPeerNetModeString(uint32_t netModel)
{
std::string str;
if (netModel == RS_NETMODE_EXT)
{
str = "External Port";
}
else if (netModel == RS_NETMODE_UPNP)
{
str = "Ext (UPnP)";
}
else if (netModel == RS_NETMODE_UDP)
{
str = "UDP Mode";
}
else
{
str = "Unknown NetMode";
}
return str;
}
std::string RsPeerLastConnectString(uint32_t lastConnect)
{
std::ostringstream out;
out << lastConnect << " secs ago";
return out.str();
}
#define P3PEERS_DEBUG 1
p3Peers::p3Peers(p3ConnectMgr *cm, p3AuthMgr *am)
:mConnMgr(cm), mAuthMgr(am)
{
return;
}
/* Updates ... */
bool p3Peers::FriendsChanged()
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::FriendsChanged()";
std::cerr << std::endl;
#endif
/* TODO */
return false;
}
bool p3Peers::OthersChanged()
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::OthersChanged()";
std::cerr << std::endl;
#endif
/* TODO */
return false;
}
/* Peer Details (Net & Auth) */
std::string p3Peers::getOwnId()
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getOwnId()";
std::cerr << std::endl;
#endif
return mAuthMgr->OwnId();
}
bool p3Peers::getOnlineList(std::list<std::string> &ids)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getOnlineList()";
std::cerr << std::endl;
#endif
/* get from mConnectMgr */
mConnMgr->getOnlineList(ids);
return true;
}
bool p3Peers::getFriendList(std::list<std::string> &ids)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getFriendList()";
std::cerr << std::endl;
#endif
/* get from mConnectMgr */
mConnMgr->getFriendList(ids);
return true;
}
bool p3Peers::getOthersList(std::list<std::string> &ids)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getOthersList()";
std::cerr << std::endl;
#endif
/* get from mAuthMgr */
mAuthMgr->getAllList(ids);
return true;
}
bool p3Peers::isFriend(std::string id)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::isFriend() " << id;
std::cerr << std::endl;
#endif
/* get from mConnectMgr */
peerConnectState state;
if (mConnMgr->getFriendNetStatus(id, state) &&
(state.state & RS_PEER_S_FRIEND))
{
return true;
}
return false;
}
bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getPeerDetails() " << id;
std::cerr << std::endl;
#endif
/* get from mAuthMgr (first) */
pqiAuthDetails authDetail;
if (!mAuthMgr->getDetails(id, authDetail))
{
return false;
}
d.id = authDetail.id;
d.name = authDetail.name;
d.email = authDetail.email;
d.location = authDetail.location;
d.org = authDetail.org;
d.signers = authDetail.signers;
d.ownsign = authDetail.ownsign;
d.trusted = authDetail.trusted;
d.trustLvl = RsPeerTranslateTrust(authDetail.trustLvl);
/* generate */
d.authcode = "AUTHCODE";
/* get from mConnectMgr */
peerConnectState pcs;
if (!mConnMgr->getFriendNetStatus(id, pcs))
{
if (!mConnMgr->getOthersNetStatus(id, pcs))
{
/* fill in blank data */
d.localPort = 0;
d.extPort = 0;
d.lastConnect = 0;
d.connectPeriod = 0;
d.state = 0;
d.netMode = 0;
return true;
}
}
/* fill from pcs */
d.localAddr = inet_ntoa(pcs.localaddr.sin_addr);
d.localPort = ntohs(pcs.localaddr.sin_port);
d.extAddr = inet_ntoa(pcs.serveraddr.sin_addr);
d.extPort = ntohs(pcs.serveraddr.sin_port);
d.lastConnect = 0;
d.connectPeriod = 0;
/* Translate */
d.state = 0;
if (pcs.state & RS_PEER_S_FRIEND)
d.state |= RS_PEER_STATE_FRIEND;
if (pcs.state & RS_PEER_S_ONLINE)
d.state |= RS_PEER_STATE_ONLINE;
if (pcs.state & RS_PEER_S_CONNECTED)
d.state |= RS_PEER_STATE_CONNECTED;
d.netMode = 0;
// TODO if (pcs.type & RS_NET_CONN_TCP_EXTERNAL)
return true;
}
std::string p3Peers::getPeerName(std::string id)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::getPeerName() " << id;
std::cerr << std::endl;
#endif
/* get from mAuthMgr as it should have more peers? */
return mAuthMgr->getName(id);
}
/* Add/Remove Friends */
bool p3Peers::addFriend(std::string id)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::addFriend() " << id;
std::cerr << std::endl;
#endif
return mConnMgr->addFriend(id);
}
bool p3Peers::removeFriend(std::string id)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::removeFriend() " << id;
std::cerr << std::endl;
#endif
return mConnMgr->removeFriend(id);
}
/* Network Stuff */
bool p3Peers::connectAttempt(std::string id)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::connectAttempt() " << id;
std::cerr << std::endl;
#endif
return mConnMgr->retryConnect(id);
}
bool p3Peers::setLocalAddress(std::string id, std::string addr_str, uint16_t port)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::setLocalAddress() " << id;
std::cerr << std::endl;
#endif
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
int ret = 1;
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
#ifndef WINDOWS_SYS
if (ret && (0 != inet_aton(addr_str.c_str(), &(addr.sin_addr))))
#else
addr.sin_addr.s_addr = inet_addr(addr_str.c_str());
if (ret)
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
{
return mConnMgr->setLocalAddress(id, addr);
}
return false;
}
bool p3Peers::setExtAddress(std::string id, std::string addr_str, uint16_t port)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::setExtAddress() " << id;
std::cerr << std::endl;
#endif
struct sockaddr_in addr;
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
int ret = 1;
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
#ifndef WINDOWS_SYS
if (ret && (0 != inet_aton(addr_str.c_str(), &(addr.sin_addr))))
#else
addr.sin_addr.s_addr = inet_addr(addr_str.c_str());
if (ret)
#endif
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
{
return mConnMgr->setExtAddress(id, addr);
}
return false;
}
bool p3Peers::setNetworkMode(std::string id, uint32_t netMode)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::setNetworkMode() " << id;
std::cerr << std::endl;
#endif
return mConnMgr->setNetworkMode(id, netMode);
}
/* Auth Stuff */
std::string p3Peers::GetRetroshareInvite()
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::GetRetroshareInvite()";
std::cerr << std::endl;
#endif
std::string ownId = mAuthMgr->OwnId();
std::string certstr = mAuthMgr->SaveCertificateToString(ownId);
std::string name = mAuthMgr->getName(ownId);
std::ostringstream out;
out << "You have been invited to join the retroshare";
out << " community by: " << name;
out << std::endl;
out << std::endl;
out << "Retroshare is a Friend-2-Friend network that enables you to";
out << " communicate securely and";
out << std::endl;
out << "privately with your friends. ";
out << "You can use it for chat, messages, ";
out << "channels, and file-sharing. ";
out << std::endl;
out << std::endl;
out << "Download it from: ";
out << "http://retroshare.sf.net";
out << std::endl;
out << std::endl;
out << "Thanks, ";
out << " " << name << ", DrBob and the RetroShare Team!";
out << std::endl;
out << std::endl;
out << certstr;
out << std::endl;
return out.str();
}
bool p3Peers::LoadCertificateFromFile(std::string fname, std::string &id)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::LoadCertificateFromFile() ";
std::cerr << std::endl;
#endif
return mAuthMgr->LoadCertificateFromFile(fname, id);
}
bool p3Peers::LoadCertificateFromString(std::string cert, std::string &id)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::LoadCertificateFromString() ";
std::cerr << std::endl;
#endif
return mAuthMgr->LoadCertificateFromString(cert, id);
}
bool p3Peers::SaveCertificateToFile(std::string id, std::string fname)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::SaveCertificateToFile() " << id;
std::cerr << std::endl;
#endif
ensureExtension(fname, "pqi");
return mAuthMgr->SaveCertificateToFile(id, fname);
}
std::string p3Peers::SaveCertificateToString(std::string id)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::SaveCertificateToString() " << id;
std::cerr << std::endl;
#endif
return mAuthMgr->SaveCertificateToString(id);
}
bool p3Peers::AuthCertificate(std::string id, std::string code)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::AuthCertificate() " << id;
std::cerr << std::endl;
#endif
if (mAuthMgr->AuthCertificate(id))
{
/* add in as a friend */
return mConnMgr->addFriend(id);
}
return false;
}
bool p3Peers::SignCertificate(std::string id)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::SignCertificate() " << id;
std::cerr << std::endl;
#endif
return mAuthMgr->SignCertificate(id);
}
bool p3Peers::TrustCertificate(std::string id, bool trust)
{
#ifdef P3PEERS_DEBUG
std::cerr << "p3Peers::TrustCertificate() " << id;
std::cerr << std::endl;
#endif
return mAuthMgr->TrustCertificate(id, trust);
}
int ensureExtension(std::string &name, std::string def_ext)
{
/* if it has an extension, don't change */
int len = name.length();
int extpos = name.find_last_of('.');
std::ostringstream out;
out << "ensureExtension() name: " << name << std::endl;
out << "\t\t extpos: " << extpos;
out << " len: " << len << std::endl;
/* check that the '.' has between 1 and 4 char after it (an extension) */
if ((extpos > 0) && (extpos < len - 1) && (extpos + 6 > len))
{
/* extension there */
std::string curext = name.substr(extpos, len);
out << "ensureExtension() curext: " << curext << std::endl;
std::cerr << out.str();
return 0;
}
if (extpos != len - 1)
{
name += ".";
}
name += def_ext;
out << "ensureExtension() added ext: " << name << std::endl;
std::cerr << out.str();
return 1;
}
RsPeerDetails::RsPeerDetails()
:trustLvl(0), ownsign(false), trusted(false), state(0), netMode(0),
lastConnect(0), connectPeriod(0)
{
return;
}
std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail)
{
out << "RsPeerDetail: " << detail.name << " <" << detail.id << ">";
out << std::endl;
out << " email: " << detail.email;
out << " location:" << detail.location;
out << " org: " << detail.org;
out << std::endl;
out << " fpr: " << detail.fpr;
out << " authcode:" << detail.authcode;
out << std::endl;
out << " signers:";
out << std::endl;
std::list<std::string>::const_iterator it;
for(it = detail.signers.begin();
it != detail.signers.end(); it++)
{
out << "\t" << *it;
out << std::endl;
}
out << std::endl;
out << " trustLvl: " << detail.trustLvl;
out << " ownSign: " << detail.ownsign;
out << " trusted: " << detail.trusted;
out << std::endl;
out << " state: " << detail.state;
out << " netMode: " << detail.netMode;
out << std::endl;
out << " localAddr: " << detail.localAddr;
out << ":" << detail.localPort;
out << std::endl;
out << " extAddr: " << detail.extAddr;
out << ":" << detail.extPort;
out << std::endl;
out << " lastConnect: " << detail.lastConnect;
out << " connectPeriod: " << detail.connectPeriod;
out << std::endl;
return out;
}
/********** TRANSLATION ****/
/**************** PQI_USE_XPGP ******************/
#if defined(PQI_USE_XPGP)
#include "pqi/authxpgp.h"
#else /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
#endif /* X509 Certificates */
/**************** PQI_USE_XPGP ******************/
uint32_t RsPeerTranslateTrust(uint32_t trustLvl)
{
switch(trustLvl)
{
case TRUST_SIGN_OWN:
case TRUST_SIGN_TRSTED:
case TRUST_SIGN_AUTHEN:
return RS_TRUST_LVL_GOOD;
break;
case TRUST_SIGN_BASIC:
return RS_TRUST_LVL_MARGINAL;
break;
case TRUST_SIGN_UNTRUSTED:
case TRUST_SIGN_UNKNOWN:
case TRUST_SIGN_NONE:
default:
return RS_TRUST_LVL_UNKNOWN;
break;
}
return RS_TRUST_LVL_UNKNOWN;
}

View File

@ -0,0 +1,83 @@
#ifndef RETROSHARE_P3_PEER_INTERFACE_H
#define RETROSHARE_P3_PEER_INTERFACE_H
/*
* libretroshare/src/rsserver: p3peers.h
*
* RetroShare C++ Interface.
*
* Copyright 2004-2008 by Robert Fernie.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include "rsiface/rspeers.h"
#include "pqi/p3connmgr.h"
#include "pqi/p3authmgr.h"
class p3Peers: public RsPeers
{
public:
p3Peers(p3ConnectMgr *cm, p3AuthMgr *am);
virtual ~p3Peers() { return; }
/* Updates ... */
virtual bool FriendsChanged();
virtual bool OthersChanged();
/* Peer Details (Net & Auth) */
virtual std::string getOwnId();
virtual bool getOnlineList(std::list<std::string> &ids);
virtual bool getFriendList(std::list<std::string> &ids);
virtual bool getOthersList(std::list<std::string> &ids);
virtual bool isFriend(std::string id);
virtual std::string getPeerName(std::string id);
virtual bool getPeerDetails(std::string id, RsPeerDetails &d);
/* Add/Remove Friends */
virtual bool addFriend(std::string id);
virtual bool removeFriend(std::string id);
/* Network Stuff */
virtual bool connectAttempt(std::string id);
virtual bool setLocalAddress(std::string id, std::string addr, uint16_t port);
virtual bool setExtAddress(std::string id, std::string addr, uint16_t port);
virtual bool setNetworkMode(std::string id, uint32_t netMode);
/* Auth Stuff */
virtual std::string GetRetroshareInvite();
virtual bool LoadCertificateFromFile(std::string fname, std::string &id);
virtual bool LoadCertificateFromString(std::string cert, std::string &id);
virtual bool SaveCertificateToFile(std::string id, std::string fname);
virtual std::string SaveCertificateToString(std::string id);
virtual bool AuthCertificate(std::string id, std::string code);
virtual bool SignCertificate(std::string id);
virtual bool TrustCertificate(std::string id, bool trust);
private:
p3ConnectMgr *mConnMgr;
p3AuthMgr *mAuthMgr;
};
#endif

View File

@ -525,12 +525,12 @@ std::string getX509Info(X509 *cert)
* into a string. * into a string.
*/ */
static char *TIME_FORMAT_STR_BRIEF = "%H:%M:%S"; static const char *TIME_FORMAT_STR_BRIEF = "%H:%M:%S";
static char *TIME_FORMAT_STR_OLDVAGUE_NOW = "%H:%M:%S"; static const char *TIME_FORMAT_STR_OLDVAGUE_NOW = "%H:%M:%S";
static char *TIME_FORMAT_STR_OLDVAGUE_WEEK = "%a %H:%M"; static const char *TIME_FORMAT_STR_OLDVAGUE_WEEK = "%a %H:%M";
static char *TIME_FORMAT_STR_OLDVAGUE_OLD = "%a, %d %b"; static const char *TIME_FORMAT_STR_OLDVAGUE_OLD = "%a, %d %b";
static char *TIME_FORMAT_STR_LONG = "%c"; static const char *TIME_FORMAT_STR_LONG = "%c";
static char *TIME_FORMAT_STR_NORMAL = "%a, %H:%M:%S"; static const char *TIME_FORMAT_STR_NORMAL = "%a, %H:%M:%S";
std::string timeFormat(int epoch, int format) std::string timeFormat(int epoch, int format)
{ {
@ -539,7 +539,7 @@ std::string timeFormat(int epoch, int format)
size_t msize = 1024; size_t msize = 1024;
char space[msize]; char space[msize];
char *fmtstr = NULL; const char *fmtstr = NULL;
if (format == TIME_FORMAT_OLDVAGUE) if (format == TIME_FORMAT_OLDVAGUE)
{ {

View File

@ -29,18 +29,6 @@
#include "rsiface/rsiface.h" #include "rsiface/rsiface.h"
#include "util/rsdir.h" #include "util/rsdir.h"
const NeighbourInfo *RsIface::getFriend(std::string id)
{
RsCertId cid(id);
std::map<RsCertId,NeighbourInfo>::const_iterator it;
it = mFriendMap.find(cid);
if (it == mFriendMap.end())
{
return NULL;
}
return &(it -> second);
}
const DirInfo *RsIface::getDirectory(std::string id, std::string path) const DirInfo *RsIface::getDirectory(std::string id, std::string path)
{ {
const DirInfo *dir = getDirectoryMod(id, path); const DirInfo *dir = getDirectoryMod(id, path);

View File

@ -35,16 +35,6 @@
#include <iomanip> #include <iomanip>
#if 0
/****************************************/
RsCertId::RsCertId()
{
for(int i = 0; i < RSCERTIDLEN; i++)
{
data[i] = 0;
}
}
/********************************************************************** /**********************************************************************
* NOTE NOTE NOTE ...... XXX * NOTE NOTE NOTE ...... XXX
* BUG in MinGW .... %hhx in sscanf overwrites 32bits, instead of 8bits. * BUG in MinGW .... %hhx in sscanf overwrites 32bits, instead of 8bits.
@ -55,84 +45,9 @@ RsCertId::RsCertId()
* *
**********************************************************************/ **********************************************************************/
RsCertId::RsCertId(std::string idstr)
{
unsigned int a, b, c, d;
/* scan the string and create an id */
if (16 != sscanf(idstr.c_str(),
"%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%x:%x:%x:%x",
&(data[0]), &(data[1]), &(data[2]), &(data[3]),
&(data[4]), &(data[5]), &(data[6]), &(data[7]),
&(data[8]), &(data[9]), &(data[10]), &(data[11]),
&a, &b, &c, &d))
{
std::cerr << "RsCertId() Invalid Parsing!" << std::endl;
/* clear it */
for(int i = 0; i < RSCERTIDLEN; i++)
{
data[i] = 0;
}
}
((unsigned char *) data)[12] = a;
((unsigned char *) data)[13] = b;
((unsigned char *) data)[14] = c;
((unsigned char *) data)[15] = d;
}
bool RsCertId::operator<(const RsCertId &ref) const
{
//compare the signature.
if (0 > memcmp(data, ref.data, RSCERTIDLEN))
return true;
return false;
}
bool RsCertId::operator==(const RsCertId &ref) const
{
//compare the signature.
return (0 == memcmp(data, ref.data, RSCERTIDLEN));
}
bool RsCertId::operator!=(const RsCertId &ref) const
{
//compare the signature.
return !(*this == ref);
}
std::ostream &operator<<(std::ostream &out, const RsCertId &id)
{
std::ostringstream str;
for(int i = 0; i < RSCERTIDLEN; i++)
{
if (i != 0)
{
str << ":";
}
str << std::hex << std::setw(2) << std::setfill('0')
<< std::setprecision(2);
str << (unsigned int) (((unsigned char *) (id.data))[i]);
}
out << str.str();
return out;
}
#endif
/****************************************/ /****************************************/
/* Print Functions for Info Classes */ /* Print Functions for Info Classes */
std::ostream &operator<<(std::ostream &out, const NeighbourInfo &info)
{
out << "Neighbour Name: " << info.name;
out << std::endl;
out << "TrustLvl: " << info.trustLvl;
out << std::endl;
out << "Status: " << info.status;
out << std::endl;
out << "Auth Code: " << info.authCode;
out << std::endl;
return out;
}
std::ostream &operator<<(std::ostream &out, const PersonInfo &info) std::ostream &operator<<(std::ostream &out, const PersonInfo &info)
{ {