* Fixed startup logic, so the DHT doesn't continually restart - if low peer count.

* properly initialised bdId.addr and other struct sockaddr_in.
 * This should fix the windows bitdht - not send - issue.



git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3687 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
drbob 2010-10-20 18:36:25 +00:00
parent 9cf531fc9a
commit 258f545361
3 changed files with 33 additions and 8 deletions

View File

@ -251,9 +251,14 @@ void bdNodeManager::iteration()
break;
case BITDHT_MGR_STATE_FINDSELF:
/* 60 seconds further startup .... then switch to ACTIVE */
#define MAX_FINDSELF_TIME 60
#define MIN_OP_SPACE_SIZE 50 /* 100 seemed hard! */
/* 60 seconds further startup .... then switch to ACTIVE
* if we reach TRANSITION_OP_SPACE_SIZE before this time, transition immediately...
* if, after 60 secs, we haven't reached MIN_OP_SPACE_SIZE, restart....
*/
#define MAX_FINDSELF_TIME 60
#define TRANSITION_OP_SPACE_SIZE 100 /* 1 query / sec, should take 12-15 secs */
#define MIN_OP_SPACE_SIZE 20
{
uint32_t nodeSpaceSize = mNodeSpace.calcSpaceSize();
@ -264,7 +269,7 @@ void bdNodeManager::iteration()
std::cerr << "NodeSpace Size:" << nodeSpaceSize;
std::cerr << std::endl;
if (nodeSpaceSize > MIN_OP_SPACE_SIZE)
if (nodeSpaceSize > TRANSITION_OP_SPACE_SIZE)
{
mMode = BITDHT_MGR_STATE_REFRESH;
mModeTS = now;
@ -272,8 +277,16 @@ void bdNodeManager::iteration()
if (modeAge > MAX_FINDSELF_TIME)
{
mMode = BITDHT_MGR_STATE_FAILED;
mModeTS = now;
if (nodeSpaceSize > MIN_OP_SPACE_SIZE)
{
mMode = BITDHT_MGR_STATE_REFRESH;
mModeTS = now;
}
else
{
mMode = BITDHT_MGR_STATE_FAILED;
mModeTS = now;
}
}
}

View File

@ -780,6 +780,7 @@ int decodeCompactPeerId(struct sockaddr_in *addr, char *enc, int len)
uint16_t *port = (uint16_t *) (&enc[4]);
addr->sin_addr.s_addr = (*ip);
addr->sin_port = (*port);
addr->sin_family = AF_INET;
return 1;
}

View File

@ -39,16 +39,27 @@
* #define BITDHT_DEBUG 1
**/
void bdSockAddrInit(struct sockaddr_in *addr)
{
memset(addr, 0, sizeof(struct sockaddr_in));
addr->sin_family = AF_INET;
}
bdId::bdId()
{
/* blank everything */
memset(&addr, 0, sizeof(struct sockaddr_in));
bdSockAddrInit(&addr);
memset(&id.data, 0, BITDHT_KEY_LEN);
}
bdId::bdId(bdNodeId in_id, struct sockaddr_in in_addr)
{
addr = in_addr;
/* this bit is to ensure the address is valid for windows / osx */
bdSockAddrInit(&addr);
addr.sin_addr.s_addr = in_addr.sin_addr.s_addr;
addr.sin_port = in_addr.sin_port;
for(int i = 0; i < BITDHT_KEY_LEN; i++)
{
id.data[i] = in_id.data[i];