mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-21 21:55:15 -05:00
Add the tunneling connection. Warning, encryption is not implemented yet for tunnel connection, use only for testing.
Redesign the udp connection Remove the rsiface duplicates from retroshare-gui. Add some randomness in timings for connect manager Merge branch 'connectionTunneling' Conflicts: libretroshare/src/libretroshare.pro libretroshare/src/pqi/p3connmgr.cc retroshare-gui/src/RetroShare.pro retroshare-gui/src/rsiface/rsfiles.h retroshare-gui/src/rsiface/rstypes.h git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1867 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
1d567a7faa
commit
fdb3673ce2
@ -181,7 +181,8 @@ HEADERS += dbase/cachestrapper.h \
|
||||
pqi/pqiservice.h \
|
||||
pqi/pqistore.h \
|
||||
pqi/pqissl.h \
|
||||
pqi/pqissllistener.h \
|
||||
pqi/pqissltunnel.h \
|
||||
pqi/pqissllistener.h \
|
||||
pqi/pqisslpersongrp.h \
|
||||
pqi/pqissludp.h \
|
||||
pqi/pqistreamer.h \
|
||||
@ -213,7 +214,8 @@ HEADERS += dbase/cachestrapper.h \
|
||||
serialiser/rsbaseitems.h \
|
||||
serialiser/rsbaseserial.h \
|
||||
serialiser/rschannelitems.h \
|
||||
serialiser/rsconfigitems.h \
|
||||
serialiser/rstunnelitems.h \
|
||||
serialiser/rsconfigitems.h \
|
||||
serialiser/rsdiscitems.h \
|
||||
serialiser/rsdistribitems.h \
|
||||
serialiser/rsforumitems.h \
|
||||
@ -234,7 +236,8 @@ HEADERS += dbase/cachestrapper.h \
|
||||
services/p3channels.h \
|
||||
services/p3chatservice.h \
|
||||
services/p3disc.h \
|
||||
services/p3distrib.h \
|
||||
services/p3tunnel.h \
|
||||
services/p3distrib.h \
|
||||
services/p3forums.h \
|
||||
services/p3gamelauncher.h \
|
||||
services/p3gameservice.h \
|
||||
@ -306,6 +309,7 @@ SOURCES += \
|
||||
services/p3distrib.cc \
|
||||
services/p3photoservice.cc \
|
||||
services/p3disc.cc \
|
||||
services/p3tunnel.cc \
|
||||
services/p3ranking.cc \
|
||||
services/p3gamelauncher.cc \
|
||||
services/p3msgservice.cc \
|
||||
@ -330,6 +334,7 @@ SOURCES += \
|
||||
pqi/pqisslpersongrp.cc \
|
||||
pqi/pqissllistener.cc \
|
||||
pqi/pqissl.cc \
|
||||
pqi/pqissltunnel.cc \
|
||||
pqi/pqistore.cc \
|
||||
pqi/p3authmgr.cc \
|
||||
pqi/p3cfgmgr.cc \
|
||||
@ -345,6 +350,7 @@ SOURCES += \
|
||||
serialiser/rsqblogitems.cc \
|
||||
serialiser/rsstatusitems.cc \
|
||||
serialiser/rschannelitems.cc \
|
||||
serialiser/rstunnelitems.cc \
|
||||
serialiser/rsforumitems.cc \
|
||||
serialiser/rsdistribitems.cc \
|
||||
serialiser/rsgameitems.cc \
|
||||
|
@ -1786,6 +1786,29 @@ bool AuthSSL::FailedCertificate(X509 *x509, bool incoming)
|
||||
return ProcessX509(x509, id);
|
||||
}
|
||||
|
||||
bool AuthSSL::encrypt(void *&out, int &outlen, const void *in, int inlen, std::string peerId)
|
||||
{
|
||||
#ifdef AUTHSSL_DEBUG
|
||||
std::cerr << "AuthSSL::encrypt() called with inlen : " << inlen << std::endl;
|
||||
#endif
|
||||
//TODO : use ssl to crypt the binary input buffer
|
||||
out = malloc(inlen);
|
||||
memcpy(out, in, inlen);
|
||||
outlen = inlen;
|
||||
}
|
||||
|
||||
bool AuthSSL::decrypt(void *&out, int &outlen, const void *in, int inlen)
|
||||
{
|
||||
#ifdef AUTHSSL_DEBUG
|
||||
std::cerr << "AuthSSL::decrypt() called with inlen : " << inlen << std::endl;
|
||||
#endif
|
||||
//TODO : use ssl to decrypt the binary input buffer
|
||||
out = malloc(inlen);
|
||||
memcpy(out, in, inlen);
|
||||
outlen = inlen;
|
||||
}
|
||||
|
||||
|
||||
/* check that they are exact match */
|
||||
bool AuthSSL::CheckCertificate(std::string x509Id, X509 *x509)
|
||||
{
|
||||
|
@ -149,6 +149,12 @@ virtual bool SignDataBin(std::string, unsigned char*, unsigned int*);
|
||||
virtual bool SignDataBin(const void*, uint32_t, unsigned char*, unsigned int*);
|
||||
virtual bool VerifySignBin(std::string, const void*, uint32_t, unsigned char*, unsigned int);
|
||||
|
||||
// return : false if encrypt failed
|
||||
bool encrypt(void *&out, int &outlen, const void *in, int inlen, std::string peerId); //return the encrypted length
|
||||
|
||||
// return : false if decrypt fails
|
||||
bool decrypt(void *&out, int &outlen, const void *in, int inlen); //return the encrypted length
|
||||
|
||||
|
||||
/*********** Overloaded Functions from p3AuthMgr **********/
|
||||
|
||||
|
@ -59,7 +59,7 @@ const uint32_t MAX_NETWORK_INIT = 70; /* timeout before network reset */
|
||||
|
||||
const uint32_t MIN_TIME_BETWEEN_NET_RESET = 5;
|
||||
|
||||
const uint32_t PEER_IP_CONNECT_STATE_MAX_LIST_SIZE = 10;
|
||||
const uint32_t PEER_IP_CONNECT_STATE_MAX_LIST_SIZE = 6;
|
||||
|
||||
/****
|
||||
* #define CONN_DEBUG 1
|
||||
@ -72,11 +72,11 @@ const uint32_t PEER_IP_CONNECT_STATE_MAX_LIST_SIZE = 10;
|
||||
***/
|
||||
|
||||
const uint32_t P3CONNMGR_TCP_DEFAULT_DELAY = 2; /* 2 Seconds? is it be enough! */
|
||||
const uint32_t P3CONNMGR_UDP_DHT_DELAY = DHT_NOTIFY_PERIOD + 60; /* + 1 minute for DHT POST */
|
||||
const uint32_t P3CONNMGR_UDP_PROXY_DELAY = 30; /* 30 seconds (NOT IMPLEMENTED YET!) */
|
||||
const uint32_t P3CONNMGR_UDP_DEFAULT_DELAY = 2; /* 2 Seconds? is it be enough! */
|
||||
const uint32_t P3CONNMGR_UDP_DEFAULT_TIMEOUT = 40; //a random timeout is set between P3CONNMGR_UDP_DEFAULT_TIMEOUT and 2 * P3CONNMGR_UDP_DEFAULT_TIMEOUT in the implementation
|
||||
|
||||
#define MAX_AVAIL_PERIOD (2 * DHT_NOTIFY_PERIOD) // If we haven't connected in 2 DHT periods.
|
||||
#define MIN_RETRY_PERIOD (DHT_CHECK_PERIOD + 120) // just over DHT CHECK_PERIOD
|
||||
#define MAX_AVAIL_PERIOD 180 //times a peer stay in available state when not connected
|
||||
#define MIN_RETRY_PERIOD 90
|
||||
|
||||
void printConnectState(peerConnectState &peer);
|
||||
|
||||
@ -143,6 +143,7 @@ p3ConnectMgr::p3ConnectMgr(p3AuthMgr *am)
|
||||
}
|
||||
//use_extr_addr_finder = true ;
|
||||
use_extr_addr_finder = false;
|
||||
allow_tunnel_connection = true;
|
||||
mExtAddrFinder = new ExtAddrFinder ;
|
||||
|
||||
return;
|
||||
@ -161,6 +162,13 @@ void p3ConnectMgr::setIPServersEnabled(bool b)
|
||||
std::cerr << "p3ConnectMgr: setIPServers to " << b << std::endl ;
|
||||
}
|
||||
|
||||
void p3ConnectMgr::setTunnelConnection(bool b)
|
||||
{
|
||||
allow_tunnel_connection = b ;
|
||||
|
||||
IndicateConfigChanged(); /**** INDICATE MSG CONFIG CHANGED! *****/
|
||||
}
|
||||
|
||||
void p3ConnectMgr::setOwnNetConfig(uint32_t netMode, uint32_t visState)
|
||||
{
|
||||
/* only change TRY flags */
|
||||
@ -1495,8 +1503,9 @@ bool p3ConnectMgr::connectAttempt(std::string id, struct sockaddr_in &addr,
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
it->second.lastattempt = time(NULL); /* time of last connect attempt */
|
||||
|
||||
it->second.lastattempt = time(NULL) + ((time(NULL)*1664525 + 1013904223) % 3);//add a random perturbation between 0 and 2 sec. pseudo random number generator from Wikipedia/Numerical Recipies.
|
||||
|
||||
it->second.inConnAttempt = true;
|
||||
it->second.currentConnAddrAttempt = it->second.connAddrs.front();
|
||||
it->second.connAddrs.pop_front();
|
||||
@ -1529,6 +1538,13 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
||||
{
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
rslog(RSL_WARNING, p3connectzone, "p3ConnectMgr::connectResult() called Connect!: id: " + id);
|
||||
if (success) {
|
||||
rslog(RSL_WARNING, p3connectzone, "p3ConnectMgr::connectResult() called with SUCCESS.");
|
||||
} else {
|
||||
rslog(RSL_WARNING, p3connectzone, "p3ConnectMgr::connectResult() called with FAILED.");
|
||||
}
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
it = mFriendList.find(id);
|
||||
@ -1549,13 +1565,14 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
||||
it->second.connAddrs.clear();
|
||||
netAssistFriend(id, false);
|
||||
|
||||
/* update address (will come through from DISC) */
|
||||
/* update address (will come through from DISC) */
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::connectResult() Connect!: id: " << id << std::endl;
|
||||
std::cerr << " Success: " << success << " flags: " << flags << std::endl;
|
||||
#endif
|
||||
|
||||
rslog(RSL_WARNING, p3connectzone, "p3ConnectMgr::connectResult() Success");
|
||||
|
||||
/* change state */
|
||||
it->second.state |= RS_PEER_S_CONNECTED;
|
||||
@ -1606,7 +1623,36 @@ bool p3ConnectMgr::connectResult(std::string id, bool success, uint32_t flags)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool p3ConnectMgr::doNextAttempt(std::string id)
|
||||
{
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
rslog(RSL_WARNING, p3connectzone, "p3ConnectMgr::doNextAttempt() called id : " + id);
|
||||
|
||||
/* check for existing */
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
it = mFriendList.find(id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::connectResult() Failed, missing Friend " << " id: " << id << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
it->second.inConnAttempt = false;
|
||||
|
||||
if (it->second.connAddrs.size() < 1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
it->second.actions |= RS_PEER_CONNECT_REQ;
|
||||
mStatusChanged = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/******************************** Feedback ...... *********************************
|
||||
@ -1779,7 +1825,7 @@ void p3ConnectMgr::peerStatus(std::string id,
|
||||
/* Determine Reachability (only advisory) */
|
||||
if (ownState.netMode & RS_NET_MODE_UDP)
|
||||
{
|
||||
if ((details.type & RS_NET_CONN_UDP_DHT_SYNC) ||
|
||||
if ((details.type & RS_NET_CONN_UDP) ||
|
||||
(details.type & RS_NET_CONN_TCP_EXTERNAL))
|
||||
{
|
||||
/* reachable! */
|
||||
@ -1849,11 +1895,7 @@ void p3ConnectMgr::peerStatus(std::string id,
|
||||
|
||||
#endif // P3CONNMGR_NO_TCP_CONNECTIONS
|
||||
|
||||
/* notify if they say we can, or we cannot connect ! */
|
||||
if (details.type & RS_NET_CONN_UDP_DHT_SYNC)
|
||||
{
|
||||
retryConnectNotify(id);
|
||||
}
|
||||
retryConnectNotify(id);
|
||||
#else
|
||||
|
||||
#endif // P3CONNMGR_NO_AUTO_CONNECTION
|
||||
@ -1886,132 +1928,7 @@ void p3ConnectMgr::peerConnectRequest(std::string id, struct sockaddr_in radd
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::peerConnectRequest() Try TCP first" << std::endl;
|
||||
#endif
|
||||
retryConnectTCP(id);
|
||||
|
||||
/******************** UDP PART *****************************/
|
||||
|
||||
RsStackMutex stack(connMtx); /****** STACK LOCK MUTEX *******/
|
||||
|
||||
if (ownState.netMode & RS_NET_MODE_UNREACHABLE)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::peerConnectRequest() Unreachable - no UDP connection" << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
/* look up the id */
|
||||
std::map<std::string, peerConnectState>::iterator it;
|
||||
bool isFriend = true;
|
||||
it = mFriendList.find(id);
|
||||
if (it == mFriendList.end())
|
||||
{
|
||||
/* check Others list */
|
||||
isFriend = false;
|
||||
it = mOthersList.find(id);
|
||||
if (it == mOthersList.end())
|
||||
{
|
||||
/* not found - ignore */
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::peerConnectRequest() Peer Not Found - Ignore" << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::peerConnectRequest() Peer is in mOthersList - Ignore" << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
/* if already connected -> done */
|
||||
if (it->second.state & RS_PEER_S_CONNECTED)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::peerConnectRequest() Already connected - Ignore";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
time_t now = time(NULL);
|
||||
/* this is a UDP connection request (DHT only for the moment!) */
|
||||
if (isValidNet(&(raddr.sin_addr)))
|
||||
{
|
||||
/* add the remote address */
|
||||
peerConnectAddress pca;
|
||||
pca.ts = now;
|
||||
pca.type = RS_NET_CONN_UDP_DHT_SYNC;
|
||||
pca.delay = 0;
|
||||
|
||||
if (source == RS_CB_DHT)
|
||||
{
|
||||
pca.period = P3CONNMGR_UDP_DHT_DELAY;
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::peerConnectRequest() source = DHT ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
else if (source == RS_CB_PROXY)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::peerConnectRequest() source = PROXY ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
pca.period = P3CONNMGR_UDP_PROXY_DELAY;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::peerConnectRequest() source = UNKNOWN ";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
/* error! */
|
||||
pca.period = P3CONNMGR_UDP_PROXY_DELAY;
|
||||
}
|
||||
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::peerConnectRequest() period = " << pca.period;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
pca.addr = raddr;
|
||||
|
||||
{
|
||||
/* Log */
|
||||
std::ostringstream out;
|
||||
out << "p3ConnectMgr::peerConnectRequest() PushBack UDP Address: id: " << id << " raddr: " << inet_ntoa(pca.addr.sin_addr);
|
||||
out << ":" << ntohs(pca.addr.sin_port) << " type: " << pca.type << " delay: " << pca.delay << " period: " << pca.period;
|
||||
out << " ts: " << pca.ts;
|
||||
rslog(RSL_WARNING, p3connectzone, out.str());
|
||||
}
|
||||
|
||||
/* push to the back ... TCP ones should be tried first */
|
||||
it->second.connAddrs.push_back(pca);
|
||||
}
|
||||
|
||||
if (it->second.inConnAttempt)
|
||||
{
|
||||
/* -> it'll automatically use the addresses */
|
||||
return;
|
||||
}
|
||||
|
||||
/* start a connection attempt */
|
||||
if (it->second.connAddrs.size() > 0)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::peerConnectRequest() Started CONNECT ATTEMPT! id: " << id << std::endl;
|
||||
#endif
|
||||
|
||||
it->second.actions |= RS_PEER_CONNECT_REQ;
|
||||
mStatusChanged = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::peerConnectRequest() No addr suitable for CONNECT ATTEMPT! id: " << id << std::endl;
|
||||
#endif
|
||||
}
|
||||
retryConnect(id);
|
||||
}
|
||||
|
||||
|
||||
@ -2261,29 +2178,27 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
|
||||
if (mFriendList.end() == (it = mFriendList.find(id)))
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::retryConnectTCP() Peer is not Friend" << std::endl;
|
||||
std::cerr << "p3ConnectMgr::retryConnectTCP() Peer is not Friend" << std::endl;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
/* if already connected -> done */
|
||||
if (it->second.state & RS_PEER_S_CONNECTED)
|
||||
if (it->second.state & RS_PEER_S_CONNECTED)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::retryConnectTCP() Peer Already Connected" << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
if (it->second.currentConnAddrAttempt.type & RS_NET_CONN_TUNNEL) {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::retryConnectTCP() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl;
|
||||
#endif
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* are the addresses different? */
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
/* add in attempts ... local(TCP), remote(TCP)
|
||||
*/
|
||||
|
||||
#ifndef P3CONNMGR_NO_TCP_CONNECTIONS
|
||||
//add the ips off the ipAdressList
|
||||
//add the ips off the ipAdressList for TCP
|
||||
std::list<IpAddressTimed> ipList = it->second.getIpAddressList();
|
||||
for (std::list<IpAddressTimed>::iterator ipListIt = ipList.begin(); ipListIt!=(ipList.end()); ipListIt++) {
|
||||
#ifdef CONN_DEBUG
|
||||
@ -2293,30 +2208,95 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
|
||||
//check that the address doens't exist already in the connAddrs
|
||||
bool found = false;
|
||||
for (std::list<peerConnectAddress>::iterator cit = it->second.connAddrs.begin(); cit != it->second.connAddrs.end(); cit++) {
|
||||
if (cit->addr.sin_addr.s_addr == ipListIt->ipAddr.sin_addr.s_addr && cit->addr.sin_port == ipListIt->ipAddr.sin_port) {
|
||||
if (cit->addr.sin_addr.s_addr == ipListIt->ipAddr.sin_addr.s_addr &&
|
||||
cit->addr.sin_port == ipListIt->ipAddr.sin_port &&
|
||||
cit->type == RS_NET_CONN_TCP_UNKNOW_TOPOLOGY) {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::retryConnectTCP() ip already in the conn addr attempt list." << std::endl;
|
||||
std::cerr << "p3ConnectMgr::retryConnectTCP() tcp attempt already in list." << std::endl;
|
||||
#endif
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
peerConnectAddress pca;
|
||||
pca.addr = ipListIt->ipAddr;
|
||||
pca.type = RS_NET_CONN_TCP_UNKNOW_TOPOLOGY;
|
||||
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
||||
pca.ts = time(NULL);
|
||||
pca.period = 0;
|
||||
it->second.connAddrs.push_back(pca);
|
||||
}
|
||||
}
|
||||
if (!found) {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "Adding tcp connection attempt list." << std::endl;
|
||||
#endif
|
||||
peerConnectAddress pca;
|
||||
pca.addr = ipListIt->ipAddr;
|
||||
pca.type = RS_NET_CONN_TCP_UNKNOW_TOPOLOGY;
|
||||
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
|
||||
pca.ts = time(NULL);
|
||||
pca.period = 0;
|
||||
it->second.connAddrs.push_back(pca);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // P3CONNMGR_NO_TCP_CONNECTIONS
|
||||
//add the first 2 ips off the ipAdressList for UDP
|
||||
ipList = it->second.getIpAddressList();
|
||||
for (std::list<IpAddressTimed>::iterator ipListIt = ipList.begin(); ipListIt!=(ipList.end()); ipListIt++) {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::retryConnectTCP() adding ip : " << inet_ntoa(ipListIt->ipAddr.sin_addr);
|
||||
std::cerr << ":" << ntohs(ipListIt->ipAddr.sin_port) << std::endl;
|
||||
#endif
|
||||
//check that the address doens't exist already in the connAddrs
|
||||
bool found = false;
|
||||
for (std::list<peerConnectAddress>::iterator cit = it->second.connAddrs.begin(); cit != it->second.connAddrs.end(); cit++) {
|
||||
if (cit->addr.sin_addr.s_addr == ipListIt->ipAddr.sin_addr.s_addr &&
|
||||
cit->addr.sin_port == ipListIt->ipAddr.sin_port &&
|
||||
cit->type == RS_NET_CONN_UDP) {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::retryConnectTCP() udp attempt already in list." << std::endl;
|
||||
#endif
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found && !isSameSubnet(&ipListIt->ipAddr.sin_addr, &ownState.currentlocaladdr.sin_addr)) {//add only if in different subnet
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "Adding udp connection attempt." << std::endl;
|
||||
#endif
|
||||
peerConnectAddress pca;
|
||||
pca.addr = ipListIt->ipAddr;
|
||||
pca.type = RS_NET_CONN_UDP;
|
||||
pca.delay = P3CONNMGR_UDP_DEFAULT_DELAY;
|
||||
pca.ts = time(NULL);
|
||||
// pseudo random number generator from Wikipedia/Numerical Recipies.
|
||||
pca.period = P3CONNMGR_UDP_DEFAULT_TIMEOUT + (time(NULL)*1664525 + 1013904223 % P3CONNMGR_UDP_DEFAULT_TIMEOUT); //add a random timeout between 1 and 2 times P3CONNMGR_UDP_DEFAULT_TIMEOUT
|
||||
it->second.connAddrs.push_back(pca);
|
||||
|
||||
break; //add only one udp address
|
||||
}
|
||||
}
|
||||
|
||||
//ad the tunnel attempt
|
||||
bool found = false;
|
||||
for (std::list<peerConnectAddress>::iterator cit = it->second.connAddrs.begin(); cit != it->second.connAddrs.end(); cit++) {
|
||||
if (cit->type == RS_NET_CONN_TUNNEL) {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::retryConnectTCP() tunnel is already in the list.." << std::endl;
|
||||
#endif
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(it->second.state & RS_PEER_S_CONNECTED) && !found && allow_tunnel_connection)
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::retryConnectTCP() Add the tunnel connection attempt." << std::endl;
|
||||
#endif
|
||||
peerConnectAddress pca;
|
||||
pca.type = RS_NET_CONN_TUNNEL;
|
||||
pca.ts = time(NULL);
|
||||
pca.period = 0;
|
||||
it->second.connAddrs.push_back(pca);
|
||||
}
|
||||
|
||||
/* flag as last attempt to prevent loop */
|
||||
it->second.lastattempt = time(NULL);
|
||||
it->second.lastattempt = time(NULL) + ((time(NULL)*1664525 + 1013904223) % 3);//add a random perturbation between 0 and 2 sec. pseudo random number generator from Wikipedia/Numerical Recipies.
|
||||
|
||||
if (it->second.inConnAttempt)
|
||||
{
|
||||
@ -2337,7 +2317,7 @@ bool p3ConnectMgr::retryConnectTCP(std::string id)
|
||||
else
|
||||
{
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::retryConnectTCP() No addr suitable for CONNECT ATTEMPT! " << " id: " << id << std::endl;
|
||||
std::cerr << "p3ConnectMgr::retryConnectTCP() No addr in the connect attempt list. Not suitable for CONNECT ATTEMPT! " << " id: " << id << std::endl;
|
||||
#endif
|
||||
}
|
||||
return true;
|
||||
@ -2367,14 +2347,20 @@ bool p3ConnectMgr::retryConnectNotify(std::string id)
|
||||
/* if already connected -> done */
|
||||
if (it->second.state & RS_PEER_S_CONNECTED)
|
||||
{
|
||||
if (it->second.currentConnAddrAttempt.type & RS_NET_CONN_TUNNEL) {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::retryConnectNotify() Peer Already Connected" << std::endl;
|
||||
std::cerr << "p3ConnectMgr::retryConnectNotify() Peer Connected through a tunnel connection, let's try a normal connection." << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
} else {
|
||||
#ifdef CONN_DEBUG
|
||||
std::cerr << "p3ConnectMgr::retryConnectNotify() Peer Already Connected, aborting retryConnect" << std::endl;
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* flag as last attempt to prevent loop */
|
||||
it->second.lastattempt = time(NULL);
|
||||
it->second.lastattempt = time(NULL) + ((time(NULL)*1664525 + 1013904223) % 3);//add a random perturbation between 0 and 2 sec. pseudo random number generator from Wikipedia/Numerical Recipies.
|
||||
|
||||
if (ownState.netMode & RS_NET_MODE_UNREACHABLE)
|
||||
{
|
||||
@ -2771,6 +2757,18 @@ std::list<RsItem *> p3ConnectMgr::saveList(bool &cleanup)
|
||||
std::cout << "Pushing item for use_extr_addr_finder = " << use_extr_addr_finder << std::endl ;
|
||||
saveData.push_back(vitem);
|
||||
|
||||
// Now save config for network digging strategies
|
||||
|
||||
RsConfigKeyValueSet *vitem2 = new RsConfigKeyValueSet ;
|
||||
|
||||
RsTlvKeyValue kv2;
|
||||
kv2.key = "ALLOW_TUNNEL_CONNECTION" ;
|
||||
kv2.value = (allow_tunnel_connection)?"TRUE":"FALSE" ;
|
||||
vitem2->tlvkvs.pairs.push_back(kv2) ;
|
||||
|
||||
std::cout << "Pushing item for allow_tunnel_connection = " << allow_tunnel_connection << std::endl ;
|
||||
saveData.push_back(vitem2);
|
||||
|
||||
return saveData;
|
||||
}
|
||||
|
||||
@ -2844,7 +2842,11 @@ bool p3ConnectMgr::loadList(std::list<RsItem *> load)
|
||||
{
|
||||
use_extr_addr_finder = (vitem->tlvkvs.pairs.front().value == "TRUE") ;
|
||||
std::cerr << "setting use_extr_addr_finder to " << use_extr_addr_finder << std::endl ;
|
||||
}
|
||||
} else if (vitem->tlvkvs.pairs.front().key == "ALLOW_TUNNEL_CONNECTION")
|
||||
{
|
||||
allow_tunnel_connection = (vitem->tlvkvs.pairs.front().value == "TRUE") ;
|
||||
std::cerr << "setting allow_tunnel_connection to " << allow_tunnel_connection << std::endl ;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -3304,3 +3306,11 @@ void peerConnectState::printIpAddressList(std::list<IpAddressTimed> ipTimedList)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
p3tunnel* p3ConnectMgr::getP3tunnel() {
|
||||
return mP3tunnel;
|
||||
}
|
||||
|
||||
void p3ConnectMgr::setP3tunnel(p3tunnel *p3tun) {
|
||||
mP3tunnel = p3tun;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@
|
||||
//#include "pqi/p3dhtmgr.h"
|
||||
//#include "pqi/p3upnpmgr.h"
|
||||
#include "pqi/pqiassist.h"
|
||||
#include "services/p3tunnel.h"
|
||||
|
||||
#include "pqi/p3cfgmgr.h"
|
||||
|
||||
@ -80,12 +81,12 @@ const uint32_t RS_NET_MODE_UNREACHABLE = 0x0008;
|
||||
/* order of attempts ... */
|
||||
const uint32_t RS_NET_CONN_TCP_ALL = 0x000f;
|
||||
const uint32_t RS_NET_CONN_UDP_ALL = 0x00f0;
|
||||
const uint32_t RS_NET_CONN_TUNNEL = 0x0f00;
|
||||
|
||||
const uint32_t RS_NET_CONN_TCP_LOCAL = 0x0001;
|
||||
const uint32_t RS_NET_CONN_TCP_EXTERNAL = 0x0002;
|
||||
const uint32_t RS_NET_CONN_TCP_UNKNOW_TOPOLOGY = 0x0003;
|
||||
const uint32_t RS_NET_CONN_UDP_DHT_SYNC = 0x0010;
|
||||
const uint32_t RS_NET_CONN_UDP_PEER_SYNC = 0x0020; /* coming soon */
|
||||
const uint32_t RS_NET_CONN_UDP = 0x0010;
|
||||
|
||||
/* extra flags */
|
||||
// not sure if needed yet.
|
||||
@ -211,6 +212,8 @@ bool getDHTEnabled();
|
||||
bool getIPServersEnabled() { return use_extr_addr_finder ;}
|
||||
void setIPServersEnabled(bool b) ;
|
||||
void getIPServersList(std::list<std::string>& ip_servers) ;
|
||||
void setTunnelConnection(bool b) ;
|
||||
bool getTunnelConnection() { return allow_tunnel_connection ;}
|
||||
|
||||
bool getNetStatusLocalOk();
|
||||
bool getNetStatusUpnpOk();
|
||||
@ -266,6 +269,10 @@ virtual void stunStatus(std::string id, struct sockaddr_in raddr, uint32_t ty
|
||||
bool connectAttempt(std::string id, struct sockaddr_in &addr,
|
||||
uint32_t &delay, uint32_t &period, uint32_t &type);
|
||||
bool connectResult(std::string id, bool success, uint32_t flags);
|
||||
bool doNextAttempt(std::string id);
|
||||
|
||||
p3tunnel* getP3tunnel();
|
||||
void setP3tunnel(p3tunnel *p3tun);
|
||||
|
||||
|
||||
protected:
|
||||
@ -365,6 +372,8 @@ private:
|
||||
|
||||
p3AuthMgr *mAuthMgr;
|
||||
|
||||
p3tunnel *mP3tunnel;
|
||||
|
||||
std::map<uint32_t, pqiNetAssistFirewall *> mFwAgents;
|
||||
std::map<uint32_t, pqiNetAssistConnect *> mDhts;
|
||||
|
||||
@ -385,6 +394,7 @@ private:
|
||||
|
||||
ExtAddrFinder *mExtAddrFinder ;
|
||||
bool use_extr_addr_finder ;
|
||||
bool allow_tunnel_connection ;
|
||||
|
||||
/* external Address determination */
|
||||
//bool mUpnpAddrValid, mStunAddrValid;
|
||||
|
@ -291,7 +291,8 @@ virtual int notifyEvent(NetInterface *ni, int event) { return 0; }
|
||||
|
||||
const uint32_t PQI_CONNECT_TCP = 0x0001;
|
||||
const uint32_t PQI_CONNECT_UDP = 0x0002;
|
||||
|
||||
const uint32_t PQI_CONNECT_TUNNEL = 0x0003;
|
||||
const uint32_t PQI_CONNECT_DO_NEXT_ATTEMPT = 0x0004;
|
||||
|
||||
/********************** Binary INTERFACE ****************************
|
||||
* This defines the binary interface used by Network/loopback/file
|
||||
@ -352,6 +353,9 @@ static const int NET_CONNECT_FAILED = 5;
|
||||
static const uint32_t NET_PARAM_CONNECT_DELAY = 1;
|
||||
static const uint32_t NET_PARAM_CONNECT_PERIOD = 2;
|
||||
static const uint32_t NET_PARAM_CONNECT_TIMEOUT = 3;
|
||||
//static const uint32_t NET_PARAM_CONNECT_TUNNEL_SOURCE_PEER_ID = 4;
|
||||
//static const uint32_t NET_PARAM_CONNECT_TUNNEL_RELAY_PEER_ID = 5;
|
||||
//static const uint32_t NET_PARAM_CONNECT_TUNNEL_DEST_PEER_ID = 6;
|
||||
|
||||
class NetInterface
|
||||
{
|
||||
|
@ -216,6 +216,9 @@ int pqihandler::HandleRsItem(RsItem *item, int allowglobal)
|
||||
out << "pqihandler::HandleSearchItem()";
|
||||
out << " Cannot send out Global RsItem";
|
||||
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << out.str();
|
||||
#endif
|
||||
delete item;
|
||||
return -1;
|
||||
}
|
||||
@ -225,7 +228,10 @@ int pqihandler::HandleRsItem(RsItem *item, int allowglobal)
|
||||
std::ostringstream out;
|
||||
out << "pqihandler::HandleRsItem() checkOutgoingPQItem";
|
||||
out << " Failed on item: " << std::endl;
|
||||
item -> print(out);
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << out.str();
|
||||
#endif
|
||||
item -> print(out);
|
||||
|
||||
pqioutput(PQL_ALERT, pqihandlerzone, out.str());
|
||||
delete item;
|
||||
@ -234,6 +240,9 @@ int pqihandler::HandleRsItem(RsItem *item, int allowglobal)
|
||||
|
||||
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
|
||||
"pqihandler::HandleRsItem() Sending to One Channel");
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << "pqihandler::HandleRsItem() Sending to One Channel" << std::endl;
|
||||
#endif
|
||||
|
||||
|
||||
// find module.
|
||||
@ -242,6 +251,9 @@ int pqihandler::HandleRsItem(RsItem *item, int allowglobal)
|
||||
std::ostringstream out;
|
||||
out << "pqihandler::HandleRsItem() Invalid chan!";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << out.str();
|
||||
#endif
|
||||
|
||||
delete item;
|
||||
return -1;
|
||||
@ -254,6 +266,9 @@ int pqihandler::HandleRsItem(RsItem *item, int allowglobal)
|
||||
out << "pqihandler::HandleRsItem() sending to chan:";
|
||||
out << it -> first << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << out.str();
|
||||
#endif
|
||||
|
||||
// if yes send on item.
|
||||
((it -> second) -> pqi) -> SendItem(item);
|
||||
@ -265,6 +280,9 @@ int pqihandler::HandleRsItem(RsItem *item, int allowglobal)
|
||||
out << "pqihandler::HandleRsItem()";
|
||||
out << " Sec not approved";
|
||||
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone, out.str());
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << out.str();
|
||||
#endif
|
||||
|
||||
delete item;
|
||||
return -1;
|
||||
@ -298,6 +316,9 @@ int pqihandler::SendRsRawItem(RsRawItem *ns)
|
||||
{
|
||||
pqioutput(PQL_DEBUG_BASIC, pqihandlerzone,
|
||||
"pqihandler::SendRsRawItem()");
|
||||
#ifdef DEBUG_TICK
|
||||
std::cerr << "pqihandler::SendRsRawItem()" << std ::endl;
|
||||
#endif
|
||||
return HandleRsItem(ns, 0);
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,11 @@ int pqiperson::SendItem(RsItem *i)
|
||||
out << "pqiperson::SendItem()";
|
||||
if (active)
|
||||
{
|
||||
out << " Active: Sending On";
|
||||
out << " Active: Sending On" << std::endl;
|
||||
i->print(out, 5);
|
||||
#ifdef PERSON_DEBUG
|
||||
std::cerr << out.str() << std::endl;
|
||||
#endif
|
||||
return activepqi -> SendItem(i);
|
||||
}
|
||||
else
|
||||
@ -76,6 +80,7 @@ int pqiperson::SendItem(RsItem *i)
|
||||
out << " Now deleting...";
|
||||
delete i;
|
||||
}
|
||||
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
return 0; // queued.
|
||||
}
|
||||
@ -145,6 +150,7 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
out << "pqiperson::notifyEvent() Id: " << PeerId();
|
||||
out << std::endl;
|
||||
out << "Message: " << newState << " from: " << ni << std::endl;
|
||||
out << "Active pqi : " << activepqi;
|
||||
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
}
|
||||
@ -166,11 +172,11 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
out << " ni: " << (it->second)->ni;
|
||||
out << " in_ni: " << ni;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
|
||||
i++;
|
||||
i++;
|
||||
|
||||
if ((it->second)->thisNetInterface(ni))
|
||||
{
|
||||
pqi = (it->second);
|
||||
pqi = (it->second);
|
||||
type = (it->first);
|
||||
}
|
||||
}
|
||||
@ -180,7 +186,6 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
pqioutput(PQL_WARNING, pqipersonzone, "Unknown notfyEvent Source!");
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
switch(newState)
|
||||
{
|
||||
@ -194,10 +199,10 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
if ((active) && (activepqi != pqi)) // already connected - trouble
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqipersonzone,
|
||||
"CONNECT_SUCCESS+active->trouble: shutdown EXISTING->switch to new one!");
|
||||
"CONNECT_SUCCESS+active-> activing new connection, shutting others");
|
||||
|
||||
// This is the RESET that's killing the connections.....
|
||||
activepqi -> reset();
|
||||
//activepqi -> reset();
|
||||
// this causes a recursive call back into this fn.
|
||||
// which cleans up state.
|
||||
// we only do this if its not going to mess with new conn.
|
||||
@ -208,18 +213,21 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
|
||||
pqioutput(PQL_WARNING, pqipersonzone,
|
||||
"CONNECT_SUCCESS->marking so! (resetting others)");
|
||||
// mark as active.
|
||||
// mark as active.
|
||||
active = true;
|
||||
activepqi = pqi;
|
||||
inConnectAttempt = false;
|
||||
inConnectAttempt = false;
|
||||
|
||||
/* reset all other children? (clear up long UDP attempt) */
|
||||
for(it = kids.begin(); it != kids.end(); it++)
|
||||
{
|
||||
if (it->second != activepqi)
|
||||
{
|
||||
it->second->reset();
|
||||
}
|
||||
std::cerr << "Resetting pqi" << std::endl;
|
||||
it->second->reset();
|
||||
} else {
|
||||
std::cerr << "Active pqi : not resetting." << std::endl;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@ -231,22 +239,17 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
|
||||
if (active)
|
||||
{
|
||||
if (activepqi == pqi)
|
||||
if (activepqi == pqi)
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqipersonzone,
|
||||
"CONNECT_FAILED->marking so!");
|
||||
active = false;
|
||||
activepqi = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqipersonzone,
|
||||
"CONNECT_FAIL+not activepqi->strange!");
|
||||
// probably UDP connect has failed,
|
||||
// TCP connection has been made since attempt started.
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
pqioutput(PQL_WARNING, pqipersonzone,
|
||||
"CONNECT_FAILED-> from an unactive connection, don't flag the peer as not connected, just try next attempt !");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
pqioutput(PQL_WARNING, pqipersonzone,
|
||||
@ -254,8 +257,14 @@ int pqiperson::notifyEvent(NetInterface *ni, int newState)
|
||||
}
|
||||
|
||||
/* notify up (But not if we are actually active: rtn -1 case above) */
|
||||
if (pqipg)
|
||||
pqipg->notifyConnect(PeerId(), type, false);
|
||||
if (!active) {
|
||||
if (pqipg)
|
||||
pqipg->notifyConnect(PeerId(), type, false);
|
||||
} else {
|
||||
if (pqipg)
|
||||
pqipg->notifyConnect(PeerId(), PQI_CONNECT_DO_NEXT_ATTEMPT, false);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
||||
@ -399,6 +408,19 @@ int pqiperson::connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay,
|
||||
}
|
||||
|
||||
|
||||
pqiconnect *pqiperson::getKid(uint32_t type)
|
||||
{
|
||||
std::map<uint32_t, pqiconnect *>::iterator it;
|
||||
|
||||
it = kids.find(type);
|
||||
if (it == kids.end())
|
||||
{
|
||||
return NULL;
|
||||
} else {
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
float pqiperson::getRate(bool in)
|
||||
{
|
||||
// get the rate from the active one.
|
||||
|
@ -122,6 +122,8 @@ int notifyEvent(NetInterface *ni, int event);
|
||||
virtual float getRate(bool in);
|
||||
virtual void setMaxRate(bool in, float val);
|
||||
|
||||
pqiconnect *getKid(uint32_t type);
|
||||
|
||||
private:
|
||||
|
||||
std::map<uint32_t, pqiconnect *> kids;
|
||||
|
@ -366,6 +366,27 @@ int pqipersongrp::removePeer(std::string id)
|
||||
return 1;
|
||||
}
|
||||
|
||||
pqiperson *pqipersongrp::getPeer(std::string id)
|
||||
{
|
||||
std::map<std::string, SearchModule *>::iterator it;
|
||||
|
||||
#ifdef PGRP_DEBUG
|
||||
std::cerr << " pqipersongrp::getPeer() id: " << id;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
|
||||
|
||||
it = mods.find(id);
|
||||
if (it != mods.end())
|
||||
{
|
||||
SearchModule *mod = it->second;
|
||||
pqiperson *p = (pqiperson *) mod -> pqi;
|
||||
return p;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int pqipersongrp::connectPeer(std::string id)
|
||||
{
|
||||
/* get status from p3connectMgr */
|
||||
@ -432,6 +453,15 @@ int pqipersongrp::connectPeer(std::string id)
|
||||
#ifdef PGRP_DEBUG
|
||||
std::cerr << " pqipersongrp::connectPeer() connecting with UDP: Timeout :" << timeout;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
else if (type & RS_NET_CONN_TUNNEL)
|
||||
{
|
||||
ptype = PQI_CONNECT_TUNNEL;
|
||||
timeout = period * 2;
|
||||
#ifdef PGRP_DEBUG
|
||||
std::cerr << " pqipersongrp::connectPeer() connecting with UDP: Timeout :" << timeout;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
}
|
||||
else
|
||||
@ -448,19 +478,27 @@ int pqipersongrp::connectPeer(std::string id)
|
||||
|
||||
bool pqipersongrp::notifyConnect(std::string id, uint32_t ptype, bool success)
|
||||
{
|
||||
uint32_t type = 0;
|
||||
uint32_t type = 0;
|
||||
if (ptype == PQI_CONNECT_TCP)
|
||||
{
|
||||
type = RS_NET_CONN_TCP_ALL;
|
||||
}
|
||||
else
|
||||
else if (ptype == PQI_CONNECT_UDP)
|
||||
{
|
||||
type = RS_NET_CONN_UDP_ALL;
|
||||
}
|
||||
else if (ptype == PQI_CONNECT_TUNNEL)
|
||||
{
|
||||
type = RS_NET_CONN_TUNNEL;
|
||||
}
|
||||
|
||||
|
||||
if (mConnMgr)
|
||||
mConnMgr->connectResult(id, success, type);
|
||||
if (mConnMgr) {
|
||||
if (ptype == PQI_CONNECT_DO_NEXT_ATTEMPT) {
|
||||
mConnMgr->doNextAttempt(id);
|
||||
} else {
|
||||
mConnMgr->connectResult(id, success, type);
|
||||
}
|
||||
}
|
||||
|
||||
return (NULL != mConnMgr);
|
||||
}
|
||||
|
@ -67,6 +67,7 @@ virtual void statusChange(const std::list<pqipeer> &plist);
|
||||
|
||||
/******************* Peer Control **************************/
|
||||
virtual int addPeer(std::string id); /* can be overloaded for testing */
|
||||
virtual pqiperson *getPeer(std::string id); /* can be overloaded for testing */
|
||||
int removePeer(std::string id);
|
||||
int connectPeer(std::string id);
|
||||
|
||||
|
@ -158,6 +158,7 @@ RsRawItem *p3ServiceServer::outgoing()
|
||||
|
||||
item -> print(out);
|
||||
out << std::endl;
|
||||
std::cerr << out.str();
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
|
||||
#endif
|
||||
|
||||
@ -179,6 +180,7 @@ RsRawItem *p3ServiceServer::outgoing()
|
||||
item -> print(out);
|
||||
out << std::endl;
|
||||
pqioutput(PQL_DEBUG_BASIC, pqiservicezone, out.str());
|
||||
std::cerr << out.str();
|
||||
#endif
|
||||
|
||||
return item;
|
||||
|
@ -57,14 +57,7 @@ const int pqissllistenzone = 49787;
|
||||
|
||||
pqissllistenbase::pqissllistenbase(struct sockaddr_in addr, p3AuthMgr *am, p3ConnectMgr *cm)
|
||||
:laddr(addr), active(false),
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
mAuthMgr((AuthXPGP *) am), mConnMgr(cm)
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
mAuthMgr((AuthSSL *) am), mConnMgr(cm)
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
{
|
||||
if (!(mAuthMgr -> active()))
|
||||
@ -471,14 +464,7 @@ int pqissllistenbase::Extract_Failed_SSL_Certificate(SSL *ssl, struct sockaddr_
|
||||
"pqissllistenbase::Extract_Failed_SSL_Certificate()");
|
||||
|
||||
// Get the Peer Certificate....
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
XPGP *peercert = SSL_get_peer_pgp_certificate(ssl);
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
X509 *peercert = SSL_get_peer_certificate(ssl);
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
if (peercert == NULL)
|
||||
{
|
||||
@ -492,14 +478,7 @@ int pqissllistenbase::Extract_Failed_SSL_Certificate(SSL *ssl, struct sockaddr_
|
||||
|
||||
// save certificate... (and ip locations)
|
||||
// false for outgoing....
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
mAuthMgr->FailedCertificateXPGP(peercert, true);
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
mAuthMgr->FailedCertificate(peercert, true);
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -631,14 +610,7 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
|
||||
{
|
||||
|
||||
// Get the Peer Certificate....
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
XPGP *peercert = SSL_get_peer_pgp_certificate(ssl);
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
X509 *peercert = SSL_get_peer_certificate(ssl);
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
if (peercert == NULL)
|
||||
{
|
||||
@ -653,11 +625,6 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
|
||||
// Check cert.
|
||||
std::string newPeerId;
|
||||
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
bool certOk = mAuthMgr->ValidateCertificateXPGP(peercert, newPeerId);
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
/****
|
||||
* As the validation is actually done before this...
|
||||
@ -666,9 +633,6 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
|
||||
|
||||
bool certOk = mAuthMgr->ValidateCertificate(peercert, newPeerId);
|
||||
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
bool found = false;
|
||||
std::map<std::string, pqissl *>::iterator it;
|
||||
|
||||
@ -680,14 +644,7 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
|
||||
|
||||
// bad - shutdown.
|
||||
// pqissllistenbase will shutdown!
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
XPGP_free(peercert);
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
X509_free(peercert);
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -723,27 +680,13 @@ int pqissllistener::completeConnection(int fd, SSL *ssl, struct sockaddr_in &rem
|
||||
out << std::endl;
|
||||
out << "pqissllistenbase: Will shut it down!" << std::endl;
|
||||
pqioutput(PQL_WARNING, pqissllistenzone, out.str());
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
XPGP_free(peercert);
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
X509_free(peercert);
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Certificate consumed! */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
bool certKnown = mAuthMgr->CheckCertificateXPGP(it->first, peercert);
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
bool certKnown = mAuthMgr->CheckCertificate(it->first, peercert);
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
if (certKnown == false)
|
||||
{
|
||||
|
@ -39,14 +39,7 @@
|
||||
#include "pqi/pqi_base.h"
|
||||
#include "pqi/pqilistener.h"
|
||||
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
#include "pqi/authxpgp.h"
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#include "pqi/authssl.h"
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
/***************************** pqi Net SSL Interface *********************************
|
||||
*/
|
||||
@ -95,19 +88,8 @@ int Extract_Failed_SSL_Certificate(SSL *ssl, struct sockaddr_in *inaddr);
|
||||
|
||||
protected:
|
||||
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
#if defined(PQI_USE_XPGP)
|
||||
|
||||
AuthXPGP *mAuthMgr;
|
||||
|
||||
#else /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
AuthSSL *mAuthMgr;
|
||||
|
||||
#endif /* X509 Certificates */
|
||||
/**************** PQI_USE_XPGP ******************/
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
|
||||
};
|
||||
|
@ -40,12 +40,14 @@ const int pqipersongrpzone = 354;
|
||||
/********************************** SSL Specific features ***************************/
|
||||
|
||||
#include "pqi/pqissl.h"
|
||||
#include "pqi/pqissltunnel.h"
|
||||
#include "pqi/pqissllistener.h"
|
||||
|
||||
#ifndef PQI_DISABLE_UDP
|
||||
#include "pqi/pqissludp.h"
|
||||
#endif
|
||||
|
||||
|
||||
pqilistener * pqisslpersongrp::createListener(struct sockaddr_in laddr)
|
||||
{
|
||||
p3AuthMgr *authMgr = getAuthMgr();
|
||||
@ -81,19 +83,27 @@ pqiperson * pqisslpersongrp::createPerson(std::string id, pqilistener *listener)
|
||||
|
||||
pqip -> addChildInterface(PQI_CONNECT_TCP, pqisc);
|
||||
|
||||
pqissltunnel *pqitun = new pqissltunnel(pqip, authMgr, mConnMgr);
|
||||
RsSerialiser *rss3 = new RsSerialiser();
|
||||
rss3->addSerialType(new RsFileItemSerialiser());
|
||||
rss3->addSerialType(new RsCacheItemSerialiser());
|
||||
rss3->addSerialType(new RsServiceSerialiser());
|
||||
pqiconnect *pqicontun = new pqiconnect(rss3, pqitun);
|
||||
pqip -> addChildInterface(PQI_CONNECT_TUNNEL, pqicontun);
|
||||
|
||||
#ifndef PQI_DISABLE_UDP
|
||||
pqissludp *pqius = new pqissludp(pqip, authMgr, mConnMgr);
|
||||
pqissludp *pqius = new pqissludp(pqip, authMgr, mConnMgr);
|
||||
|
||||
RsSerialiser *rss2 = new RsSerialiser();
|
||||
rss2->addSerialType(new RsFileItemSerialiser());
|
||||
rss2->addSerialType(new RsCacheItemSerialiser());
|
||||
rss2->addSerialType(new RsServiceSerialiser());
|
||||
RsSerialiser *rss2 = new RsSerialiser();
|
||||
rss2->addSerialType(new RsFileItemSerialiser());
|
||||
rss2->addSerialType(new RsCacheItemSerialiser());
|
||||
rss2->addSerialType(new RsServiceSerialiser());
|
||||
|
||||
pqiconnect *pqiusc = new pqiconnect(rss2, pqius);
|
||||
pqiconnect *pqiusc = new pqiconnect(rss2, pqius);
|
||||
|
||||
// add a ssl + proxy interface.
|
||||
// Add Proxy First.
|
||||
pqip -> addChildInterface(PQI_CONNECT_UDP, pqiusc);
|
||||
// add a ssl + proxy interface.
|
||||
// Add Proxy First.
|
||||
pqip -> addChildInterface(PQI_CONNECT_UDP, pqiusc);
|
||||
#endif
|
||||
|
||||
return pqip;
|
||||
|
562
libretroshare/src/pqi/pqissltunnel.cc
Normal file
562
libretroshare/src/pqi/pqissltunnel.cc
Normal file
@ -0,0 +1,562 @@
|
||||
/*
|
||||
* "$Id: pqissl.cc,v 1.28 2007-03-17 19:32:59 rmf24 Exp $"
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2006 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 "pqi/pqissltunnel.h"
|
||||
#include "pqi/pqinetwork.h"
|
||||
|
||||
#include "services/p3tunnel.h"
|
||||
|
||||
#include "util/rsnet.h"
|
||||
#include "util/rsdebug.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include <sstream>
|
||||
|
||||
const int pqisslzone = 37714;
|
||||
|
||||
#define TUNNEL_WAITING_NOT 0
|
||||
#define TUNNEL_WAITING_DELAY 1
|
||||
#define TUNNEL_WAITING_SPAM_PING 2
|
||||
#define TUNNEL_WAITING_PING_RETURN 3
|
||||
|
||||
|
||||
#define TUNNEL_PASSIVE 0x00
|
||||
#define TUNNEL_ACTIVE 0x01
|
||||
|
||||
#define TUNNEL_START_CONNECTION_DELAY 1
|
||||
#define TUNNEL_PING_TIMEOUT 6
|
||||
#define TUNNEL_REPEAT_PING_TIME 2
|
||||
#define TUNNEL_TIMEOUT_AFTER_RESET 30
|
||||
|
||||
#define TUNNEL_TRY_OTHER_CONNECTION_INTERVAL 190 //let's try a normal tcp or udp connection every 190 sec
|
||||
|
||||
//const int TUNNEL_LOCAL_FLAG = 0x01;
|
||||
//const int TUNNEL_REMOTE_FLAG = 0x02;
|
||||
//const int TUNNEL_UDP_FLAG = 0x02;
|
||||
//
|
||||
//static const int PQISSL_MAX_READ_ZERO_COUNT = 20;
|
||||
//static const int PQISSL_SSL_CONNECT_TIMEOUT = 30;
|
||||
|
||||
/********** PQI SSL STUFF ******************************************
|
||||
*
|
||||
* A little note on the notifyEvent(FAILED)....
|
||||
*
|
||||
* this is called from
|
||||
* (1) reset if needed!
|
||||
* (2) Determine_Remote_Address (when all options have failed).
|
||||
*
|
||||
* reset() is only called when a TCP/SSL connection has been
|
||||
* established, and there is an error. If there is a failed TCP
|
||||
* connection, then an alternative address can be attempted.
|
||||
*
|
||||
* reset() is called from
|
||||
* (1) destruction.
|
||||
* (2) disconnect()
|
||||
* (3) bad waiting state.
|
||||
*
|
||||
* // TCP/or SSL connection already established....
|
||||
* (5) pqissltunnel::SSL_Connection_Complete() <- okay -> cos we made a TCP connection already.
|
||||
* (6) pqissltunnel::accept() <- okay cos something went wrong.
|
||||
* (7) moretoread()/cansend() <- okay cos
|
||||
*
|
||||
*/
|
||||
|
||||
pqissltunnel::pqissltunnel(PQInterface *parent, p3AuthMgr *am, p3ConnectMgr *cm)
|
||||
:NetBinInterface(parent, parent->PeerId()),
|
||||
mAuthMgr((AuthSSL *) am), mConnMgr(cm)
|
||||
{
|
||||
active = false;
|
||||
waiting = TUNNEL_WAITING_NOT;
|
||||
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqissltunnel for PeerId: " << PeerId();
|
||||
rslog(RSL_ALERT, pqisslzone, out.str());
|
||||
}
|
||||
|
||||
if (!(mAuthMgr->isAuthenticated(PeerId()))) {
|
||||
rslog(RSL_ALERT, pqisslzone,
|
||||
"pqissltunnel::Warning Certificate Not Approved!");
|
||||
rslog(RSL_ALERT, pqisslzone,
|
||||
"\t pqissltunnel will not initialise....");
|
||||
}
|
||||
mP3tunnel = mConnMgr->getP3tunnel();
|
||||
current_data_offset = 0;
|
||||
curent_data_packet.length = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
pqissltunnel::~pqissltunnel() {
|
||||
rslog(RSL_ALERT, pqisslzone,
|
||||
"pqissltunnel::~pqissltunnel -> destroying pqissl");
|
||||
stoplistening(); /* remove from pqissllistener only */
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/********** Implementation of NetInterface *************************/
|
||||
|
||||
int pqissltunnel::connect(struct sockaddr_in raddr) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::connect() called : " << PeerId() << std::endl;
|
||||
#endif
|
||||
last_normal_connection_attempt_time = time(NULL);
|
||||
mConnectTS = time(NULL);
|
||||
resetTime = time(NULL) - TUNNEL_TIMEOUT_AFTER_RESET;
|
||||
waiting = TUNNEL_WAITING_DELAY;
|
||||
return 0;
|
||||
}
|
||||
|
||||
// tells pqilistener to listen for us.
|
||||
int pqissltunnel::listen()
|
||||
{
|
||||
//no use
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pqissltunnel::stoplistening()
|
||||
{
|
||||
//no use
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqissltunnel::disconnect()
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::disconnect() called : " << PeerId() << std::endl;
|
||||
#endif
|
||||
return reset();
|
||||
}
|
||||
|
||||
/* BinInterface version of reset() for pqistreamer */
|
||||
int pqissltunnel::close()
|
||||
{
|
||||
return reset();
|
||||
}
|
||||
|
||||
// put back on the listening queue.
|
||||
int pqissltunnel::reset()
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::reset() called : " << PeerId() << std::endl;
|
||||
#endif
|
||||
|
||||
if (active)
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::reset() Reset Required because tunnel was activated !" << std::endl;
|
||||
std::cerr << "pqissltunnel::reset() Will Attempt notifyEvent(FAILED)" << std::endl;
|
||||
#endif
|
||||
waiting = TUNNEL_WAITING_NOT;
|
||||
active = false;
|
||||
resetTime = time(NULL);
|
||||
// clean up the streamer
|
||||
if (parent()) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::reset() notifyEvent(FAILED)" << std::endl;
|
||||
#endif
|
||||
parent() -> notifyEvent(this, NET_CONNECT_FAILED);
|
||||
}
|
||||
} else {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::reset() Reset not required because tunnel was not activated !" << std::endl;
|
||||
#endif
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool pqissltunnel::connect_parameter(uint32_t type, uint32_t value)
|
||||
{
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqissltunnel::connect_parameter() Peer: " << PeerId();
|
||||
out << " type: " << type << "value: " << value;
|
||||
rslog(RSL_DEBUG_ALL, pqisslzone, out.str());
|
||||
}
|
||||
|
||||
if (type == NET_PARAM_CONNECT_DELAY)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqissltunnel::connect_parameter() Peer: " << PeerId();
|
||||
out << " DELAY: " << value;
|
||||
rslog(RSL_WARNING, pqisslzone, out.str());
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (type == NET_PARAM_CONNECT_TIMEOUT)
|
||||
{
|
||||
std::ostringstream out;
|
||||
out << "pqissltunnel::connect_parameter() Peer: " << PeerId();
|
||||
out << " TIMEOUT: " << value;
|
||||
rslog(RSL_WARNING, pqisslzone, out.str());
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/********** End of Implementation of NetInterface ******************/
|
||||
/********** Implementation of BinInterface **************************
|
||||
* Only status() + tick() are here ... as they are really related
|
||||
* to the NetInterface, and not the BinInterface,
|
||||
*
|
||||
*/
|
||||
|
||||
/* returns ...
|
||||
* -1 if inactive.
|
||||
* 0 if connecting.
|
||||
* 1 if connected.
|
||||
*/
|
||||
|
||||
int pqissltunnel::status()
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::status() called." << std::endl;
|
||||
#endif
|
||||
|
||||
if (active) {
|
||||
std::cerr << " active: " << std::endl;
|
||||
// print out connection.
|
||||
std::cerr << "dest : " << PeerId();
|
||||
std::cerr << "relay : " << relayPeerId;
|
||||
std::cerr << std::endl;
|
||||
}
|
||||
else {
|
||||
std::cerr << " Waiting for connection!" << std::endl;
|
||||
}
|
||||
|
||||
if (active) {
|
||||
return 1;
|
||||
} else if (waiting > 0) {
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int pqissltunnel::tick()
|
||||
{
|
||||
if (active && ((time(NULL) - last_normal_connection_attempt_time) > TUNNEL_TRY_OTHER_CONNECTION_INTERVAL)) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::tick() attempt to connect through a normal tcp or udp connection." << std::endl;
|
||||
#endif
|
||||
last_normal_connection_attempt_time = time(NULL);
|
||||
mConnMgr->retryConnect(parent()->PeerId());
|
||||
}
|
||||
|
||||
if (active && ((time(NULL) - last_ping_send_time) > TUNNEL_REPEAT_PING_TIME)) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::tick() sending a ping." << std::endl;
|
||||
#endif
|
||||
last_ping_send_time = time(NULL);;
|
||||
mP3tunnel->pingTunnelConnection(relayPeerId, parent()->PeerId());
|
||||
}
|
||||
|
||||
if (active && ((time(NULL) - last_packet_time) > TUNNEL_PING_TIMEOUT)) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::tick() no packet received since PING_RECEIVE_TIME_OUT. Connection is broken." << std::endl;
|
||||
#endif
|
||||
reset();
|
||||
}
|
||||
// continue existing connection attempt.
|
||||
if (!active)
|
||||
{
|
||||
// if we are waiting.. continue the connection (only)
|
||||
if (waiting > 0)
|
||||
{
|
||||
std::cerr << "pqissltunnel::tick() Continuing Connection Attempt!" << std::endl;
|
||||
ConnectAttempt();
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
/********** End of Implementation of BinInterface ******************/
|
||||
/********** Internals of Tunnel Connection ****************************/
|
||||
int pqissltunnel::ConnectAttempt()
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::ConnectAttempt() called." << std::endl;
|
||||
#endif
|
||||
switch(waiting)
|
||||
{
|
||||
case TUNNEL_WAITING_NOT:
|
||||
|
||||
active = true; /* we're starting this one */
|
||||
std::cerr << "pqissltunnel::ConnectAttempt() STATE = Not Waiting." << std::endl;
|
||||
|
||||
case TUNNEL_WAITING_DELAY:
|
||||
|
||||
std::cerr << "pqissltunnel::ConnectAttempt() STATE = Waiting Delay, starting connection" << std::endl;
|
||||
|
||||
if ((time(NULL) - mConnectTS) > TUNNEL_START_CONNECTION_DELAY) {
|
||||
waiting = TUNNEL_WAITING_SPAM_PING;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case TUNNEL_WAITING_SPAM_PING:
|
||||
|
||||
std::cerr << "pqissltunnel::ConnectAttempt() STATE = Waiting for spamming ping." << std::endl;
|
||||
|
||||
Spam_Ping();
|
||||
waiting = TUNNEL_WAITING_PING_RETURN;
|
||||
break;
|
||||
|
||||
case TUNNEL_WAITING_PING_RETURN:
|
||||
if ((time(NULL) - mConnectTS) < TUNNEL_PING_TIMEOUT) {
|
||||
std::cerr << "pqissltunnel::ConnectAttempt() STATE = Waiting for ping reply." << std::endl;
|
||||
} else {
|
||||
std::cerr << "pqissltunnel::ConnectAttempt() no ping reply during imparing time. Connection failed." << std::endl;
|
||||
waiting = TUNNEL_WAITING_NOT;
|
||||
active = false;
|
||||
// clean up the streamer
|
||||
if (parent()) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::reset() Reset not required because tunnel was not activated !" << std::endl;
|
||||
#endif
|
||||
parent() -> notifyEvent(this, NET_CONNECT_FAILED);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
default:
|
||||
std::cerr << "pqissltunnel::ConnectAttempt() STATE = Unknown - Reset" << std::endl;
|
||||
|
||||
reset();
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void pqissltunnel::Spam_Ping()
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::Spam_Ping() starting to spam ping tunnel packet." << std::endl;
|
||||
#endif
|
||||
std::list<std::string> peers;
|
||||
mConnMgr->getOnlineList(peers);
|
||||
std::list<std::string>::iterator it = peers.begin();
|
||||
while (it != peers.end()) {
|
||||
//send a ping to the destination through the relay
|
||||
if (*it != parent()->PeerId()) {
|
||||
std::cerr << "sending ping with relay id : " << *it << std::endl;
|
||||
mP3tunnel->pingTunnelConnection(*it, parent()->PeerId());
|
||||
}
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
||||
void pqissltunnel::addIncomingPacket(void* encoded_data, int encoded_data_length) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::addIncomingPacket() called." << std::endl;
|
||||
std::cerr << "pqissltunnel::addIncomingPacket() getRsItemSize(encoded_data) : " << getRsItemSize(encoded_data) << std::endl;
|
||||
#endif
|
||||
last_packet_time = time(NULL);
|
||||
|
||||
data_with_length data_w_l;
|
||||
data_w_l.data = (void*)malloc(encoded_data_length) ;
|
||||
memcpy(data_w_l.data, encoded_data, encoded_data_length);
|
||||
data_w_l.length = encoded_data_length;
|
||||
data_packet_queue.push_front(data_w_l);
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::addIncomingPacket() getRsItemSize(data_w_l.data) : " << getRsItemSize(data_w_l.data) << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void pqissltunnel::IncommingPingPacket(std::string incRelayPeerId) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::IncommingPingPacket() called with incRelayPeerId : " << incRelayPeerId << std::endl;
|
||||
#endif
|
||||
|
||||
if ((time(NULL) - resetTime) <= TUNNEL_TIMEOUT_AFTER_RESET) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::IncommingPingPacket() a reset occured, don't activate the connection." << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
last_packet_time = time(NULL);
|
||||
|
||||
std::string message = "pqissltunnel::IncommingPingPacket() mConnMgr->isOnline(parent()->PeerId() : ";
|
||||
if (mConnMgr->isOnline(parent()->PeerId())) {
|
||||
message += "true";
|
||||
} else {
|
||||
message += "false";
|
||||
}
|
||||
rslog(RSL_DEBUG_BASIC, pqisslzone, message);
|
||||
|
||||
if (active || mConnMgr->isOnline(parent()->PeerId())) {
|
||||
//connection is already active, or peer is already online don't do nothing
|
||||
return;
|
||||
}
|
||||
//TODO : check if cert is in order before accepting
|
||||
|
||||
//activate connection
|
||||
waiting = TUNNEL_WAITING_NOT;
|
||||
active = true;
|
||||
relayPeerId = incRelayPeerId;
|
||||
|
||||
if (parent())
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cerr << "pqissltunnel::IncommingPingPacket() Notify the pqiperson.... (Both Connect/Receive)" << parent()->PeerId() <<std::endl;
|
||||
#endif
|
||||
rslog(RSL_DEBUG_BASIC, pqisslzone, "pqissltunnel::IncommingPingPacket() Notify the pqiperson.... (Both Connect/Receive)");
|
||||
parent() -> notifyEvent(this, NET_CONNECT_SUCCESS);
|
||||
}
|
||||
}
|
||||
|
||||
/********** Implementation of BinInterface **************************
|
||||
* All the rest of the BinInterface.
|
||||
*
|
||||
*/
|
||||
|
||||
int pqissltunnel::senddata(void *data, int len)
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cout << "pqissltunnel::senddata() called" << std::endl ;
|
||||
#endif
|
||||
if (!active) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cout << "pqissltunnel::senddata() connection is not active" << std::endl ;
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
//create RsTunnelDataItem
|
||||
RsTunnelDataItem *item = new RsTunnelDataItem;
|
||||
item->destPeerId = parent()->PeerId();
|
||||
item->relayPeerId = relayPeerId;
|
||||
item->sourcePeerId = mConnMgr->getOwnId();
|
||||
item->PeerId(relayPeerId);
|
||||
item->connection_accepted = 1;
|
||||
|
||||
int oulen;
|
||||
if (!mAuthMgr->encrypt(item->encoded_data, oulen, data, len, parent()->PeerId())) {
|
||||
std::cerr << "pqissltunnel::readdata() problem while crypting packet, ignoring it." << std::endl;
|
||||
return -1;
|
||||
}
|
||||
item->encoded_data_len = oulen;
|
||||
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cout << "pqissltunnel::senddata() sending item (Putting it into queue)" << std::endl ;
|
||||
#endif
|
||||
mP3tunnel->sendItem(item);
|
||||
|
||||
return oulen;
|
||||
}
|
||||
|
||||
int pqissltunnel::readdata(void *data, int len)
|
||||
{
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cout << "pqissltunnel::readdata() called" << std::endl ;
|
||||
#endif
|
||||
//let's see if we got a new packet to read
|
||||
if (current_data_offset >= curent_data_packet.length) {
|
||||
//current packet has finished reading, let's pop out a new packet if available
|
||||
if (data_packet_queue.size() ==0) {
|
||||
//no more to read
|
||||
return -1;
|
||||
} else {
|
||||
//let's read a new packet
|
||||
current_data_offset = 0;
|
||||
//decrypt one packet from the queue and put it into the current data packet.
|
||||
if (!mAuthMgr->decrypt(curent_data_packet.data, curent_data_packet.length, data_packet_queue.back().data, data_packet_queue.back().length)) {
|
||||
std::cerr << "pqissltunnel::readdata() problem while decrypting packet, ignoring it." << std::endl;
|
||||
curent_data_packet.length = 0;
|
||||
return -1;
|
||||
}
|
||||
data_packet_queue.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
if (current_data_offset < curent_data_packet.length) {
|
||||
#ifdef DEBUG_PQISSL_TUNNEL
|
||||
std::cout << "pqissltunnel::readdata() reading..." << std::endl ;
|
||||
std::cout << "pqissltunnel::readdata() len : " << len << std::endl ;
|
||||
std::cout << "pqissltunnel::readdata() current_data_offset : " << current_data_offset << std::endl ;
|
||||
std::cout << "pqissltunnel::readdata() curent_data_packet.length : " << curent_data_packet.length << std::endl ;
|
||||
std::cerr << "pqissltunnel::readdata() getRsItemSize(curent_data_packet.data) : " << getRsItemSize(curent_data_packet.data) << std::endl;
|
||||
#endif
|
||||
|
||||
//read from packet
|
||||
memcpy(data, (void*)((unsigned long int)curent_data_packet.data+(unsigned long int)current_data_offset), len);
|
||||
current_data_offset += len;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// dummy function currently.
|
||||
int pqissltunnel::netstatus()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
int pqissltunnel::isactive()
|
||||
{
|
||||
return active;
|
||||
}
|
||||
|
||||
bool pqissltunnel::moretoread()
|
||||
{
|
||||
//let's see if we got an old packet or a new packet to read
|
||||
if (current_data_offset >= curent_data_packet.length && data_packet_queue.size() ==0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool pqissltunnel::cansend()
|
||||
{
|
||||
if (!mConnMgr->isOnline(relayPeerId)) {
|
||||
reset();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string pqissltunnel::gethash()
|
||||
{
|
||||
std::string dummyhash;
|
||||
return dummyhash;
|
||||
}
|
||||
|
||||
/********** End of Implementation of BinInterface ******************/
|
145
libretroshare/src/pqi/pqissltunnel.h
Normal file
145
libretroshare/src/pqi/pqissltunnel.h
Normal file
@ -0,0 +1,145 @@
|
||||
/*
|
||||
* "$Id: pqissl.h,v 1.18 2007-03-11 14:54:22 rmf24 Exp $"
|
||||
*
|
||||
* 3P/PQI network interface for RetroShare.
|
||||
*
|
||||
* Copyright 2004-2006 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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef MRK_PQI_SSL_TUNNEL_HEADER
|
||||
#define MRK_PQI_SSL_TUNNEL_HEADER
|
||||
|
||||
|
||||
#include <openssl/ssl.h>
|
||||
|
||||
// operating system specific network header.
|
||||
//#include "pqi/pqinetwork.h"
|
||||
|
||||
#include "pqi/pqi_base.h"
|
||||
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
#include "services/p3tunnel.h"
|
||||
|
||||
#include "pqi/authssl.h"
|
||||
|
||||
/***************************** pqi Net SSL Interface *********************************
|
||||
* This provides the base SSL interface class,
|
||||
* and handles most of the required functionality.
|
||||
*
|
||||
* there are a series of small fn's that can be overloaded
|
||||
* to provide alternative behaviour....
|
||||
*
|
||||
* Classes expected to inherit from this are:
|
||||
*
|
||||
* pqissllistener -> pqissllistener (tcp only)
|
||||
* -> pqixpgplistener (tcp only)
|
||||
*
|
||||
* pqissl -> pqissltcp
|
||||
* -> pqissludp
|
||||
* -> pqixpgptcp
|
||||
* -> pqixpgpudp
|
||||
*
|
||||
*/
|
||||
|
||||
class pqissl;
|
||||
class cert;
|
||||
|
||||
class pqissltunnellistener;
|
||||
|
||||
struct data_with_length {
|
||||
int length;
|
||||
void *data;
|
||||
};
|
||||
|
||||
class pqissltunnel: public NetBinInterface
|
||||
{
|
||||
public:
|
||||
pqissltunnel(PQInterface *parent, p3AuthMgr *am, p3ConnectMgr *cm);
|
||||
virtual ~pqissltunnel();
|
||||
|
||||
// NetInterface
|
||||
|
||||
//the addr is not used for the tunnel
|
||||
virtual int connect(struct sockaddr_in raddr);
|
||||
virtual int listen();
|
||||
virtual int stoplistening();
|
||||
virtual int reset();
|
||||
virtual int disconnect();
|
||||
|
||||
virtual bool connect_parameter(uint32_t type, uint32_t value);
|
||||
|
||||
// BinInterface
|
||||
virtual int tick();
|
||||
virtual int status();
|
||||
|
||||
virtual int senddata(void*, int);
|
||||
virtual int readdata(void*, int);
|
||||
virtual int netstatus();
|
||||
virtual int isactive();
|
||||
virtual bool moretoread();
|
||||
virtual bool cansend();
|
||||
|
||||
virtual int close(); /* BinInterface version of reset() */
|
||||
virtual std::string gethash(); /* not used here */
|
||||
virtual bool bandwidthLimited() { return true ; } // replace by !sameLAN to avoid bandwidth limiting on lAN
|
||||
|
||||
//called by the p3tunnel service to add incoming packets that will be read by the read data function.
|
||||
void addIncomingPacket(void* encoded_data, int data_length);
|
||||
void IncommingPingPacket(std::string incRelayPeerId);
|
||||
|
||||
private:
|
||||
//if no packet (last_time_packet_time) is received since PING_RECEIVE_TIME_OUT, let's assume the connection is broken
|
||||
int last_normal_connection_attempt_time;
|
||||
|
||||
//if no packet (last_time_packet_time) is received since PING_RECEIVE_TIME_OUT, let's assume the connection is broken
|
||||
int last_packet_time;
|
||||
|
||||
//send a ping on a regular basis
|
||||
int last_ping_send_time;
|
||||
|
||||
int ConnectAttempt();
|
||||
void Spam_Ping();
|
||||
int waiting;
|
||||
bool active;
|
||||
time_t resetTime;
|
||||
pqissltunnellistener *pqil;
|
||||
|
||||
/* Need Certificate specific functions here! */
|
||||
time_t mConnectTS;
|
||||
|
||||
AuthSSL *mAuthMgr;
|
||||
|
||||
p3ConnectMgr *mConnMgr;
|
||||
|
||||
p3tunnel *mP3tunnel;
|
||||
|
||||
std::list<data_with_length> data_packet_queue;
|
||||
data_with_length curent_data_packet;
|
||||
int current_data_offset;
|
||||
|
||||
//tunneling details
|
||||
std::string relayPeerId;
|
||||
|
||||
};
|
||||
|
||||
#endif // MRK_PQI_SSL_HEADER
|
@ -167,6 +167,7 @@ int pqistreamer::SendItem(RsItem *si)
|
||||
out << "pqistreamer::SendItem():" << std::endl;
|
||||
si -> print(out);
|
||||
pqioutput(PQL_DEBUG_ALL, pqistreamerzone, out.str());
|
||||
std::cerr << out.str();
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -297,7 +298,10 @@ int pqistreamer::status()
|
||||
|
||||
int pqistreamer::queue_outpqi(RsItem *pqi)
|
||||
{
|
||||
RsStackMutex stack(streamerMtx) ; // lock out_pkt and out_data
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
std::cerr << "pqistreamer::queue_outpqi() called." << std::endl;
|
||||
#endif
|
||||
RsStackMutex stack(streamerMtx) ; // lock out_pkt and out_data
|
||||
|
||||
// This is called by different threads, and by threads that are not the handleoutgoing thread,
|
||||
// so it should be protected by a mutex !!
|
||||
@ -323,7 +327,10 @@ int pqistreamer::queue_outpqi(RsItem *pqi)
|
||||
uint32_t pktsize = rsSerialiser->size(pqi);
|
||||
void *ptr = malloc(pktsize);
|
||||
|
||||
if (rsSerialiser->serialise(pqi, ptr, &pktsize))
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
std::cerr << "pqistreamer::queue_outpqi() serializing packet with packet size : " << pktsize << std::endl;
|
||||
#endif
|
||||
if (rsSerialiser->serialise(pqi, ptr, &pktsize))
|
||||
{
|
||||
if (isCntrl)
|
||||
{
|
||||
@ -462,7 +469,9 @@ int pqistreamer::handleoutgoing()
|
||||
// write packet.
|
||||
len = getRsItemSize(pkt_wpending);
|
||||
|
||||
// std::cout << "Sending Out Pkt of size " << len << " !" << std::endl ;
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
std::cout << "Sending Out Pkt of size " << len << " !" << std::endl;
|
||||
#endif
|
||||
|
||||
if (len != (ss = bio->senddata(pkt_wpending, len)))
|
||||
{
|
||||
@ -599,7 +608,10 @@ continue_packet:
|
||||
int extralen = getRsItemSize(block) - blen;
|
||||
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "continuing packet state=" << reading_state << std::endl ;
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "continuing packet getRsItemSize(block) = " << getRsItemSize(block) << std::endl ;
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "continuing packet extralen = " << extralen << std::endl ;
|
||||
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "continuing packet state=" << reading_state << std::endl ;
|
||||
std::cerr << "[" << (void*)pthread_self() << "] " << "block 1 : " << (int)(((unsigned char*)block)[0]) << " " << (int)(((unsigned char*)block)[1]) << " " << (int)(((unsigned char*)block)[2]) << " " << (int)(((unsigned char*)block)[3]) << " "
|
||||
<< (int)(((unsigned char*)block)[4]) << " "
|
||||
<< (int)(((unsigned char*)block)[5]) << " "
|
||||
@ -738,7 +750,7 @@ continue_packet:
|
||||
pqioutput(PQL_DEBUG_BASIC, pqistreamerzone, out.str());
|
||||
}
|
||||
|
||||
// std::cerr << "Deserializing packet of size " << pktlen <<std::endl ;
|
||||
// std::cerr << "Deserializing packet of size " << pktlen <<std::endl ;
|
||||
|
||||
uint32_t pktlen = blen+extralen ;
|
||||
#ifdef DEBUG_PQISTREAMER
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <stdint.h>
|
||||
|
||||
/******************************************************************************************
|
||||
Enumerations defining the Operators usable in the Boolean search expressions
|
||||
|
@ -96,7 +96,7 @@ class RsPeerDetails
|
||||
std::string localAddr;
|
||||
uint16_t localPort;
|
||||
std::string extAddr;
|
||||
uint16_t extPort;
|
||||
uint16_t extPort;
|
||||
std::list<std::string> ipAddressList;
|
||||
|
||||
uint32_t netMode;
|
||||
@ -156,7 +156,9 @@ virtual bool setVisState(std::string id, uint32_t vis) = 0;
|
||||
|
||||
virtual void getIPServersList(std::list<std::string>& ip_servers) = 0;
|
||||
virtual void allowServerIPDetermination(bool) = 0;
|
||||
virtual void allowTunnelConnection(bool) = 0;
|
||||
virtual bool getAllowServerIPDetermination() = 0 ;
|
||||
virtual bool getAllowTunnelConnection() = 0 ;
|
||||
|
||||
/* Auth Stuff */
|
||||
virtual std::string GetRetroshareInvite() = 0;
|
||||
|
@ -437,7 +437,13 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
|
||||
std::ostringstream autostr;
|
||||
if (pcs.inConnAttempt)
|
||||
{
|
||||
autostr << "Trying " << inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr) << ":" << ntohs(pcs.currentConnAddrAttempt.addr.sin_port);
|
||||
if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_TUNNEL) {
|
||||
autostr << "Trying tunnel connection";
|
||||
} else if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_TCP_ALL) {
|
||||
autostr << "Trying TCP : " << inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr) << ":" << ntohs(pcs.currentConnAddrAttempt.addr.sin_port);
|
||||
} else if (pcs.currentConnAddrAttempt.type & RS_NET_CONN_UDP_ALL) {
|
||||
autostr << "Trying UDP : " << inet_ntoa(pcs.currentConnAddrAttempt.addr.sin_addr) << ":" << ntohs(pcs.currentConnAddrAttempt.addr.sin_port);
|
||||
}
|
||||
}
|
||||
else if (pcs.state & RS_PEER_S_CONNECTED)
|
||||
{
|
||||
@ -449,7 +455,11 @@ bool p3Peers::getPeerDetails(std::string id, RsPeerDetails &d)
|
||||
{
|
||||
autostr << "Connected: UDP";
|
||||
}
|
||||
else
|
||||
else if (pcs.connecttype == RS_NET_CONN_TUNNEL)
|
||||
{
|
||||
autostr << "Connected: Tunnel";
|
||||
}
|
||||
else
|
||||
{
|
||||
autostr << "Connected: Unknown";
|
||||
}
|
||||
@ -600,11 +610,24 @@ void p3Peers::allowServerIPDetermination(bool b)
|
||||
{
|
||||
mConnMgr->setIPServersEnabled(b) ;
|
||||
}
|
||||
bool p3Peers::getAllowServerIPDetermination()
|
||||
|
||||
void p3Peers::allowTunnelConnection(bool b)
|
||||
{
|
||||
std::cerr << "p3Peers::allowTunnelConnection() set tunnel to : " << b << std::endl;
|
||||
mConnMgr->setTunnelConnection(b) ;
|
||||
}
|
||||
|
||||
bool p3Peers::getAllowServerIPDetermination()
|
||||
{
|
||||
return mConnMgr->getIPServersEnabled() ;
|
||||
}
|
||||
|
||||
bool p3Peers::getAllowTunnelConnection()
|
||||
{
|
||||
std::cerr << "p3Peers::getAllowTunnelConnection() tunnel is : " << mConnMgr->getTunnelConnection() << std::endl;
|
||||
return mConnMgr->getTunnelConnection() ;
|
||||
}
|
||||
|
||||
bool p3Peers::setLocalAddress(std::string id, std::string addr_str, uint16_t port)
|
||||
{
|
||||
#ifdef P3PEERS_DEBUG
|
||||
|
@ -76,7 +76,9 @@ virtual bool setVisState(std::string id, uint32_t mode);
|
||||
|
||||
virtual void getIPServersList(std::list<std::string>& ip_servers) ;
|
||||
virtual void allowServerIPDetermination(bool) ;
|
||||
virtual void allowTunnelConnection(bool) ;
|
||||
virtual bool getAllowServerIPDetermination() ;
|
||||
virtual bool getAllowTunnelConnection() ;
|
||||
|
||||
/* Auth Stuff */
|
||||
virtual std::string GetRetroshareInvite();
|
||||
|
@ -1421,7 +1421,7 @@ std::string RsInit::getHomePath()
|
||||
}
|
||||
|
||||
out << "fltkserver::getHomePath() -> " << home << std::endl;
|
||||
std::cerr << out;
|
||||
std::cerr << out.str();
|
||||
|
||||
// convert to FLTK desired format.
|
||||
home = make_path_unix(home);
|
||||
@ -1827,6 +1827,7 @@ RsTurtle *rsTurtle = NULL ;
|
||||
#include "services/p3status.h"
|
||||
#include "services/p3Qblog.h"
|
||||
#include "turtle/p3turtle.h"
|
||||
#include "services/p3tunnel.h"
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
@ -1976,6 +1977,10 @@ int RsServer::StartupRetroShare()
|
||||
msgSrv = new p3MsgService(mConnMgr);
|
||||
chatSrv = new p3ChatService(mConnMgr);
|
||||
|
||||
p3tunnel *tn = new p3tunnel(mAuthMgr,mConnMgr, pqih);
|
||||
pqih -> addService(tn);
|
||||
mConnMgr->setP3tunnel(tn);
|
||||
|
||||
p3turtle *tr = new p3turtle(mConnMgr,ftserver) ;
|
||||
rsTurtle = tr ;
|
||||
pqih -> addService(tr);
|
||||
|
@ -682,14 +682,21 @@ uint32_t RsServiceSerialiser::size(RsItem *i)
|
||||
/* serialise the data to the buffer */
|
||||
bool RsServiceSerialiser::serialise(RsItem *i, void *data, uint32_t *pktsize)
|
||||
{
|
||||
RsRawItem *item = dynamic_cast<RsRawItem *>(i);
|
||||
RsRawItem *item = dynamic_cast<RsRawItem *>(i);
|
||||
if (!item)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsServiceSerialiser::serialise() serializing raw item. pktsize : " << *pktsize;
|
||||
#endif
|
||||
|
||||
uint32_t tlvsize = item->getRawLength();
|
||||
uint32_t offset = 0;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "tlvsize : " << tlvsize << std::endl;
|
||||
#endif
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (*pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
@ -164,7 +164,7 @@ class RsRawItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsRawItem(uint32_t t, uint32_t size)
|
||||
:RsItem(t), len(size) { data = malloc(len); }
|
||||
:RsItem(t), len(size) { data = malloc(len);}
|
||||
|
||||
virtual ~RsRawItem()
|
||||
{
|
||||
|
@ -46,6 +46,7 @@ const uint16_t RS_SERVICE_TYPE_DISC = 0x0011;
|
||||
const uint16_t RS_SERVICE_TYPE_CHAT = 0x0012;
|
||||
const uint16_t RS_SERVICE_TYPE_MSG = 0x0013;
|
||||
const uint16_t RS_SERVICE_TYPE_TURTLE = 0x0014;
|
||||
const uint16_t RS_SERVICE_TYPE_TUNNEL = 0x0015;
|
||||
|
||||
/* Combined Cache/Service ids */
|
||||
|
||||
|
179
libretroshare/src/serialiser/rstunnelitems.cc
Normal file
179
libretroshare/src/serialiser/rstunnelitems.cc
Normal file
@ -0,0 +1,179 @@
|
||||
#ifndef WINDOWS_SYS
|
||||
#include <stdexcept>
|
||||
#endif
|
||||
#include <iostream>
|
||||
#include "rstunnelitems.h"
|
||||
|
||||
// -----------------------------------------------------------------------------------//
|
||||
// -------------------------------- Serialization. --------------------------------- //
|
||||
// -----------------------------------------------------------------------------------//
|
||||
//
|
||||
|
||||
//
|
||||
// ---------------------------------- Packet sizes -----------------------------------//
|
||||
//
|
||||
|
||||
uint32_t RsTunnelDataItem::serial_size()
|
||||
{
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "RsTunnelDataItem::serial_size() called." << std::endl ;
|
||||
#endif
|
||||
uint32_t s = 0 ;
|
||||
|
||||
s += 8 ; // header
|
||||
s += GetTlvStringSize(sourcePeerId) ;
|
||||
s += GetTlvStringSize(relayPeerId) ;
|
||||
s += GetTlvStringSize(destPeerId) ;
|
||||
s += 4 ; //connection_accept
|
||||
|
||||
s += 4 ; //encoded_data_len
|
||||
s += encoded_data_len;
|
||||
|
||||
return s ;
|
||||
}
|
||||
|
||||
//
|
||||
// ---------------------------------- Serialization ----------------------------------//
|
||||
//
|
||||
RsItem *RsTunnelSerialiser::deserialise(void *data, uint32_t *size)
|
||||
{
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "RsTunnelDataItem::deserialise() called." << std::endl ;
|
||||
#endif
|
||||
// look what we have...
|
||||
|
||||
/* get the type */
|
||||
uint32_t rstype = getRsItemId(data);
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel: deserialising packet: " << std::endl ;
|
||||
#endif
|
||||
if ((RS_PKT_VERSION_SERVICE != getRsItemVersion(rstype)) || (RS_SERVICE_TYPE_TUNNEL != getRsItemService(rstype)))
|
||||
{
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << " Wrong type !!" << std::endl ;
|
||||
#endif
|
||||
return NULL; /* wrong type */
|
||||
}
|
||||
|
||||
#ifndef WINDOWS_SYS
|
||||
try
|
||||
{
|
||||
#endif
|
||||
switch(getRsItemSubType(rstype))
|
||||
{
|
||||
case RS_TUNNEL_SUBTYPE_DATA : return new RsTunnelDataItem(data,*size) ;
|
||||
|
||||
default:
|
||||
std::cerr << "Unknown packet type in Rstunnel!" << std::endl ;
|
||||
return NULL ;
|
||||
}
|
||||
#ifndef WINDOWS_SYS
|
||||
}
|
||||
catch(std::exception& e)
|
||||
{
|
||||
std::cerr << "Exception raised: " << e.what() << std::endl ;
|
||||
return NULL ;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
bool RsTunnelDataItem::serialize(void *data,uint32_t& pktsize)
|
||||
{
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "RsTunnelDataItem::serialize() called." << std::endl ;
|
||||
#endif
|
||||
uint32_t tlvsize = serial_size();
|
||||
uint32_t offset = 0;
|
||||
|
||||
if (pktsize < tlvsize)
|
||||
return false; /* not enough space */
|
||||
|
||||
pktsize = tlvsize;
|
||||
|
||||
bool ok = true;
|
||||
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "RsTunnelDataItem::serialize() tlvsize : " << tlvsize << std::endl ;
|
||||
#endif
|
||||
|
||||
ok &= setRsItemHeader(data,tlvsize,PacketId(), tlvsize);
|
||||
|
||||
/* skip the header */
|
||||
offset += 8;
|
||||
|
||||
/* add mandatory parts first */
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, sourcePeerId);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, relayPeerId);
|
||||
ok &= SetTlvString(data, tlvsize, &offset, TLV_TYPE_STR_VALUE, destPeerId);
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, connection_accepted);
|
||||
|
||||
ok &= setRawUInt32(data, tlvsize, &offset, encoded_data_len) ;
|
||||
memcpy((void*)((unsigned char*)data+offset),encoded_data,encoded_data_len) ;
|
||||
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "RsTunnelDataItem::serialise() (offset + encoded_data_len) " << (offset + encoded_data_len) << std::endl;
|
||||
std::cerr << "RsTunnelDataItem::serialise() tlvsize " << tlvsize << std::endl;
|
||||
#endif
|
||||
|
||||
if ((offset + encoded_data_len) != tlvsize )
|
||||
{
|
||||
ok = false;
|
||||
#ifdef RSSERIAL_DEBUG
|
||||
std::cerr << "RsTunnelDataItem::serialiseTransfer() Size Error! " << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "RsTunnelDataItem::serialize() packet size inside serialised data : " << getRsItemSize(data) << std::endl ;
|
||||
#endif
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
//deserialize in constructor
|
||||
RsTunnelDataItem::RsTunnelDataItem(void *data,uint32_t pktsize)
|
||||
: RsTunnelItem(RS_TUNNEL_SUBTYPE_DATA)
|
||||
{
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "RsTunnelDataItem constructor called : deserializing packet." << std::endl ;
|
||||
#endif
|
||||
uint32_t offset = 8; // skip the header
|
||||
uint32_t rssize = getRsItemSize(data);
|
||||
bool ok = true ;
|
||||
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "RsTunnelDataItem constructor rssize : " << rssize << std::endl ;
|
||||
#endif
|
||||
|
||||
ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_VALUE, sourcePeerId);
|
||||
ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_VALUE, relayPeerId);
|
||||
ok &= GetTlvString(data, pktsize, &offset, TLV_TYPE_STR_VALUE, destPeerId);
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &connection_accepted);
|
||||
|
||||
ok &= getRawUInt32(data, pktsize, &offset, &encoded_data_len) ;
|
||||
encoded_data = (void*)malloc(encoded_data_len) ;
|
||||
memcpy(encoded_data, (void*)((unsigned char*)data+offset), encoded_data_len);
|
||||
|
||||
#ifdef WINDOWS_SYS // No Exceptions in Windows compile. (drbobs).
|
||||
#else
|
||||
if ((offset + encoded_data_len) != rssize)
|
||||
throw std::runtime_error("Size error while deserializing.") ;
|
||||
if (!ok)
|
||||
throw std::runtime_error("Unknown error while deserializing.") ;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::ostream& RsTunnelDataItem::print(std::ostream& o, uint16_t)
|
||||
{
|
||||
o << "RsTunnelDataItem :" << std::endl ;
|
||||
o << " sourcePeerId : " << sourcePeerId << std::endl ;
|
||||
o << " relayPeerId : " << relayPeerId << std::endl ;
|
||||
o << " destPeerId : " << destPeerId << std::endl ;
|
||||
o << " connection_accepted : " << connection_accepted << std::endl ;
|
||||
o << " encoded_data_len : " << encoded_data_len << std::endl ;
|
||||
if (encoded_data_len != 0 ) {
|
||||
o << "getRsItemSize(encoded_data)" << getRsItemSize(encoded_data) << std::endl ;
|
||||
}
|
||||
return o ;
|
||||
}
|
105
libretroshare/src/serialiser/rstunnelitems.h
Normal file
105
libretroshare/src/serialiser/rstunnelitems.h
Normal file
@ -0,0 +1,105 @@
|
||||
#ifndef RS_TUNNEL_ITEMS_H
|
||||
#define RS_TUNNEL_ITEMS_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/serialiser: rschannelitems.h
|
||||
*
|
||||
* RetroShare Serialiser.
|
||||
*
|
||||
* Copyright 2007-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 <map>
|
||||
|
||||
#include "serialiser/rstlvbase.h"
|
||||
#include "serialiser/rsbaseserial.h"
|
||||
#include "serialiser/rsserviceids.h"
|
||||
#include "serialiser/rsserial.h"
|
||||
#include "serialiser/rstlvtypes.h"
|
||||
#include "serialiser/rstlvkeys.h"
|
||||
|
||||
const uint8_t RS_TUNNEL_SUBTYPE_DATA = 0x01 ;
|
||||
|
||||
/***********************************************************************************/
|
||||
/* Basic Tunnel Item Class */
|
||||
/***********************************************************************************/
|
||||
|
||||
class RsTunnelItem: public RsItem
|
||||
{
|
||||
public:
|
||||
RsTunnelItem(uint8_t tunnel_subtype) : RsItem(RS_PKT_VERSION_SERVICE,RS_SERVICE_TYPE_TUNNEL,tunnel_subtype) {}
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) = 0 ; // Isn't it better that items can serialize themselves ?
|
||||
virtual uint32_t serial_size() { return 0;}
|
||||
|
||||
virtual void clear() {}
|
||||
};
|
||||
|
||||
class RsTunnelDataItem: public RsTunnelItem
|
||||
{
|
||||
public:
|
||||
RsTunnelDataItem() : RsTunnelItem(RS_TUNNEL_SUBTYPE_DATA) {}
|
||||
RsTunnelDataItem(void *data,uint32_t size) ; // deserialization
|
||||
|
||||
uint32_t encoded_data_len;
|
||||
void *encoded_data;
|
||||
|
||||
std::string sourcePeerId ;
|
||||
std::string relayPeerId ;
|
||||
std::string destPeerId ;
|
||||
uint32_t connection_accepted;
|
||||
|
||||
std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
|
||||
bool serialize(void *data,uint32_t& size) ;
|
||||
uint32_t serial_size() ;
|
||||
};
|
||||
|
||||
class RsTunnelSerialiser: public RsSerialType
|
||||
{
|
||||
public:
|
||||
RsTunnelSerialiser() : RsSerialType(RS_PKT_VERSION_SERVICE, RS_SERVICE_TYPE_TUNNEL) {}
|
||||
|
||||
virtual uint32_t size(RsItem *item)
|
||||
{
|
||||
RsTunnelItem * rst;
|
||||
if (NULL != (rst = dynamic_cast<RsTunnelItem *>(item)))
|
||||
{
|
||||
return rst->serial_size() ;
|
||||
} else {
|
||||
std::cerr << "RsTunnelSerialiser::size() problem, not a RsTunnelItem." << std::endl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
RsTunnelItem * rst;
|
||||
if (NULL != (rst = dynamic_cast<RsTunnelItem *>(item)))
|
||||
{
|
||||
return rst->serialize(data,*size) ;
|
||||
} else {
|
||||
std::cerr << "RsTunnelSerialiser::serialise() problem, not a RsTunnelItem." << std::endl;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
virtual RsItem *deserialise (void *data, uint32_t *size) ;
|
||||
};
|
||||
|
||||
#endif /* RS_TUNNEL_ITEMS_H */
|
@ -627,7 +627,7 @@ void p3disc::recvPeerOwnMsg(RsDiscOwnItem *item)
|
||||
|
||||
if (item->discFlags & P3DISC_FLAGS_STABLE_UDP)
|
||||
{
|
||||
type |= RS_NET_CONN_UDP_DHT_SYNC;
|
||||
type |= RS_NET_CONN_UDP;
|
||||
flags |= RS_NET_FLAGS_STABLE_UDP;
|
||||
}
|
||||
|
||||
@ -697,7 +697,7 @@ void p3disc::recvPeerFriendMsg(RsDiscReply *item)
|
||||
|
||||
if (item->discFlags & P3DISC_FLAGS_STABLE_UDP)
|
||||
{
|
||||
type |= RS_NET_CONN_UDP_DHT_SYNC;
|
||||
type |= RS_NET_CONN_UDP;
|
||||
flags |= RS_NET_FLAGS_STABLE_UDP;
|
||||
}
|
||||
|
||||
|
@ -204,6 +204,10 @@ RsRawItem *p3Service::send()
|
||||
delete si;
|
||||
|
||||
srvMtx.unlock(); /***** UNLOCK MUTEX *****/
|
||||
#ifdef SERV_DEBUG
|
||||
std::cerr << "p3Service::send() returning RawItem.";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
return raw;
|
||||
}
|
||||
|
||||
|
@ -50,6 +50,7 @@
|
||||
|
||||
std::string generateRandomServiceId();
|
||||
|
||||
//TODO : encryption and upload / download rate implementation
|
||||
|
||||
class p3Service: public pqiService
|
||||
{
|
||||
|
290
libretroshare/src/services/p3tunnel.cc
Normal file
290
libretroshare/src/services/p3tunnel.cc
Normal file
@ -0,0 +1,290 @@
|
||||
/*
|
||||
* libretroshare/src/services: p3tunnel.cc
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* 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/rsiface.h"
|
||||
#include "rsiface/rsinit.h" /* for PGPSSL flag */
|
||||
#include "rsiface/rspeers.h"
|
||||
#include "services/p3tunnel.h"
|
||||
#include "pqi/pqissltunnel.h"
|
||||
|
||||
#include "pqi/p3authmgr.h"
|
||||
#include "pqi/p3connmgr.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <errno.h>
|
||||
#include <cmath>
|
||||
|
||||
const uint32_t AUTODISC_LDI_SUBTYPE_PING = 0x01;
|
||||
const uint32_t AUTODISC_LDI_SUBTYPE_RPLY = 0x02;
|
||||
|
||||
#include <sstream>
|
||||
|
||||
#include "util/rsdebug.h"
|
||||
#include "util/rsprint.h"
|
||||
#include "util/rsversion.h"
|
||||
|
||||
static int convertTDeltaToTRange(double tdelta);
|
||||
static int convertTRangeToTDelta(int trange);
|
||||
|
||||
// Operating System specific includes.
|
||||
|
||||
|
||||
const uint32_t p3tunnel_FLAGS_USE_DISC = 0x0001;
|
||||
const uint32_t p3tunnel_FLAGS_USE_DHT = 0x0002;
|
||||
|
||||
p3tunnel::p3tunnel(p3AuthMgr *am, p3ConnectMgr *cm, pqipersongrp *perGrp)
|
||||
:p3Service(RS_SERVICE_TYPE_TUNNEL), mAuthMgr(am), mConnMgr(cm), mPqiPersonGrp(perGrp)
|
||||
{
|
||||
RsStackMutex stack(mTunnelMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
ownId = mConnMgr->getOwnId();
|
||||
std::cerr << "ownId : " << mConnMgr->getOwnId() << std::endl;
|
||||
addSerialType(new RsTunnelSerialiser());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void p3tunnel::statusChange(const std::list<pqipeer> &plist) {
|
||||
}
|
||||
|
||||
int p3tunnel::tick()
|
||||
{
|
||||
if (!mConnMgr->getTunnelConnection()) {
|
||||
//no tunnel allowed, just drop the packet
|
||||
return -1;
|
||||
}
|
||||
|
||||
return handleIncoming();
|
||||
}
|
||||
|
||||
int p3tunnel::handleIncoming()
|
||||
{
|
||||
if (!mConnMgr->getTunnelConnection()) {
|
||||
//no tunnel allowed, just drop the packet
|
||||
return -1;
|
||||
}
|
||||
|
||||
RsItem *item = NULL;
|
||||
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::handleIncoming() called";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
int nhandled = 0;
|
||||
// While messages read
|
||||
while(NULL != (item = recvItem()))
|
||||
{
|
||||
RsTunnelDataItem *tdi = NULL;
|
||||
|
||||
{
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::ostringstream out;
|
||||
out << "p3tunnel::handleIncoming()";
|
||||
out << " Received Message!" << std::endl;
|
||||
item -> print(out);
|
||||
out << std::endl;
|
||||
std::cerr << out.str();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (NULL != (tdi = dynamic_cast<RsTunnelDataItem *> (item))) {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::handleIncoming() getRsItemSize(tdi->encoded_data) : " << getRsItemSize(tdi->encoded_data) << std::endl;
|
||||
#endif
|
||||
recvTunnelData(tdi);
|
||||
nhandled++;
|
||||
}
|
||||
delete item;
|
||||
}
|
||||
return nhandled;
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/* Output Network Msgs */
|
||||
/*************************************************************************************/
|
||||
void p3tunnel::sendTunnelData(std::string destPeerId, std::string relayPeerId, void *data, int data_length)
|
||||
{
|
||||
sendTunnelDataPrivate(1, relayPeerId, ownId,relayPeerId, destPeerId, data, data_length);
|
||||
}
|
||||
|
||||
void p3tunnel::sendTunnelDataPrivate(int accept, std::string to, std::string sourcePeerId, std::string relayPeerId, std::string destPeerId, void *data, int data_length)
|
||||
{
|
||||
if (!mConnMgr->getTunnelConnection()) {
|
||||
//no tunnel allowed, just drop the request
|
||||
return;
|
||||
}
|
||||
|
||||
RsStackMutex stack(mTunnelMtx); /********** STACK LOCKED MTX ******/
|
||||
|
||||
// Then send message.
|
||||
{
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::ostringstream out;
|
||||
out << "p3tunnel::sendTunnelDataPrivate() Constructing a RsTunnelItem Message!" << std::endl;
|
||||
out << "Sending to: " << to;
|
||||
std::cerr << out.str() << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
// Construct a message
|
||||
RsTunnelDataItem *rdi = new RsTunnelDataItem();
|
||||
rdi->destPeerId = destPeerId;
|
||||
rdi->sourcePeerId = sourcePeerId;
|
||||
rdi->relayPeerId = relayPeerId;
|
||||
rdi->connection_accepted = accept;
|
||||
rdi->encoded_data_len = data_length;
|
||||
|
||||
rdi->encoded_data = (void*)malloc(data_length);
|
||||
memcpy(rdi->encoded_data, data, data_length);
|
||||
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::sendTunnelDataPrivate() getRsItemSize(rdi->encoded_data) : "<< getRsItemSize(rdi->encoded_data) << std::endl;
|
||||
#endif
|
||||
|
||||
rdi->PeerId(to);
|
||||
|
||||
/* send msg */
|
||||
sendItem(rdi);
|
||||
}
|
||||
|
||||
void p3tunnel::pingTunnelConnection(std::string relayPeerId, std::string destPeerId) {
|
||||
std::cerr << "p3tunnel::pingTunnelConnection() sending ping with relay id : " << relayPeerId << std::endl;
|
||||
std::cerr << "ownId : " << ownId << std::endl;
|
||||
std::cerr << "destPeerId : " << destPeerId << std::endl;
|
||||
this->sendTunnelDataPrivate(1, relayPeerId, ownId, relayPeerId, destPeerId, NULL, 0);
|
||||
}
|
||||
|
||||
/*************************************************************************************/
|
||||
/* Input Network Msgs */
|
||||
/*************************************************************************************/
|
||||
void p3tunnel::recvTunnelData(RsTunnelDataItem *item)
|
||||
{
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::recvPeerConnectRequest() From: " << item->PeerId() << std::endl;
|
||||
#endif
|
||||
|
||||
//compare the peer id from the item sender to the ids in the item.
|
||||
if (item->PeerId() == item->sourcePeerId && ownId == item->relayPeerId) {
|
||||
privateRecvTunnelDataRelaying(item);
|
||||
} else if (item->PeerId() == item->relayPeerId && ownId == item->destPeerId) {
|
||||
privateRecvTunnelDataDestination(item);
|
||||
} else if (item->PeerId() == item->destPeerId && ownId == item->relayPeerId) {
|
||||
//it's a ping reply from a destination, I'm relaying. Just forward the packet to the source
|
||||
if (item->connection_accepted && mConnMgr->isOnline(item->sourcePeerId)) {
|
||||
sendTunnelDataPrivate(1, item->sourcePeerId, item->sourcePeerId, ownId, item->destPeerId, NULL, 0);
|
||||
return;
|
||||
}
|
||||
} else if (item->PeerId() == item->relayPeerId && ownId == item->sourcePeerId) {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataRelaying() it's a ping reply. Let's see if the tunnel is accepted." << std::endl;
|
||||
#endif
|
||||
if (item->connection_accepted) {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataRelaying() tunnel is accepted. activate the pqissltunnel connection." << std::endl;
|
||||
#endif
|
||||
pqiperson *pers = mPqiPersonGrp->getPeer(item->destPeerId);
|
||||
pqissltunnel *pqicon = (pqissltunnel *)(((pqiconnect *) pers->getKid(PQI_CONNECT_TUNNEL))->ni);
|
||||
pqicon->IncommingPingPacket(item->relayPeerId);
|
||||
} else {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataRelaying() tunnel is not accepted." << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void p3tunnel::privateRecvTunnelDataRelaying(RsTunnelDataItem *item) {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataRelaying() I am relaying, let's see if it's possible to send the packet to destination." << std::endl;
|
||||
#endif
|
||||
if (mConnMgr->isOnline(item->destPeerId)) {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataRelaying() I am relaying, relay the packet to destination." << std::endl;
|
||||
#endif
|
||||
sendTunnelDataPrivate(1, item->destPeerId, item->sourcePeerId, ownId, item->destPeerId, item->encoded_data, item->encoded_data_len);
|
||||
return;
|
||||
} else {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataRelaying() destination peer is not online, send back the request with a deny" << std::endl;
|
||||
#endif
|
||||
sendTunnelDataPrivate(0, item->sourcePeerId, item->sourcePeerId, ownId, item->destPeerId, NULL, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void p3tunnel::privateRecvTunnelDataDestination(RsTunnelDataItem *item) {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() I am the destination Id, let's make some checks and read the packet." << std::endl;
|
||||
#endif
|
||||
if (!mConnMgr->isFriend(item->sourcePeerId) || !mConnMgr->isFriend(item->relayPeerId)) {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() not trusting rely or source peer. Aborting." << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
//peer is online when connected through a tunnel so we should not drop the packet
|
||||
// if (mConnMgr->isOnline(item->sourcePeerId)) {
|
||||
//#ifdef P3TUNNEL_DEBUG
|
||||
// std::cerr << "p3tunnel::privateRecvTunnelDataDestination() no need to make tunnel connection, source peer is online. Aborting." << std::endl;
|
||||
//#endif
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (!mConnMgr->isOnline(item->relayPeerId)) {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() relay peer is not connected, connection impossible. Aborting." << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
pqiperson *pers = mPqiPersonGrp->getPeer(item->sourcePeerId);
|
||||
if (pers == NULL) {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() internal source pqiperson peer not found. Aborting." << std::endl;
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
//if data is empty, then it's a ping, send the packet to the net emulation layer
|
||||
if (item->encoded_data_len == 0) {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() receiving a ping packet, activating connection and sending back acknowlegment." << std::endl;
|
||||
#endif
|
||||
pqissltunnel *pqicon = (pqissltunnel *)(((pqiconnect *) pers->getKid(PQI_CONNECT_TUNNEL))->ni);
|
||||
pqicon->IncommingPingPacket(item->relayPeerId);
|
||||
//sendTunnelDataPrivate(1, item->relayPeerId, item->sourcePeerId, item->relayPeerId, ownId, NULL, 0);
|
||||
} else {
|
||||
#ifdef P3TUNNEL_DEBUG
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() receiving a data packet, transfer it to the pqissltunnel connection." << std::endl;
|
||||
std::cerr << "p3tunnel::privateRecvTunnelDataDestination() getRsItemSize(item->encoded_data) : " << getRsItemSize(item->encoded_data) << std::endl;
|
||||
#endif
|
||||
pqissltunnel *pqicon = (pqissltunnel *)(((pqiconnect *) pers->getKid(PQI_CONNECT_TUNNEL))->ni);
|
||||
pqicon->addIncomingPacket(item->encoded_data, item->encoded_data_len);
|
||||
}
|
||||
return;
|
||||
}
|
82
libretroshare/src/services/p3tunnel.h
Normal file
82
libretroshare/src/services/p3tunnel.h
Normal file
@ -0,0 +1,82 @@
|
||||
/*
|
||||
* libretroshare/src/services: p3tunnel.h
|
||||
*
|
||||
* Services for RetroShare.
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef MRK_PQI_TUNNEL_H
|
||||
#define MRK_PQI_TUNNEL_H
|
||||
|
||||
// The AutoDiscovery Class
|
||||
|
||||
#include "pqi/pqipersongrp.h"
|
||||
|
||||
// system specific network headers
|
||||
#include "pqi/pqi.h"
|
||||
|
||||
class p3ConnectMgr;
|
||||
class p3AuthMgr;
|
||||
|
||||
#include "pqi/pqimonitor.h"
|
||||
#include "services/p3service.h"
|
||||
#include "serialiser/rstunnelitems.h"
|
||||
|
||||
class p3tunnel: public p3Service, public pqiMonitor
|
||||
{
|
||||
public:
|
||||
|
||||
virtual void statusChange(const std::list<pqipeer> &plist);
|
||||
|
||||
p3tunnel(p3AuthMgr *am, p3ConnectMgr *cm, pqipersongrp *persGrp);
|
||||
|
||||
int tick();
|
||||
|
||||
void sendTunnelData(std::string destPeerId, std::string relayPeerId, void *data, int data_length);
|
||||
|
||||
//to establish a connection, send a ping (just a empty data packet)
|
||||
void pingTunnelConnection(std::string relayPeerId, std::string destPeerId);
|
||||
|
||||
private:
|
||||
|
||||
void sendTunnelDataPrivate(int connection_accept, std::string to, std::string sourcePeerId, std::string relayPeerId, std::string destPeerId, void *data, int data_length);
|
||||
|
||||
void privateRecvTunnelDataRelaying(RsTunnelDataItem *item); //invoked when I am relaying
|
||||
void privateRecvTunnelDataDestination(RsTunnelDataItem *item); //invoked when I am the destination of the tunnel
|
||||
|
||||
/* Network Input */
|
||||
int handleIncoming();
|
||||
void recvTunnelData(RsTunnelDataItem *item);
|
||||
|
||||
|
||||
private:
|
||||
|
||||
p3AuthMgr *mAuthMgr;
|
||||
p3ConnectMgr *mConnMgr;
|
||||
pqipersongrp *mPqiPersonGrp;
|
||||
std::string ownId;
|
||||
|
||||
|
||||
/* data */
|
||||
RsMutex mTunnelMtx;
|
||||
};
|
||||
|
||||
#endif // MRK_PQI_TUNNEL_H
|
@ -205,7 +205,7 @@ class RsTurtleFileDataItem: public RsTurtleItem
|
||||
void *chunk_data ; // actual data.
|
||||
|
||||
virtual std::ostream& print(std::ostream& o, uint16_t) ;
|
||||
protected:
|
||||
|
||||
virtual bool serialize(void *data,uint32_t& size) ;
|
||||
virtual uint32_t serial_size() ;
|
||||
};
|
||||
@ -221,11 +221,11 @@ class RsTurtleSerialiser: public RsSerialType
|
||||
|
||||
virtual uint32_t size (RsItem *item)
|
||||
{
|
||||
return static_cast<RsTurtleItem *>(item)->serial_size() ;
|
||||
return dynamic_cast<RsTurtleItem *>(item)->serial_size() ;
|
||||
}
|
||||
virtual bool serialise(RsItem *item, void *data, uint32_t *size)
|
||||
{
|
||||
return static_cast<RsTurtleItem *>(item)->serialize(data,*size) ;
|
||||
return dynamic_cast<RsTurtleItem *>(item)->serialize(data,*size) ;
|
||||
}
|
||||
virtual RsItem *deserialise (void *data, uint32_t *size) ;
|
||||
};
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -40,6 +40,7 @@ ServerPage::ServerPage(QWidget * parent, Qt::WFlags flags)
|
||||
|
||||
connect( ui.netModeComboBox, SIGNAL( activated ( int ) ), this, SLOT( toggleUPnP( ) ) );
|
||||
connect( ui.allowIpDeterminationCB, SIGNAL( toggled( bool ) ), this, SLOT( toggleIpDetermination(bool) ) );
|
||||
connect( ui.allowTunnelConnectionCB, SIGNAL( toggled( bool ) ), this, SLOT( toggleTunnelConnection(bool) ) );
|
||||
connect( ui._showTurtleDialogPB,SIGNAL(clicked()),this,SLOT( showTurtleRouterDialog() )) ;
|
||||
|
||||
ui._enableTurtleCB->setChecked(true) ;
|
||||
@ -56,6 +57,9 @@ ServerPage::ServerPage(QWidget * parent, Qt::WFlags flags)
|
||||
ui.allowIpDeterminationCB->setChecked(b) ;
|
||||
ui.IPServersLV->setEnabled(b) ;
|
||||
|
||||
b = rsPeers->getAllowTunnelConnection() ;
|
||||
ui.allowTunnelConnectionCB->setChecked(b) ;
|
||||
|
||||
std::list<std::string> ip_servers ;
|
||||
rsPeers->getIPServersList(ip_servers) ;
|
||||
|
||||
@ -79,6 +83,12 @@ void ServerPage::toggleIpDetermination(bool b)
|
||||
ui.IPServersLV->setEnabled(b) ;
|
||||
}
|
||||
|
||||
void ServerPage::toggleTunnelConnection(bool b)
|
||||
{
|
||||
std::cerr << "ServerPage::toggleTunnelConnection() set tunnel to : " << b << std::endl;
|
||||
rsPeers->allowTunnelConnection(b) ;
|
||||
}
|
||||
|
||||
void
|
||||
ServerPage::closeEvent (QCloseEvent * event)
|
||||
{
|
||||
|
@ -47,6 +47,7 @@ private slots:
|
||||
void saveAddresses();
|
||||
void toggleUPnP();
|
||||
void toggleIpDetermination(bool) ;
|
||||
void toggleTunnelConnection(bool) ;
|
||||
void showTurtleRouterDialog();
|
||||
|
||||
|
||||
|
@ -581,7 +581,7 @@
|
||||
<item row="1" column="0">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>0</number>
|
||||
<number>3</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
@ -688,7 +688,14 @@
|
||||
<string>IP check service</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<item row="2" column="0">
|
||||
<widget class="QListWidget" name="IPServersLV">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QCheckBox" name="allowIpDeterminationCB">
|
||||
<property name="toolTip">
|
||||
<string>If you unckeck this, RetroShare can only determine your IP
|
||||
@ -704,13 +711,6 @@ behind a firewall or a VPN.</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QListWidget" name="IPServersLV">
|
||||
<property name="editTriggers">
|
||||
<set>QAbstractItemView::NoEditTriggers</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
@ -764,19 +764,46 @@ behind a firewall or a VPN.</string>
|
||||
<string><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
|
||||
<html><head><meta name="qrichtext" content="1" /><style type="text/css">
|
||||
p, li { white-space: pre-wrap; }
|
||||
</style></head><body style=" font-family:'Sans'; font-size:10pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt; font-weight:600;">RetroShare</span><span style=" font-size:8pt;"> is capable of transfering data and search requests between peers that are not necessarily friends. This traffic however only transits through a connected list of friends and is anonymous.</span></p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">If want to you use </span><span style=" font-size:8pt; font-weight:600;">RetroShare</span><span style=" font-size:8pt;"> to anonymously share and download files, leaving this checked drastically increases your download scope, and participate into the overall network bandwidth. </span></p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:8pt;"></p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-size:8pt;">You can separately setup share flags for each shared directory:</span></p>
|
||||
<ul style="-qt-list-indent: 1;"><li style=" font-size:8pt;" style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Browsable by friends</span>: files are browsable from your direct friends.</li>
|
||||
<li style=" font-size:8pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Anonymously shared</span>: files can be downloaded by anybody through anonymous tunnels.</li></ul></body></html></string>
|
||||
</style></head><body style=" font-family:'DejaVu Sans'; font-size:10pt; font-weight:400; font-style:normal;">
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans'; font-size:8pt; font-weight:600;">RetroShare</span><span style=" font-family:'Sans'; font-size:8pt;"> is capable of transfering data and search requests between peers that are not necessarily friends. This traffic however only transits through a connected list of friends and is anonymous.</span></p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans'; font-size:8pt;"></p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans'; font-size:8pt;">If want to you use </span><span style=" font-family:'Sans'; font-size:8pt; font-weight:600;">RetroShare</span><span style=" font-family:'Sans'; font-size:8pt;"> to anonymously share and download files, leaving this checked drastically increases your download scope, and participate into the overall network bandwidth. </span></p>
|
||||
<p style="-qt-paragraph-type:empty; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-family:'Sans'; font-size:8pt;"></p>
|
||||
<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-family:'Sans'; font-size:8pt;">You can separately setup share flags for each shared directory:</span></p>
|
||||
<ul style="-qt-list-indent: 1;"><li style=" font-family:'Sans'; font-size:8pt;" style=" margin-top:12px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Browsable by friends</span>: files are browsable from your direct friends.</li>
|
||||
<li style=" font-family:'Sans'; font-size:8pt;" style=" margin-top:0px; margin-bottom:12px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;"><span style=" font-weight:600;">Anonymously shared</span>: files can be downloaded by anybody through anonymous tunnels.</li></ul></body></html></string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tab_4">
|
||||
<attribute name="title">
|
||||
<string>Tunneling</string>
|
||||
</attribute>
|
||||
<widget class="QCheckBox" name="allowTunnelConnectionCB">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>20</x>
|
||||
<y>10</y>
|
||||
<width>407</width>
|
||||
<height>20</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>If you unckeck this, RetroShare can only determine your IP
|
||||
when you connect to somebody. Leaving this checked helps
|
||||
connecting when you have few friends. It also helps if you're
|
||||
behind a firewall or a VPN.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Allow Tunnel Connection</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
|
@ -1,77 +0,0 @@
|
||||
#ifndef RSQBLOG_H_
|
||||
#define RSQBLOG_H_
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsQblog.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-2008 by Chris Evi-Parker, 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 <iostream>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
#include "../rsiface/rstypes.h"
|
||||
|
||||
|
||||
/* delcare interafce for everyone o use */
|
||||
class RsQblog;
|
||||
extern RsQblog *rsQblog;
|
||||
|
||||
/*! allows gui to interface with the rsQblogs service */
|
||||
class RsQblog
|
||||
{
|
||||
public:
|
||||
|
||||
|
||||
RsQblog() { return; }
|
||||
virtual ~RsQblog() { return; }
|
||||
|
||||
|
||||
/**
|
||||
* send blog info, will send to a data structure for transmission
|
||||
* @param msg The msg the usr wants to send
|
||||
*/
|
||||
virtual bool sendBlog(const std::wstring &msg) = 0;
|
||||
|
||||
/**
|
||||
* retrieve blog of a usr
|
||||
* @param blogs contains the blog msgs of usr along with time posted for sorting
|
||||
*/
|
||||
virtual bool getBlogs(std::map< std::string, std::multimap<long int, std::wstring> > &blogs) = 0;
|
||||
|
||||
/**
|
||||
* Stuff DrBob Added for Profile View!
|
||||
*/
|
||||
|
||||
/**
|
||||
* get users Latest Blog Post.
|
||||
* @param id the usr whose idetails you want to get.
|
||||
* @param ts Timestamp of the Blog Post.
|
||||
* @param post the actual Blog Post.
|
||||
*/
|
||||
virtual bool getPeerLatestBlog(std::string id, uint32_t &ts, std::wstring &post) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif /*RSQBLOG_H_*/
|
@ -1,120 +0,0 @@
|
||||
#ifndef RS_CHANNEL_GUI_INTERFACE_H
|
||||
#define RS_CHANNEL_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rschannels.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 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 <list>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "rsiface/rstypes.h"
|
||||
#include "rsiface/rsdistrib.h" /* For FLAGS */
|
||||
|
||||
class ChannelInfo
|
||||
{
|
||||
public:
|
||||
ChannelInfo() {}
|
||||
std::string channelId;
|
||||
std::wstring channelName;
|
||||
std::wstring channelDesc;
|
||||
|
||||
uint32_t channelFlags;
|
||||
uint32_t pop;
|
||||
|
||||
time_t lastPost;
|
||||
};
|
||||
|
||||
class ChannelMsgInfo
|
||||
{
|
||||
public:
|
||||
ChannelMsgInfo() {}
|
||||
std::string channelId;
|
||||
std::string msgId;
|
||||
|
||||
unsigned int msgflags;
|
||||
|
||||
std::wstring subject;
|
||||
std::wstring msg;
|
||||
time_t ts;
|
||||
|
||||
std::list<FileInfo> files;
|
||||
uint32_t count;
|
||||
uint64_t size;
|
||||
};
|
||||
|
||||
|
||||
class ChannelMsgSummary
|
||||
{
|
||||
public:
|
||||
ChannelMsgSummary() {}
|
||||
std::string channelId;
|
||||
std::string msgId;
|
||||
|
||||
uint32_t msgflags;
|
||||
|
||||
std::wstring subject;
|
||||
std::wstring msg;
|
||||
uint32_t count; /* file count */
|
||||
time_t ts;
|
||||
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const ChannelInfo &info);
|
||||
std::ostream &operator<<(std::ostream &out, const ChannelMsgSummary &info);
|
||||
std::ostream &operator<<(std::ostream &out, const ChannelMsgInfo &info);
|
||||
|
||||
class RsChannels;
|
||||
extern RsChannels *rsChannels;
|
||||
|
||||
class RsChannels
|
||||
{
|
||||
public:
|
||||
|
||||
RsChannels() { return; }
|
||||
virtual ~RsChannels() { return; }
|
||||
|
||||
/****************************************/
|
||||
|
||||
virtual bool channelsChanged(std::list<std::string> &chanIds) = 0;
|
||||
|
||||
|
||||
virtual std::string createChannel(std::wstring chanName, std::wstring chanDesc, uint32_t chanFlags) = 0;
|
||||
|
||||
virtual bool getChannelInfo(std::string cId, ChannelInfo &ci) = 0;
|
||||
virtual bool getChannelList(std::list<ChannelInfo> &chanList) = 0;
|
||||
virtual bool getChannelMsgList(std::string cId, std::list<ChannelMsgSummary> &msgs) = 0;
|
||||
virtual bool getChannelMessage(std::string cId, std::string mId, ChannelMsgInfo &msg) = 0;
|
||||
|
||||
virtual bool ChannelMessageSend(ChannelMsgInfo &info) = 0;
|
||||
|
||||
virtual bool channelSubscribe(std::string cId, bool subscribe) = 0;
|
||||
/****************************************/
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,50 +0,0 @@
|
||||
#ifndef RETROSHARE_DISC_GUI_INTERFACE_H
|
||||
#define RETROSHARE_DISC_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsdisc.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2008-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 <inttypes.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <map>
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsDisc;
|
||||
extern RsDisc *rsDisc;
|
||||
|
||||
class RsDisc
|
||||
{
|
||||
public:
|
||||
|
||||
RsDisc() { return; }
|
||||
virtual ~RsDisc() { return; }
|
||||
|
||||
virtual bool getDiscFriends(std::string id, std::list<std::string> &friends) = 0;
|
||||
virtual bool getDiscVersions(std::map<std::string, std::string> &versions) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -1,46 +0,0 @@
|
||||
#ifndef RS_DISTRIB_GUI_INTERFACE_H
|
||||
#define RS_DISTRIB_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsdistrib.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#define RS_DISTRIB_PRIVACY_MASK 0x000f /* who can publish & view */
|
||||
#define RS_DISTRIB_AUTHEN_MASK 0x00f0 /* how to publish */
|
||||
#define RS_DISTRIB_LISTEN_MASK 0x0f00 /* distribution flags */
|
||||
|
||||
#define RS_DISTRIB_PUBLIC 0x0001 /* anyone can publish */
|
||||
#define RS_DISTRIB_PRIVATE 0x0002 /* anyone with key can publish */
|
||||
#define RS_DISTRIB_ENCRYPTED 0x0004 /* need publish key to view */
|
||||
|
||||
#define RS_DISTRIB_AUTHEN_REQ 0x0010 /* you must sign messages */
|
||||
#define RS_DISTRIB_AUTHEN_ANON 0x0020 /* you can send anonymous messages */
|
||||
|
||||
#define RS_DISTRIB_ADMIN 0x0100
|
||||
#define RS_DISTRIB_PUBLISH 0x0200
|
||||
#define RS_DISTRIB_SUBSCRIBED 0x0400
|
||||
|
||||
|
||||
#endif
|
@ -1,332 +0,0 @@
|
||||
#ifndef RS_EXPRESSIONS_H
|
||||
#define RS_EXPRESSIONS_H
|
||||
|
||||
/*
|
||||
* rs-core/src/rsiface: rsexpr.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-2008 by Kashif Kaleem.
|
||||
*
|
||||
* 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 <string>
|
||||
#include <list>
|
||||
#include <stdint.h>
|
||||
|
||||
/******************************************************************************************
|
||||
Enumerations defining the Operators usable in the Boolean search expressions
|
||||
******************************************************************************************/
|
||||
|
||||
|
||||
enum LogicalOperator{
|
||||
AndOp=0, /* exp AND exp */
|
||||
OrOp=1, /* exp OR exp */
|
||||
XorOp=2 /* exp XOR exp */
|
||||
};
|
||||
|
||||
|
||||
/*Operators for String Queries*/
|
||||
enum StringOperator{
|
||||
ContainsAnyStrings = 0, /* e.g. name contains any of 'conference' 'meeting' 'presentation' */
|
||||
ContainsAllStrings = 1, /* same as above except that it contains ALL of the strings */
|
||||
EqualsString = 2 /* exactly equal*/
|
||||
};
|
||||
|
||||
/*Relational operators ( >, <, >=, <=, == and InRange )*/
|
||||
enum RelOperator{
|
||||
Equals = 0,
|
||||
GreaterEquals = 1,
|
||||
Greater = 2,
|
||||
SmallerEquals = 3,
|
||||
Smaller = 4,
|
||||
InRange = 5 /* lower limit <= value <= upper limit*/
|
||||
};
|
||||
|
||||
/********************************************************************************************
|
||||
* Helper class for further serialisation
|
||||
********************************************************************************************/
|
||||
|
||||
class StringExpression ;
|
||||
class Expression ;
|
||||
|
||||
class LinearizedExpression
|
||||
{
|
||||
public:
|
||||
std::vector<uint8_t> _tokens ;
|
||||
std::vector<uint32_t> _ints ;
|
||||
std::vector<std::string> _strings ;
|
||||
|
||||
typedef enum { EXPR_DATE= 0,
|
||||
EXPR_POP = 1,
|
||||
EXPR_SIZE= 2,
|
||||
EXPR_HASH= 3,
|
||||
EXPR_NAME= 4,
|
||||
EXPR_PATH= 5,
|
||||
EXPR_EXT = 6,
|
||||
EXPR_COMP= 7 } token ;
|
||||
|
||||
static Expression *toExpr(const LinearizedExpression& e) ;
|
||||
|
||||
private:
|
||||
static Expression *toExpr(const LinearizedExpression& e,int&,int&,int&) ;
|
||||
static void readStringExpr(const LinearizedExpression& e,int& n_ints,int& n_strings,std::list<std::string>& strings,bool& b,StringOperator& op) ;
|
||||
};
|
||||
|
||||
|
||||
/******************************************************************************************
|
||||
Boolean Search Expression
|
||||
classes:
|
||||
|
||||
Expression: The base class of all expression typest
|
||||
CompoundExpression: The expression which uses a logical operator to combine
|
||||
the results of two expressions
|
||||
StringExpression: An expression which uses some sort of string comparison.
|
||||
RelExpression: A Relational Expression where > < >= <= == make sense.
|
||||
e.g. size date etc
|
||||
|
||||
******************************************************************************************/
|
||||
|
||||
class FileEntry;
|
||||
|
||||
class Expression
|
||||
{
|
||||
public:
|
||||
virtual bool eval (FileEntry *file) = 0;
|
||||
virtual ~Expression() {};
|
||||
|
||||
virtual void linearize(LinearizedExpression& e) const = 0 ;
|
||||
};
|
||||
|
||||
|
||||
class CompoundExpression : public Expression
|
||||
{
|
||||
public:
|
||||
CompoundExpression( enum LogicalOperator op, Expression * exp1, Expression *exp2)
|
||||
: Lexp(exp1), Rexp(exp2), Op(op){ }
|
||||
|
||||
bool eval (FileEntry *file) {
|
||||
if (Lexp == NULL or Rexp == NULL) {
|
||||
return false;
|
||||
}
|
||||
switch (Op){
|
||||
case AndOp:
|
||||
return Lexp->eval(file) && Rexp->eval(file);
|
||||
case OrOp:
|
||||
return Lexp->eval(file) || Rexp->eval(file);
|
||||
case XorOp:
|
||||
return Lexp->eval(file) ^ Rexp->eval(file);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
virtual ~CompoundExpression(){
|
||||
delete Lexp;
|
||||
delete Rexp;
|
||||
}
|
||||
|
||||
virtual void linearize(LinearizedExpression& e) const ;
|
||||
private:
|
||||
Expression *Lexp;
|
||||
Expression *Rexp;
|
||||
enum LogicalOperator Op;
|
||||
|
||||
};
|
||||
|
||||
class StringExpression: public Expression
|
||||
{
|
||||
public:
|
||||
StringExpression(enum StringOperator op, std::list<std::string> &t, bool ic): Op(op),terms(t), IgnoreCase(ic){}
|
||||
|
||||
virtual void linearize(LinearizedExpression& e) const ;
|
||||
protected:
|
||||
bool evalStr(std::string &str);
|
||||
|
||||
enum StringOperator Op;
|
||||
std::list<std::string> terms;
|
||||
bool IgnoreCase;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
class RelExpression: public Expression
|
||||
{
|
||||
public:
|
||||
RelExpression(enum RelOperator op, T lv, T hv): Op(op), LowerValue(lv), HigherValue(hv) {}
|
||||
|
||||
virtual void linearize(LinearizedExpression& e) const ;
|
||||
protected:
|
||||
bool evalRel(T val);
|
||||
|
||||
enum RelOperator Op;
|
||||
T LowerValue;
|
||||
T HigherValue;
|
||||
};
|
||||
|
||||
template<> void RelExpression<int>::linearize(LinearizedExpression& e) const ;
|
||||
|
||||
template <class T>
|
||||
bool RelExpression<T>::evalRel(T val) {
|
||||
switch (Op) {
|
||||
case Equals:
|
||||
return LowerValue == val;
|
||||
case GreaterEquals:
|
||||
return LowerValue >= val;
|
||||
case Greater:
|
||||
return LowerValue > val;
|
||||
case SmallerEquals:
|
||||
return LowerValue <= val;
|
||||
case Smaller:
|
||||
return LowerValue < val;
|
||||
case InRange:
|
||||
return (LowerValue <= val) && (val <= HigherValue);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/******************************************************************************************
|
||||
Binary Predicate for Case Insensitive search
|
||||
|
||||
******************************************************************************************/
|
||||
/*Binary predicate for case insensitive character comparison.*/
|
||||
/*TODOS:
|
||||
*Factor locales in the comparison
|
||||
*/
|
||||
struct CompareCharIC :
|
||||
public std::binary_function< char , char , bool> {
|
||||
|
||||
bool operator () ( char ch1 , char ch2 ) const {
|
||||
return tolower( static_cast < unsigned char > (ch1) )
|
||||
== tolower( static_cast < unsigned char > (ch2) );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
/******************************************************************************************
|
||||
Some implementations of StringExpressions.
|
||||
|
||||
******************************************************************************************/
|
||||
|
||||
class NameExpression: public StringExpression
|
||||
{
|
||||
public:
|
||||
NameExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
|
||||
StringExpression(op,t,ic) {}
|
||||
bool eval(FileEntry *file);
|
||||
|
||||
virtual void linearize(LinearizedExpression& e) const
|
||||
{
|
||||
e._tokens.push_back(LinearizedExpression::EXPR_NAME) ;
|
||||
StringExpression::linearize(e) ;
|
||||
}
|
||||
};
|
||||
|
||||
class PathExpression: public StringExpression {
|
||||
public:
|
||||
PathExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
|
||||
StringExpression(op,t,ic) {}
|
||||
bool eval(FileEntry *file);
|
||||
|
||||
virtual void linearize(LinearizedExpression& e) const
|
||||
{
|
||||
e._tokens.push_back(LinearizedExpression::EXPR_PATH) ;
|
||||
StringExpression::linearize(e) ;
|
||||
}
|
||||
};
|
||||
|
||||
class ExtExpression: public StringExpression {
|
||||
public:
|
||||
ExtExpression(enum StringOperator op, std::list<std::string> &t, bool ic):
|
||||
StringExpression(op,t,ic) {}
|
||||
bool eval(FileEntry *file);
|
||||
|
||||
virtual void linearize(LinearizedExpression& e) const
|
||||
{
|
||||
e._tokens.push_back(LinearizedExpression::EXPR_EXT) ;
|
||||
StringExpression::linearize(e) ;
|
||||
}
|
||||
};
|
||||
|
||||
class HashExpression: public StringExpression {
|
||||
public:
|
||||
HashExpression(enum StringOperator op, std::list<std::string> &t):
|
||||
StringExpression(op,t, true) {}
|
||||
bool eval(FileEntry *file);
|
||||
|
||||
virtual void linearize(LinearizedExpression& e) const
|
||||
{
|
||||
e._tokens.push_back(LinearizedExpression::EXPR_HASH) ;
|
||||
StringExpression::linearize(e) ;
|
||||
}
|
||||
};
|
||||
|
||||
/******************************************************************************************
|
||||
Some implementations of Relational Expressions.
|
||||
|
||||
******************************************************************************************/
|
||||
|
||||
class DateExpression: public RelExpression<int>
|
||||
{
|
||||
public:
|
||||
DateExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
|
||||
DateExpression(enum RelOperator op, int lv, int hv):
|
||||
RelExpression<int>(op,lv,hv) {}
|
||||
bool eval(FileEntry *file);
|
||||
|
||||
virtual void linearize(LinearizedExpression& e) const
|
||||
{
|
||||
e._tokens.push_back(LinearizedExpression::EXPR_DATE) ;
|
||||
RelExpression<int>::linearize(e) ;
|
||||
}
|
||||
};
|
||||
|
||||
class SizeExpression: public RelExpression<int>
|
||||
{
|
||||
public:
|
||||
SizeExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
|
||||
SizeExpression(enum RelOperator op, int lv, int hv):
|
||||
RelExpression<int>(op,lv,hv) {}
|
||||
bool eval(FileEntry *file);
|
||||
|
||||
virtual void linearize(LinearizedExpression& e) const
|
||||
{
|
||||
e._tokens.push_back(LinearizedExpression::EXPR_SIZE) ;
|
||||
RelExpression<int>::linearize(e) ;
|
||||
}
|
||||
};
|
||||
|
||||
class PopExpression: public RelExpression<int>
|
||||
{
|
||||
public:
|
||||
PopExpression(enum RelOperator op, int v): RelExpression<int>(op,v,v){}
|
||||
PopExpression(enum RelOperator op, int lv, int hv): RelExpression<int>(op,lv,hv) {}
|
||||
PopExpression(const LinearizedExpression& e) ;
|
||||
bool eval(FileEntry *file);
|
||||
|
||||
virtual void linearize(LinearizedExpression& e) const
|
||||
{
|
||||
e._tokens.push_back(LinearizedExpression::EXPR_POP) ;
|
||||
RelExpression<int>::linearize(e) ;
|
||||
}
|
||||
};
|
||||
|
||||
#endif /* RS_EXPRESSIONS_H */
|
||||
|
@ -1,185 +0,0 @@
|
||||
#ifndef RS_FILES_GUI_INTERFACE_H
|
||||
#define RS_FILES_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsfiles.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 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 <list>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "rsiface/rstypes.h"
|
||||
|
||||
class RsFiles;
|
||||
extern RsFiles *rsFiles;
|
||||
|
||||
class Expression;
|
||||
|
||||
/* These are used mainly by ftController at the moment */
|
||||
const uint32_t RS_FILE_CTRL_PAUSE = 0x00000100;
|
||||
const uint32_t RS_FILE_CTRL_START = 0x00000200;
|
||||
|
||||
const uint32_t RS_FILE_RATE_TRICKLE = 0x00000001;
|
||||
const uint32_t RS_FILE_RATE_SLOW = 0x00000002;
|
||||
const uint32_t RS_FILE_RATE_STANDARD = 0x00000003;
|
||||
const uint32_t RS_FILE_RATE_FAST = 0x00000004;
|
||||
const uint32_t RS_FILE_RATE_STREAM_AUDIO = 0x00000005;
|
||||
const uint32_t RS_FILE_RATE_STREAM_VIDEO = 0x00000006;
|
||||
|
||||
const uint32_t RS_FILE_PEER_ONLINE = 0x00001000;
|
||||
const uint32_t RS_FILE_PEER_OFFLINE = 0x00002000;
|
||||
|
||||
/************************************
|
||||
* Used To indicate where to search.
|
||||
*
|
||||
* The Order of these is very important,
|
||||
* it specifies the search order too.
|
||||
*
|
||||
*/
|
||||
|
||||
const uint32_t RS_FILE_HINTS_MASK = 0x00ffffff;
|
||||
|
||||
const uint32_t RS_FILE_HINTS_CACHE = 0x00000001;
|
||||
const uint32_t RS_FILE_HINTS_EXTRA = 0x00000002;
|
||||
const uint32_t RS_FILE_HINTS_LOCAL = 0x00000004;
|
||||
const uint32_t RS_FILE_HINTS_REMOTE = 0x00000008;
|
||||
const uint32_t RS_FILE_HINTS_DOWNLOAD = 0x00000010;
|
||||
const uint32_t RS_FILE_HINTS_UPLOAD = 0x00000020;
|
||||
const uint32_t RS_FILE_HINTS_TURTLE = 0x00000040;
|
||||
const uint32_t RS_FILE_HINTS_NETWORK_WIDE = 0x00000080; // anonymously shared over network
|
||||
const uint32_t RS_FILE_HINTS_BROWSABLE = 0x00000100; // browsable by friends
|
||||
|
||||
const uint32_t RS_FILE_HINTS_SPEC_ONLY = 0x01000000;
|
||||
const uint32_t RS_FILE_HINTS_NO_SEARCH = 0x02000000;
|
||||
|
||||
/* Callback Codes */
|
||||
//const uint32_t RS_FILE_HINTS_CACHE = 0x00000001; // ALREADY EXISTS
|
||||
const uint32_t RS_FILE_HINTS_MEDIA = 0x00001000;
|
||||
|
||||
const uint32_t RS_FILE_HINTS_BACKGROUND = 0x00002000; // To download slowly.
|
||||
|
||||
const uint32_t RS_FILE_EXTRA_DELETE = 0x0010;
|
||||
|
||||
const uint32_t CB_CODE_CACHE = 0x0001;
|
||||
const uint32_t CB_CODE_EXTRA = 0x0002;
|
||||
const uint32_t CB_CODE_MEDIA = 0x0004;
|
||||
|
||||
struct SharedDirInfo
|
||||
{
|
||||
std::string filename ;
|
||||
uint32_t shareflags ; // RS_FILE_HINTS_NETWORK_WIDE | RS_FILE_HINTS_BROWSABLE
|
||||
};
|
||||
|
||||
class RsFiles
|
||||
{
|
||||
public:
|
||||
|
||||
RsFiles() { return; }
|
||||
virtual ~RsFiles() { return; }
|
||||
|
||||
/****************************************/
|
||||
/* download */
|
||||
|
||||
|
||||
/***
|
||||
* Control of Downloads.
|
||||
***/
|
||||
virtual bool FileRequest(std::string fname, std::string hash, uint64_t size,
|
||||
std::string dest, uint32_t flags, std::list<std::string> srcIds) = 0;
|
||||
virtual bool FileCancel(std::string hash) = 0;
|
||||
virtual bool setChunkStrategy(const std::string& hash,FileChunksInfo::ChunkStrategy) = 0;
|
||||
virtual bool FileControl(std::string hash, uint32_t flags) = 0;
|
||||
virtual bool FileClearCompleted() = 0;
|
||||
|
||||
/***
|
||||
* Control of Downloads Priority.
|
||||
***/
|
||||
virtual bool changePriority(const std::string hash, int priority) = 0;
|
||||
virtual bool getPriority(const std::string hash, int & priority) = 0;
|
||||
virtual bool clearDownload(const std::string hash) = 0;
|
||||
virtual void clearQueue() = 0;
|
||||
virtual void getDwlDetails(std::list<DwlDetails> & details) = 0;
|
||||
|
||||
/***
|
||||
* Download / Upload Details.
|
||||
***/
|
||||
virtual bool FileDownloads(std::list<std::string> &hashs) = 0;
|
||||
virtual bool FileUploads(std::list<std::string> &hashs) = 0;
|
||||
virtual bool FileDetails(std::string hash, uint32_t hintflags, FileInfo &info) = 0;
|
||||
virtual bool FileChunksDetails(const std::string& hash,FileChunksInfo& info) = 0 ;
|
||||
|
||||
/***
|
||||
* Extra List Access
|
||||
***/
|
||||
virtual bool ExtraFileAdd(std::string fname, std::string hash, uint64_t size,
|
||||
uint32_t period, uint32_t flags) = 0;
|
||||
virtual bool ExtraFileRemove(std::string hash, uint32_t flags) = 0;
|
||||
virtual bool ExtraFileHash(std::string localpath,
|
||||
uint32_t period, uint32_t flags) = 0;
|
||||
virtual bool ExtraFileStatus(std::string localpath, FileInfo &info) = 0;
|
||||
virtual bool ExtraFileMove(std::string fname, std::string hash, uint64_t size,
|
||||
std::string destpath) = 0;
|
||||
|
||||
|
||||
|
||||
/***
|
||||
* Directory Listing / Search Interface
|
||||
*/
|
||||
virtual int RequestDirDetails(std::string uid, std::string path, DirDetails &details) = 0;
|
||||
virtual int RequestDirDetails(void *ref, DirDetails &details, uint32_t flags) = 0;
|
||||
|
||||
virtual int SearchKeywords(std::list<std::string> keywords, std::list<DirDetails> &results,uint32_t flags) = 0;
|
||||
virtual int SearchBoolExp(Expression * exp, std::list<DirDetails> &results,uint32_t flags) = 0;
|
||||
|
||||
/***
|
||||
* Utility Functions.
|
||||
***/
|
||||
virtual bool ConvertSharedFilePath(std::string path, std::string &fullpath) = 0;
|
||||
virtual void ForceDirectoryCheck() = 0;
|
||||
virtual bool InDirectoryCheck() = 0;
|
||||
|
||||
/***
|
||||
* Directory Control
|
||||
***/
|
||||
virtual void setDownloadDirectory(std::string path) = 0;
|
||||
virtual void setPartialsDirectory(std::string path) = 0;
|
||||
virtual std::string getDownloadDirectory() = 0;
|
||||
virtual std::string getPartialsDirectory() = 0;
|
||||
|
||||
virtual bool getSharedDirectories(std::list<SharedDirInfo> &dirs) = 0;
|
||||
virtual bool addSharedDirectory(SharedDirInfo dir) = 0;
|
||||
virtual bool updateShareFlags(const SharedDirInfo& dir) = 0; // updates the flags. The directory should already exist !
|
||||
virtual bool removeSharedDirectory(std::string dir) = 0;
|
||||
|
||||
virtual void setShareDownloadDirectory(bool value) = 0;
|
||||
virtual bool getShareDownloadDirectory() = 0;
|
||||
virtual bool shareDownloadDirectory() = 0;
|
||||
virtual bool unshareDownloadDirectory() = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,129 +0,0 @@
|
||||
#ifndef RS_FORUM_GUI_INTERFACE_H
|
||||
#define RS_FORUM_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsforums.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-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 <list>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "rsiface/rstypes.h"
|
||||
#include "rsiface/rsdistrib.h" /* For FLAGS */
|
||||
|
||||
#define RS_FORUMMSG_NEW 0x0010
|
||||
|
||||
|
||||
class ForumInfo
|
||||
{
|
||||
public:
|
||||
ForumInfo() {}
|
||||
std::string forumId;
|
||||
std::wstring forumName;
|
||||
std::wstring forumDesc;
|
||||
|
||||
uint32_t forumFlags;
|
||||
uint32_t subscribeFlags;
|
||||
|
||||
uint32_t pop;
|
||||
|
||||
time_t lastPost;
|
||||
};
|
||||
|
||||
class ForumMsgInfo
|
||||
{
|
||||
public:
|
||||
ForumMsgInfo() {}
|
||||
std::string forumId;
|
||||
std::string threadId;
|
||||
std::string parentId;
|
||||
std::string msgId;
|
||||
|
||||
std::string srcId; /* if Authenticated -> signed here */
|
||||
|
||||
unsigned int msgflags;
|
||||
|
||||
std::wstring title;
|
||||
std::wstring msg;
|
||||
time_t ts;
|
||||
time_t childTS;
|
||||
};
|
||||
|
||||
|
||||
class ThreadInfoSummary
|
||||
{
|
||||
public:
|
||||
ThreadInfoSummary() {}
|
||||
std::string forumId;
|
||||
std::string threadId;
|
||||
std::string parentId;
|
||||
std::string msgId;
|
||||
|
||||
uint32_t msgflags;
|
||||
|
||||
std::wstring title;
|
||||
std::wstring msg;
|
||||
int count; /* file count */
|
||||
time_t ts;
|
||||
time_t childTS;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const ForumInfo &info);
|
||||
std::ostream &operator<<(std::ostream &out, const ThreadInfoSummary &info);
|
||||
std::ostream &operator<<(std::ostream &out, const ForumMsgInfo &info);
|
||||
|
||||
class RsForums;
|
||||
extern RsForums *rsForums;
|
||||
|
||||
class RsForums
|
||||
{
|
||||
public:
|
||||
|
||||
RsForums() { return; }
|
||||
virtual ~RsForums() { return; }
|
||||
|
||||
/****************************************/
|
||||
|
||||
virtual bool forumsChanged(std::list<std::string> &forumIds) = 0;
|
||||
|
||||
|
||||
virtual std::string createForum(std::wstring forumName, std::wstring forumDesc, uint32_t forumFlags) = 0;
|
||||
|
||||
virtual bool getForumInfo(std::string fId, ForumInfo &fi) = 0;
|
||||
virtual bool getForumList(std::list<ForumInfo> &forumList) = 0;
|
||||
virtual bool getForumThreadList(std::string fId, std::list<ThreadInfoSummary> &msgs) = 0;
|
||||
virtual bool getForumThreadMsgList(std::string fId, std::string pId, std::list<ThreadInfoSummary> &msgs) = 0;
|
||||
virtual bool getForumMessage(std::string fId, std::string mId, ForumMsgInfo &msg) = 0;
|
||||
|
||||
virtual bool ForumMessageSend(ForumMsgInfo &info) = 0;
|
||||
|
||||
virtual bool forumSubscribe(std::string fId, bool subscribe) = 0;
|
||||
/****************************************/
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,113 +0,0 @@
|
||||
#ifndef RS_GAME_GUI_INTERFACE_H
|
||||
#define RS_GAME_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsgame.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-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 "rstypes.h"
|
||||
|
||||
|
||||
class RsGameLauncher;
|
||||
|
||||
/* declare single RsIface for everyone to use! */
|
||||
|
||||
extern RsGameLauncher *rsGameLauncher;
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <inttypes.h>
|
||||
|
||||
class RsGameInfo
|
||||
{
|
||||
public:
|
||||
|
||||
std::string gameId;
|
||||
std::string serverId;
|
||||
|
||||
std::string gameType;
|
||||
std::wstring gameName;
|
||||
std::string serverName;
|
||||
std::string status;
|
||||
uint16_t numPlayers;
|
||||
|
||||
};
|
||||
|
||||
class RsGamePeer
|
||||
{
|
||||
public:
|
||||
std::string id;
|
||||
bool invite;
|
||||
bool interested;
|
||||
bool play;
|
||||
};
|
||||
|
||||
class RsGameDetail
|
||||
{
|
||||
public:
|
||||
std::string gameId;
|
||||
std::string gameType;
|
||||
std::wstring gameName;
|
||||
|
||||
bool areServer; /* are we the server? */
|
||||
std::string serverId; /* if not, who is? */
|
||||
std::string serverName;
|
||||
|
||||
std::string status;
|
||||
|
||||
uint16_t numPlayers;
|
||||
std::map<std::string, RsGamePeer> gamers;
|
||||
|
||||
};
|
||||
|
||||
class RsGameLauncher
|
||||
{
|
||||
public:
|
||||
|
||||
/* server commands */
|
||||
virtual std::string createGame(uint32_t gameType, std::wstring name) = 0;
|
||||
virtual bool deleteGame(std::string gameId) = 0;
|
||||
virtual bool inviteGame(std::string gameId) = 0;
|
||||
virtual bool playGame(std::string gameId) = 0;
|
||||
//virtual bool quitGame(std::string gameId) = 0;
|
||||
|
||||
virtual bool invitePeer(std::string gameId, std::string peerId) = 0;
|
||||
virtual bool uninvitePeer(std::string gameId, std::string peerId) = 0;
|
||||
virtual bool confirmPeer(std::string gameId, std::string peerId,
|
||||
int16_t pos = -1) = 0;
|
||||
virtual bool unconfirmPeer(std::string gameId, std::string peerId) = 0;
|
||||
|
||||
/* client commands */
|
||||
virtual bool interestedPeer(std::string gameId) = 0;
|
||||
virtual bool uninterestedPeer(std::string gameId) = 0;
|
||||
|
||||
/* get details */
|
||||
virtual bool getGameList(std::list<RsGameInfo> &gameList) = 0;
|
||||
virtual bool getGameDetail(std::string gameId, RsGameDetail &detail) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,231 +0,0 @@
|
||||
#ifndef RETROSHARE_GUI_INTERFACE_H
|
||||
#define RETROSHARE_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* "$Id: rsiface.h,v 1.9 2007-04-21 19:08:51 rmf24 Exp $"
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2004-2006 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 "rstypes.h"
|
||||
|
||||
#include <map>
|
||||
|
||||
class NotifyBase;
|
||||
class RsIface;
|
||||
class RsControl;
|
||||
class RsInit;
|
||||
struct TurtleFileInfo ;
|
||||
|
||||
/* declare single RsIface for everyone to use! */
|
||||
|
||||
extern RsIface *rsiface;
|
||||
extern RsControl *rsicontrol;
|
||||
|
||||
/* RsInit -> Configuration Parameters for RetroShare Startup
|
||||
*/
|
||||
|
||||
RsInit *InitRsConfig();
|
||||
/* extract various options for GUI */
|
||||
const char *RsConfigDirectory(RsInit *config);
|
||||
bool RsConfigStartMinimised(RsInit *config);
|
||||
void CleanupRsConfig(RsInit *);
|
||||
|
||||
|
||||
// Called First... (handles comandline options)
|
||||
int InitRetroShare(int argc, char **argv, RsInit *config);
|
||||
|
||||
// This Functions are used for Login.
|
||||
bool ValidateCertificate(RsInit *config, std::string &userName);
|
||||
bool ValidateTrustedUser(RsInit *config, std::string fname, std::string &userName);
|
||||
bool LoadPassword(RsInit *config, std::string passwd);
|
||||
bool RsGenerateCertificate(RsInit *config, std::string name, std::string org,
|
||||
std::string loc, std::string country, std::string passwd, std::string &errString);
|
||||
|
||||
/* Auto Login Fns */
|
||||
bool RsTryAutoLogin(RsInit *config);
|
||||
bool RsStoreAutoLogin(RsInit *config);
|
||||
bool RsClearAutoLogin(std::string basedir);
|
||||
|
||||
// Handle actual Login.
|
||||
int LoadCertificates(RsInit *config, bool autoLoginNT);
|
||||
|
||||
RsIface *createRsIface (NotifyBase ¬ify);
|
||||
RsControl *createRsControl(RsIface &iface, NotifyBase ¬ify);
|
||||
|
||||
|
||||
class RsIface /* The Main Interface Class - create a single one! */
|
||||
{
|
||||
public:
|
||||
RsIface(NotifyBase &callback)
|
||||
:cb(callback) { return; }
|
||||
virtual ~RsIface() { return; }
|
||||
|
||||
/****************************************/
|
||||
|
||||
/* Stubs for Very Important Fns -> Locking Functions */
|
||||
virtual void lockData() = 0;
|
||||
virtual void unlockData() = 0;
|
||||
|
||||
const std::list<FileInfo> &getRecommendList()
|
||||
{ return mRecommendList; }
|
||||
|
||||
const RsConfig &getConfig()
|
||||
{ return mConfig; }
|
||||
/****************************************/
|
||||
|
||||
|
||||
/* Flags to indicate used or not */
|
||||
enum DataFlags
|
||||
{
|
||||
Neighbour = 0,
|
||||
Friend = 1,
|
||||
DirLocal = 2, /* Not Used - QModel instead */
|
||||
DirRemote = 3, /* Not Used - QModel instead */
|
||||
Transfer = 4,
|
||||
Message = 5,
|
||||
Channel = 6,
|
||||
Chat = 7,
|
||||
Recommend = 8,
|
||||
Config = 9,
|
||||
NumOfFlags = 10
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Operations for flags
|
||||
*/
|
||||
|
||||
bool setChanged(DataFlags set); /* set to true */
|
||||
bool getChanged(DataFlags set); /* leaves it */
|
||||
bool hasChanged(DataFlags set); /* resets it */
|
||||
|
||||
private:
|
||||
|
||||
void fillLists(); /* create some dummy data to display */
|
||||
|
||||
/* Internals */
|
||||
std::list<FileInfo> mRecommendList;
|
||||
|
||||
bool mChanged[NumOfFlags];
|
||||
|
||||
RsConfig mConfig;
|
||||
|
||||
NotifyBase &cb;
|
||||
|
||||
/* Classes which can update the Lists! */
|
||||
friend class RsControl;
|
||||
friend class RsServer;
|
||||
};
|
||||
|
||||
|
||||
class RsControl /* The Main Interface Class - for controlling the server */
|
||||
{
|
||||
public:
|
||||
|
||||
RsControl(RsIface &i, NotifyBase &callback)
|
||||
:cb(callback), rsIface(i) { return; }
|
||||
|
||||
virtual ~RsControl() { return; }
|
||||
|
||||
/* Real Startup Fn */
|
||||
virtual int StartupRetroShare() = 0;
|
||||
|
||||
/****************************************/
|
||||
|
||||
/* Flagging Persons / Channels / Files in or out of a set (CheckLists) */
|
||||
virtual int SetInChat(std::string id, bool in) = 0; /* friend : chat msgs */
|
||||
virtual int SetInMsg(std::string id, bool in) = 0; /* friend : msg receipients */
|
||||
virtual int SetInBroadcast(std::string id, bool in) = 0; /* channel : channel broadcast */
|
||||
virtual int SetInSubscribe(std::string id, bool in) = 0; /* channel : subscribed channels */
|
||||
virtual int SetInRecommend(std::string id, bool in) = 0; /* file : recommended file */
|
||||
virtual int ClearInChat() = 0;
|
||||
virtual int ClearInMsg() = 0;
|
||||
virtual int ClearInBroadcast() = 0;
|
||||
virtual int ClearInSubscribe() = 0;
|
||||
virtual int ClearInRecommend() = 0;
|
||||
|
||||
virtual bool IsInChat(std::string id) = 0; /* friend : chat msgs */
|
||||
virtual bool IsInMsg(std::string id) = 0; /* friend : msg recpts*/
|
||||
|
||||
/****************************************/
|
||||
/* Config */
|
||||
|
||||
virtual int ConfigSetDataRates( int totalDownload, int totalUpload ) = 0;
|
||||
virtual int ConfigGetDataRates( float &inKb, float &outKb) = 0;
|
||||
virtual int ConfigSetBootPrompt( bool on ) = 0;
|
||||
virtual void ConfigFinalSave( ) = 0;
|
||||
virtual void rsGlobalShutDown( ) = 0;
|
||||
|
||||
/****************************************/
|
||||
|
||||
NotifyBase &getNotify() { return cb; }
|
||||
RsIface &getIface() { return rsIface; }
|
||||
|
||||
private:
|
||||
NotifyBase &cb;
|
||||
RsIface &rsIface;
|
||||
};
|
||||
|
||||
|
||||
/********************** Overload this Class for callback *****************/
|
||||
|
||||
|
||||
class NotifyBase
|
||||
{
|
||||
public:
|
||||
NotifyBase() { return; }
|
||||
virtual ~NotifyBase() { return; }
|
||||
virtual void notifyListPreChange(int list, int type) { (void) list; (void) type; return; }
|
||||
virtual void notifyListChange(int list, int type) { (void) list; (void) type; return; }
|
||||
virtual void notifyErrorMsg(int list, int sev, std::string msg) { (void) list; (void) sev; (void) msg; return; }
|
||||
virtual void notifyChat() { return; }
|
||||
virtual void notifyChatStatus(const std::string& peer_id,const std::string& status_string,bool is_private) {}
|
||||
virtual void notifyCustomState(const std::string& peer_id) {}
|
||||
virtual void notifyHashingInfo(std::string fileinfo) { (void)fileinfo; return ; }
|
||||
virtual void notifyTurtleSearchResult(uint32_t search_id,const std::list<TurtleFileInfo>& files) { (void)files; }
|
||||
virtual void notifyPeerHasNewAvatar(std::string peer_id) { (void)peer_id; }
|
||||
virtual void notifyOwnAvatarChanged() {}
|
||||
virtual void notifyOwnStatusMessageChanged() {}
|
||||
|
||||
virtual std::string askForPassword(const std::string& window_title,const std::string& text) { return "" ;}
|
||||
};
|
||||
|
||||
const int NOTIFY_LIST_NEIGHBOURS = 1;
|
||||
const int NOTIFY_LIST_FRIENDS = 2;
|
||||
const int NOTIFY_LIST_SEARCHLIST = 4;
|
||||
const int NOTIFY_LIST_MESSAGELIST = 5;
|
||||
const int NOTIFY_LIST_CHANNELLIST = 6;
|
||||
const int NOTIFY_LIST_TRANSFERLIST = 7;
|
||||
const int NOTIFY_LIST_CONFIG = 8;
|
||||
const int NOTIFY_LIST_DIRLIST_LOCAL = 9;
|
||||
const int NOTIFY_LIST_DIRLIST_FRIENDS = 10;
|
||||
|
||||
const int NOTIFY_TYPE_SAME = 0x01;
|
||||
const int NOTIFY_TYPE_MOD = 0x02; /* general purpose, check all */
|
||||
const int NOTIFY_TYPE_ADD = 0x04; /* flagged additions */
|
||||
const int NOTIFY_TYPE_DEL = 0x08; /* flagged deletions */
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,105 +0,0 @@
|
||||
#ifndef RETROSHARE_INIT_INTERFACE_H
|
||||
#define RETROSHARE_INIT_INTERFACE_H
|
||||
|
||||
/*
|
||||
* "$Id: rsiface.h,v 1.9 2007-04-21 19:08:51 rmf24 Exp $"
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2004-2006 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".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* Initialisation Class (not publicly disclosed to RsIFace) */
|
||||
|
||||
/****
|
||||
* #define RS_USE_PGPSSL 1
|
||||
***/
|
||||
|
||||
#define RS_USE_PGPSSL 1
|
||||
|
||||
class RsInit
|
||||
{
|
||||
public:
|
||||
/* reorganised RsInit system */
|
||||
|
||||
/* PreLogin */
|
||||
static void InitRsConfig() ;
|
||||
static int InitRetroShare(int argc, char **argv);
|
||||
|
||||
|
||||
/* Account Details (Combined GPG+SSL Setup) */
|
||||
static bool getPreferedAccountId(std::string &id);
|
||||
static bool getPGPEngineFileName(std::string &fileName);
|
||||
static bool getAccountIds(std::list<std::string> &ids);
|
||||
static bool getAccountDetails(std::string id,
|
||||
std::string &gpgId, std::string &gpgName,
|
||||
std::string &gpgEmail, std::string &sslName);
|
||||
|
||||
static bool ValidateCertificate(std::string &userName) ;
|
||||
|
||||
|
||||
/* Generating GPGme Account */
|
||||
static int GetPGPLogins(std::list<std::string> &pgpIds);
|
||||
static int GetPGPLoginDetails(std::string id, std::string &name, std::string &email);
|
||||
static bool GeneratePGPCertificate(std::string name, std::string comment, std::string email, std::string passwd, std::string &pgpId, std::string &errString);
|
||||
|
||||
/* Login PGP */
|
||||
static bool SelectGPGAccount(std::string id);
|
||||
static bool LoadGPGPassword(std::string passwd);
|
||||
|
||||
/* Create SSL Certificates */
|
||||
static bool GenerateSSLCertificate(std::string name, std::string org, std::string loc, std::string country, std::string passwd, std::string &sslId, std::string &errString);
|
||||
|
||||
/* Login SSL */
|
||||
static bool LoadPassword(std::string id, std::string passwd) ;
|
||||
|
||||
/* Final Certificate load. This can be called if:
|
||||
* a) InitRetroshare() returns true -> autoLoad/password Set.
|
||||
* b) SelectGPGAccount() && LoadPassword()
|
||||
*/
|
||||
static int LoadCertificates(bool autoLoginNT) ;
|
||||
|
||||
|
||||
/* Post Login Options */
|
||||
static std::string RsConfigDirectory();
|
||||
static bool setStartMinimised() ;
|
||||
|
||||
|
||||
private:
|
||||
/* PreLogin */
|
||||
static std::string getHomePath() ;
|
||||
static void setupBaseDir();
|
||||
|
||||
/* Account Details */
|
||||
static bool get_configinit(std::string dir, std::string &id);
|
||||
static bool create_configinit(std::string dir, std::string id);
|
||||
|
||||
static bool setupAccount(std::string accountdir);
|
||||
|
||||
/* Auto Login */
|
||||
static bool RsStoreAutoLogin() ;
|
||||
static bool RsTryAutoLogin() ;
|
||||
static bool RsClearAutoLogin() ;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,152 +0,0 @@
|
||||
#ifndef RS_MSG_GUI_INTERFACE_H
|
||||
#define RS_MSG_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsmsgs.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-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 <list>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "rsiface/rstypes.h"
|
||||
|
||||
/********************** For Messages and Channels *****************/
|
||||
|
||||
#define RS_MSG_BOXMASK 0x000f /* Mask for determining Box */
|
||||
|
||||
#define RS_MSG_OUTGOING 0x0001 /* !Inbox */
|
||||
#define RS_MSG_PENDING 0x0002 /* OutBox */
|
||||
#define RS_MSG_DRAFT 0x0004 /* Draft */
|
||||
|
||||
/* ORs of above */
|
||||
#define RS_MSG_INBOX 0x00 /* Inbox */
|
||||
#define RS_MSG_SENTBOX 0x01 /* Sentbox */
|
||||
#define RS_MSG_OUTBOX 0x03 /* Outbox */
|
||||
#define RS_MSG_DRAFTBOX 0x05 /* Draftbox */
|
||||
|
||||
#define RS_MSG_NEW 0x0010
|
||||
|
||||
class MessageInfo
|
||||
{
|
||||
public:
|
||||
MessageInfo() {}
|
||||
std::string msgId;
|
||||
std::string srcId;
|
||||
|
||||
unsigned int msgflags;
|
||||
|
||||
std::list<std::string> msgto;
|
||||
std::list<std::string> msgcc;
|
||||
std::list<std::string> msgbcc;
|
||||
|
||||
std::wstring title;
|
||||
std::wstring msg;
|
||||
|
||||
std::wstring attach_title;
|
||||
std::wstring attach_comment;
|
||||
std::list<FileInfo> files;
|
||||
int size; /* total of files */
|
||||
int count; /* file count */
|
||||
|
||||
int ts;
|
||||
};
|
||||
|
||||
class MsgInfoSummary
|
||||
{
|
||||
public:
|
||||
MsgInfoSummary() {}
|
||||
|
||||
std::string msgId;
|
||||
std::string srcId;
|
||||
|
||||
uint32_t msgflags;
|
||||
|
||||
std::wstring title;
|
||||
int count; /* file count */
|
||||
time_t ts;
|
||||
|
||||
};
|
||||
|
||||
#define RS_CHAT_PUBLIC 0x0001
|
||||
#define RS_CHAT_PRIVATE 0x0002
|
||||
#define RS_CHAT_AVATAR_AVAILABLE 0x0004
|
||||
|
||||
class ChatInfo
|
||||
{
|
||||
public:
|
||||
std::string rsid;
|
||||
unsigned int chatflags;
|
||||
std::string name;
|
||||
std::wstring msg;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const MessageInfo &info);
|
||||
std::ostream &operator<<(std::ostream &out, const ChatInfo &info);
|
||||
|
||||
class RsMsgs;
|
||||
extern RsMsgs *rsMsgs;
|
||||
|
||||
class RsMsgs
|
||||
{
|
||||
public:
|
||||
|
||||
RsMsgs() { return; }
|
||||
virtual ~RsMsgs() { return; }
|
||||
|
||||
/****************************************/
|
||||
/* Message Items */
|
||||
|
||||
virtual bool getMessageSummaries(std::list<MsgInfoSummary> &msgList) = 0;
|
||||
virtual bool getMessage(std::string mId, MessageInfo &msg) = 0;
|
||||
|
||||
virtual bool MessageSend(MessageInfo &info) = 0;
|
||||
virtual bool MessageDelete(std::string mid) = 0;
|
||||
virtual bool MessageRead(std::string mid) = 0;
|
||||
|
||||
/****************************************/
|
||||
/* Chat */
|
||||
virtual bool chatAvailable() = 0;
|
||||
virtual bool ChatSend(ChatInfo &ci) = 0;
|
||||
virtual bool getNewChat(std::list<ChatInfo> &chats) = 0;
|
||||
virtual void sendStatusString(const std::string& id,const std::string& status_string) = 0 ;
|
||||
virtual void sendGroupChatStatusString(const std::string& status_string) = 0 ;
|
||||
|
||||
virtual void setCustomStateString(const std::string& status_string) = 0 ;
|
||||
virtual std::string getCustomStateString() = 0 ;
|
||||
virtual std::string getCustomStateString(const std::string& peer_id) = 0 ;
|
||||
|
||||
// get avatar data for peer pid
|
||||
virtual void getAvatarData(std::string pid,unsigned char *& data,int& size) = 0 ;
|
||||
// set own avatar data
|
||||
virtual void setOwnAvatarData(const unsigned char *data,int size) = 0 ;
|
||||
virtual void getOwnAvatarData(unsigned char *& data,int& size) = 0 ;
|
||||
|
||||
/****************************************/
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,126 +0,0 @@
|
||||
#ifndef RS_NOTIFY_GUI_INTERFACE_H
|
||||
#define RS_NOTIFY_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsnotify.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-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 <map>
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
class RsNotify;
|
||||
extern RsNotify *rsNotify;
|
||||
|
||||
const uint32_t RS_SYS_ERROR = 0x0001;
|
||||
const uint32_t RS_SYS_WARNING = 0x0002;
|
||||
const uint32_t RS_SYS_INFO = 0x0004;
|
||||
|
||||
const uint32_t RS_POPUP_MSG = 0x0001;
|
||||
const uint32_t RS_POPUP_CHAT = 0x0002;
|
||||
const uint32_t RS_POPUP_CALL = 0x0004;
|
||||
const uint32_t RS_POPUP_CONNECT = 0x0008;
|
||||
const uint32_t RS_SYSTRAY_GROUP_MSG = 0x0010;
|
||||
|
||||
/* CHAT flags are here - so they are in the same place as
|
||||
* other Notify flags... not used by libretroshare though
|
||||
*/
|
||||
const uint32_t RS_CHAT_OPEN_NEW = 0x0001;
|
||||
const uint32_t RS_CHAT_REOPEN = 0x0002;
|
||||
const uint32_t RS_CHAT_FOCUS = 0x0004;
|
||||
|
||||
const uint32_t RS_FEED_TYPE_PEER = 0x0010;
|
||||
const uint32_t RS_FEED_TYPE_CHAN = 0x0020;
|
||||
const uint32_t RS_FEED_TYPE_FORUM = 0x0040;
|
||||
const uint32_t RS_FEED_TYPE_BLOG = 0x0080;
|
||||
const uint32_t RS_FEED_TYPE_CHAT = 0x0100;
|
||||
const uint32_t RS_FEED_TYPE_MSG = 0x0200;
|
||||
const uint32_t RS_FEED_TYPE_FILES = 0x0400;
|
||||
|
||||
const uint32_t RS_FEED_ITEM_PEER_CONNECT = RS_FEED_TYPE_PEER | 0x0001;
|
||||
const uint32_t RS_FEED_ITEM_PEER_DISCONNECT = RS_FEED_TYPE_PEER | 0x0002;
|
||||
const uint32_t RS_FEED_ITEM_PEER_NEW = RS_FEED_TYPE_PEER | 0x0003;
|
||||
const uint32_t RS_FEED_ITEM_PEER_HELLO = RS_FEED_TYPE_PEER | 0x0004;
|
||||
|
||||
const uint32_t RS_FEED_ITEM_CHAN_NEW = RS_FEED_TYPE_CHAN | 0x0001;
|
||||
const uint32_t RS_FEED_ITEM_CHAN_UPDATE = RS_FEED_TYPE_CHAN | 0x0002;
|
||||
const uint32_t RS_FEED_ITEM_CHAN_MSG = RS_FEED_TYPE_CHAN | 0x0003;
|
||||
|
||||
const uint32_t RS_FEED_ITEM_FORUM_NEW = RS_FEED_TYPE_FORUM | 0x0001;
|
||||
const uint32_t RS_FEED_ITEM_FORUM_UPDATE = RS_FEED_TYPE_FORUM | 0x0002;
|
||||
const uint32_t RS_FEED_ITEM_FORUM_MSG = RS_FEED_TYPE_FORUM | 0x0003;
|
||||
|
||||
const uint32_t RS_FEED_ITEM_BLOG_MSG = RS_FEED_TYPE_BLOG | 0x0001;
|
||||
const uint32_t RS_FEED_ITEM_CHAT_NEW = RS_FEED_TYPE_CHAT | 0x0001;
|
||||
const uint32_t RS_FEED_ITEM_MESSAGE = RS_FEED_TYPE_MSG | 0x0001;
|
||||
const uint32_t RS_FEED_ITEM_FILES_NEW = RS_FEED_TYPE_FILES | 0x0001;
|
||||
|
||||
|
||||
class RsFeedItem
|
||||
{
|
||||
public:
|
||||
RsFeedItem(uint32_t type, std::string id1, std::string id2, std::string id3)
|
||||
:mType(type), mId1(id1), mId2(id2), mId3(id3)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RsFeedItem() :mType(0) { return; }
|
||||
|
||||
uint32_t mType;
|
||||
std::string mId1, mId2, mId3;
|
||||
};
|
||||
|
||||
|
||||
class RsNotify
|
||||
{
|
||||
public:
|
||||
|
||||
RsNotify() { return; }
|
||||
virtual ~RsNotify() { return; }
|
||||
|
||||
/* Output for retroshare-gui */
|
||||
virtual bool NotifySysMessage(uint32_t &sysid, uint32_t &type,
|
||||
std::string &title, std::string &msg) = 0;
|
||||
virtual bool NotifyPopupMessage(uint32_t &ptype, std::string &name, std::string &msg) = 0;
|
||||
virtual bool NotifyLogMessage(uint32_t &sysid, uint32_t &type,
|
||||
std::string &title, std::string &msg) = 0;
|
||||
|
||||
/* Control over Messages */
|
||||
virtual bool GetSysMessageList(std::map<uint32_t, std::string> &list) = 0;
|
||||
virtual bool GetPopupMessageList(std::map<uint32_t, std::string> &list) = 0;
|
||||
|
||||
virtual bool SetSysMessageMode(uint32_t sysid, uint32_t mode) = 0;
|
||||
virtual bool SetPopupMessageMode(uint32_t ptype, uint32_t mode) = 0;
|
||||
|
||||
/* Feed Output */
|
||||
virtual bool GetFeedItem(RsFeedItem &item) = 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
@ -1,175 +0,0 @@
|
||||
#ifndef RETROSHARE_PEER_GUI_INTERFACE_H
|
||||
#define RETROSHARE_PEER_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rspeer.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 <inttypes.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsPeers;
|
||||
extern RsPeers *rsPeers;
|
||||
|
||||
/* Trust Levels */
|
||||
const uint32_t RS_TRUST_LVL_UNKNOWN = 0x0001;
|
||||
const uint32_t RS_TRUST_LVL_MARGINAL = 0x0002;
|
||||
const uint32_t RS_TRUST_LVL_GOOD = 0x0003;
|
||||
|
||||
|
||||
/* Net Mode */
|
||||
const uint32_t RS_NETMODE_UDP = 0x0001;
|
||||
const uint32_t RS_NETMODE_UPNP = 0x0002;
|
||||
const uint32_t RS_NETMODE_EXT = 0x0003;
|
||||
const uint32_t RS_NETMODE_UNREACHABLE = 0x0004;
|
||||
|
||||
/* Visibility */
|
||||
const uint32_t RS_VS_DHT_ON = 0x0001;
|
||||
const uint32_t RS_VS_DISC_ON = 0x0002;
|
||||
|
||||
/* State */
|
||||
const uint32_t RS_PEER_STATE_FRIEND = 0x0001;
|
||||
const uint32_t RS_PEER_STATE_ONLINE = 0x0002;
|
||||
const uint32_t RS_PEER_STATE_CONNECTED = 0x0004;
|
||||
const uint32_t RS_PEER_STATE_UNREACHABLE= 0x0008;
|
||||
|
||||
/* A couple of helper functions for translating the numbers games */
|
||||
|
||||
std::string RsPeerTrustString(uint32_t trustLvl);
|
||||
std::string RsPeerStateString(uint32_t state);
|
||||
std::string RsPeerNetModeString(uint32_t netModel);
|
||||
std::string RsPeerLastConnectString(uint32_t lastConnect);
|
||||
|
||||
|
||||
/* Details class */
|
||||
class RsPeerDetails
|
||||
{
|
||||
public:
|
||||
|
||||
RsPeerDetails();
|
||||
|
||||
/* Auth details */
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string email;
|
||||
std::string location;
|
||||
std::string org;
|
||||
|
||||
std::string issuer;
|
||||
|
||||
std::string fpr; /* pgp fingerprint */
|
||||
std::string authcode;
|
||||
std::list<std::string> signers;
|
||||
|
||||
uint32_t trustLvl;
|
||||
uint32_t validLvl;
|
||||
|
||||
bool ownsign; /* we have signed certificate */
|
||||
bool trusted; /* we trust their signature on others */
|
||||
|
||||
/* Network details (only valid if friend) */
|
||||
uint32_t state;
|
||||
|
||||
std::string localAddr;
|
||||
uint16_t localPort;
|
||||
std::string extAddr;
|
||||
uint16_t extPort;
|
||||
std::list<std::string> ipAddressList;
|
||||
|
||||
uint32_t netMode;
|
||||
uint32_t tryNetMode; /* only for ownState */
|
||||
uint32_t visState;
|
||||
|
||||
/* basic stats */
|
||||
uint32_t lastConnect; /* how long ago */
|
||||
std::string autoconnect;
|
||||
uint32_t connectPeriod;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsPeerDetails &detail);
|
||||
|
||||
class RsPeers
|
||||
{
|
||||
public:
|
||||
|
||||
RsPeers() { return; }
|
||||
virtual ~RsPeers() { return; }
|
||||
|
||||
/* Updates ... */
|
||||
virtual bool FriendsChanged() = 0;
|
||||
virtual bool OthersChanged() = 0;
|
||||
|
||||
/* Peer Details (Net & Auth) */
|
||||
virtual std::string getOwnId() = 0;
|
||||
|
||||
virtual bool getOnlineList(std::list<std::string> &ids) = 0;
|
||||
virtual bool getFriendList(std::list<std::string> &ids) = 0;
|
||||
virtual bool getOthersList(std::list<std::string> &ids) = 0;
|
||||
|
||||
virtual bool isOnline(std::string id) = 0;
|
||||
virtual bool isFriend(std::string id) = 0;
|
||||
virtual std::string getPeerName(std::string id) = 0;
|
||||
virtual std::string getPeerPGPName(std::string pgp_id) = 0;
|
||||
virtual bool getPeerDetails(std::string id, RsPeerDetails &d) = 0;
|
||||
|
||||
/* Using PGP Ids */
|
||||
virtual std::string getPGPOwnId() = 0;
|
||||
virtual bool getPGPFriendList(std::list<std::string> &ids) = 0;
|
||||
virtual bool getPGPAllList(std::list<std::string> &ids) = 0;
|
||||
|
||||
/* Add/Remove Friends */
|
||||
virtual bool addFriend(std::string id) = 0;
|
||||
virtual bool removeFriend(std::string id) = 0;
|
||||
|
||||
/* get/set third party info about who trusts me */
|
||||
virtual bool isTrustingMe(std::string id) const = 0 ;
|
||||
|
||||
/* Network Stuff */
|
||||
virtual bool connectAttempt(std::string id) = 0;
|
||||
virtual bool setLocalAddress(std::string id, std::string addr, uint16_t port) = 0;
|
||||
virtual bool setExtAddress( std::string id, std::string addr, uint16_t port) = 0;
|
||||
virtual bool setNetworkMode(std::string id, uint32_t netMode) = 0;
|
||||
virtual bool setVisState(std::string id, uint32_t vis) = 0;
|
||||
|
||||
virtual void getIPServersList(std::list<std::string>& ip_servers) = 0;
|
||||
virtual void allowServerIPDetermination(bool) = 0;
|
||||
virtual bool getAllowServerIPDetermination() = 0 ;
|
||||
|
||||
/* Auth Stuff */
|
||||
virtual std::string GetRetroshareInvite() = 0;
|
||||
|
||||
virtual bool LoadCertificateFromFile(std::string fname, std::string &id) = 0;
|
||||
virtual bool LoadCertificateFromString(std::string cert, std::string &id) = 0;
|
||||
virtual bool SaveCertificateToFile(std::string id, std::string fname) = 0;
|
||||
virtual std::string SaveCertificateToString(std::string id) = 0;
|
||||
|
||||
virtual bool AuthCertificate(std::string id, std::string code) = 0;
|
||||
virtual bool SignCertificate(std::string id) = 0;
|
||||
virtual bool TrustCertificate(std::string id, bool trust) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -1,127 +0,0 @@
|
||||
#ifndef RETROSHARE_PHOTO_GUI_INTERFACE_H
|
||||
#define RETROSHARE_PHOTO_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsphoto.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2008-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 <inttypes.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsPhoto;
|
||||
extern RsPhoto *rsPhoto;
|
||||
|
||||
class RsPhotoDetails;
|
||||
class RsPhotoShowDetails;
|
||||
|
||||
class RsPhotoShowInfo
|
||||
{
|
||||
public:
|
||||
|
||||
std::string photoId;
|
||||
std::wstring altComment;
|
||||
uint32_t deltaT; /* in 100ths of sec? */
|
||||
};
|
||||
|
||||
class RsPhotoShowDetails
|
||||
{
|
||||
public:
|
||||
|
||||
RsPhotoShowDetails();
|
||||
|
||||
std::string id;
|
||||
std::string showid;
|
||||
|
||||
std::string name;
|
||||
std::wstring location;
|
||||
std::wstring comment;
|
||||
std::string date;
|
||||
std::list<RsPhotoShowInfo> photos;
|
||||
};
|
||||
|
||||
/* Details class */
|
||||
class RsPhotoDetails
|
||||
{
|
||||
public:
|
||||
|
||||
RsPhotoDetails();
|
||||
|
||||
std::string id;
|
||||
std::string srcid;
|
||||
|
||||
std::string hash;
|
||||
uint64_t size;
|
||||
|
||||
std::string name;
|
||||
std::wstring comment;
|
||||
|
||||
std::string location;
|
||||
std::string date;
|
||||
|
||||
uint32_t format;
|
||||
|
||||
bool isAvailable;
|
||||
std::string path;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsPhotoShowDetails &detail);
|
||||
std::ostream &operator<<(std::ostream &out, const RsPhotoDetails &detail);
|
||||
|
||||
class RsPhoto
|
||||
{
|
||||
public:
|
||||
|
||||
RsPhoto() { return; }
|
||||
virtual ~RsPhoto() { return; }
|
||||
|
||||
/* changed? */
|
||||
virtual bool updated() = 0;
|
||||
|
||||
/* access data */
|
||||
virtual bool getPhotoList(std::string id, std::list<std::string> &hashs) = 0;
|
||||
virtual bool getShowList(std::string id, std::list<std::string> &showIds) = 0;
|
||||
virtual bool getShowDetails(std::string id, std::string showId, RsPhotoShowDetails &detail) = 0;
|
||||
virtual bool getPhotoDetails(std::string id, std::string photoId, RsPhotoDetails &detail) = 0;
|
||||
|
||||
/* add / delete */
|
||||
virtual std::string createShow(std::string name) = 0;
|
||||
virtual bool deleteShow(std::string showId) = 0;
|
||||
virtual bool addPhotoToShow(std::string showId, std::string photoId, int16_t index) = 0;
|
||||
virtual bool movePhotoInShow(std::string showId, std::string photoId, int16_t index) = 0;
|
||||
virtual bool removePhotoFromShow(std::string showId, std::string photoId) = 0;
|
||||
|
||||
virtual std::string addPhoto(std::string path) = 0; /* add from file */
|
||||
virtual bool addPhoto(std::string srcId, std::string photoId) = 0; /* add from peers photos */
|
||||
virtual bool deletePhoto(std::string photoId) = 0;
|
||||
|
||||
/* modify properties (TODO) */
|
||||
virtual bool modifyShow(std::string showId, std::wstring name, std::wstring comment) = 0;
|
||||
virtual bool modifyPhoto(std::string photoId, std::wstring name, std::wstring comment) = 0;
|
||||
virtual bool modifyShowComment(std::string showId, std::string photoId, std::wstring comment) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -1,96 +0,0 @@
|
||||
#ifndef RETROSHARE_RANKING_GUI_INTERFACE_H
|
||||
#define RETROSHARE_RANKING_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsrank.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2007-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 <inttypes.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
|
||||
/* The Main Interface Class - for information about your Peers */
|
||||
class RsRanks;
|
||||
extern RsRanks *rsRanks;
|
||||
|
||||
class RsRankComment
|
||||
{
|
||||
public:
|
||||
|
||||
std::string id;
|
||||
std::wstring comment;
|
||||
int32_t score;
|
||||
time_t timestamp;
|
||||
};
|
||||
|
||||
class RsRankDetails
|
||||
{
|
||||
public:
|
||||
|
||||
std::string rid;
|
||||
std::wstring link;
|
||||
std::wstring title;
|
||||
float rank;
|
||||
bool ownTag;
|
||||
|
||||
std::list<RsRankComment> comments;
|
||||
};
|
||||
|
||||
const uint32_t RS_RANK_SCORE = 0x0001;
|
||||
const uint32_t RS_RANK_TIME = 0x0002;
|
||||
const uint32_t RS_RANK_ALG = 0x0003;
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const RsRankDetails &detail);
|
||||
|
||||
class RsRanks
|
||||
{
|
||||
public:
|
||||
|
||||
RsRanks() { return; }
|
||||
virtual ~RsRanks() { return; }
|
||||
|
||||
/* needs update? */
|
||||
virtual bool updated() = 0;
|
||||
|
||||
/* Set Sort Methods */
|
||||
virtual bool setSortPeriod(uint32_t period) = 0;
|
||||
virtual bool setSortMethod(uint32_t type) = 0;
|
||||
virtual bool clearPeerFilter() = 0;
|
||||
virtual bool setPeerFilter(std::list<std::string> peers) = 0;
|
||||
|
||||
/* get Ids */
|
||||
virtual uint32_t getRankingsCount() = 0;
|
||||
virtual float getMaxRank() = 0;
|
||||
virtual bool getRankings(uint32_t first, uint32_t count, std::list<std::string> &rids) = 0;
|
||||
virtual bool getRankDetails(std::string rid, RsRankDetails &details) = 0;
|
||||
|
||||
/* Add New Comment / Msg */
|
||||
virtual std::string newRankMsg(std::wstring link, std::wstring title, std::wstring comment, int32_t score) = 0;
|
||||
virtual bool updateComment(std::string rid, std::wstring comment, int32_t score) = 0;
|
||||
|
||||
virtual std::string anonRankMsg(std::string rid, std::wstring link, std::wstring title) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
@ -1,61 +0,0 @@
|
||||
#ifndef RS_STATUS_INTERFACE_H
|
||||
#define RS_STATUS_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsstatus.h
|
||||
*
|
||||
* RetroShare C++ .
|
||||
*
|
||||
* Copyright 2007-2008 by Vinny Do.
|
||||
*
|
||||
* 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".
|
||||
*
|
||||
*/
|
||||
|
||||
class RsStatus;
|
||||
|
||||
extern RsStatus *rsStatus;
|
||||
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <inttypes.h>
|
||||
|
||||
const uint32_t RS_STATUS_OFFLINE = 0x0001;
|
||||
const uint32_t RS_STATUS_AWAY = 0x0002;
|
||||
const uint32_t RS_STATUS_BUSY = 0x0003;
|
||||
const uint32_t RS_STATUS_ONLINE = 0x0004;
|
||||
|
||||
std::string RsStatusString(uint32_t status);
|
||||
|
||||
class StatusInfo
|
||||
{
|
||||
public:
|
||||
std::string id;
|
||||
uint32_t status;
|
||||
};
|
||||
|
||||
class RsStatus
|
||||
{
|
||||
public:
|
||||
virtual bool getStatus(std::string id, StatusInfo& statusInfo) = 0;
|
||||
virtual bool setStatus(StatusInfo& statusInfo) = 0;
|
||||
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const StatusInfo& statusInfo);
|
||||
|
||||
#endif
|
@ -1,100 +0,0 @@
|
||||
#ifndef RETROSHARE_TURTLE_GUI_INTERFACE_H
|
||||
#define RETROSHARE_TURTLE_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* libretroshare/src/rsiface: rsturtle.h
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2009 by Cyril Soler.
|
||||
*
|
||||
* 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 "csoler@users.sourceforge.net"
|
||||
*
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <vector>
|
||||
|
||||
class LinearizedExpression ;
|
||||
|
||||
class RsTurtle;
|
||||
extern RsTurtle *rsTurtle ;
|
||||
|
||||
typedef uint32_t TurtleRequestId ;
|
||||
|
||||
// This is the structure used to send back results of the turtle search
|
||||
// to the notifyBase class.
|
||||
|
||||
struct TurtleFileInfo
|
||||
{
|
||||
std::string hash ;
|
||||
std::string name ;
|
||||
uint64_t size ;
|
||||
};
|
||||
|
||||
// Interface class for turtle hopping.
|
||||
//
|
||||
// This class mainly interacts with the turtle router, that is responsible
|
||||
// for routing turtle packets between peers, accepting/forwarding search
|
||||
// requests and dowloading files.
|
||||
//
|
||||
// As seen from here, the interface is really simple.
|
||||
//
|
||||
class RsTurtle
|
||||
{
|
||||
public:
|
||||
enum FileSharingStrategy { SHARE_ENTIRE_NETWORK, SHARE_FRIENDS_ONLY } ;
|
||||
|
||||
RsTurtle() { _sharing_strategy = SHARE_ENTIRE_NETWORK ;}
|
||||
virtual ~RsTurtle() {}
|
||||
|
||||
// Lauches a search request through the pipes, and immediately returns
|
||||
// the request id, which will be further used by the gui to store results
|
||||
// as they come back.
|
||||
//
|
||||
virtual TurtleRequestId turtleSearch(const std::string& match_string) = 0 ;
|
||||
virtual TurtleRequestId turtleSearch(const LinearizedExpression& expr) = 0 ;
|
||||
|
||||
// Initiates tunnel handling for the given file hash. tunnels. Launches
|
||||
// an exception if an error occurs during the initialization process. The
|
||||
// turtle router itself does not initiate downloads, it only maintains
|
||||
// tunnels for the given hash. The download should be driven by the file
|
||||
// transfer module by calling ftServer::FileRequest().
|
||||
//
|
||||
virtual void monitorFileTunnels(const std::string& name,const std::string& file_hash,uint64_t size) = 0 ;
|
||||
|
||||
// Tells the turtle router to stop handling tunnels for the given file hash. Traditionally this should
|
||||
// be called after calling ftServer::fileCancel().
|
||||
//
|
||||
virtual void stopMonitoringFileTunnels(const std::string& file_hash) = 0 ;
|
||||
|
||||
// Sets the file sharing strategy. It concerns all local files. It would
|
||||
// be better to handle this for each file, of course.
|
||||
|
||||
void setFileSharingStrategy(FileSharingStrategy f) { _sharing_strategy = f ; }
|
||||
|
||||
// Get info from the turtle router. I use std strings to hide the internal structs.
|
||||
virtual void getInfo(std::vector<std::vector<std::string> >&,std::vector<std::vector<std::string> >&,
|
||||
std::vector<std::vector<std::string> >&,std::vector<std::vector<std::string> >&) const = 0;
|
||||
|
||||
protected:
|
||||
FileSharingStrategy _sharing_strategy ;
|
||||
};
|
||||
|
||||
#endif
|
@ -1,286 +0,0 @@
|
||||
#ifndef RS_TYPES_GUI_INTERFACE_H
|
||||
#define RS_TYPES_GUI_INTERFACE_H
|
||||
|
||||
/*
|
||||
* "$Id: rstypes.h,v 1.7 2007-05-05 16:10:05 rmf24 Exp $"
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2004-2006 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 <list>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef std::string RsCertId;
|
||||
typedef std::string RsChanId;
|
||||
typedef std::string RsMsgId;
|
||||
typedef std::string RsAuthId;
|
||||
|
||||
#ifndef FT_STATE_FAILED
|
||||
const uint32_t FT_STATE_FAILED = 0x0000;
|
||||
const uint32_t FT_STATE_OKAY = 0x0001;
|
||||
const uint32_t FT_STATE_WAITING = 0x0002;
|
||||
const uint32_t FT_STATE_DOWNLOADING = 0x0003;
|
||||
const uint32_t FT_STATE_COMPLETE = 0x0004;
|
||||
#endif
|
||||
|
||||
class TransferInfo
|
||||
{
|
||||
public:
|
||||
/**** Need Some of these Fields ****/
|
||||
std::string peerId;
|
||||
std::string name; /* if has alternative name? */
|
||||
double tfRate; /* kbytes */
|
||||
int status; /* FT_STATE_... */
|
||||
};
|
||||
|
||||
|
||||
class FileInfo
|
||||
{
|
||||
/* old BaseInfo Entries */
|
||||
public:
|
||||
|
||||
FileInfo() :flags(0), mId(0) { return; }
|
||||
RsCertId id; /* key for matching everything */
|
||||
int flags; /* INFO_TAG above */
|
||||
|
||||
/* allow this to be tweaked by the GUI Model */
|
||||
mutable unsigned int mId; /* (GUI) Model Id -> unique number */
|
||||
|
||||
/* Old FileInfo Entries */
|
||||
public:
|
||||
|
||||
static const int kRsFiStatusNone = 0;
|
||||
static const int kRsFiStatusStall = 1;
|
||||
static const int kRsFiStatusProgress = 2;
|
||||
static const int kRsFiStatusDone = 2;
|
||||
|
||||
/* FileInfo(); */
|
||||
|
||||
int searchId; /* 0 if none */
|
||||
std::string path;
|
||||
std::string fname;
|
||||
std::string hash;
|
||||
std::string ext;
|
||||
|
||||
uint64_t size;
|
||||
uint64_t avail; /* how much we have */
|
||||
int status;
|
||||
|
||||
bool inRecommend;
|
||||
|
||||
double rank;
|
||||
int age;
|
||||
|
||||
/* Transfer Stuff */
|
||||
uint64_t transfered;
|
||||
double tfRate; /* in kbytes */
|
||||
uint32_t downloadStatus; /* 0 = Err, 1 = Ok, 2 = Done */
|
||||
std::list<TransferInfo> peers;
|
||||
|
||||
time_t lastTS;
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const FileInfo &info);
|
||||
|
||||
|
||||
/* matched to the uPnP states */
|
||||
#define UPNP_STATE_UNINITIALISED 0
|
||||
#define UPNP_STATE_UNAVAILABILE 1
|
||||
#define UPNP_STATE_READY 2
|
||||
#define UPNP_STATE_FAILED_TCP 3
|
||||
#define UPNP_STATE_FAILED_UDP 4
|
||||
#define UPNP_STATE_ACTIVE 5
|
||||
|
||||
class RsConfig
|
||||
{
|
||||
public:
|
||||
std::string ownId;
|
||||
std::string ownName;
|
||||
|
||||
std::string localAddr;
|
||||
int localPort;
|
||||
std::string extAddr;
|
||||
int extPort;
|
||||
std::string extName;
|
||||
|
||||
bool firewalled;
|
||||
bool forwardPort;
|
||||
|
||||
int maxDownloadDataRate; /* kb */
|
||||
int maxUploadDataRate; /* kb */
|
||||
int maxIndivDataRate; /* kb */
|
||||
|
||||
int promptAtBoot; /* popup the password prompt */
|
||||
|
||||
/* older data types */
|
||||
bool DHTActive;
|
||||
bool uPnPActive;
|
||||
|
||||
int uPnPState;
|
||||
int DHTPeers;
|
||||
|
||||
/* Flags for Network Status */
|
||||
bool netLocalOk; /* That we've talked to someone! */
|
||||
bool netUpnpOk; /* upnp is enabled and active */
|
||||
bool netDhtOk; /* response from dht */
|
||||
bool netStunOk; /* recvd stun / udp packets */
|
||||
bool netExtraAddressOk; /* recvd ip address with external finder*/
|
||||
};
|
||||
|
||||
/********************** For Search Interface *****************/
|
||||
|
||||
/* This is still rough, implement later! */
|
||||
|
||||
/* text based ones */
|
||||
const std::string TypeExt = "ext";
|
||||
const std::string TypeName = "name";
|
||||
const std::string TypeHash = "hash";
|
||||
const std::string TypeSize = "size";
|
||||
|
||||
const int OpContains = 0x001;
|
||||
const int OpExactMatch = 0x002;
|
||||
const int OpLessThan = 0x003;
|
||||
const int OpGreaterThan = 0x004;
|
||||
|
||||
class Condition
|
||||
{
|
||||
public:
|
||||
|
||||
std::string type;
|
||||
int op;
|
||||
double value;
|
||||
std::string name;
|
||||
};
|
||||
|
||||
class SearchRequest
|
||||
{
|
||||
public:
|
||||
int searchId;
|
||||
RsCertId toId; /* all zeros for everyone! */
|
||||
std::list<Condition> tests;
|
||||
};
|
||||
|
||||
|
||||
/********************** For FileCache Interface *****************/
|
||||
|
||||
#define DIR_TYPE_ROOT 0x01
|
||||
#define DIR_TYPE_PERSON 0x02
|
||||
#define DIR_TYPE_DIR 0x04
|
||||
#define DIR_TYPE_FILE 0x08
|
||||
|
||||
/* flags for Directry request -
|
||||
* two types;
|
||||
* (1) Local / Remote (top byte)
|
||||
* (2) Request type: Parent / Child - allows reduction in workload.
|
||||
* (TODO)
|
||||
*/
|
||||
|
||||
#define DIR_FLAGS_LOCAL 0x1000
|
||||
#define DIR_FLAGS_REMOTE 0x2000
|
||||
|
||||
#define DIR_FLAGS_PARENT 0x0001
|
||||
#define DIR_FLAGS_DETAILS 0x0002
|
||||
#define DIR_FLAGS_CHILDREN 0x0004
|
||||
#define DIR_FLAGS_NETWORK_WIDE 0x0008
|
||||
#define DIR_FLAGS_BROWSABLE 0x0010
|
||||
|
||||
class DirStub
|
||||
{
|
||||
public:
|
||||
uint8_t type;
|
||||
std::string name;
|
||||
void *ref;
|
||||
};
|
||||
|
||||
class DirDetails
|
||||
{
|
||||
public:
|
||||
void *parent;
|
||||
uint32_t prow; /* parent row */
|
||||
|
||||
void *ref;
|
||||
uint8_t type;
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string hash;
|
||||
std::string path;
|
||||
uint64_t count;
|
||||
uint32_t age;
|
||||
uint32_t flags;
|
||||
|
||||
std::list<DirStub> children;
|
||||
};
|
||||
|
||||
class FileDetail
|
||||
{
|
||||
public:
|
||||
std::string id;
|
||||
std::string name;
|
||||
std::string hash;
|
||||
std::string path;
|
||||
uint64_t size;
|
||||
uint32_t age;
|
||||
uint32_t rank;
|
||||
};
|
||||
|
||||
enum DwlPriority { Low = 0, Normal, High, Auto };
|
||||
|
||||
class FileChunksInfo
|
||||
{
|
||||
public:
|
||||
enum ChunkState { CHUNK_DONE, CHUNK_ACTIVE, CHUNK_OUTSTANDING } ;
|
||||
enum ChunkStrategy { CHUNK_STRATEGY_STREAMING, CHUNK_STRATEGY_RANDOM } ;
|
||||
|
||||
uint64_t file_size ; // real size of the file
|
||||
uint32_t chunk_size ; // size of chunks
|
||||
std::vector<ChunkState> chunks ; // dl state of chunks. Only the last chunk may have size < chunk_size
|
||||
};
|
||||
|
||||
/* class which encapsulates download details */
|
||||
class DwlDetails {
|
||||
public:
|
||||
DwlDetails() { return; }
|
||||
DwlDetails(std::string fname, std::string hash, int count, std::string dest,
|
||||
uint32_t flags, std::list<std::string> srcIds, DwlPriority priority)
|
||||
: fname(fname), hash(hash), count(count), dest(dest), flags(flags),
|
||||
srcIds(srcIds), priority(priority), retries(0) { return; }
|
||||
|
||||
/* download details */
|
||||
std::string fname;
|
||||
std::string hash;
|
||||
int count;
|
||||
std::string dest;
|
||||
uint32_t flags;
|
||||
std::list<std::string> srcIds;
|
||||
|
||||
/* internally used in download queue */
|
||||
DwlPriority priority;
|
||||
|
||||
/* how many times a failed dwl will be requeued */
|
||||
unsigned int retries;
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user