mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-28 00:49:28 -05:00
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:
parent
7c2d5611bd
commit
fd8adceb7e
@ -2,14 +2,18 @@
|
||||
RS_TOP_DIR = ..
|
||||
include ../make.opt
|
||||
|
||||
OBJ = pqistrings.o \
|
||||
p3face-people.o p3face-file.o \
|
||||
p3face-msgs.o p3face-server.o \
|
||||
OBJ = p3face-file.o \
|
||||
p3face-msgs.o \
|
||||
p3face-server.o \
|
||||
p3face-config.o \
|
||||
p3face-network.o \
|
||||
p3face-startup.o \
|
||||
rstypes.o \
|
||||
rsiface.o
|
||||
rsiface.o \
|
||||
p3peers.o
|
||||
|
||||
# pqistrings.o \
|
||||
# p3face-people.o
|
||||
# p3face-network.o \
|
||||
|
||||
TESTS =
|
||||
|
||||
|
@ -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 )
|
||||
{
|
||||
@ -182,7 +182,6 @@ int RsServer::ConfigSetExtAddr( std::string ipAddr, int port )
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* MOVE_TO_RS_NETWORK */
|
||||
|
||||
|
||||
int RsServer::ConfigSetLanConfig( bool firewalled, bool forwarded )
|
||||
@ -239,6 +238,7 @@ int RsServer::ConfigSetExtName( std::string addr )
|
||||
return 1;
|
||||
}
|
||||
|
||||
#endif /* 0 */
|
||||
|
||||
int RsServer::ConfigSetDataRates( int total, int indiv ) /* in kbrates */
|
||||
{
|
||||
@ -283,42 +283,26 @@ int RsServer::UpdateAllConfig()
|
||||
|
||||
RsConfig &config = iface.mConfig;
|
||||
|
||||
cert *own = sslr -> getOwnCert();
|
||||
|
||||
/* set the id. */
|
||||
{
|
||||
RsCertId rid = intGetCertId(own);
|
||||
std::ostringstream out;
|
||||
out << rid;
|
||||
config.ownId = out.str();
|
||||
}
|
||||
|
||||
config.ownName = own->Name();
|
||||
config.ownId = mAuthMgr->OwnId();
|
||||
config.ownName = mAuthMgr->getName(config.ownId);
|
||||
peerConnectState pstate;
|
||||
mConnMgr->getOwnNetStatus(pstate);
|
||||
|
||||
/* shared dirs */
|
||||
std::list<std::string> &dirs = server -> getSearchDirectories();
|
||||
config.sharedDirList = dirs;
|
||||
config.incomingDir = server->getSaveDir();
|
||||
|
||||
|
||||
/* ports */
|
||||
config.localAddr = inet_ntoa(own -> localaddr.sin_addr);
|
||||
config.localPort = ntohs(own -> localaddr.sin_port);
|
||||
config.localAddr = inet_ntoa(pstate.localaddr.sin_addr);
|
||||
config.localPort = ntohs(pstate.localaddr.sin_port);
|
||||
|
||||
config.firewalled = own -> Firewalled();
|
||||
config.forwardPort = own -> Forwarded();
|
||||
config.firewalled = true;
|
||||
config.forwardPort = true;
|
||||
|
||||
if (own -> Firewalled() && !own -> Forwarded())
|
||||
{
|
||||
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!>";
|
||||
}
|
||||
config.extAddr = inet_ntoa(pstate.serveraddr.sin_addr);
|
||||
config.extPort = ntohs(pstate.serveraddr.sin_port);
|
||||
|
||||
/* data rates */
|
||||
config.maxDataRate = (int) pqih -> getMaxRate(true); /* kb */
|
||||
@ -326,7 +310,11 @@ int RsServer::UpdateAllConfig()
|
||||
config.promptAtBoot = true; /* popup the password prompt */
|
||||
|
||||
/* update DHT/UPnP config */
|
||||
UpdateNetworkConfig(config);
|
||||
|
||||
config.uPnPState = mConnMgr->getUPnPState();
|
||||
config.uPnPActive = mConnMgr->getUPnPEnabled();
|
||||
config.DHTPeers = 20;
|
||||
config.DHTActive = mConnMgr->getDHTEnabled();;
|
||||
|
||||
/* Notify of Changes */
|
||||
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;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -42,12 +42,7 @@ const int p3facefilezone = 11452;
|
||||
|
||||
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)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
//int ensureExtension(std::string &name, std::string def_ext);
|
||||
|
||||
/****************************************/
|
||||
/****************************************/
|
||||
@ -91,27 +86,8 @@ int RsServer::UpdateAllTransfers()
|
||||
{
|
||||
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.source = mAuthMgr->getName(ti.id);
|
||||
ti.peerIds = (*it) -> allPeerIds.ids;
|
||||
|
||||
ti.fname = (*it) -> file.name;
|
||||
|
@ -377,11 +377,7 @@ int RsServer::UpdateAllChannels()
|
||||
void RsServer::initRsChatInfo(RsChatItem *c, ChatInfo &i)
|
||||
{
|
||||
i.rsid = c -> PeerId();
|
||||
cert *peer = intFindCert(c->PeerId());
|
||||
if (peer)
|
||||
i.name = peer -> Name();
|
||||
else
|
||||
i.name = "Unknown";
|
||||
i.name = mAuthMgr->getName(i.rsid);
|
||||
|
||||
i.msg = c -> message;
|
||||
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 */
|
||||
if ((msg->msgFlags & RS_MSG_FLAGS_OUTGOING)
|
||||
|| (msg->PeerId() == sslr->getOwnCert()->PeerId()))
|
||||
|| (msg->PeerId() == mAuthMgr->OwnId()))
|
||||
{
|
||||
mi.msgflags |= RS_MSG_OUTGOING;
|
||||
}
|
||||
@ -529,11 +525,7 @@ void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
|
||||
}
|
||||
|
||||
mi.id = msg->PeerId();
|
||||
cert *c = intFindCert(mi.id);
|
||||
if (c)
|
||||
mi.srcname = c->Name();
|
||||
else
|
||||
mi.srcname = "Unknown";
|
||||
mi.srcname = mAuthMgr->getName(mi.id);
|
||||
|
||||
std::list<std::string>::iterator pit;
|
||||
|
||||
@ -542,11 +534,7 @@ void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
|
||||
{
|
||||
PersonInfo pi;
|
||||
pi.id = (*pit);
|
||||
cert *peer = intFindCert(pi.id);
|
||||
if (peer)
|
||||
pi.name = peer->Name();
|
||||
else
|
||||
pi.name = "Unknown";
|
||||
pi.name = mAuthMgr->getName(pi.id);
|
||||
mi.msgto.push_back(pi);
|
||||
}
|
||||
|
||||
@ -555,11 +543,7 @@ void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
|
||||
{
|
||||
PersonInfo pi;
|
||||
pi.id = (*pit);
|
||||
cert *peer = intFindCert(pi.id);
|
||||
if (peer)
|
||||
pi.name = peer->Name();
|
||||
else
|
||||
pi.name = "Unknown";
|
||||
pi.name = mAuthMgr->getName(pi.id);
|
||||
mi.msgcc.push_back(pi);
|
||||
}
|
||||
|
||||
@ -568,11 +552,7 @@ void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
|
||||
{
|
||||
PersonInfo pi;
|
||||
pi.id = (*pit);
|
||||
cert *peer = intFindCert(pi.id);
|
||||
if (peer)
|
||||
pi.name = peer->Name();
|
||||
else
|
||||
pi.name = "Unknown";
|
||||
pi.name = mAuthMgr->getName(pi.id);
|
||||
mi.msgbcc.push_back(pi);
|
||||
}
|
||||
|
||||
@ -607,7 +587,7 @@ void RsServer::initRsMI(RsMsgItem *msg, MessageInfo &mi)
|
||||
int RsServer::ClearInChat()
|
||||
{
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
#if 0
|
||||
std::list<cert *>::iterator it;
|
||||
std::list<cert *> &certs = sslr -> getCertList();
|
||||
|
||||
@ -617,7 +597,7 @@ int RsServer::ClearInChat()
|
||||
}
|
||||
|
||||
sslr->IndicateCertsChanged();
|
||||
|
||||
#endif
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
return 1;
|
||||
@ -630,6 +610,7 @@ int RsServer::SetInChat(std::string id, bool in) /* friend : cha
|
||||
/* so we send this.... */
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
#if 0
|
||||
RsCertId rsid(id);
|
||||
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;
|
||||
}
|
||||
#endif
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
UpdateAllCerts();
|
||||
//UpdateAllCerts();
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -655,6 +637,7 @@ int RsServer::ClearInMsg()
|
||||
{
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
#if 0
|
||||
std::list<cert *>::iterator it;
|
||||
std::list<cert *> &certs = sslr -> getCertList();
|
||||
|
||||
@ -663,6 +646,7 @@ int RsServer::ClearInMsg()
|
||||
(*it)->InMessage(false);
|
||||
}
|
||||
sslr->IndicateCertsChanged();
|
||||
#endif
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
@ -675,6 +659,7 @@ int RsServer::SetInMsg(std::string id, bool in) /* friend : msgs
|
||||
/* so we send this.... */
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
#if 0
|
||||
RsCertId rsid(id);
|
||||
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;
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
UpdateAllCerts();
|
||||
//UpdateAllCerts();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -119,40 +119,21 @@ int RsServer::FriendStatus(std::string uid, bool accept)
|
||||
|
||||
RsCertId id(uid);
|
||||
|
||||
cert *c = intFindCert(id);
|
||||
std::string errstr;
|
||||
int err = 0;
|
||||
if ((c == NULL) || (c == sslr -> getOwnCert()))
|
||||
std::cerr << "RsServer::FriendStatus() " << uid << " accept: " << accept << std::endl;
|
||||
if (accept)
|
||||
{
|
||||
if (accept)
|
||||
{
|
||||
pqih -> cert_accept(c);
|
||||
pqih -> cert_auto(c, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
pqih -> cert_auto(c, false);
|
||||
pqih -> cert_deny(c);
|
||||
}
|
||||
mConnMgr->addFriend(uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* error */
|
||||
err = 1;
|
||||
mConnMgr->removeFriend(uid);
|
||||
}
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
if (err)
|
||||
{
|
||||
/* notify */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* call the repopulate fn */
|
||||
UpdateAllCerts();
|
||||
|
||||
}
|
||||
return err;
|
||||
/* call the repopulate fn */
|
||||
UpdateAllCerts();
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -161,34 +142,15 @@ int RsServer::FriendRemove(std::string uid)
|
||||
{
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
RsCertId id(uid);
|
||||
cert * c = intFindCert(id);
|
||||
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);
|
||||
}
|
||||
std::cerr << "RsServer::FriendRemove() " << uid << std::endl;
|
||||
mConnMgr->removeFriend(uid);
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
if (err)
|
||||
{
|
||||
/* notify */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* call the repopulate fn */
|
||||
UpdateAllCerts();
|
||||
/* call the repopulate fn */
|
||||
UpdateAllCerts();
|
||||
|
||||
}
|
||||
return err;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
@ -199,26 +161,13 @@ int RsServer::FriendConnectAttempt(std::string uid)
|
||||
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
RsCertId id(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);
|
||||
err = mConnMgr->connectFriend(uid);
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
if (err)
|
||||
{
|
||||
/* notify */
|
||||
}
|
||||
else
|
||||
{
|
||||
/* call the repopulate fn */
|
||||
UpdateAllCerts();
|
||||
/* call the repopulate fn */
|
||||
UpdateAllCerts();
|
||||
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -226,25 +175,7 @@ int RsServer::FriendSignCert(std::string uid)
|
||||
{
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
RsCertId id(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);
|
||||
}
|
||||
int ret = mConnMgr->signCertificate(uid);
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
@ -260,17 +191,8 @@ int RsServer::FriendTrustSignature(std::string uid, bool trust)
|
||||
{
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
RsCertId id(uid);
|
||||
int ret = -1;
|
||||
cert *c = intFindCert(id);
|
||||
|
||||
if ((c == NULL) || (c == sslr -> getOwnCert()))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = sslr -> trustCertificate(c, !(c -> Trusted()));
|
||||
|
||||
ret = mConnMgr -> trustCertificate(uid, trust);
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
@ -329,17 +251,9 @@ int RsServer::FriendSetLocalAddress(std::string uid,
|
||||
struct sockaddr_in addr;
|
||||
|
||||
lockRsCore(); /* LOCK */
|
||||
RsCertId id(uid);
|
||||
|
||||
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 *******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
if (ret && (0 != inet_aton(addr_str.c_str(), &(addr.sin_addr))))
|
||||
@ -349,11 +263,11 @@ int RsServer::FriendSetLocalAddress(std::string uid,
|
||||
#endif
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
||||
{
|
||||
// get the server address.
|
||||
c -> localaddr.sin_addr = addr.sin_addr;
|
||||
c -> localaddr.sin_port = htons(port);
|
||||
/* tell SSL */
|
||||
getSSLRoot() -> IndicateCertsChanged();
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
|
||||
mConnMgr->setPeerLocalAddress(uid, addr);
|
||||
|
||||
ret = 1;
|
||||
}
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
@ -378,16 +292,9 @@ int RsServer::FriendSetExtAddress(std::string uid,
|
||||
struct sockaddr_in addr;
|
||||
|
||||
lockRsCore(); /* LOCK */
|
||||
RsCertId id(uid);
|
||||
|
||||
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 *******************/
|
||||
#ifndef WINDOWS_SYS
|
||||
@ -399,10 +306,10 @@ int RsServer::FriendSetExtAddress(std::string uid,
|
||||
/********************************** WINDOWS/UNIX SPECIFIC PART *******************/
|
||||
{
|
||||
// get the server address.
|
||||
c -> serveraddr.sin_addr = addr.sin_addr;
|
||||
c -> serveraddr.sin_port = htons(port);
|
||||
/* tell SSL */
|
||||
getSSLRoot() -> IndicateCertsChanged();
|
||||
addr.sin_family = AF_INET;
|
||||
addr.sin_port = htons(port);
|
||||
|
||||
mConnMgr->setPeerExtAddress(uid, addr);
|
||||
ret = 1;
|
||||
}
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
@ -428,33 +335,8 @@ int RsServer::FriendSetDNSAddress(std::string uid, std::string addr_str)
|
||||
|
||||
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 */
|
||||
|
||||
if (ret)
|
||||
{
|
||||
/* notify */
|
||||
UpdateAllCerts();
|
||||
}
|
||||
else
|
||||
{
|
||||
/* error message? */
|
||||
intNotifyCertError(id, "Failed to Change Cert Address");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -467,30 +349,9 @@ int RsServer::FriendSaveCertificate(std::string uid, std::string fname)
|
||||
|
||||
int ret = 1;
|
||||
|
||||
cert *c = intFindCert(id);
|
||||
if (c == NULL)
|
||||
{
|
||||
pqioutput(PQL_ALERT, p3facepersonzone, "FriendSaveCertificate: Invalid cert!");
|
||||
ret = 0;
|
||||
}
|
||||
ensureExtension(fname, "pqi");
|
||||
|
||||
if (ret)
|
||||
{
|
||||
ensureExtension(fname, "pqi");
|
||||
|
||||
if (c -> certificate == NULL)
|
||||
{
|
||||
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());
|
||||
}
|
||||
}
|
||||
mConnMgr->saveCertificate(uid, fname);
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
@ -526,7 +387,6 @@ int RsServer::UpdateAllCerts()
|
||||
NotifyBase &cb = getNotify();
|
||||
cb.notifyListPreChange(NOTIFY_LIST_FRIENDS, NOTIFY_TYPE_MOD);
|
||||
|
||||
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
|
||||
@ -536,34 +396,27 @@ int RsServer::UpdateAllCerts()
|
||||
int i;
|
||||
int ret = 1;
|
||||
|
||||
//Fl_Funky_Browser *cb = ui -> cert_list;
|
||||
// Get the Current Cert, by getting current item
|
||||
// and extracting ref.
|
||||
std::list<std::string> peers;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
// only do if
|
||||
if ((sslr -> CertsChanged()) ||
|
||||
(sslr -> CertsMajorChanged()))
|
||||
mConnMgr->getFriendList(peers);
|
||||
|
||||
// clear the data.
|
||||
std::map<RsChanId, NeighbourInfo> &frnds = iface.mFriendMap;
|
||||
frnds.clear();
|
||||
|
||||
for(it = peers.begin(); it != peers.end(); it++)
|
||||
{
|
||||
// clear the data.
|
||||
std::map<RsChanId, NeighbourInfo> &frnds = iface.mFriendMap;
|
||||
peerConnectState state;
|
||||
mConnMgr->setFriendNetStatus(*it, state);
|
||||
|
||||
frnds.clear();
|
||||
|
||||
std::list<cert *>::iterator it;
|
||||
std::list<cert *> &certs = sslr -> getCertList();
|
||||
|
||||
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 */
|
||||
iface.setChanged(RsIface::Friend);
|
||||
@ -638,9 +491,6 @@ void RsServer::intNotifyChangeCert(RsCertId &id)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************** NEIGHBOUR FNS *******************
|
||||
*
|
||||
*
|
||||
@ -654,9 +504,11 @@ std::string RsServer::NeighGetInvite()
|
||||
{
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
cert *own = sslr -> getOwnCert();
|
||||
std::string name = own -> Name();
|
||||
std::string certstr = sslr -> saveCertAsString(own);
|
||||
peerConnectState state;
|
||||
mConnMgr->getOwnNetStatus(state);
|
||||
|
||||
std::string name = state.name;
|
||||
std::string certstr = mConnMgr -> getCertificateAsString(state.id);
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
@ -692,27 +544,7 @@ int RsServer::NeighLoadPEMString(std::string pem, std::string &id)
|
||||
{
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
int ret = 1;
|
||||
|
||||
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!)
|
||||
}
|
||||
id = mConnMgr -> loadCertificateAsString(pem);
|
||||
|
||||
/* ensure it gets to p3disc */
|
||||
if (ad)
|
||||
@ -722,17 +554,12 @@ int RsServer::NeighLoadPEMString(std::string pem, std::string &id)
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
if (ret)
|
||||
if (id != "")
|
||||
{
|
||||
UpdateAllNetwork();
|
||||
|
||||
/* set the id. */
|
||||
RsCertId rid = intGetCertId(nc);
|
||||
std::ostringstream out;
|
||||
out << rid;
|
||||
id = out.str();
|
||||
return 1;
|
||||
}
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -742,27 +569,9 @@ int RsServer::NeighLoadCertificate(std::string fname, std::string &id)
|
||||
|
||||
int ret = 1;
|
||||
|
||||
std::ostringstream out;
|
||||
std::string nullhash(""); // empty hash - as signature not correct.
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
cert *nc;
|
||||
|
||||
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!)
|
||||
}
|
||||
id = mConnMgr -> loadCertificateFromFile(fname);
|
||||
|
||||
/* ensure it gets to p3disc */
|
||||
if (ad)
|
||||
@ -772,17 +581,12 @@ int RsServer::NeighLoadCertificate(std::string fname, std::string &id)
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
if (ret)
|
||||
if (id != "")
|
||||
{
|
||||
UpdateAllNetwork();
|
||||
|
||||
/* set the id. */
|
||||
RsCertId rid = intGetCertId(nc);
|
||||
std::ostringstream out;
|
||||
out << rid;
|
||||
id = out.str();
|
||||
return 1;
|
||||
}
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@ -791,45 +595,8 @@ int RsServer::NeighAuthFriend(std::string uid, RsAuthId code)
|
||||
lockRsCore(); /* LOCK */
|
||||
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 */
|
||||
|
||||
if (ret)
|
||||
@ -845,46 +612,7 @@ int RsServer::NeighAddFriend(std::string uid)
|
||||
{
|
||||
lockRsCore(); /* LOCK */
|
||||
|
||||
int ret = 1;
|
||||
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 */
|
||||
}
|
||||
}
|
||||
int ret = mConnMgr -> AddNeighbour(uid);
|
||||
|
||||
unlockRsCore(); /* UNLOCK */
|
||||
|
||||
@ -897,39 +625,6 @@ int RsServer::NeighAddFriend(std::string uid)
|
||||
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)
|
||||
{
|
||||
lockRsCore(); /* LOCK */
|
||||
@ -982,21 +677,29 @@ int RsServer::UpdateAllNetwork()
|
||||
int ret = 1;
|
||||
int i;
|
||||
|
||||
|
||||
std::list<std::string> peers;
|
||||
std::list<std::string>::iterator it;
|
||||
|
||||
mConnMgr->getOthersList(peers);
|
||||
|
||||
// clear the data.
|
||||
std::map<RsChanId, NeighbourInfo> &neighs = iface.mNeighbourMap;
|
||||
|
||||
neighs.clear();
|
||||
|
||||
std::list<cert *>::iterator it;
|
||||
std::list<cert *> &certs = ad -> getDiscovered();
|
||||
|
||||
for(it = certs.begin(), i = 0; it != certs.end(); it++, i++)
|
||||
for(it = peers.begin(); it != peers.end(); it++)
|
||||
{
|
||||
peerConnectState state;
|
||||
mConnMgr->getOthersNetStatus(*it, state);
|
||||
|
||||
NeighbourInfo ni;
|
||||
cert *c = (*it);
|
||||
initRsNI(c, ni);
|
||||
|
||||
initRsNI(state, ni); /* same as for neighbour */
|
||||
|
||||
neighs[ni.id] = ni;
|
||||
|
||||
/* let the GUI know */
|
||||
iface.setChanged(RsIface::Friend);
|
||||
}
|
||||
|
||||
/* let the GUI know */
|
||||
|
@ -45,6 +45,7 @@ RsServer::~RsServer()
|
||||
----> MUST BE LOCKED!
|
||||
*/
|
||||
|
||||
#if 0
|
||||
cert *RsServer::intFindCert(RsCertId id)
|
||||
{
|
||||
certsign cs;
|
||||
@ -59,6 +60,7 @@ RsCertId RsServer::intGetCertId(cert *c)
|
||||
RsCertId id = convert_to_str(cs);
|
||||
return id;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS_SYS
|
||||
#include <time.h>
|
||||
@ -122,9 +124,14 @@ void RsServer::run()
|
||||
|
||||
/******************************** RUN SERVER *****************/
|
||||
lockRsCore();
|
||||
|
||||
// std::cerr << "RsServer::run() Lock() -> Run()" << std::endl;
|
||||
int moreToTick = server -> tick();
|
||||
|
||||
unlockRsCore();
|
||||
|
||||
/* tick the connection Manager */
|
||||
mConnMgr->tick();
|
||||
/******************************** RUN SERVER *****************/
|
||||
|
||||
/* adjust tick rate depending on whether there is more.
|
||||
@ -184,9 +191,9 @@ void RsServer::run()
|
||||
|
||||
// These two have been completed!
|
||||
//std::cerr << "RsServer::run() UpdateAllCerts()" << std::endl;
|
||||
UpdateAllCerts();
|
||||
//UpdateAllCerts();
|
||||
//std::cerr << "RsServer::run() UpdateAllNetwork()" << std::endl;
|
||||
UpdateAllNetwork();
|
||||
//UpdateAllNetwork();
|
||||
|
||||
// currently Dummy Functions.
|
||||
//std::cerr << "RsServer::run() UpdateAllTransfers()" << std::endl;
|
||||
@ -210,7 +217,7 @@ void RsServer::run()
|
||||
|
||||
|
||||
//std::cerr << "RsServer::run() CheckDHT()" << std::endl;
|
||||
CheckNetworking();
|
||||
//CheckNetworking();
|
||||
|
||||
}
|
||||
|
||||
@ -222,7 +229,7 @@ void RsServer::run()
|
||||
// save the config every 5 minutes.
|
||||
if (min % 5 == 1)
|
||||
{
|
||||
ConfigSave();
|
||||
//ConfigSave();
|
||||
#ifdef PQI_USE_CHANNELS
|
||||
/* hack to update for now
|
||||
* Only occassionally - cos disabled
|
||||
|
@ -27,12 +27,19 @@
|
||||
#include <unistd.h>
|
||||
//#include <getopt.h>
|
||||
|
||||
#include "dbase/cachestrapper.h"
|
||||
#include "server/filedexserver.h"
|
||||
#include "pqi/pqipersongrp.h"
|
||||
#include "pqi/pqisslpersongrp.h"
|
||||
#include "pqi/pqiloopback.h"
|
||||
#include "pqi/p3cfgmgr.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/p3chatservice.h"
|
||||
#include "services/p3gamelauncher.h"
|
||||
@ -41,20 +48,23 @@
|
||||
#include <string>
|
||||
#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
|
||||
#include <signal.h>
|
||||
|
||||
#include "pqi/pqidebug.h"
|
||||
#include "rsserver/p3face.h"
|
||||
#include "rsserver/p3peers.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;
|
||||
|
||||
// initial configuration bootstrapping...
|
||||
@ -364,10 +374,10 @@ int InitRetroShare(int argcIgnored, char **argvIgnored, RsInit *config)
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
/* do a null init to allow the SSL libray to startup! */
|
||||
getSSLRoot() -> initssl(NULL, NULL, NULL);
|
||||
getAuthMgr() -> InitAuth(NULL, NULL, NULL);
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
getSSLRoot() -> initssl(NULL, NULL, NULL, NULL);
|
||||
getAuthMgr() -> InitAuth(NULL, NULL, NULL, NULL);
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
@ -393,16 +403,21 @@ int InitRetroShare(int argcIgnored, char **argvIgnored, 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.
|
||||
sslr = getSSLRoot();
|
||||
/**************************************************************************/
|
||||
/* STARTUP procedure */
|
||||
/**************************************************************************/
|
||||
/**************************************************************************/
|
||||
/* (1) Load up own certificate (DONE ALREADY) - just CHECK */
|
||||
/**************************************************************************/
|
||||
|
||||
mAuthMgr = getAuthMgr();
|
||||
|
||||
/**************** 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 */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
if (1 != sslr -> initssl(NULL, NULL, NULL, NULL))
|
||||
if (1 != mAuthMgr -> InitAuth(NULL, NULL, NULL, NULL))
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
{
|
||||
@ -412,6 +427,12 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
exit(1);
|
||||
}
|
||||
|
||||
std::string ownId = mAuthMgr->OwnId();
|
||||
|
||||
/**************************************************************************/
|
||||
/* Any Initial Configuration (Commandline Options) */
|
||||
/**************************************************************************/
|
||||
|
||||
/* set the debugging to crashMode */
|
||||
if ((!config->haveLogFile) && (!config->outStderr))
|
||||
{
|
||||
@ -420,19 +441,78 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
setDebugCrashMode(crashfile.c_str());
|
||||
}
|
||||
|
||||
unsigned long flags = 0;
|
||||
if (config->udpListenerOnly)
|
||||
{
|
||||
flags |= PQIPERSON_NO_LISTENER;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
// set the directories for full configuration load.
|
||||
sslr -> setConfigDirs(config->basedir.c_str(), configCertDir.c_str());
|
||||
sslr -> loadCertificates(configConfFile.c_str());
|
||||
sslr -> checkNetAddress();
|
||||
mAuthMgr -> setConfigDirectories(config->basedir.c_str(), configCertDir.c_str());
|
||||
//sslr -> loadCertificates(configConfFile.c_str());
|
||||
|
||||
// Create Classes.
|
||||
// filedex server.
|
||||
server = new filedexserver();
|
||||
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();
|
||||
//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)
|
||||
{
|
||||
@ -444,13 +524,10 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
// universal
|
||||
laddr.sin_addr.s_addr = inet_addr(config->inet);
|
||||
|
||||
cert *own = sslr -> getOwnCert();
|
||||
if (own != NULL)
|
||||
{
|
||||
own -> localaddr = laddr;
|
||||
}
|
||||
mConnMgr->setLocalAddress(ownId, laddr);
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* must load the trusted_peer before setting up the pqipersongrp */
|
||||
if (config->firsttime_run)
|
||||
{
|
||||
@ -461,16 +538,45 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
sslr -> loadInitialTrustedPeer(config->load_trustedpeer_file);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
unsigned long flags = 0;
|
||||
if (config->udpListenerOnly)
|
||||
{
|
||||
flags |= PQIPERSON_NO_SSLLISTENER;
|
||||
}
|
||||
mConnMgr -> checkNetAddress();
|
||||
|
||||
/**************************************************************************/
|
||||
/* 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();
|
||||
server->setSearchInterface(pqih, sslr);
|
||||
|
||||
/* must be after server->setSearchInterface() */
|
||||
server->setFileCallback(ownId, mCacheStrapper, &(getNotify()));
|
||||
|
||||
|
||||
|
||||
#ifdef PQI_USE_CHANNELS
|
||||
server->setP3Channel(pqih->getP3Channel());
|
||||
@ -478,11 +584,10 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
|
||||
// create loopback device, and add to pqisslgrp.
|
||||
|
||||
std::string ownPeerId = sslr->getOwnCert()->PeerId();
|
||||
SearchModule *mod = new SearchModule();
|
||||
pqiloopback *ploop = new pqiloopback(ownPeerId);
|
||||
pqiloopback *ploop = new pqiloopback(ownId);
|
||||
|
||||
mod -> peerid = ownPeerId;
|
||||
mod -> peerid = ownId;
|
||||
mod -> pqi = ploop;
|
||||
mod -> sp = secpolicy_create();
|
||||
|
||||
@ -492,15 +597,15 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
// Load from config will overwrite...
|
||||
server->setSaveDir(config->homePath.c_str());
|
||||
|
||||
server->load_config();
|
||||
//server->load_config();
|
||||
|
||||
/* create Services */
|
||||
ad = new p3disc(sslr);
|
||||
msgSrv = new p3MsgService();
|
||||
chatSrv = new p3ChatService();
|
||||
//ad = new p3disc(sslr); // XXX
|
||||
msgSrv = new p3MsgService(mConnMgr);
|
||||
chatSrv = new p3ChatService(mConnMgr);
|
||||
p3GameLauncher *gameLauncher = new p3GameLauncher();
|
||||
|
||||
pqih -> addService(ad);
|
||||
//pqih -> addService(ad);
|
||||
pqih -> addService(msgSrv);
|
||||
pqih -> addService(chatSrv);
|
||||
pqih -> addService(gameLauncher);
|
||||
@ -520,10 +625,10 @@ int RsServer::StartupRetroShare(RsInit *config)
|
||||
helppage += configHelpName;
|
||||
|
||||
/* for DHT/UPnP stuff */
|
||||
InitNetworking(config->basedir + "/kadc.ini");
|
||||
//InitNetworking(config->basedir + "/kadc.ini");
|
||||
|
||||
/* Startup this thread! */
|
||||
pthread_t coreId = createThread(*this);
|
||||
createThread(*this);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -553,16 +658,16 @@ int LoadCertificates(RsInit *config, bool autoLoginNT)
|
||||
std::string ca_loc = config->basedir + config->dirSeperator;
|
||||
ca_loc += configCaFile;
|
||||
|
||||
sslroot *sr = getSSLRoot();
|
||||
p3AuthMgr *authMgr = getAuthMgr();
|
||||
|
||||
/**************** 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->passwd.c_str()))
|
||||
#else /* X509 Certificates */
|
||||
/**************** 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(),
|
||||
ca_loc.c_str(),
|
||||
config->passwd.c_str()))
|
||||
|
@ -27,16 +27,21 @@
|
||||
*/
|
||||
|
||||
#include "server/filedexserver.h"
|
||||
//#include "pqi/pqissl.h"
|
||||
|
||||
#include "pqi/p3connmgr.h"
|
||||
#include "pqi/pqipersongrp.h"
|
||||
#include "pqi/pqissl.h"
|
||||
|
||||
#include "rsiface/rsiface.h"
|
||||
#include "rsiface/rstypes.h"
|
||||
#include "util/rsthreads.h"
|
||||
|
||||
#include "services/p3disc.h"
|
||||
#include "services/p3msgservice.h"
|
||||
class p3disc;
|
||||
class p3MsgService;
|
||||
class p3ChatService;
|
||||
|
||||
#include "services/p3chatservice.h"
|
||||
#include "services/p3msgservice.h"
|
||||
|
||||
/* The Main Interface Class - for controlling the server */
|
||||
|
||||
@ -105,55 +110,14 @@ void unlockRsCore()
|
||||
/* General Internal Helper Functions
|
||||
(Must be Locked)
|
||||
*/
|
||||
|
||||
#if 0
|
||||
cert *intFindCert(RsCertId id);
|
||||
RsCertId intGetCertId(cert *c);
|
||||
#endif
|
||||
|
||||
/****************************************/
|
||||
/* 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 */
|
||||
@ -256,24 +220,24 @@ void initRsMI(RsMsgItem *msg, MessageInfo &mi);
|
||||
public:
|
||||
/****************************************/
|
||||
/* RsIface Networking */
|
||||
virtual int NetworkDHTActive(bool active);
|
||||
virtual int NetworkUPnPActive(bool active);
|
||||
virtual int NetworkDHTStatus();
|
||||
virtual int NetworkUPnPStatus();
|
||||
//virtual int NetworkDHTActive(bool active);
|
||||
//virtual int NetworkUPnPActive(bool active);
|
||||
//virtual int NetworkDHTStatus();
|
||||
//virtual int NetworkUPnPStatus();
|
||||
|
||||
private:
|
||||
/* internal */
|
||||
int InitNetworking(std::string);
|
||||
int CheckNetworking();
|
||||
//int InitNetworking(std::string);
|
||||
//int CheckNetworking();
|
||||
|
||||
int InitDHT(std::string);
|
||||
int CheckDHT();
|
||||
//int InitDHT(std::string);
|
||||
//int CheckDHT();
|
||||
|
||||
int InitUPnP();
|
||||
int CheckUPnP();
|
||||
//int InitUPnP();
|
||||
//int CheckUPnP();
|
||||
|
||||
int UpdateNetworkConfig(RsConfig &config);
|
||||
int SetExternalPorts();
|
||||
//int UpdateNetworkConfig(RsConfig &config);
|
||||
//int SetExternalPorts();
|
||||
|
||||
|
||||
public:
|
||||
@ -284,14 +248,14 @@ virtual int ConfigAddSharedDir( std::string dir );
|
||||
virtual int ConfigRemoveSharedDir( std::string dir );
|
||||
virtual int ConfigSetIncomingDir( std::string dir );
|
||||
|
||||
virtual int ConfigSetLocalAddr( std::string ipAddr, int port );
|
||||
virtual int ConfigSetExtAddr( std::string ipAddr, int port );
|
||||
virtual int ConfigSetExtName( std::string addr );
|
||||
virtual int ConfigSetLanConfig( bool fire, bool forw );
|
||||
//virtual int ConfigSetLocalAddr( std::string ipAddr, int port );
|
||||
//virtual int ConfigSetExtAddr( std::string ipAddr, int port );
|
||||
//virtual int ConfigSetExtName( std::string addr );
|
||||
//virtual int ConfigSetLanConfig( bool fire, bool forw );
|
||||
|
||||
virtual int ConfigSetDataRates( int total, int indiv );
|
||||
virtual int ConfigSetBootPrompt( bool on );
|
||||
virtual int ConfigSave( );
|
||||
//virtual int ConfigSave( );
|
||||
|
||||
private:
|
||||
int UpdateAllConfig();
|
||||
@ -304,8 +268,13 @@ int UpdateAllConfig();
|
||||
// The real Server Parts.
|
||||
|
||||
filedexserver *server;
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
p3AuthMgr *mAuthMgr;
|
||||
|
||||
pqipersongrp *pqih;
|
||||
sslroot *sslr;
|
||||
|
||||
//sslroot *sslr;
|
||||
|
||||
/* services */
|
||||
p3disc *ad;
|
||||
|
635
libretroshare/src/rsserver/p3peers.cc
Normal file
635
libretroshare/src/rsserver/p3peers.cc
Normal 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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
83
libretroshare/src/rsserver/p3peers.h
Normal file
83
libretroshare/src/rsserver/p3peers.h
Normal 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
|
@ -525,12 +525,12 @@ std::string getX509Info(X509 *cert)
|
||||
* into a string.
|
||||
*/
|
||||
|
||||
static char *TIME_FORMAT_STR_BRIEF = "%H:%M:%S";
|
||||
static char *TIME_FORMAT_STR_OLDVAGUE_NOW = "%H:%M:%S";
|
||||
static char *TIME_FORMAT_STR_OLDVAGUE_WEEK = "%a %H:%M";
|
||||
static char *TIME_FORMAT_STR_OLDVAGUE_OLD = "%a, %d %b";
|
||||
static char *TIME_FORMAT_STR_LONG = "%c";
|
||||
static char *TIME_FORMAT_STR_NORMAL = "%a, %H:%M:%S";
|
||||
static const char *TIME_FORMAT_STR_BRIEF = "%H:%M:%S";
|
||||
static const char *TIME_FORMAT_STR_OLDVAGUE_NOW = "%H:%M:%S";
|
||||
static const char *TIME_FORMAT_STR_OLDVAGUE_WEEK = "%a %H:%M";
|
||||
static const char *TIME_FORMAT_STR_OLDVAGUE_OLD = "%a, %d %b";
|
||||
static const char *TIME_FORMAT_STR_LONG = "%c";
|
||||
static const char *TIME_FORMAT_STR_NORMAL = "%a, %H:%M:%S";
|
||||
|
||||
std::string timeFormat(int epoch, int format)
|
||||
{
|
||||
@ -539,7 +539,7 @@ std::string timeFormat(int epoch, int format)
|
||||
|
||||
size_t msize = 1024;
|
||||
char space[msize];
|
||||
char *fmtstr = NULL;
|
||||
const char *fmtstr = NULL;
|
||||
|
||||
if (format == TIME_FORMAT_OLDVAGUE)
|
||||
{
|
||||
|
@ -29,18 +29,6 @@
|
||||
#include "rsiface/rsiface.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 *dir = getDirectoryMod(id, path);
|
||||
|
@ -35,16 +35,6 @@
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
#if 0
|
||||
/****************************************/
|
||||
RsCertId::RsCertId()
|
||||
{
|
||||
for(int i = 0; i < RSCERTIDLEN; i++)
|
||||
{
|
||||
data[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
* NOTE NOTE NOTE ...... XXX
|
||||
* 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 */
|
||||
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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user