More Plumbing changes.

* Forgot that RELAY connections need extra parameters.
 * Added proxyAddr, srcAddr and Bandwidth parameters to connection attempts.
 * Completed UDP connection callouts from p3bitdht.
 * Added TCP connection attempt initiation from p3bitdht.
 * Added PASSIVE / ACTIVE determination in p3bitdht.
 * completed UDP connection logic in pqissludp.
 * enabled UDPSTUN_ALLOW_LOCALNET for testing.
 * added CONSTs for TOU Receiver Indices.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-netupgrade@4446 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-14 14:56:33 +00:00
parent 22debbce34
commit 86bdc5dfd0
14 changed files with 399 additions and 60 deletions

View File

@ -96,6 +96,7 @@ class DhtPeerDetails
#define PEERNET_ACTION_TYPE_START 3 #define PEERNET_ACTION_TYPE_START 3
#define PEERNET_ACTION_TYPE_RESTARTREQ 4 #define PEERNET_ACTION_TYPE_RESTARTREQ 4
#define PEERNET_ACTION_TYPE_KILLREQ 5 #define PEERNET_ACTION_TYPE_KILLREQ 5
#define PEERNET_ACTION_TYPE_TCPATTEMPT 6
class PeerAction class PeerAction
{ {
@ -215,6 +216,14 @@ int removeRelayConnection(const bdId *srcId, const bdId *destId);
void monitorConnections(); void monitorConnections();
void ConnectCallout(const std::string &peerId, struct sockaddr_in addr, uint32_t connectMode); void ConnectCallout(const std::string &peerId, struct sockaddr_in addr, uint32_t connectMode);
void ConnectCalloutTCPAttempt(const std::string &peerId, struct sockaddr_in addr);
void ConnectCalloutDirectOrProxy(const std::string &peerId, struct sockaddr_in raddr, uint32_t connectFlags, uint32_t delay);
void ConnectCalloutRelay(const std::string &peerId, struct sockaddr_in srcaddr,
struct sockaddr_in proxyaddr, struct sockaddr_in destaddr,
uint32_t connectMode, uint32_t bandwidth);
void Feedback_Connected(std::string pid); void Feedback_Connected(std::string pid);
void Feedback_ConnectionFailed(std::string pid); void Feedback_ConnectionFailed(std::string pid);
void UdpConnectionFailed_locked(DhtPeerDetails *dpd); void UdpConnectionFailed_locked(DhtPeerDetails *dpd);

View File

@ -18,6 +18,7 @@
#include "tcponudp/udprelay.h" #include "tcponudp/udprelay.h"
#include "pqi/p3netmgr.h" #include "pqi/p3netmgr.h"
#include "pqi/pqimonitor.h"
#define PEERNET_CONNECT_TIMEOUT 45 #define PEERNET_CONNECT_TIMEOUT 45
@ -308,6 +309,7 @@ int p3BitDht::OnlinePeerCallback_locked(const bdId *id, uint32_t status, DhtPeer
} }
bool connectOk = true; bool connectOk = true;
bool doTCPCallback = false;
/* work out network state */ /* work out network state */
uint32_t connectFlags = dpd->mConnectLogic.connectCb(CSB_CONNECT_DIRECT, uint32_t connectFlags = dpd->mConnectLogic.connectCb(CSB_CONNECT_DIRECT,
@ -322,6 +324,11 @@ int p3BitDht::OnlinePeerCallback_locked(const bdId *id, uint32_t status, DhtPeer
connectOk = false; connectOk = false;
} }
break; break;
case CSB_ACTION_TCP_CONN:
{
connectOk = false;
doTCPCallback = true;
}
case CSB_ACTION_DIRECT_CONN: case CSB_ACTION_DIRECT_CONN:
{ {
@ -361,6 +368,24 @@ int p3BitDht::OnlinePeerCallback_locked(const bdId *id, uint32_t status, DhtPeer
mActions.push_back(ca); mActions.push_back(ca);
} }
/* might need to make this an ACTION - leave for now */
if (doTCPCallback)
{
std::cerr << "dhtPeerCallback. Peer Online, triggering TCP Connection for: ";
bdStdPrintId(std::cerr, id);
std::cerr << std::endl;
/* Push Back PeerAction */
PeerAction ca;
ca.mType = PEERNET_ACTION_TYPE_TCPATTEMPT;
ca.mMode = BITDHT_CONNECT_MODE_DIRECT;
ca.mDestId = *id;
ca.mAnswer = BITDHT_CONNECT_ERROR_NONE;
//ConnectCalloutTCPAttempt(dpd->mRsId, id->addr);
}
return 1; return 1;
} }
@ -1206,6 +1231,46 @@ int p3BitDht::doActions()
} }
break; break;
case PEERNET_ACTION_TYPE_TCPATTEMPT:
{
/* connect attempt */
std::cerr << "PeerAction. TCP Connection Attempt to: ";
bdStdPrintId(std::cerr, &(action.mDestId));
std::cerr << " mode: " << action.mMode;
std::cerr << std::endl;
struct sockaddr_in laddr;
sockaddr_clear(&laddr);
uint32_t start = 0;
mUdpBitDht->ConnectionRequest(&laddr, &(action.mDestId.id), action.mMode, start);
std::string peerRsId;
bool foundPeerId = false;
{
RsStackMutex stack(dhtMtx); /********** LOCKED MUTEX ***************/
DhtPeerDetails *dpd = findInternalDhtPeer_locked(&(action.mDestId.id), RSDHT_PEERTYPE_ANY);
if (dpd)
{
peerRsId = dpd->mRsId;
foundPeerId = true;
std::cerr << "PeerAction. TCP Connection Attempt. DoingCallback for RsID: ";
std::cerr << peerRsId;
std::cerr << std::endl;
}
else
{
std::cerr << "PeerAction. TCP Connection Attempt. ERROR unknown peer";
std::cerr << std::endl;
}
}
if (foundPeerId)
{
ConnectCalloutTCPAttempt(peerRsId, action.mDestId.addr);
}
}
break;
} }
} }
return 1; return 1;
@ -1364,12 +1429,59 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
*/ */
void p3BitDht::ConnectCallout(const std::string &peerId, struct sockaddr_in addr, uint32_t connectMode) void p3BitDht::ConnectCalloutTCPAttempt(const std::string &peerId, struct sockaddr_in raddr)
{
struct sockaddr_in proxyaddr;
struct sockaddr_in srcaddr;
sockaddr_clear(&proxyaddr);
sockaddr_clear(&srcaddr);
uint32_t source = RS_CB_DHT;
uint32_t connectFlags = RS_CB_FLAG_ORDER_UNSPEC | RS_CB_FLAG_MODE_TCP;
uint32_t delay = 0;
uint32_t bandwidth = 0;
mConnCb->peerConnectRequest(peerId, raddr, proxyaddr, srcaddr, source, connectFlags, delay, bandwidth);
}
void p3BitDht::ConnectCalloutDirectOrProxy(const std::string &peerId, struct sockaddr_in raddr, uint32_t connectFlags, uint32_t delay)
{
struct sockaddr_in proxyaddr;
struct sockaddr_in srcaddr;
sockaddr_clear(&proxyaddr);
sockaddr_clear(&srcaddr);
uint32_t source = RS_CB_DHT;
uint32_t bandwidth = 0;
mConnCb->peerConnectRequest(peerId, raddr, proxyaddr, srcaddr, source, connectFlags, delay, bandwidth);
}
void p3BitDht::ConnectCalloutRelay(const std::string &peerId,
struct sockaddr_in srcaddr, struct sockaddr_in proxyaddr, struct sockaddr_in destaddr,
uint32_t connectFlags, uint32_t bandwidth)
{ {
sockaddr_clear(&proxyaddr);
sockaddr_clear(&srcaddr);
uint32_t source = RS_CB_DHT;
uint32_t delay = 0;
mConnCb->peerConnectRequest(peerId, destaddr, proxyaddr, srcaddr, source, connectFlags, delay, bandwidth);
} }
//virtual void peerConnectRequest(std::string id, struct sockaddr_in raddr,
// struct sockaddr_in proxyaddr, struct sockaddr_in srcaddr,
// uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth) = 0;
void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const bdId *destId, uint32_t mode, uint32_t loc, uint32_t answer) void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const bdId *destId, uint32_t mode, uint32_t loc, uint32_t answer)
{ {
std::cerr << "p3BitDht::initiateConnection()"; std::cerr << "p3BitDht::initiateConnection()";
@ -1378,16 +1490,38 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
bdId peerConnectId; bdId peerConnectId;
uint32_t connectFlags = 0;
uint32_t delay = 0;
uint32_t bandwidth = 0;
/* determine who the actual destination is. /* determine who the actual destination is.
* as we always specify the remote address, this is all we need. * as we always specify the remote address, this is all we need.
*/ */
if (loc == BD_PROXY_CONNECTION_START_POINT) if (loc == BD_PROXY_CONNECTION_START_POINT)
{ {
peerConnectId = *destId; peerConnectId = *destId;
/* lowest is active */
if (srcId < destId)
{
connectFlags |= RS_CB_FLAG_ORDER_ACTIVE;
}
else
{
connectFlags |= RS_CB_FLAG_ORDER_PASSIVE;
}
} }
else if (loc == BD_PROXY_CONNECTION_END_POINT) else if (loc == BD_PROXY_CONNECTION_END_POINT)
{ {
peerConnectId = *srcId; peerConnectId = *srcId;
/* lowest is active (we are now dest - in this case) */
if (destId < srcId)
{
connectFlags |= RS_CB_FLAG_ORDER_ACTIVE;
}
else
{
connectFlags |= RS_CB_FLAG_ORDER_PASSIVE;
}
} }
else else
{ {
@ -1432,6 +1566,8 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
default: default:
case BITDHT_CONNECT_MODE_DIRECT: case BITDHT_CONNECT_MODE_DIRECT:
touConnectMode = RSDHT_TOU_MODE_DIRECT; touConnectMode = RSDHT_TOU_MODE_DIRECT;
connectFlags |= RS_CB_FLAG_MODE_UDP_DIRECT;
delay = answer;
break; break;
case BITDHT_CONNECT_MODE_PROXY: case BITDHT_CONNECT_MODE_PROXY:
@ -1443,13 +1579,16 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
std::cerr << " UseProxyPort? " << useProxyPort; std::cerr << " UseProxyPort? " << useProxyPort;
std::cerr << std::endl; std::cerr << std::endl;
delay = answer;
if (useProxyPort) if (useProxyPort)
{ {
touConnectMode = RSDHT_TOU_MODE_PROXY; touConnectMode = RSDHT_TOU_MODE_PROXY;
connectFlags |= RS_CB_FLAG_MODE_UDP_PROXY;
} }
else else
{ {
touConnectMode = RSDHT_TOU_MODE_DIRECT; touConnectMode = RSDHT_TOU_MODE_DIRECT;
connectFlags |= RS_CB_FLAG_MODE_UDP_DIRECT;
} }
} }
@ -1457,6 +1596,8 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
case BITDHT_CONNECT_MODE_RELAY: case BITDHT_CONNECT_MODE_RELAY:
touConnectMode = RSDHT_TOU_MODE_RELAY; touConnectMode = RSDHT_TOU_MODE_RELAY;
connectFlags |= RS_CB_FLAG_MODE_UDP_DIRECT;
bandwidth = answer;
break; break;
} }
@ -1475,7 +1616,23 @@ void p3BitDht::initiateConnection(const bdId *srcId, const bdId *proxyId, const
/* finally we call out to start the connection (Outside of Mutex) */ /* finally we call out to start the connection (Outside of Mutex) */
ConnectCallout(rsId, peerConnectId.addr, touConnectMode); if ((mode == BITDHT_CONNECT_MODE_DIRECT) || (mode == BITDHT_CONNECT_MODE_PROXY))
{
ConnectCalloutDirectOrProxy(rsId, peerConnectId.addr, connectFlags, delay);
}
else if (mode == BITDHT_CONNECT_MODE_RELAY)
{
if (loc == BD_PROXY_CONNECTION_START_POINT)
{
ConnectCalloutRelay(rsId, srcId->addr, proxyId->addr, destId->addr, connectFlags, bandwidth);
}
else // END_POINT
{
/* reverse order connection call */
ConnectCalloutRelay(rsId, destId->addr, proxyId->addr, srcId->addr, connectFlags, bandwidth);
}
}
} }

