Added Proper State Machine for ConnectionRequests. Finished up this part of the code.

* Reworked ConnectionRequest iterations.
 * Added Special ConnectionRequest Callback (CB_REQUEST)
 * Added Extra Error codes for ConnectionRequest Callbacks.
 * Internal callback mechanism for connections locally started.
 * Fixed up Potential Proxy filtering (Must be BitDHT peer with valid version)
 * Added extra parameter to ConnectionRequest() Interface call. to allow start/stop.
 * Installed addPotentialConnectionProxy() into bdnode for incoming peers.
 * added find_exactnode() function to bdSpace.
 * added killConnectionRequest() to properly stop then - instead of letting timeout.
 * added ERROR SOURCE parameters and Handling, including decode helper functions.
 * Added WIN Networking Error code WSAINITIALISED.
 * Changed various ERRORs to WARNINGs



git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-peernet@4317 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2011-06-22 13:22:37 +00:00
parent 7f072e6ae5
commit d92f368c24
12 changed files with 976 additions and 66 deletions

File diff suppressed because it is too large Load Diff

View File

@ -34,10 +34,14 @@
************************************** ProxyTuple + Connection State ****************************************
************************************************************************************************************/
#define BITDHT_CONNREQUEST_INIT 1
#define BITDHT_CONNREQUEST_INPROGRESS 2
#define BITDHT_CONNREQUEST_DONE 3
#define BITDHT_CONNREQUEST_READY 1
#define BITDHT_CONNREQUEST_PAUSED 2
#define BITDHT_CONNREQUEST_INPROGRESS 3
#define BITDHT_CONNREQUEST_EXTCONNECT 4
#define BITDHT_CONNREQUEST_DONE 5
#define BITDHT_CONNREQUEST_TIMEOUT_CONNECT 30
#define BITDHT_CONNREQUEST_TIMEOUT_INPROGRESS 30
#define BITDHT_CONNREQUEST_MAX_AGE 60
@ -147,7 +151,12 @@ class bdConnectionRequest
int mState;
time_t mStateTS;
time_t mPauseTS;
uint32_t mErrCode;
std::list<bdId> mPotentialProxies;
int mRecycled;
bdId mCurrentAttempt;
std::list<bdId> mPeersTried;

View File

@ -151,13 +151,19 @@ virtual void bdPrintNodeId(std::ostream &out, const bdNodeId *a) = 0;
#define BITDHT_CONNECT_ERROR_NONE (BITDHT_CONNECT_ANSWER_OKAY)
#define BITDHT_CONNECT_ERROR_MASK_TYPE 0x0000ffff
#define BITDHT_CONNECT_ERROR_MASK_SOURCE 0x000f0000
#define BITDHT_CONNECT_ERROR_MASK_SOURCE 0x00ff0000
#define BITDHT_CONNECT_ERROR_MASK_CRMOVE 0xff000000
#define BITDHT_CONNECT_ERROR_SOURCE_START 0x00010000
#define BITDHT_CONNECT_ERROR_SOURCE_MID 0x00020000
#define BITDHT_CONNECT_ERROR_SOURCE_END 0x00040000
#define BITDHT_CONNECT_ERROR_SOURCE_OTHER 0x00080000
#define BITDHT_CONNECT_ERROR_CRMOVE_FATAL 0x01000000
#define BITDHT_CONNECT_ERROR_CRMOVE_NOMOREIDS 0x02000000
#define BITDHT_CONNECT_ERROR_CRMOVE_NEXTID 0x04000000
#define BITDHT_CONNECT_ERROR_CRMOVE_PAUSED 0x08000000
// ERROR CODES.
#define BITDHT_CONNECT_ERROR_GENERIC 0x00000001
#define BITDHT_CONNECT_ERROR_PROTOCOL 0x00000002
@ -171,6 +177,12 @@ virtual void bdPrintNodeId(std::ostream &out, const bdNodeId *a) = 0;
#define BITDHT_CONNECT_ERROR_AUTH_DENIED 0x00000009
#define BITDHT_CONNECT_ERROR_DUPLICATE 0x0000000a
// These are slightly special ones used for CB_REQUEST
#define BITDHT_CONNECT_ERROR_TOOMANYRETRY 0x0000000b
#define BITDHT_CONNECT_ERROR_OUTOFPROXY 0x0000000c
#define BITDHT_CONNECT_ERROR_USER 0x0000000d
@ -248,6 +260,7 @@ class bdQuerySummary
#define BITDHT_CONNECT_CB_START 3
#define BITDHT_CONNECT_CB_PROXY 4
#define BITDHT_CONNECT_CB_FAILED 5
#define BITDHT_CONNECT_CB_REQUEST 6
#define BD_PROXY_CONNECTION_UNKNOWN_POINT 0
#define BD_PROXY_CONNECTION_START_POINT 1
@ -283,7 +296,7 @@ virtual void removeFindNode(bdNodeId *id) = 0;
virtual void findDhtValue(bdNodeId *id, std::string key, uint32_t mode) = 0;
/***** Connections Requests *****/
virtual void ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode) = 0;
virtual void ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start) = 0;
virtual void ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId, uint32_t mode, uint32_t loc, uint32_t answer) = 0;
virtual void ConnectionOptions(uint32_t allowedModes, uint32_t flags) = 0;
@ -308,5 +321,13 @@ virtual uint32_t statsNetworkSize() = 0;
virtual uint32_t statsBDVersionSize() = 0; /* same version as us! */
};
// general helper functions for decoding error messages.
std::string decodeConnectionError(uint32_t errcode);
std::string decodeConnectionErrorCRMove(uint32_t errcode);
std::string decodeConnectionErrorSource(uint32_t errcode);
std::string decodeConnectionErrorType(uint32_t errcode);
#endif

