diff --git a/libbitdht/src/bitdht/bdmanager.cc b/libbitdht/src/bitdht/bdmanager.cc index 0809c8837..a19ed6763 100644 --- a/libbitdht/src/bitdht/bdmanager.cc +++ b/libbitdht/src/bitdht/bdmanager.cc @@ -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; + } } } diff --git a/libbitdht/src/bitdht/bdmsgs.cc b/libbitdht/src/bitdht/bdmsgs.cc index cef99ddcb..ad500bda2 100644 --- a/libbitdht/src/bitdht/bdmsgs.cc +++ b/libbitdht/src/bitdht/bdmsgs.cc @@ -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; } diff --git a/libbitdht/src/bitdht/bdpeer.cc b/libbitdht/src/bitdht/bdpeer.cc index 988f5e852..e16158eef 100644 --- a/libbitdht/src/bitdht/bdpeer.cc +++ b/libbitdht/src/bitdht/bdpeer.cc @@ -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];