View File

@ -942,9 +942,9 @@ int p3DhtMgr::checkNotifyDHT()
/* feedback to say we started it! */ /* feedback to say we started it! */
#ifdef P3DHTMGR_USE_LOCAL_UDP_CONN #ifdef P3DHTMGR_USE_LOCAL_UDP_CONN
mConnCb->peerConnectRequest(peer.id, peer.laddr, RS_CB_DHT, 0, 0); mConnCb->peerConnectRequest(peer.id, peer.laddr,peer.laddr,peer.laddr, RS_CB_DHT, 0, 0,0);
#else #else
mConnCb->peerConnectRequest(peer.id, peer.raddr, RS_CB_DHT, 0, 0); mConnCb->peerConnectRequest(peer.id, peer.raddr,peer.laddr,peer.laddr, RS_CB_DHT, 0, 0, 0);
#endif #endif
return DHT_MIN_PERIOD; return DHT_MIN_PERIOD;

View File

@ -586,8 +586,10 @@ const std::string p3LinkMgrIMPL::getOwnId()
} }
bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_in &addr, bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_in &raddr,
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags) struct sockaddr_in &proxyaddr,
struct sockaddr_in &srcaddr,
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth)
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -626,19 +628,23 @@ bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_in &ad
it->second.currentConnAddrAttempt = it->second.connAddrs.front(); it->second.currentConnAddrAttempt = it->second.connAddrs.front();
it->second.connAddrs.pop_front(); it->second.connAddrs.pop_front();
addr = it->second.currentConnAddrAttempt.addr; raddr = it->second.currentConnAddrAttempt.addr;
delay = it->second.currentConnAddrAttempt.delay; delay = it->second.currentConnAddrAttempt.delay;
period = it->second.currentConnAddrAttempt.period; period = it->second.currentConnAddrAttempt.period;
type = it->second.currentConnAddrAttempt.type; type = it->second.currentConnAddrAttempt.type;
flags = it->second.currentConnAddrAttempt.flags; flags = it->second.currentConnAddrAttempt.flags;
proxyaddr = it->second.currentConnAddrAttempt.proxyaddr;
srcaddr = it->second.currentConnAddrAttempt.srcaddr;
bandwidth = it->second.currentConnAddrAttempt.bandwidth;
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::connectAttempt() found an address: id: " << id << std::endl; std::cerr << "p3LinkMgrIMPL::connectAttempt() found an address: id: " << id << std::endl;
std::cerr << " laddr: " << rs_inet_ntoa(addr.sin_addr) << " lport: " << ntohs(addr.sin_port) << " delay: " << delay << " period: " << period; std::cerr << " laddr: " << rs_inet_ntoa(addr.sin_addr) << " lport: " << ntohs(addr.sin_port) << " delay: " << delay << " period: " << period;
std::cerr << " type: " << type << std::endl; std::cerr << " type: " << type << std::endl;
#endif #endif
if (addr.sin_addr.s_addr == 0 || addr.sin_port == 0) { if (raddr.sin_addr.s_addr == 0 || raddr.sin_port == 0) {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::connectAttempt() WARNING: address or port is null" << std::endl; std::cerr << "p3LinkMgrIMPL::connectAttempt() WARNING: address or port is null" << std::endl;
std::cerr << " type: " << type << std::endl; std::cerr << " type: " << type << std::endl;
@ -1158,24 +1164,33 @@ void p3LinkMgrIMPL::peerStatus(std::string id, const pqiIpAddrSet &addrs,
} }
void p3LinkMgrIMPL::peerConnectRequest(std::string id, struct sockaddr_in raddr, /* This has become very unwieldy - as extra arguments are required for UDP connections */
uint32_t source, uint32_t flags, uint32_t delay) void p3LinkMgrIMPL::peerConnectRequest(std::string id, struct sockaddr_in raddr, struct sockaddr_in proxyaddr, struct sockaddr_in srcaddr,
uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth)
{ {
#ifdef LINKMGR_DEBUG #ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() id: " << id; std::cerr << "p3LinkMgrIMPL::peerConnectRequest() id: " << id;
std::cerr << " raddr: " << rs_inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port); std::cerr << " raddr: " << rs_inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port);
std::cerr << " proxyaddr: " << rs_inet_ntoa(proxyaddr.sin_addr) << ":" << ntohs(proxyaddr.sin_port);
std::cerr << " srcaddr: " << rs_inet_ntoa(srcaddr.sin_addr) << ":" << ntohs(srcaddr.sin_port);
std::cerr << " source: " << source; std::cerr << " source: " << source;
std::cerr << " flags: " << flags; std::cerr << " flags: " << flags;
std::cerr << " delay: " << delay; std::cerr << " delay: " << delay;
std::cerr << " bandwidth: " << bandwidth;
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
{ {
/* Log */ /* Log */
std::ostringstream out; std::ostringstream out;
out << "p3LinkMgrIMPL::peerConnectRequest() id: " << id << " raddr: " << rs_inet_ntoa(raddr.sin_addr); out << "p3LinkMgrIMPL::peerConnectRequest() id: " << id;
out << ":" << ntohs(raddr.sin_port) << " source: " << source; out << " raddr: " << rs_inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port);
std::cerr << " proxyaddr: " << rs_inet_ntoa(proxyaddr.sin_addr) << ":" << ntohs(proxyaddr.sin_port);
std::cerr << " srcaddr: " << rs_inet_ntoa(srcaddr.sin_addr) << ":" << ntohs(srcaddr.sin_port);
out << " source: " << source;
out << " flags: " << flags; out << " flags: " << flags;
out << " delay: " << delay; out << " delay: " << delay;
out << " bandwidth: " << bandwidth;
rslog(RSL_WARNING, p3connectzone, out.str()); rslog(RSL_WARNING, p3connectzone, out.str());
} }
@ -1225,7 +1240,7 @@ void p3LinkMgrIMPL::peerConnectRequest(std::string id, struct sockaddr_in rad
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() DHT says CONNECT ==> tryConnectUDP()"; std::cerr << "p3LinkMgrIMPL::peerConnectRequest() DHT says CONNECT ==> tryConnectUDP()";
std::cerr << std::endl; std::cerr << std::endl;
#endif #endif
tryConnectUDP(id, raddr, flags, delay); tryConnectUDP(id, raddr, proxyaddr, srcaddr, flags, delay, bandwidth);
} }
return; return;
@ -1262,7 +1277,10 @@ bool p3LinkMgrIMPL::retryConnect(const std::string &id)
bool p3LinkMgrIMPL::tryConnectUDP(const std::string &id, struct sockaddr_in &rUdpAddr, uint32_t flags, uint32_t delay) bool p3LinkMgrIMPL::tryConnectUDP(const std::string &id, struct sockaddr_in &rUdpAddr,
struct sockaddr_in &proxyaddr, struct sockaddr_in &srcaddr,
uint32_t flags, uint32_t delay, uint32_t bandwidth)
{ {
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/ RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -1323,6 +1341,10 @@ bool p3LinkMgrIMPL::tryConnectUDP(const std::string &id, struct sockaddr_in &r
pca.period = P3CONNMGR_UDP_DEFAULT_PERIOD; pca.period = P3CONNMGR_UDP_DEFAULT_PERIOD;
pca.flags = flags; pca.flags = flags;
pca.proxyaddr = proxyaddr;
pca.srcaddr = srcaddr;
pca.bandwidth = bandwidth;
// Push address to the front... so it happens quickly (before any timings are lost). // Push address to the front... so it happens quickly (before any timings are lost).
addAddressIfUnique(it->second.connAddrs, pca, true); addAddressIfUnique(it->second.connAddrs, pca, true);
} }
@ -1563,6 +1585,9 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_SpecificAddress(peerConnectState *pee
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY; pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
pca.ts = time(NULL); pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD; pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
sockaddr_clear(&(pca.proxyaddr));
sockaddr_clear(&(pca.srcaddr));
pca.bandwidth = 0;
addAddressIfUnique(peer->connAddrs, pca, false); addAddressIfUnique(peer->connAddrs, pca, false);
} }
@ -1592,6 +1617,9 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_CurrentAddresses(peerConnectState *pe
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY; pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
pca.ts = time(NULL); pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD; pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
sockaddr_clear(&(pca.proxyaddr));
sockaddr_clear(&(pca.srcaddr));
pca.bandwidth = 0;
addAddressIfUnique(peer->connAddrs, pca, false); addAddressIfUnique(peer->connAddrs, pca, false);
} }
@ -1611,6 +1639,9 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_CurrentAddresses(peerConnectState *pe
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY; pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
pca.ts = time(NULL); pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD; pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
sockaddr_clear(&(pca.proxyaddr));
sockaddr_clear(&(pca.srcaddr));
pca.bandwidth = 0;
addAddressIfUnique(peer->connAddrs, pca, false); addAddressIfUnique(peer->connAddrs, pca, false);
} }
@ -1648,6 +1679,9 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_HistoricalAddresses(peerConnectState
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY; pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
pca.ts = time(NULL); pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD; pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
sockaddr_clear(&(pca.proxyaddr));
sockaddr_clear(&(pca.srcaddr));
pca.bandwidth = 0;
addAddressIfUnique(peer->connAddrs, pca, false); addAddressIfUnique(peer->connAddrs, pca, false);
} }
@ -1672,6 +1706,9 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_HistoricalAddresses(peerConnectState
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY; pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
pca.ts = time(NULL); pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD; pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
sockaddr_clear(&(pca.proxyaddr));
sockaddr_clear(&(pca.srcaddr));
pca.bandwidth = 0;
addAddressIfUnique(peer->connAddrs, pca, false); addAddressIfUnique(peer->connAddrs, pca, false);
} }
@ -1707,6 +1744,10 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std
pca.ts = time(NULL); pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD; pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
sockaddr_clear(&(pca.proxyaddr));
sockaddr_clear(&(pca.srcaddr));
pca.bandwidth = 0;
/* check address validity */ /* check address validity */
if (locked_CheckPotentialAddr(&(pca.addr), 0)) if (locked_CheckPotentialAddr(&(pca.addr), 0))
{ {
@ -1746,6 +1787,11 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_AddTunnel(peerConnectState *peer)
sockaddr_clear(&pca.addr); sockaddr_clear(&pca.addr);
sockaddr_clear(&(pca.proxyaddr));
sockaddr_clear(&(pca.srcaddr));
pca.bandwidth = 0;
addAddressIfUnique(peer->connAddrs, pca, false); addAddressIfUnique(peer->connAddrs, pca, false);
} }
} }