View File

@ -1066,12 +1066,12 @@ int bdDebugCallback::dhtValueCallback(const bdNodeId *id, std::string key, uint3
void bdNodeManager::ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode)
void bdNodeManager::ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start)
{
std::cerr << "bdNodeManager::ConnectionRequest()";
std::cerr << std::endl;
bdNode::requestConnection(laddr, target, mode);
bdNode::requestConnection(laddr, target, mode, start);
}
void bdNodeManager::ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId, uint32_t mode, uint32_t loc, uint32_t answer)

View File

@ -119,7 +119,7 @@ virtual int getDhtQueries(std::map<bdNodeId, bdQueryStatus> &queries);
virtual int getDhtQueryStatus(const bdNodeId *id, bdQuerySummary &query);
/***** Connection Interface ****/
virtual void ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode);
virtual void ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start);
virtual void ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId,
uint32_t mode, uint32_t loc, uint32_t answer);
virtual void ConnectionOptions(uint32_t allowedModes, uint32_t flags);

View File

@ -559,7 +559,13 @@ void bdNode::checkPotentialPeer(bdId *id, bdId *src)
if (isWorthyPeer)
{
addPotentialPeer(id, src);
// Should this be inside about check? (Probably!)
// We can only really connect to peers that we are searching for???
// Its not enforced, but sensible!
bdNode::addPotentialConnectionProxy(src, id); // CAUTION: Order switched!
}
}

View File

@ -209,17 +209,24 @@ void recvPkt(char *msg, int len, struct sockaddr_in addr);
/* Connections: Initiation */
int requestConnection(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode);
int requestConnection(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start);
int requestConnection_direct(struct sockaddr_in *laddr, bdNodeId *target);
int requestConnection_proxy(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode);
int killConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode);
int checkExistingConnectionAttempt(bdNodeId *target);
void addPotentialConnectionProxy(bdId *srcId, bdId *target);
int checkPeerForFlag(const bdId *id, uint32_t with_flag);
int tickConnections();
void iterateConnectionRequests();
int startConnectionAttempt(bdConnectionRequest *req);
// internal Callback -> normally continues to callbackConnect().
void callbackConnectRequest(bdId *srcId, bdId *proxyId, bdId *destId,
int mode, int point, int cbtype, int errcode);
/* Connections: Outgoing */
int startConnectionAttempt(bdId *proxyId, bdId *srcConnAddr, bdId *destConnAddr, int mode);

View File

@ -382,6 +382,46 @@ int bdSpace::find_node(const bdNodeId *id, int number, std::list<bdId> &matchIds
return matchCount;
}
/* even cheaper again... no big lists */
int bdSpace::find_exactnode(const bdId *id, bdPeer &peer)
{
bdMetric dist;
mFns->bdDistance(&(id->id), &(mOwnId), &dist);
int buckno = mFns->bdBucketDistance(&dist);
std::cerr << "bdSpace::find_exactnode(Id:";
mFns->bdPrintId(std::cerr, id);
std::cerr << ")";
std::cerr << " Bucket #: " << buckno;
std::cerr << std::endl;
#ifdef DEBUG_BD_SPACE
#endif
bdBucket &buck = buckets[buckno];
std::list<bdPeer>::iterator eit;
int matchCount = 0;
for(eit = buck.entries.begin(); eit != buck.entries.end(); eit++)
{
if (*id == eit->mPeerId)
{
std::cerr << "bdSpace::find_exactnode() Found Matching Peer: ";
mFns->bdPrintId(std::cerr, &(eit->mPeerId));
std::cerr << " withFlags: " << eit->mPeerFlags;
std::cerr << std::endl;
peer = (*eit);
return 1;
}
}
std::cerr << "bdSpace::find_exactnode() ERROR Failed to find Matching Peer: ";
std::cerr << std::endl;
return 0;
}
int bdSpace::out_of_date_peer(bdId &id)

View File

@ -169,6 +169,7 @@ int find_nearest_nodes_with_flags(const bdNodeId *id, int number,
int find_node(const bdNodeId *id, int number,
std::list<bdId> &matchIds, uint32_t with_flag);
int find_exactnode(const bdId *id, bdPeer &peer);
int out_of_date_peer(bdId &id); // side-effect updates, send flag on peer.
int add_peer(const bdId *id, uint32_t mode);

View File

@ -122,11 +122,11 @@ void UdpBitDht::removeCallback(BitDhtCallback *cb)
mBitDhtManager->removeCallback(cb);
}
void UdpBitDht::ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode)
void UdpBitDht::ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start)
{
bdStackMutex stack(dhtMtx); /********** MUTEX LOCKED *************/
mBitDhtManager->ConnectionRequest(laddr, target, mode);
mBitDhtManager->ConnectionRequest(laddr, target, mode, start);
}

View File

@ -68,7 +68,7 @@ virtual void addCallback(BitDhtCallback *cb);
virtual void removeCallback(BitDhtCallback *cb);
/***** Connections Requests *****/
virtual void ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode);
virtual void ConnectionRequest(struct sockaddr_in *laddr, bdNodeId *target, uint32_t mode, uint32_t start);
virtual void ConnectionAuth(bdId *srcId, bdId *proxyId, bdId *destId, uint32_t mode, uint32_t loc, uint32_t answer);
virtual void ConnectionOptions(uint32_t allowedModes, uint32_t flags);

View File

@ -256,7 +256,11 @@ int bdnet_w2u_errno(int err)
break;
*
***/
case WSANOTINITIALISED:
std::cerr << "tou_net_w2u_errno(" << err << ") WSANOTINITIALISED. Fix Your Code!";
std::cerr << std::endl;
break;
default:
std::cerr << "tou_net_w2u_errno(" << err << ") Unknown";
std::cerr << std::endl;