Done most of the piping/callback between the DHT and LinkMgr/NetMgr.

* Added ConnectionFeedback fn to NetAssistConnect & p3BitDht.
 * Added TYPE definitions to pqiassist.h
 * added extra parameters to p3LinkMgr::connectAttempt() (flags which will be used to pass DIRECT/PROXY/DIRECT + PASSIVE/ACTIVE)
 * Added callback from p3LinkMgr to NetMgr::netAssistStatusUpdate() => Dht::ConnectionFeedback.
 * updated peerConnectRequest to trigger either TCP attempt (first) or UDP connection.
 * updated parameters for p3LinkMgrIMPL::tryConnectUDP()
 * added p3LinkMgrIMPL::locked_ConnectAttempt_SpecificAddress() for DHT => TCP attempt.
 * added extra parameter to addAddressIfUnique... bool addFront =>  DHT attempts get pushed to front of Queue due to timing requirements.
 * added extra parameter (flags) to pqiperson::connect() - matches extra parameters to p3LinkMgr::connectAttempt().
 * added p3NetMgr::netAssistStatusUpdate()
 * added mConnectFlags to pqissludp



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-netupgrade@4443 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-07-13 22:23:40 +00:00
parent 8d5bde1b50
commit 387db6e7b6
15 changed files with 275 additions and 49 deletions

View File