View File

@ -81,6 +81,11 @@ class peerConnectAddress
uint32_t type; uint32_t type;
uint32_t flags; /* CB FLAGS defined in pqimonitor.h */ uint32_t flags; /* CB FLAGS defined in pqimonitor.h */
time_t ts; time_t ts;
// Extra Parameters for Relay connections.
struct sockaddr_in proxyaddr;
struct sockaddr_in srcaddr;
uint32_t bandwidth;
}; };
class peerConnectState class peerConnectState
@ -169,8 +174,10 @@ virtual void addMonitor(pqiMonitor *mon) = 0;
virtual void removeMonitor(pqiMonitor *mon) = 0; virtual void removeMonitor(pqiMonitor *mon) = 0;
/****************** Connections *******************/ /****************** Connections *******************/
virtual bool connectAttempt(const std::string &id, struct sockaddr_in &addr, virtual bool connectAttempt(const std::string &id, struct sockaddr_in &raddr,
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags) = 0; struct sockaddr_in &proxyaddr, struct sockaddr_in &srcaddr,
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth) = 0;
virtual bool connectResult(const std::string &id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address) = 0; virtual bool connectResult(const std::string &id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address) = 0;
virtual bool retryConnect(const std::string &id) = 0; virtual bool retryConnect(const std::string &id) = 0;
@ -194,7 +201,8 @@ virtual bool getTunnelConnection() = 0; // ONLY used by p3peermgr.cc & p3
//virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs, //virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
// uint32_t type, uint32_t flags, uint32_t source) = 0; // uint32_t type, uint32_t flags, uint32_t source) = 0;
//virtual void peerConnectRequest(std::string id, struct sockaddr_in raddr, //virtual void peerConnectRequest(std::string id, struct sockaddr_in raddr,
// uint32_t source, uint32_t flags, uint32_t delay) = 0; // struct sockaddr_in proxyaddr, struct sockaddr_in srcaddr,
// uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth) = 0;
/****************************************************************************/ /****************************************************************************/
/****************************************************************************/ /****************************************************************************/
@ -222,8 +230,10 @@ virtual void addMonitor(pqiMonitor *mon);
virtual void removeMonitor(pqiMonitor *mon); virtual void removeMonitor(pqiMonitor *mon);
/****************** Connections *******************/ /****************** Connections *******************/
virtual bool connectAttempt(const std::string &id, struct sockaddr_in &addr, virtual bool connectAttempt(const std::string &id, struct sockaddr_in &raddr,
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags); struct sockaddr_in &proxyaddr, struct sockaddr_in &srcaddr,
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags, uint32_t &bandwidth);
virtual bool connectResult(const std::string &id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address); virtual bool connectResult(const std::string &id, bool success, uint32_t flags, struct sockaddr_in remote_peer_address);
virtual bool retryConnect(const std::string &id); virtual bool retryConnect(const std::string &id);
@ -235,7 +245,8 @@ virtual struct sockaddr_in getLocalAddress();
virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs, virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
uint32_t type, uint32_t flags, uint32_t source); uint32_t type, uint32_t flags, uint32_t source);
virtual void peerConnectRequest(std::string id, struct sockaddr_in raddr, virtual void peerConnectRequest(std::string id, struct sockaddr_in raddr,
uint32_t source, uint32_t flags, uint32_t delay); struct sockaddr_in proxyaddr, struct sockaddr_in srcaddr,
uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth);
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/ /************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
@ -281,7 +292,9 @@ void statusTick();
void tickMonitors(); void tickMonitors();
/* connect attempts UDP */ /* connect attempts UDP */
bool tryConnectUDP(const std::string &id, struct sockaddr_in &rUdpAddr, uint32_t flags, uint32_t delay); bool tryConnectUDP(const std::string &id, struct sockaddr_in &rUdpAddr,
struct sockaddr_in &proxyaddr, struct sockaddr_in &srcaddr,
uint32_t flags, uint32_t delay, uint32_t bandwidth);
/* connect attempts TCP */ /* connect attempts TCP */
bool retryConnectTCP(const std::string &id); bool retryConnectTCP(const std::string &id);