@ -169,6 +169,9 @@ virtual bool getNetworkStats(uint32_t &netsize, uint32_t &localnetsize);
virtual bool findPeer(std::string id);
virtual bool dropPeer(std::string id);
/* feedback on success failure of Connections */
virtual void ConnectionFeedback(std::string pid, int state);
/* extract current peer status */
virtual bool getPeerStatus(std::string id,
struct sockaddr_in &laddr, struct sockaddr_in &raddr,
@ -181,12 +184,16 @@ virtual bool getExternalInterface(struct sockaddr_in &raddr,
* hould all be removed from NetAssist?
*/
/* pqiNetAssistConnect - external interface functions */
/***********************************************************************************************
****************************** Connections (p3bitdht_peernet.cc) ******************************
************************************************************************************************/
/* Feedback from RS Upper Layers */
//virtual void ConnectionFeedback(std::string pid, int state);
/* Callback functions - from bitdht */
int NodeCallback(const bdId *id, uint32_t peerflags);
@ -213,6 +220,7 @@ void Feedback_ConnectionFailed(std::string pid);
void UdpConnectionFailed_locked(DhtPeerDetails *dpd);
void Feedback_ConnectionClosed(std::string pid);
/***********************************************************************************************
************************** Internal Accounting (p3bitdht_peers.cc) ****************************
************************************************************************************************/

View File

@ -1357,6 +1357,10 @@ int p3BitDht::checkConnectionAllowed(const bdId *peerId, int mode)
/* So initiateConnection has to call out to other bits of RS.
* critical information is:
* Peer RsId, Peer Address, Connect Mode (includes Proxy/OrNot).
*
* What do we need: ACTIVE / PASSIVE / UNSPEC
* + Min Delay Time,
*/
@ -1760,4 +1764,34 @@ void p3BitDht::Feedback_ConnectionClosed(std::string pid)
void p3BitDht::ConnectionFeedback(std::string pid, int mode)
{
std::cerr << "p3BitDht::ConnectionFeedback() peer: " << pid;
std::cerr << " mode: " << mode;
std::cerr << std::endl;
switch(mode)
{
case NETMGR_DHT_FEEDBACK_CONNECTED:
std::cerr << "p3BitDht::ConnectionFeedback() HAVE CONNECTED (tcp?/udp) to peer: " << pid;
std::cerr << std::endl;
Feedback_Connected(pid);
break;
case NETMGR_DHT_FEEDBACK_CONN_FAILED:
std::cerr << "p3BitDht::ConnectionFeedback() UDP CONNECTION FAILED to peer: " << pid;
std::cerr << std::endl;
Feedback_ConnectionFailed(pid);
break;
case NETMGR_DHT_FEEDBACK_CONN_CLOSED:
std::cerr << "p3BitDht::ConnectionFeedback() CONNECTION (tcp?/udp) CLOSED to peer: " << pid;
std::cerr << std::endl;
Feedback_ConnectionClosed(pid);
break;
}
}

View File

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

View File

@ -587,7 +587,7 @@ const std::string p3LinkMgrIMPL::getOwnId()
bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_in &addr,
uint32_t &delay, uint32_t &period, uint32_t &type)
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags)
{
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -630,6 +630,7 @@ bool p3LinkMgrIMPL::connectAttempt(const std::string &id, struct sockaddr_in &ad
delay = it->second.currentConnAddrAttempt.delay;
period = it->second.currentConnAddrAttempt.period;
type = it->second.currentConnAddrAttempt.type;
flags = it->second.currentConnAddrAttempt.flags;
#ifdef LINKMGR_DEBUG
@ -812,6 +813,41 @@ bool p3LinkMgrIMPL::connectResult(const std::string &id, bool success, uint32_t
}
/* inform NetAssist of result. This is slightly duplicating below, as we switch it on/off
* in a second anyway. However, the FAILURE of UDP connection, must be informed.
*
* actually the way the DHT works at the moment, both forms of feedback are required.
* this handles connection requests, the other searches. As they are independent... do both.
*/
if (flags == RS_NET_CONN_UDP_ALL)
{
#ifdef LINKMGR_DEBUG
#endif
std::cerr << "p3LinkMgrIMPL::connectResult() Sending Feedback for UDP connection";
std::cerr << std::endl;
if (success)
{
#ifdef LINKMGR_DEBUG
#endif
std::cerr << "p3LinkMgrIMPL::connectResult() UDP Update CONNECTED to: " << id;
std::cerr << std::endl;
mNetMgr->netAssistStatusUpdate(id, NETMGR_DHT_FEEDBACK_CONNECTED);
}
else
{
#ifdef LINKMGR_DEBUG
#endif
std::cerr << "p3LinkMgrIMPL::connectResult() UDP Update FAILED to: " << id;
std::cerr << std::endl;
/* have no differentiation between failure and closed? */
mNetMgr->netAssistStatusUpdate(id, NETMGR_DHT_FEEDBACK_CONN_FAILED);
}
}
if (success)
{
#ifdef LINKMGR_DEBUG
@ -1122,42 +1158,84 @@ void p3LinkMgrIMPL::peerStatus(std::string id, const pqiIpAddrSet &addrs,
}
void p3LinkMgrIMPL::peerConnectRequest(std::string id, struct sockaddr_in raddr,
uint32_t source)
void p3LinkMgrIMPL::peerConnectRequest(std::string id, struct sockaddr_in raddr,
uint32_t source, uint32_t flags, uint32_t delay)
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() id: " << id << " raddr: " << rs_inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port);
std::cerr << " source: " << source << std::endl;
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() id: " << id;
std::cerr << " raddr: " << rs_inet_ntoa(raddr.sin_addr) << ":" << ntohs(raddr.sin_port);
std::cerr << " source: " << source;
std::cerr << " flags: " << flags;
std::cerr << " delay: " << delay;
std::cerr << std::endl;
#endif
{
/* Log */
std::ostringstream out;
out << "p3LinkMgrIMPL::peerConnectRequest() id: " << id << " raddr: " << rs_inet_ntoa(raddr.sin_addr);
out << ":" << ntohs(raddr.sin_port) << " source: " << source;
out << " flags: " << flags;
out << " delay: " << delay;
rslog(RSL_WARNING, p3connectzone, out.str());
}
/******************** TCP PART *****************************/
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() Try TCP first" << std::endl;
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() (From DHT Only)" << std::endl;
#endif
if (source == RS_CB_DHT)
{
if (flags & RS_CB_FLAG_MODE_TCP)
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() source DHT ==> retryConnectUDP()";
std::cerr << std::endl;
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() DHT says Online ==> so try TCP";
std::cerr << std::endl;
#endif
retryConnectUDP(id, raddr);
{
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
std::map<std::string, peerConnectState>::iterator it;
if (mFriendList.end() == (it = mFriendList.find(id)))
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() ERROR Peer is not Friend" << std::endl;
#endif
return;
}
/* if already connected -> done */
if (it->second.state & RS_PEER_S_CONNECTED)
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() ERROR Peer Already Connected" << std::endl;
#endif
}
/* setup specific attempt for DHT found address. */
locked_ConnectAttempt_SpecificAddress(&(it->second), &raddr);
}
retryConnect(id);
}
else
{
/* UDP Attempt! */
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() DHT says CONNECT ==> tryConnectUDP()";
std::cerr << std::endl;
#endif
tryConnectUDP(id, raddr, flags, delay);
}
return;
}
else
{ // IS THIS USED???
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() ERROR source OTHER ==> retryConnect()" << std::endl;
std::cerr << "p3LinkMgrIMPL::peerConnectRequest() ERROR source OTHER ==> NOOP" << std::endl;
std::cerr << std::endl;
retryConnect(id);
return;
}
}
@ -1184,7 +1262,7 @@ bool p3LinkMgrIMPL::retryConnect(const std::string &id)
bool p3LinkMgrIMPL::retryConnectUDP(const std::string &id, struct sockaddr_in &rUdpAddr)
bool p3LinkMgrIMPL::tryConnectUDP(const std::string &id, struct sockaddr_in &rUdpAddr, uint32_t flags, uint32_t delay)
{
RsStackMutex stack(mLinkMtx); /****** STACK LOCK MUTEX *******/
@ -1240,11 +1318,13 @@ bool p3LinkMgrIMPL::retryConnectUDP(const std::string &id, struct sockaddr_in
peerConnectAddress pca;
pca.addr = rUdpAddr;
pca.type = RS_NET_CONN_UDP_PEER_SYNC;
pca.delay = P3CONNMGR_UDP_DEFAULT_DELAY;
pca.delay = delay;
pca.ts = time(NULL);
pca.period = P3CONNMGR_UDP_DEFAULT_PERIOD;
pca.flags = flags;
addAddressIfUnique(it->second.connAddrs, pca);
// Push address to the front... so it happens quickly (before any timings are lost).
addAddressIfUnique(it->second.connAddrs, pca, true);
}
/* finish it off */
@ -1462,6 +1542,33 @@ bool p3LinkMgrIMPL::locked_CheckPotentialAddr(const struct sockaddr_in *addr, t
}
void p3LinkMgrIMPL::locked_ConnectAttempt_SpecificAddress(peerConnectState *peer, struct sockaddr_in *remoteAddr)
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_SpecificAddresses()";
std::cerr << std::endl;
#endif
if ((remoteAddr) && (locked_CheckPotentialAddr(remoteAddr, 0)))
{
#ifdef LINKMGR_DEBUG
std::cerr << "p3LinkMgrIMPL::locked_ConnectAttempt_SpecificAddresses() ";
std::cerr << "Adding tcp connection attempt: ";
std::cerr << "Addr: " << rs_inet_ntoa(remoteAddr->sin_addr);
std::cerr << ":" << ntohs(remoteAddr->sin_port);
std::cerr << std::endl;
#endif
peerConnectAddress pca;
pca.addr = *remoteAddr;
pca.type = RS_NET_CONN_TCP_EXTERNAL;
pca.delay = P3CONNMGR_TCP_DEFAULT_DELAY;
pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
addAddressIfUnique(peer->connAddrs, pca, false);
}
}
void p3LinkMgrIMPL::locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, struct sockaddr_in *localAddr, struct sockaddr_in *serverAddr)
{
#ifdef LINKMGR_DEBUG
@ -1486,7 +1593,7 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_CurrentAddresses(peerConnectState *pe
pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
addAddressIfUnique(peer->connAddrs, pca);
addAddressIfUnique(peer->connAddrs, pca, false);
}
if ((serverAddr) && (locked_CheckPotentialAddr(serverAddr, 0)))
@ -1505,7 +1612,7 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_CurrentAddresses(peerConnectState *pe
pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
addAddressIfUnique(peer->connAddrs, pca);
addAddressIfUnique(peer->connAddrs, pca, false);
}
}
@ -1542,7 +1649,7 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_HistoricalAddresses(peerConnectState
pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
addAddressIfUnique(peer->connAddrs, pca);
addAddressIfUnique(peer->connAddrs, pca, false);
}
}
@ -1566,7 +1673,7 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_HistoricalAddresses(peerConnectState
pca.ts = time(NULL);
pca.period = P3CONNMGR_TCP_DEFAULT_PERIOD;
addAddressIfUnique(peer->connAddrs, pca);
addAddressIfUnique(peer->connAddrs, pca, false);
}
}
}
@ -1603,7 +1710,7 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std
/* check address validity */
if (locked_CheckPotentialAddr(&(pca.addr), 0))
{
addAddressIfUnique(peer->connAddrs, pca);
addAddressIfUnique(peer->connAddrs, pca, false);
}
}
else
@ -1639,12 +1746,12 @@ void p3LinkMgrIMPL::locked_ConnectAttempt_AddTunnel(peerConnectState *peer)
sockaddr_clear(&pca.addr);
addAddressIfUnique(peer->connAddrs, pca);
addAddressIfUnique(peer->connAddrs, pca, false);
}
}
bool p3LinkMgrIMPL::addAddressIfUnique(std::list<peerConnectAddress> &addrList, peerConnectAddress &pca)
bool p3LinkMgrIMPL::addAddressIfUnique(std::list<peerConnectAddress> &addrList, peerConnectAddress &pca, bool pushFront)
{
/* iterate through the list, and make sure it isn't already
* in the list
@ -1675,7 +1782,14 @@ bool p3LinkMgrIMPL::addAddressIfUnique(std::list<peerConnectAddress> &addrList,
std::cerr << std::endl;
#endif
addrList.push_back(pca);
if (pushFront)
{
addrList.push_front(pca);
}
else
{
addrList.push_back(pca);
}
return true;
}

View File

@ -79,6 +79,7 @@ class peerConnectAddress
uint32_t delay; /* to stop simultaneous connects */
uint32_t period; /* UDP only */
uint32_t type;
uint32_t flags; /* CB FLAGS defined in pqimonitor.h */
time_t ts;
};
@ -169,7 +170,7 @@ virtual void removeMonitor(pqiMonitor *mon) = 0;
/****************** Connections *******************/
virtual bool connectAttempt(const std::string &id, struct sockaddr_in &addr,
uint32_t &delay, uint32_t &period, uint32_t &type) = 0;
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags) = 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;
@ -192,8 +193,8 @@ virtual bool getTunnelConnection() = 0; // ONLY used by p3peermgr.cc & p3
// THESE MUSTn't BE specfied HERE - as overloaded from pqiConnectCb.
//virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
// uint32_t type, uint32_t flags, uint32_t source) = 0;
//virtual void peerConnectRequest(std::string id,
// struct sockaddr_in raddr, uint32_t source) = 0;
//virtual void peerConnectRequest(std::string id, struct sockaddr_in raddr,
// uint32_t source, uint32_t flags, uint32_t delay) = 0;
/****************************************************************************/
/****************************************************************************/
@ -222,7 +223,7 @@ virtual void removeMonitor(pqiMonitor *mon);
/****************** Connections *******************/
virtual bool connectAttempt(const std::string &id, struct sockaddr_in &addr,
uint32_t &delay, uint32_t &period, uint32_t &type);
uint32_t &delay, uint32_t &period, uint32_t &type, uint32_t &flags);
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);
@ -233,8 +234,8 @@ virtual struct sockaddr_in getLocalAddress();
/******* overloaded from pqiConnectCb *************/
virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
uint32_t type, uint32_t flags, uint32_t source);
virtual void peerConnectRequest(std::string id,
struct sockaddr_in raddr, uint32_t source);
virtual void peerConnectRequest(std::string id, struct sockaddr_in raddr,
uint32_t source, uint32_t flags, uint32_t delay);
/************* DEPRECIATED FUNCTIONS (TO REMOVE) ********/
@ -280,11 +281,12 @@ void statusTick();
void tickMonitors();
/* connect attempts UDP */
bool retryConnectUDP(const std::string &id, struct sockaddr_in &rUdpAddr);
bool tryConnectUDP(const std::string &id, struct sockaddr_in &rUdpAddr, uint32_t flags, uint32_t delay);
/* connect attempts TCP */
bool retryConnectTCP(const std::string &id);
void locked_ConnectAttempt_SpecificAddress(peerConnectState *peer, struct sockaddr_in *remoteAddr);
void locked_ConnectAttempt_CurrentAddresses(peerConnectState *peer, struct sockaddr_in *localAddr, struct sockaddr_in *serverAddr);
void locked_ConnectAttempt_HistoricalAddresses(peerConnectState *peer, const pqiIpAddrSet &ipAddrs);
void locked_ConnectAttempt_AddDynDNS(peerConnectState *peer, std::string dyndns, uint16_t dynPort);
@ -293,8 +295,7 @@ void locked_ConnectAttempt_AddTunnel(peerConnectState *peer);
bool locked_ConnectAttempt_Complete(peerConnectState *peer);
bool locked_CheckPotentialAddr(const struct sockaddr_in *addr, time_t age);
bool addAddressIfUnique(std::list<peerConnectAddress> &addrList,
peerConnectAddress &pca);
bool addAddressIfUnique(std::list<peerConnectAddress> &addrList, peerConnectAddress &pca, bool pushFront);
private:

View File

@ -1306,6 +1306,24 @@ bool p3NetMgrIMPL::netAssistFriend(std::string id, bool on)
}
bool p3NetMgrIMPL::netAssistStatusUpdate(std::string id, int state)
{
std::map<uint32_t, pqiNetAssistConnect *>::iterator it;
#ifdef NETMGR_DEBUG
std::cerr << "p3NetMgrIMPL::netAssistFriend(" << id << ", " << on << ")";
std::cerr << std::endl;
#endif
for(it = mDhts.begin(); it != mDhts.end(); it++)
{
(it->second)->ConnectionFeedback(id, state);
}
return true;
}
bool p3NetMgrIMPL::netAssistSetAddress( struct sockaddr_in &laddr,
struct sockaddr_in &eaddr,
uint32_t mode)

View File

@ -93,6 +93,9 @@ class p3BitDht;
class UdpRelayReceiver;
#define NETMGR_DHT_FEEDBACK_CONNECTED 0x0001
#define NETMGR_DHT_FEEDBACK_CONN_FAILED 0x0002
#define NETMGR_DHT_FEEDBACK_CONN_CLOSED 0x0003
/**********
* p3NetMgr Interface....
@ -115,6 +118,7 @@ virtual bool setVisState(uint32_t visState) = 0;
// Switch DHT On/Off.
virtual bool netAssistFriend(std::string id, bool on) = 0;
virtual bool netAssistStatusUpdate(std::string id, int mode) = 0;
/* Get Network State */
virtual uint32_t getNetStateMode() = 0;
@ -168,6 +172,7 @@ virtual bool setVisState(uint32_t visState);
// Switch DHT On/Off.
virtual bool netAssistFriend(std::string id, bool on);
virtual bool netAssistStatusUpdate(std::string id, int mode);
/* Get Network State */
virtual uint32_t getNetStateMode();