View File

@ -230,6 +230,10 @@ 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_PERIOD = 2;
static const uint32_t NET_PARAM_CONNECT_TIMEOUT = 3; static const uint32_t NET_PARAM_CONNECT_TIMEOUT = 3;
static const uint32_t NET_PARAM_CONNECT_FLAGS = 4; static const uint32_t NET_PARAM_CONNECT_FLAGS = 4;
static const uint32_t NET_PARAM_CONNECT_BANDWIDTH = 5;
static const uint32_t NET_PARAM_CONNECT_PROXY = 6;
static const uint32_t NET_PARAM_CONNECT_SOURCE = 7;
/*! /*!
@ -266,6 +270,7 @@ virtual std::string PeerId() { return peerId; }
virtual int getConnectAddress(struct sockaddr_in &raddr) = 0; virtual int getConnectAddress(struct sockaddr_in &raddr) = 0;
virtual bool connect_parameter(uint32_t type, uint32_t value) = 0; virtual bool connect_parameter(uint32_t type, uint32_t value) = 0;
virtual bool connect_additional_address(uint32_t type, struct sockaddr_in *addr) { return false; } // only needed by udp.
protected: protected:
PQInterface *parent() { return p; } PQInterface *parent() { return p; }

View File

@ -76,14 +76,22 @@ const uint32_t RS_STUN_FRIEND_OF_FRIEND = 0x0040;
#define RS_CB_FLAG_MASK_MODE 0x00ff #define RS_CB_FLAG_MASK_MODE 0x00ff
#define RS_CB_FLAG_MASK_CONN 0x00ff #define RS_CB_FLAG_MASK_ORDER 0xff00
#define RS_CB_FLAG_MODE_TCP 0x0001 #define RS_CB_FLAG_MODE_TCP 0x0001
#define RS_CB_FLAG_MODE_UDP 0x0002 #define RS_CB_FLAG_MODE_UDP_DIRECT 0x0002
#define RS_CB_FLAG_MODE_UDP_PROXY 0x0004
#define RS_CB_FLAG_MODE_UDP_RELAY 0x0008
#define RS_CB_FLAG_CONN_UNSPEC 0x0000 #define RS_CB_FLAG_ORDER_UNSPEC 0x0100
#define RS_CB_FLAG_CONN_PASSIVE 0x0100 #define RS_CB_FLAG_ORDER_PASSIVE 0x0200
#define RS_CB_FLAG_CONN_ACTIVE 0x0200 #define RS_CB_FLAG_ORDER_ACTIVE 0x0400
#define RSUDP_NUM_TOU_RECVERS 3
#define RSUDP_TOU_RECVER_DIRECT_IDX 0
#define RSUDP_TOU_RECVER_PROXY_IDX 1
#define RSUDP_TOU_RECVER_RELAY_IDX 2
class pqipeer class pqipeer
@ -149,7 +157,8 @@ virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
uint32_t type, uint32_t flags, uint32_t source) = 0; uint32_t type, uint32_t flags, uint32_t source) = 0;
virtual void peerConnectRequest(std::string id, struct sockaddr_in raddr, virtual void peerConnectRequest(std::string id, struct sockaddr_in raddr,
uint32_t source, uint32_t flags, uint32_t delay) = 0; struct sockaddr_in proxyaddr, struct sockaddr_in srcaddr,
uint32_t source, uint32_t flags, uint32_t delay, uint32_t bandwidth) = 0;
//virtual void stunStatus(std::string id, struct sockaddr_in raddr, uint32_t type, uint32_t flags) = 0; //virtual void stunStatus(std::string id, struct sockaddr_in raddr, uint32_t type, uint32_t flags) = 0;
}; };

View File

@ -378,19 +378,23 @@ int pqiperson::stoplistening()
return 1; return 1;
} }
int pqiperson::connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay, uint32_t period, uint32_t timeout, uint32_t flags) int pqiperson::connect(uint32_t type, struct sockaddr_in raddr,
struct sockaddr_in &proxyaddr, struct sockaddr_in &srcaddr,
uint32_t delay, uint32_t period, uint32_t timeout, uint32_t flags, uint32_t bandwidth)
{ {
#ifdef PERSON_DEBUG #ifdef PERSON_DEBUG
{ {
std::ostringstream out; std::ostringstream out;
out << "pqiperson::connect() Id: " << PeerId(); out << "pqiperson::connect() Id: " << PeerId();
out << " type: " << type; out << " type: " << type;
out << " addr: " << rs_inet_ntoa(raddr.sin_addr); out << " addr: " << rs_inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port);
out << ":" << ntohs(raddr.sin_port); out << " proxyaddr: " << rs_inet_ntoa(proxyaddr.sin_addr) << ":" << ntohs(proxyaddr.sin_port);
out << " srcaddr: " << rs_inet_ntoa(srcaddr.sin_addr) << ":" << ntohs(srcaddr.sin_port);
out << " delay: " << delay; out << " delay: " << delay;
out << " period: " << period; out << " period: " << period;
out << " timeout: " << timeout; out << " timeout: " << timeout;
out << " flags: " << flags; out << " flags: " << flags;
out << " bandwidth: " << bandwidth;
out << std::endl; out << std::endl;
std::cerr << out.str(); std::cerr << out.str();
//pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str()); //pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
@ -430,6 +434,10 @@ int pqiperson::connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay,
(it->second)->connect_parameter(NET_PARAM_CONNECT_PERIOD, period); (it->second)->connect_parameter(NET_PARAM_CONNECT_PERIOD, period);
(it->second)->connect_parameter(NET_PARAM_CONNECT_TIMEOUT, timeout); (it->second)->connect_parameter(NET_PARAM_CONNECT_TIMEOUT, timeout);
(it->second)->connect_parameter(NET_PARAM_CONNECT_FLAGS, flags); (it->second)->connect_parameter(NET_PARAM_CONNECT_FLAGS, flags);
(it->second)->connect_parameter(NET_PARAM_CONNECT_BANDWIDTH, bandwidth);
(it->second)->connect_additional_address(NET_PARAM_CONNECT_PROXY, &proxyaddr);
(it->second)->connect_additional_address(NET_PARAM_CONNECT_SOURCE, &srcaddr);
(it->second)->connect(raddr); (it->second)->connect(raddr);

View File

@ -71,6 +71,10 @@ virtual int stoplistening() { return ni -> stoplistening(); }
virtual int reset() { return ni -> reset(); } virtual int reset() { return ni -> reset(); }
virtual int disconnect() { return ni -> reset(); } virtual int disconnect() { return ni -> reset(); }
virtual bool connect_parameter(uint32_t type, uint32_t value) { return ni -> connect_parameter(type, value);} virtual bool connect_parameter(uint32_t type, uint32_t value) { return ni -> connect_parameter(type, value);}
virtual bool connect_additional_address(uint32_t type, struct sockaddr_in *addr) { return ni -> connect_additional_address(type, addr);}
virtual int getConnectAddress(struct sockaddr_in &raddr){ return ni->getConnectAddress(raddr); } virtual int getConnectAddress(struct sockaddr_in &raddr){ return ni->getConnectAddress(raddr); }
// get the contact from the net side! // get the contact from the net side!
@ -106,7 +110,11 @@ virtual ~pqiperson(); // must clean up children.
int reset(); int reset();
int listen(); int listen();
int stoplistening(); int stoplistening();
int connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay, uint32_t period, uint32_t timeout, uint32_t flags);
int connect(uint32_t type, struct sockaddr_in raddr,
struct sockaddr_in &proxyaddr, struct sockaddr_in &srcaddr,
uint32_t delay, uint32_t period, uint32_t timeout, uint32_t flags, uint32_t bandwidth);
int receiveHeartbeat(); int receiveHeartbeat();
// add in connection method. // add in connection method.
int addChildInterface(uint32_t type, pqiconnect *pqi); int addChildInterface(uint32_t type, pqiconnect *pqi);

View File

@ -550,7 +550,11 @@ int pqipersongrp::connectPeer(std::string id
uint32_t type; uint32_t type;
uint32_t flags; uint32_t flags;
if (!mLinkMgr->connectAttempt(id, addr, delay, period, type, flags)) struct sockaddr_in proxyaddr;
struct sockaddr_in srcaddr;
uint32_t bandwidth;
if (!mLinkMgr->connectAttempt(id, addr, proxyaddr, srcaddr, delay, period, type, flags, bandwidth))
{ {
#ifdef PGRP_DEBUG #ifdef PGRP_DEBUG
std::cerr << " pqipersongrp::connectPeer() No Net Address"; std::cerr << " pqipersongrp::connectPeer() No Net Address";
@ -607,7 +611,7 @@ int pqipersongrp::connectPeer(std::string id
return 0; return 0;
} }
p->connect(ptype, addr, delay, period, timeout, flags); p->connect(ptype, addr, proxyaddr, srcaddr, delay, period, timeout, flags, bandwidth);
} /* UNLOCKED */ } /* UNLOCKED */