View File

@ -229,6 +229,7 @@ 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_FLAGS = 4;
/*!

View File

@ -118,6 +118,8 @@ virtual int tick() = 0; /* for internal accounting */
virtual bool findPeer(std::string id) = 0;
virtual bool dropPeer(std::string id) = 0;
virtual void ConnectionFeedback(std::string pid, int mode) = 0;
/* extract current peer status */
virtual bool getPeerStatus(std::string id,
struct sockaddr_in &laddr, struct sockaddr_in &raddr,

View File

@ -65,14 +65,25 @@ const uint32_t RS_STUN_FRIEND = 0x0020;
const uint32_t RS_STUN_FRIEND_OF_FRIEND = 0x0040;
// for the old p3dhtmgr - amazed it still compiles ;)
#define RS_CONNECT_PASSIVE 1
#define RS_CONNECT_ACTIVE 2
#define RS_CB_DHT 1 /* from dht */
#define RS_CB_DISC 2 /* from peers */
#define RS_CB_PERSON 3 /* from connection */
#define RS_CB_PROXY 4 /* via proxy */
#define RS_CB_DHT 0x0001 /* from dht */
#define RS_CB_DISC 0x0002 /* from peers */
#define RS_CB_PERSON 0x0003 /* from connection */
#define RS_CB_PROXY 0x0004 /* via proxy */
#define RS_CB_FLAG_MASK_MODE 0x00ff
#define RS_CB_FLAG_MASK_CONN 0x00ff
#define RS_CB_FLAG_MODE_TCP 0x0001
#define RS_CB_FLAG_MODE_UDP 0x0002
#define RS_CB_FLAG_CONN_UNSPEC 0x0000
#define RS_CB_FLAG_CONN_PASSIVE 0x0100
#define RS_CB_FLAG_CONN_ACTIVE 0x0200
class pqipeer
@ -137,8 +148,8 @@ virtual ~pqiConnectCb() { return; }
virtual void peerStatus(std::string id, const pqiIpAddrSet &addrs,
uint32_t type, uint32_t flags, uint32_t source) = 0;
virtual void peerConnectRequest(std::string id,
struct sockaddr_in raddr, uint32_t source) = 0;
virtual void peerConnectRequest(std::string id, struct sockaddr_in raddr,
uint32_t source, uint32_t flags, uint32_t delay) = 0;
//virtual void stunStatus(std::string id, struct sockaddr_in raddr, uint32_t type, uint32_t flags) = 0;
};

View File

@ -378,7 +378,7 @@ int pqiperson::stoplistening()
return 1;
}
int pqiperson::connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay, uint32_t period, uint32_t timeout)
int pqiperson::connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay, uint32_t period, uint32_t timeout, uint32_t flags)
{
#ifdef PERSON_DEBUG
{
@ -390,6 +390,7 @@ int pqiperson::connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay,
out << " delay: " << delay;
out << " period: " << period;
out << " timeout: " << timeout;
out << " flags: " << flags;
out << std::endl;
std::cerr << out.str();
//pqioutput(PQL_DEBUG_BASIC, pqipersonzone, out.str());
@ -416,6 +417,9 @@ int pqiperson::connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay,
return 0;
}
std::cerr << "pqiperson::connect() WARNING, resetting for new connection attempt" << std::endl;
#ifdef PERSON_DEBUG
#endif
/* set the parameters */
(it->second)->reset();
@ -425,6 +429,7 @@ int pqiperson::connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay,
(it->second)->connect_parameter(NET_PARAM_CONNECT_DELAY, delay);
(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_FLAGS, flags);
(it->second)->connect(raddr);

View File

@ -106,7 +106,7 @@ virtual ~pqiperson(); // must clean up children.
int reset();
int listen();
int stoplistening();
int connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay, uint32_t period, uint32_t timeout);
int connect(uint32_t type, struct sockaddr_in raddr, uint32_t delay, uint32_t period, uint32_t timeout, uint32_t flags);
int receiveHeartbeat();
// add in connection method.
int addChildInterface(uint32_t type, pqiconnect *pqi);

View File

@ -492,10 +492,12 @@ int pqipersongrp::connectPeer(std::string id
std::cerr << std::endl;
#endif
{ RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
if (id == mLinkMgr->getOwnId()) {
{
RsStackMutex stack(coreMtx); /**************** LOCKED MUTEX ****************/
if (id == mLinkMgr->getOwnId())
{
std::cerr << "pqipersongrp::connectPeer() ERROR Failed, connecting to own id." << std::endl;
#ifdef PGRP_DEBUG
std::cerr << "pqipersongrp::connectPeer() Failed, connecting to own id." << std::endl;
#endif
return 0;
}
@ -546,8 +548,9 @@ int pqipersongrp::connectPeer(std::string id
uint32_t period;
uint32_t timeout;
uint32_t type;
uint32_t flags;
if (!mLinkMgr->connectAttempt(id, addr, delay, period, type))
if (!mLinkMgr->connectAttempt(id, addr, delay, period, type, flags))
{
#ifdef PGRP_DEBUG
std::cerr << " pqipersongrp::connectPeer() No Net Address";
@ -562,6 +565,7 @@ int pqipersongrp::connectPeer(std::string id
std::cerr << " delay: " << delay;
std::cerr << " period: " << period;
std::cerr << " type: " << type;
std::cerr << " flags: " << flags;
std::cerr << std::endl;
#endif
@ -603,7 +607,7 @@ int pqipersongrp::connectPeer(std::string id
return 0;
}
p->connect(ptype, addr, delay, period, timeout);
p->connect(ptype, addr, delay, period, timeout, flags);
} /* UNLOCKED */

View File

@ -88,6 +88,8 @@ pqissludp::~pqissludp()
int pqissludp::reset()
{
/* reset for next time.*/
mConnectFlags = 0;
mConnectPeriod = PQI_SSLUDP_DEF_CONN_PERIOD;
return pqissl::reset();
}
@ -131,14 +133,25 @@ int pqissludp::Initiate_Connection()
"pqissludp::Initiate_Connection() Attempting Outgoing Connection....");
/* decide if we're active or passive */
if (PeerId() < mLinkMgr->getOwnId())
if (mConnectFlags & RS_CB_FLAG_CONN_ACTIVE)
{
sslmode = PQISSL_ACTIVE;
}
else
else if (mConnectFlags & RS_CB_FLAG_CONN_PASSIVE)
{
sslmode = PQISSL_PASSIVE;
}
else // likely UNSPEC - use old method to decide.
{
if (PeerId() < mLinkMgr->getOwnId())
{
sslmode = PQISSL_ACTIVE;
}
else
{
sslmode = PQISSL_PASSIVE;
}
}
if (waiting != WAITING_DELAY)
{
@ -419,6 +432,15 @@ bool pqissludp::connect_parameter(uint32_t type, uint32_t value)
mConnectPeriod = value;
return true;
}
else if (type == NET_PARAM_CONNECT_FLAGS)
{
std::ostringstream out;
out << "pqissludp::connect_parameter() Peer: " << PeerId() << " FLAGS: " << value;
rslog(RSL_WARNING, pqissludpzone, out.str());
mConnectFlags = value;
return true;
}
return pqissl::connect_parameter(type, value);
}

View File

@ -99,6 +99,7 @@ private:
long listen_checktime;
uint32_t mConnectPeriod;
uint32_t mConnectFlags;
};
#endif // MRK_PQI_SSL_UDP_HEADER