View File

@ -105,7 +105,26 @@ int pqissludp::attach()
{ {
// IN THE IMPROVED TOU LIBRARY, we need to be careful with the tou_socket PARAMETERS. // IN THE IMPROVED TOU LIBRARY, we need to be careful with the tou_socket PARAMETERS.
// For now, this should do! // For now, this should do!
sockfd = tou_socket(0,TOU_RECEIVER_TYPE_UDPPEER,0); sockfd = -1;
if (mConnectFlags & RS_CB_FLAG_MODE_UDP_DIRECT)
{
sockfd = tou_socket(RSUDP_TOU_RECVER_DIRECT_IDX,TOU_RECEIVER_TYPE_UDPPEER,0);
}
else if (mConnectFlags & RS_CB_FLAG_MODE_UDP_PROXY)
{
sockfd = tou_socket(RSUDP_TOU_RECVER_PROXY_IDX,TOU_RECEIVER_TYPE_UDPPEER,0);
}
else if (mConnectFlags & RS_CB_FLAG_MODE_UDP_RELAY)
{
sockfd = tou_socket(RSUDP_TOU_RECVER_RELAY_IDX,TOU_RECEIVER_TYPE_UDPRELAY,0);
}
else
{
std::cerr << "pqissludp::attach() ERROR unknown Connect Mode" << std::endl;
sockfd = -1;
}
if (0 > sockfd) if (0 > sockfd)
{ {
rslog(RSL_WARNING, pqissludpzone, rslog(RSL_WARNING, pqissludpzone,
@ -133,11 +152,11 @@ int pqissludp::Initiate_Connection()
"pqissludp::Initiate_Connection() Attempting Outgoing Connection...."); "pqissludp::Initiate_Connection() Attempting Outgoing Connection....");
/* decide if we're active or passive */ /* decide if we're active or passive */
if (mConnectFlags & RS_CB_FLAG_CONN_ACTIVE) if (mConnectFlags & RS_CB_FLAG_ORDER_ACTIVE)
{ {
sslmode = PQISSL_ACTIVE; sslmode = PQISSL_ACTIVE;
} }
else if (mConnectFlags & RS_CB_FLAG_CONN_PASSIVE) else if (mConnectFlags & RS_CB_FLAG_ORDER_PASSIVE)
{ {
sslmode = PQISSL_PASSIVE; sslmode = PQISSL_PASSIVE;
} }
@ -207,8 +226,21 @@ int pqissludp::Initiate_Connection()
//std::cerr << " Connect Period is:" << mConnectPeriod << std::endl; //std::cerr << " Connect Period is:" << mConnectPeriod << std::endl;
/* <===================== UDP Difference *******************/ /* <===================== UDP Difference *******************/
if (0 != (err = tou_connect(sockfd, (struct sockaddr *) &remote_addr,
sizeof(remote_addr), mConnectPeriod))) if (mConnectFlags & RS_CB_FLAG_MODE_UDP_DIRECT)
{
err = tou_connect(sockfd, (struct sockaddr *) &remote_addr, sizeof(remote_addr), mConnectPeriod);
}
else if (mConnectFlags & RS_CB_FLAG_MODE_UDP_PROXY)
{
err = tou_connect(sockfd, (struct sockaddr *) &remote_addr, sizeof(remote_addr), mConnectPeriod);
}
else if (mConnectFlags & RS_CB_FLAG_MODE_UDP_RELAY)
{
tou_connect_via_relay(sockfd, &(mConnectSrcAddr), &(mConnectProxyAddr), &(remote_addr));
}
if (0 != err)
/* <===================== UDP Difference *******************/ /* <===================== UDP Difference *******************/
{ {
int tou_err = tou_errno(sockfd); int tou_err = tou_errno(sockfd);
@ -441,9 +473,49 @@ bool pqissludp::connect_parameter(uint32_t type, uint32_t value)
mConnectFlags = value; mConnectFlags = value;
return true; return true;
} }
else if (type == NET_PARAM_CONNECT_BANDWIDTH)
{
std::ostringstream out;
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " BANDWIDTH: " << value;
rslog(RSL_WARNING, pqissludpzone, out.str());
mConnectFlags = value;
return true;
}
return pqissl::connect_parameter(type, value); return pqissl::connect_parameter(type, value);
} }
bool pqissludp::connect_additional_address(uint32_t type, struct sockaddr_in *addr)
{
struct sockaddr_in mConnectProxyAddr;
struct sockaddr_in mConnectSrcAddr;
if (type == NET_PARAM_CONNECT_PROXY)
{
std::ostringstream out;
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " PROXYADDR: ";
out << rs_inet_ntoa(addr->sin_addr) << ":" << ntohs(addr->sin_port);
rslog(RSL_WARNING, pqissludpzone, out.str());
mConnectProxyAddr = *addr;
std::cerr << out.str() << std::endl;
return true;
}
else if (type == NET_PARAM_CONNECT_SOURCE)
{
std::ostringstream out;
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " SRCADDR: ";
out << rs_inet_ntoa(addr->sin_addr) << ":" << ntohs(addr->sin_port);
rslog(RSL_WARNING, pqissludpzone, out.str());
mConnectSrcAddr = *addr;
std::cerr << out.str() << std::endl;
return true;
}
return pqissl::connect_additional_address(type, addr);
}
/********** PQI STREAMER OVERLOADING *********************************/ /********** PQI STREAMER OVERLOADING *********************************/
bool pqissludp::moretoread() bool pqissludp::moretoread()

View File

@ -67,6 +67,7 @@ virtual int tick();
virtual int reset(); virtual int reset();
virtual bool connect_parameter(uint32_t type, uint32_t value); virtual bool connect_parameter(uint32_t type, uint32_t value);
virtual bool connect_additional_address(uint32_t type, struct sockaddr_in *addr);
// BinInterface. // BinInterface.
// These are reimplemented. // These are reimplemented.
@ -100,6 +101,10 @@ private:
uint32_t mConnectPeriod; uint32_t mConnectPeriod;
uint32_t mConnectFlags; uint32_t mConnectFlags;
uint32_t mConnectBandwidth;
struct sockaddr_in mConnectProxyAddr;
struct sockaddr_in mConnectSrcAddr;
}; };
#endif // MRK_PQI_SSL_UDP_HEADER #endif // MRK_PQI_SSL_UDP_HEADER

View File

@ -1905,8 +1905,8 @@ int RsServer::StartupRetroShare()
/* construct the rest of the stack, important to build them in the correct order! */ /* construct the rest of the stack, important to build them in the correct order! */
/* MOST OF THIS IS COMMENTED OUT UNTIL THE REST OF libretroshare IS READY FOR IT! */ /* MOST OF THIS IS COMMENTED OUT UNTIL THE REST OF libretroshare IS READY FOR IT! */
UdpSubReceiver *udpReceivers[3]; UdpSubReceiver *udpReceivers[RSUDP_NUM_TOU_RECVERS];
int udpTypes[3]; int udpTypes[RSUDP_NUM_TOU_RECVERS];
// FIRST DHT STUNNER. // FIRST DHT STUNNER.
UdpStunner *mDhtStunner = new UdpStunner(mDhtStack); UdpStunner *mDhtStunner = new UdpStunner(mDhtStack);
@ -1920,14 +1920,14 @@ int RsServer::StartupRetroShare()
// NEXT THE RELAY (NEED to keep a reference for installing RELAYS) // NEXT THE RELAY (NEED to keep a reference for installing RELAYS)
UdpRelayReceiver *mRelay = new UdpRelayReceiver(mDhtStack); UdpRelayReceiver *mRelay = new UdpRelayReceiver(mDhtStack);
udpReceivers[2] = mRelay; /* RELAY Connections (DHT Port) */ udpReceivers[RSUDP_TOU_RECVER_RELAY_IDX] = mRelay; /* RELAY Connections (DHT Port) */
udpTypes[2] = TOU_RECEIVER_TYPE_UDPRELAY; udpTypes[RSUDP_TOU_RECVER_RELAY_IDX] = TOU_RECEIVER_TYPE_UDPRELAY;
mDhtStack->addReceiver(udpReceivers[2]); mDhtStack->addReceiver(udpReceivers[RSUDP_TOU_RECVER_RELAY_IDX]);
// LAST ON THIS STACK IS STANDARD DIRECT TOU // LAST ON THIS STACK IS STANDARD DIRECT TOU
udpReceivers[0] = new UdpPeerReceiver(mDhtStack); /* standard DIRECT Connections (DHT Port) */ udpReceivers[RSUDP_TOU_RECVER_DIRECT_IDX] = new UdpPeerReceiver(mDhtStack); /* standard DIRECT Connections (DHT Port) */
udpTypes[0] = TOU_RECEIVER_TYPE_UDPPEER; udpTypes[RSUDP_TOU_RECVER_DIRECT_IDX] = TOU_RECEIVER_TYPE_UDPPEER;
mDhtStack->addReceiver(udpReceivers[0]); mDhtStack->addReceiver(udpReceivers[RSUDP_TOU_RECVER_DIRECT_IDX]);
// NOW WE BUILD THE SECOND STACK. // NOW WE BUILD THE SECOND STACK.
// Create the Second UdpStack... Port should be random (but openable!). // Create the Second UdpStack... Port should be random (but openable!).
@ -1947,12 +1947,12 @@ int RsServer::StartupRetroShare()
mProxyStack->addReceiver(mProxyStunner); mProxyStack->addReceiver(mProxyStunner);
// FINALLY THE PROXY UDP CONNECTIONS // FINALLY THE PROXY UDP CONNECTIONS
udpReceivers[1] = new UdpPeerReceiver(mProxyStack); /* PROXY Connections (Alt UDP Port) */ udpReceivers[RSUDP_TOU_RECVER_PROXY_IDX] = new UdpPeerReceiver(mProxyStack); /* PROXY Connections (Alt UDP Port) */
udpTypes[1] = TOU_RECEIVER_TYPE_UDPPEER; udpTypes[RSUDP_TOU_RECVER_PROXY_IDX] = TOU_RECEIVER_TYPE_UDPPEER;
mProxyStack->addReceiver(udpReceivers[1]); mProxyStack->addReceiver(udpReceivers[RSUDP_TOU_RECVER_PROXY_IDX]);
// REAL INITIALISATION - WITH THREE MODES // REAL INITIALISATION - WITH THREE MODES
tou_init((void **) udpReceivers, udpTypes, 3); tou_init((void **) udpReceivers, udpTypes, RSUDP_NUM_TOU_RECVERS);
mBitDht->setupConnectBits(mDhtStunner, mProxyStunner, mRelay); mBitDht->setupConnectBits(mDhtStunner, mProxyStunner, mRelay);

View File

@ -68,9 +68,12 @@ class TouStunPeer
}; };
/* /*
* FOR TESTING ONLY.
* #define UDPSTUN_ALLOW_LOCALNET 1 * #define UDPSTUN_ALLOW_LOCALNET 1
*/ */
#define UDPSTUN_ALLOW_LOCALNET 1
class UdpStunner: public UdpSubReceiver class UdpStunner: public UdpSubReceiver
{ {
public: public: