Official eMule-Board: Improvement Of Emule-Kad Lookup Performance - Official eMule-Board

Jump to content


  • (2 Pages)
  • +
  • 1
  • 2

Improvement Of Emule-Kad Lookup Performance packet loss; inconsistency of round-trip UDP ports

#1 User is offline   liubingshuang 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 11

Post icon  Posted 31 August 2011 - 03:13 PM

Nowadays high lookup performance of Kad is urgently needed by new P2P applications, such as P2P IM, P2P DNS, and P2P Browser. In the past few months, we have done a series of experiments to evaluate and optimize Kad lookup performance. The evaluation results show that the lookup performance is dissatisfactory. The lookup success rate (single point publishing and single point searching) is only about 85% in standard Kad. After optimization, we have increased the lookup success rate to 98%. There are two main issues: First, packet loss of eMule-kad; Second, the inconsistency of round-trip UDP ports.
To solve the problems above, We have made a patch on eMule 0.50a. For more detailed descriptions and a full patch, please Email me.
0

#2 User is offline   Stulle 

  • [Enter Mod] Dev
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 5738
  • Joined: 07-April 04

Posted 31 August 2011 - 03:42 PM

This sounds really interesting. Why aren't you simply sharing your code and findings in public so everybody can discuss your proposed changes without having to email you in private? This is Open Source after all. No offense intended, though!

This post has been edited by Stulle: 31 August 2011 - 03:43 PM

I am an emule-web.de member and fan! Hate me or people will get suspicious about you! Ever wondered if it's all worth the trouble?

Posted Image

No, there will not be a new version of my mods. No, I do not want your PM. No, I am certain, use the board and quit sending PMs. No, I am not kidding, there will not be a new version of my mods just because of YOU asking for it!
0

#3 User is offline   pier4r 

  • Ex falso quodlibet ; Kad is the major concept behind emule.
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 564
  • Joined: 31-March 09

Posted 31 August 2011 - 04:26 PM

moreover open (and free) knowledge is better for all :)
>>> My wiki (ITA) on emule >>>Feature Request (ICS) or SOTN, ClientAnalyzer(fixing fastXs and reask punishment),, EmuleCollectionV2 >>> Emule on old hardware (intel pentium 2 or 3 - via c3 - and so on) with good OS settings and enough ram (256+ mb): great >>>user of: eMule - Xtreme - ZZUL bastard - SharX - SharkX 1.8b5 pierQR - ZZUL-Tra - ZZUL-Tra-TL - kMule - Beba

Extended signature: click.
1

#4 User is offline   liubingshuang 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 11

Posted 01 September 2011 - 02:23 AM

I agree with u very much. But there is no right place to provide my patch file. I would like to send the patch to eMule project developers firstly. After being examined and verified, the path will be provided at liberty.

View PostStulle, on 31 August 2011 - 03:42 PM, said:

This sounds really interesting. Why aren't you simply sharing your code and findings in public so everybody can discuss your proposed changes without having to email you in private? This is Open Source after all. No offense intended, though!

0

#5 User is offline   liubingshuang 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 11

Posted 01 September 2011 - 02:27 AM

Yes! See my answer on the third floor :bouncehi:

View Postpier4r, on 31 August 2011 - 04:26 PM, said:

moreover open (and free) knowledge is better for all :)

0

#6 User is offline   pier4r 

  • Ex falso quodlibet ; Kad is the major concept behind emule.
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 564
  • Joined: 31-March 09

Posted 01 September 2011 - 08:26 AM

View Postliubingshuang, on 01 September 2011 - 04:23 AM, said:

I agree with u very much. But there is no right place to provide my patch file. I would like to send the patch to eMule project developers firstly. After being examined and verified, the path will be provided at liberty.

View PostStulle, on 31 August 2011 - 03:42 PM, said:

This sounds really interesting. Why aren't you simply sharing your code and findings in public so everybody can discuss your proposed changes without having to email you in private? This is Open Source after all. No offense intended, though!


A place to upload your patch? Maybe a dropbox account or a personal wiki?
Bear in mind that official developers are quite busy, instead all developers on emule project forum can analyze your patch more quickly.
>>> My wiki (ITA) on emule >>>Feature Request (ICS) or SOTN, ClientAnalyzer(fixing fastXs and reask punishment),, EmuleCollectionV2 >>> Emule on old hardware (intel pentium 2 or 3 - via c3 - and so on) with good OS settings and enough ram (256+ mb): great >>>user of: eMule - Xtreme - ZZUL bastard - SharX - SharkX 1.8b5 pierQR - ZZUL-Tra - ZZUL-Tra-TL - kMule - Beba

Extended signature: click.
1

#7 User is offline   liubingshuang 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 11

Posted 01 September 2011 - 09:59 AM

Yes, I know it. Thx. But there my be some bugs before being examined and verified by eMule project developers.

View Postpier4r, on 01 September 2011 - 08:26 AM, said:

View Postliubingshuang, on 01 September 2011 - 04:23 AM, said:

I agree with u very much. But there is no right place to provide my patch file. I would like to send the patch to eMule project developers firstly. After being examined and verified, the path will be provided at liberty.

View PostStulle, on 31 August 2011 - 03:42 PM, said:

This sounds really interesting. Why aren't you simply sharing your code and findings in public so everybody can discuss your proposed changes without having to email you in private? This is Open Source after all. No offense intended, though!


A place to upload your patch? Maybe a dropbox account or a personal wiki?
Bear in mind that official developers are quite busy, instead all developers on emule project forum can analyze your patch more quickly.

0

#8 User is offline   fox88 

  • Golden eMule
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 4473
  • Joined: 13-May 07

Posted 01 September 2011 - 11:08 AM

View Postliubingshuang, on 01 September 2011 - 01:59 PM, said:

Yes, I know it. Thx. But there my be some bugs before being examined and verified by eMule project developers.

Then, why you posted it here, while it's clearly written in Code Snippets' subtitle: To post validated fixes & important addons (only!)?
-1

#9 User is offline   Nissenice 

  • clippetty-clopping...
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 4231
  • Joined: 05-January 06

Posted 01 September 2011 - 11:33 AM

View Postfox88, on 01 September 2011 - 01:08 PM, said:

Then, why you posted it here, while it's clearly written in Code Snippets' subtitle: To post validated fixes & important addons (only!)?

Ok, I'm not sure, but I can't remember it was posted in Code Snippets yesterday but only in the eMule Development section, so I think it's a slight chance the topic has been moved.

Well, memory is what it is, but I have strange feeling about it though...

This post has been edited by Nissenice: 01 September 2011 - 11:34 AM

0

#10 User is offline   Stulle 

  • [Enter Mod] Dev
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 5738
  • Joined: 07-April 04

Posted 01 September 2011 - 11:36 AM

be that as it may, discussing code is not implementing it mindlessly. so i still think it should just be posted here and other people - such as netfinity - can discuss it at their leisure.
I am an emule-web.de member and fan! Hate me or people will get suspicious about you! Ever wondered if it's all worth the trouble?

Posted Image

No, there will not be a new version of my mods. No, I do not want your PM. No, I am certain, use the board and quit sending PMs. No, I am not kidding, there will not be a new version of my mods just because of YOU asking for it!
0

#11 User is offline   pier4r 

  • Ex falso quodlibet ; Kad is the major concept behind emule.
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 564
  • Joined: 31-March 09

Posted 01 September 2011 - 03:15 PM

View Postliubingshuang, on 01 September 2011 - 11:59 AM, said:

Yes, I know it. Thx. But there my be some bugs before being examined and verified by eMule project developers.


Ok then, i don't agree with your protocol of sharing knowledge but anyway i can't say "i'm right" or "you must do this!". I hope that sooner or later your work will be available to emule community :flowers: .
>>> My wiki (ITA) on emule >>>Feature Request (ICS) or SOTN, ClientAnalyzer(fixing fastXs and reask punishment),, EmuleCollectionV2 >>> Emule on old hardware (intel pentium 2 or 3 - via c3 - and so on) with good OS settings and enough ram (256+ mb): great >>>user of: eMule - Xtreme - ZZUL bastard - SharX - SharkX 1.8b5 pierQR - ZZUL-Tra - ZZUL-Tra-TL - kMule - Beba

Extended signature: click.
0

#12 User is offline   liubingshuang 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 11

Posted 02 September 2011 - 02:23 AM

Ok, I admit that I am too cautious about it, please forgive me :worthy: . Here is the download link of the patch file in rapidshare: http://www.rapidshar...file-4562.html. Welcome to check it together.
4

#13 User is offline   fox88 

  • Golden eMule
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 4473
  • Joined: 13-May 07

Posted 02 September 2011 - 07:02 AM

404 Error File Not Found
0

#14 User is offline   Stulle 

  • [Enter Mod] Dev
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 5738
  • Joined: 07-April 04

Posted 02 September 2011 - 07:14 AM

the "." at the end of the link is the problem. proper link: click me. anyway, lacking any chinese skills i am lost on that page.

come on liubingshuang, now it's just getting weird! you were speaking about a detailed description and some code. post an abstract here and upload the files to a file hoster anyone with basic english skills can use without having to use his personal crystal ball.

This post has been edited by Stulle: 02 September 2011 - 07:16 AM

I am an emule-web.de member and fan! Hate me or people will get suspicious about you! Ever wondered if it's all worth the trouble?

Posted Image

No, there will not be a new version of my mods. No, I do not want your PM. No, I am certain, use the board and quit sending PMs. No, I am not kidding, there will not be a new version of my mods just because of YOU asking for it!
0

#15 User is offline   Nissenice 

  • clippetty-clopping...
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 4231
  • Joined: 05-January 06

Posted 02 September 2011 - 07:29 AM

Try this one, it's one of the links from that page: http://www.rapidshar...2-QTieoCXc.html
Hope it works. The file is named eMule_srchybrid.patch.

Posted Image

This post has been edited by Nissenice: 02 September 2011 - 07:33 AM

0

#16 User is offline   liubingshuang 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 11

Posted 02 September 2011 - 05:04 PM

The doc file is mainly some experiment results in various kinds of network conditions, so we will write an explanation file about the code.

View PostStulle, on 02 September 2011 - 07:14 AM, said:

the "." at the end of the link is the problem. proper link: click me. anyway, lacking any chinese skills i am lost on that page.

come on liubingshuang, now it's just getting weird! you were speaking about a detailed description and some code. post an abstract here and upload the files to a file hoster anyone with basic english skills can use without having to use his personal crystal ball.

0

#17 User is offline   Stulle 

  • [Enter Mod] Dev
  • PipPipPipPipPipPipPip
  • Group: Members
  • Posts: 5738
  • Joined: 07-April 04

Posted 02 September 2011 - 05:14 PM

That's cool!
I am an emule-web.de member and fan! Hate me or people will get suspicious about you! Ever wondered if it's all worth the trouble?

Posted Image

No, there will not be a new version of my mods. No, I do not want your PM. No, I am certain, use the board and quit sending PMs. No, I am not kidding, there will not be a new version of my mods just because of YOU asking for it!
0

#18 User is offline   xilolee 

  • eMule 0.50b BETA1 user
  • PipPipPipPipPipPipPip
  • Group: Italian Moderators
  • Posts: 7670
  • Joined: 20-August 08

Posted 02 September 2011 - 06:39 PM

You can also insert your code here between [spoiler][code] (and their endings)... I've tried and it works. :flowers:
INCONCEIVABLE! - You keep using that word. I do not think it means what you think it means.
come ottenere aiuto italian guides - guide della sezione italiana
italian support - sezione italiana scaricare la lista server
ottenere id alto impostare le porte nel router
recuperare file corrotti i filtri ip
Sembra talco ma non č serve a darti l'allegrIa! Se lo lanci e poi lo respiri ti dā subito l'allegrIa! Immagine Postata
0

#19 User is offline   sonoro 

  • Splendid Member
  • PipPipPipPip
  • Group: Members
  • Posts: 146
  • Joined: 02-July 06

Posted 02 September 2011 - 08:04 PM

diff -urB srchybrid/ClientUDPSocket.cpp srchybrid_withpatch/ClientUDPSocket.cpp
--- srchybrid/ClientUDPSocket.cpp	2009-02-22 19:36:56.000000000 +0800
+++ srchybrid_withpatch/ClientUDPSocket.cpp	2011-08-31 10:48:16.000000000 +0800
@@ -62,7 +62,8 @@
     POSITION pos = controlpacket_queue.GetHeadPosition();
 	while (pos){
 		UDPPack* p = controlpacket_queue.GetNext(pos);
-		delete p->packet;
+		if(!p->bKad)//delete kad packet in packet resend method
+			delete p->packet;
 		delete p;
 	}
 }
@@ -523,7 +524,8 @@
                 sentBytes += nLen; // ZZ:UploadBandWithThrottler (UDP)
 
 				controlpacket_queue.RemoveHead();
-				delete cur_packet->packet;
+				if(!cur_packet->bKad)//delete kad packet in packet resend method
+					delete cur_packet->packet;
 				delete cur_packet;
             }
 			delete[] sendbuffer;
@@ -531,7 +533,8 @@
 		else
 		{
 			controlpacket_queue.RemoveHead();
-			delete cur_packet->packet;
+			if(!cur_packet->bKad)//delete kad packet in packet resend method
+				delete cur_packet->packet;
 			delete cur_packet;
 		}
 	}
Only in srchybrid_withpatch/: ClientUDPSocket.cpp.bak
diff -urB srchybrid/kademlia/kademlia/Kademlia.cpp srchybrid_withpatch/kademlia/kademlia/Kademlia.cpp
--- srchybrid/kademlia/kademlia/Kademlia.cpp	2010-03-10 18:57:44.000000000 +0800
+++ srchybrid_withpatch/kademlia/kademlia/Kademlia.cpp	2011-08-31 10:48:18.000000000 +0800
@@ -315,8 +315,10 @@
 		delete pContact;
 	}
 
-	if (GetUDPListener() != NULL)
+	if (GetUDPListener() != NULL){
 		GetUDPListener()->ExpireClientSearch(); // function does only one compare in most cases, so no real need for a timer
+		GetUDPListener()->ResendPackets();//resend no reply packets here
+	}
 }
 
 void CKademlia::AddEvent(CRoutingZone *pZone)
Only in srchybrid_withpatch/kademlia/kademlia: Kademlia.cpp.bak
diff -urB srchybrid/kademlia/kademlia/Search.cpp srchybrid_withpatch/kademlia/kademlia/Search.cpp
--- srchybrid/kademlia/kademlia/Search.cpp	2010-04-05 12:39:52.000000000 +0800
+++ srchybrid_withpatch/kademlia/kademlia/Search.cpp	2011-08-31 10:48:20.000000000 +0800
@@ -361,15 +361,28 @@
 	//Find contact that is responding.
 	CUInt128 uFromDistance((ULONG)0);
 	CContact* pFromContact = NULL;
+	CUInt128 uWeakFromDistance((ULONG)0);
+	CContact* pWeakFromContact = NULL;
 	for (ContactMap::const_iterator itContactMap = m_mapTried.begin(); itContactMap != m_mapTried.end(); ++itContactMap)
 	{
 		CContact* pTmpContact = itContactMap->second;
-		if ((pTmpContact->GetIPAddress() == uFromIP) && (pTmpContact->GetUDPPort() == uFromPort))
+		if ((pTmpContact->GetIPAddress() == uFromIP) && (pTmpContact->GetUDPPort() == uFromPort))//first find ip and port
 		{
 			uFromDistance = itContactMap->first;
 			pFromContact = pTmpContact;
 			break;
 		}
+		//if there are more than one contact having the same ip in m_mapTried, we chose the farthest one.
+		if(pTmpContact->GetIPAddress() == uFromIP && m_mapResponded.count(itContactMap->first) == 0)//if not find, find only ip
+		{
+			uWeakFromDistance = itContactMap->first;
+			pWeakFromContact = pTmpContact;
+		}
+	}
+	if(pFromContact == NULL)
+	{
+			uFromDistance = uWeakFromDistance;
+			pFromContact = pWeakFromContact;
 	}
 	
 	// Make sure the node is not sending more results than we requested, which is not only a protocol vialoation
@@ -400,7 +413,8 @@
 		// Add contacts to the History for GUI purposes
 		for (ContactList::iterator itContactList = plistResults->begin(); itContactList != plistResults->end(); ++itContactList)
 		{			
-			CUInt128 uDistance(((CContact*)*itContactList)->GetClientID().Xor(m_uTarget));
+			//CUInt128 uDistance(((CContact*)*itContactList)->GetClientID().Xor(m_uTarget));//there modfy (*itContactList)'s clientID by mistake
+			CUInt128 uDistance(CUInt128(((CContact*)*itContactList)->GetClientID()).Xor(m_uTarget));
 			m_pLookupHistory->ContactReceived(*itContactList, pFromContact, uDistance, uDistance < uFromDistance, true);
 		}
 		theApp.emuledlg->kademliawnd->UpdateSearchGraph(m_pLookupHistory);
Only in srchybrid_withpatch/kademlia/kademlia: Search.cpp.bak
diff -urB srchybrid/kademlia/net/KademliaUDPListener.cpp srchybrid_withpatch/kademlia/net/KademliaUDPListener.cpp
--- srchybrid/kademlia/net/KademliaUDPListener.cpp	2010-04-05 09:47:30.000000000 +0800
+++ srchybrid_withpatch/kademlia/net/KademliaUDPListener.cpp	2011-08-31 10:48:18.000000000 +0800
@@ -42,8 +42,8 @@
 #include "../routing/RoutingZone.h"
 #include "../io/ByteIO.h"
 #include "../../emule.h"
-#include "../../ClientUDPSocket.h"
-#include "../../Packets.h"
+//#include "../../ClientUDPSocket.h"
+//#include "../../Packets.h"
 #include "../../emuledlg.h"
 #include "../../KadContactListCtrl.h"
 #include "../../kademliawnd.h"
@@ -1172,6 +1172,11 @@
 		strError.Format(_T("***NOTE: Received wrong size (%u) packet in %hs"), uLenPacket, __FUNCTION__);
 		throw strError;
 	}
+	else if (!IsOnOutTrackList(uIP, KADEMLIA_SEARCH_REQ, true)){
+		CString strError;
+		strError.Format(_T("***NOTE: Received unrequested response packet, size (%u) in %hs"), uLenPacket, __FUNCTION__);
+		throw strError;
+	}
 
 	// What search does this relate to
 	CByteIO byteIO(pbyPacketData, uLenPacket);
@@ -1212,6 +1217,12 @@
 // Used in Kad2.0 only
 void CKademliaUDPListener::Process_KADEMLIA2_SEARCH_RES (const byte *pbyPacketData, uint32 uLenPacket, CKadUDPKey /*senderUDPKey*/, uint32 uIP, uint16 uUDPPort)
 {
+	//there may be more than one response packet
+	if (!IsOnOutTrackList(uIP, KADEMLIA2_SEARCH_KEY_REQ, true) && !IsOnOutTrackList(uIP, KADEMLIA2_SEARCH_SOURCE_REQ, true)){
+		CString strError;
+		strError.Format(_T("***NOTE: Received unrequested response packet, size (%u) in %hs"), uLenPacket, __FUNCTION__);
+		throw strError;
+	}
 	CByteIO byteIO(pbyPacketData, uLenPacket);
 
 	// Who sent this packet.
@@ -1592,6 +1603,11 @@
 // Used only by Kad2.0
 void CKademliaUDPListener::Process_KADEMLIA2_SEARCH_NOTES_REQ (const byte *pbyPacketData, uint32 uLenPacket, uint32 uIP, uint16 uUDPPort, CKadUDPKey senderUDPKey)
 {
+	if (!IsOnOutTrackList(uIP, KADEMLIA2_SEARCH_NOTES_REQ, true)){
+		CString strError;
+		strError.Format(_T("***NOTE: Received unrequested response packet, size (%u) in %hs"), uLenPacket, __FUNCTION__);
+		throw strError;
+	}
 	CSafeMemFile fileIO(pbyPacketData, uLenPacket);
 	CUInt128 uTarget;
 	fileIO.ReadUInt128(&uTarget);
@@ -2046,7 +2062,6 @@
 		ASSERT(0);
 		return;
 	}
-	AddTrackedOutPacket(uDestinationHost, pbyData[1]);
 	Packet* pPacket = new Packet(OP_KADEMLIAHEADER);
 	pPacket->opcode = pbyData[1];
 	pPacket->pBuffer = new char[uLenData+8];
@@ -2055,6 +2070,10 @@
 	if( uLenData > 200 )
 		pPacket->PackPacket();
 	theStats.AddUpDataOverheadKad(pPacket->size);
+	bool bAdd = true;
+	bAdd = AddTrackedOutPacket(uDestinationHost, uDestinationPort, ((const uchar*) (uCryptTargetID != NULL) ? uCryptTargetID->GetData() : NULL), targetUDPKey.GetKeyValue(theApp.GetPublicIP(false)), pPacket, pbyData[1]);
+	if(!bAdd)
+		return;
 	theApp.clientudp->SendPacket(pPacket, ntohl(uDestinationHost), uDestinationPort, true
 		, (uCryptTargetID != NULL) ? uCryptTargetID->GetData() : NULL
 		, true , targetUDPKey.GetKeyValue(theApp.GetPublicIP(false)));
@@ -2062,7 +2081,6 @@
 
 void CKademliaUDPListener::SendPacket(const byte *pbyData, uint32 uLenData, byte byOpcode, uint32 uDestinationHost, uint16 uDestinationPort, CKadUDPKey targetUDPKey, const CUInt128* uCryptTargetID)
 {
-	AddTrackedOutPacket(uDestinationHost, byOpcode);
 	Packet* pPacket = new Packet(OP_KADEMLIAHEADER);
 	pPacket->opcode = byOpcode;
 	pPacket->pBuffer = new char[uLenData];
@@ -2071,6 +2089,10 @@
 	if( uLenData > 200 )
 		pPacket->PackPacket();
 	theStats.AddUpDataOverheadKad(pPacket->size);
+	bool bAdd = true;
+	bAdd = AddTrackedOutPacket(uDestinationHost, uDestinationPort, ((const uchar*) (uCryptTargetID != NULL) ? uCryptTargetID->GetData() : NULL), targetUDPKey.GetKeyValue(theApp.GetPublicIP(false)), pPacket, byOpcode);
+	if(!bAdd)
+		return;
 	theApp.clientudp->SendPacket(pPacket, ntohl(uDestinationHost), uDestinationPort, true
 		, (uCryptTargetID != NULL) ? uCryptTargetID->GetData() : NULL
 		, true , targetUDPKey.GetKeyValue(theApp.GetPublicIP(false)));
@@ -2078,12 +2100,15 @@
 
 void CKademliaUDPListener::SendPacket(CSafeMemFile *pbyData, byte byOpcode, uint32 uDestinationHost, uint16 uDestinationPort, CKadUDPKey targetUDPKey, const CUInt128* uCryptTargetID)
 {
-	AddTrackedOutPacket(uDestinationHost, byOpcode);
 	Packet* pPacket = new Packet(pbyData, OP_KADEMLIAHEADER);
 	pPacket->opcode = byOpcode;
 	if( pPacket->size > 200 )
 		pPacket->PackPacket();
 	theStats.AddUpDataOverheadKad(pPacket->size);
+	bool bAdd = true;
+	bAdd = AddTrackedOutPacket(uDestinationHost, uDestinationPort,  ((const uchar*) (uCryptTargetID != NULL) ? uCryptTargetID->GetData() : NULL), targetUDPKey.GetKeyValue(theApp.GetPublicIP(false)), pPacket, byOpcode);
+	if(!bAdd)
+		return;
 	theApp.clientudp->SendPacket(pPacket, ntohl(uDestinationHost), uDestinationPort, true
 		, (uCryptTargetID != NULL) ? uCryptTargetID->GetData() : NULL
 		, true , targetUDPKey.GetKeyValue(theApp.GetPublicIP(false)));
Only in srchybrid_withpatch/kademlia/net: KademliaUDPListener.cpp.bak
diff -urB srchybrid/kademlia/net/PacketTracking.cpp srchybrid_withpatch/kademlia/net/PacketTracking.cpp
--- srchybrid/kademlia/net/PacketTracking.cpp	2010-03-09 23:33:04.000000000 +0800
+++ srchybrid_withpatch/kademlia/net/PacketTracking.cpp	2011-08-31 10:48:20.000000000 +0800
@@ -37,24 +37,61 @@
 }
 
 CPacketTracking::~CPacketTracking(){
+	for (POSITION pos = listTrackedRequests.GetTailPosition(); pos != NULL; listTrackedRequests.GetPrev(pos)){
+		delete listTrackedRequests.GetAt(pos).pPacket;
+		delete[]  listTrackedRequests.GetAt(pos).pachTargetClientHashORKadID;
+	}
 	m_mapTrackPacketsIn.RemoveAll();
 	while (!m_liTrackPacketsIn.IsEmpty())
 		delete m_liTrackPacketsIn.RemoveHead();
 }
 
-void CPacketTracking::AddTrackedOutPacket(uint32 dwIP, uint8 byOpcode){
+bool CPacketTracking::AddTrackedOutPacket(uint32 dwIP, uint16 nPort, const uchar* pachTargetClientHashORKadID, uint32 nReceiverVerifyKey, Packet* packet, uint8 byOpcode){
 	// this tracklist tacks _outgoing_ request packets, to make sure incoming answer packets were requested
 	// only track packets which we actually check for later
-	if (!IsTrackedOutListRequestPacket(byOpcode))
-		return;
-	TrackPackets_Struct sTrack = {dwIP, ::GetTickCount(), byOpcode};
+	if (!IsTrackedOutListRequestPacket(byOpcode)){
+		delete packet;
+		return false;
+	}
+	uchar* pachTargetClientHashORKadIDTmp = NULL;
+	if( pachTargetClientHashORKadID != NULL){
+		pachTargetClientHashORKadIDTmp =  new uchar[32];
+		memcpy(pachTargetClientHashORKadIDTmp, pachTargetClientHashORKadID, 32);
+	}
+	TrackPackets_Struct sTrack = {packet, dwIP, nPort, pachTargetClientHashORKadIDTmp, nReceiverVerifyKey, ::GetTickCount(), byOpcode, PACKET_RESEND_TIMES, false};
 	listTrackedRequests.AddHead(sTrack);
-	while (!listTrackedRequests.IsEmpty()){
-		if (::GetTickCount() - listTrackedRequests.GetTail().dwInserted > SEC2MS(180))
-			listTrackedRequests.RemoveTail();
-		else
+	//while (!listTrackedRequests.IsEmpty()){
+	//	if (::GetTickCount() - listTrackedRequests.GetTail().dwInserted > SEC2MS(180))
+	//		listTrackedRequests.RemoveTail();
+	//	else
+	//		break;
+	//}
+	return true;
+}
+
+void CPacketTracking::ResendPackets(){
+	CList<TrackPackets_Struct> listTrackedRequestsTmp;
+	for (POSITION pos = listTrackedRequests.GetTailPosition(); pos != NULL; listTrackedRequests.GetPrev(pos)){
+		TrackPackets_Struct& sTrack = listTrackedRequests.GetAt(pos);
+		if (::GetTickCount() - sTrack.dwInserted > SEC2MS(180)){//clean expired packet after 180 seconds
+			delete sTrack.pPacket;
+			delete[] sTrack.pachTargetClientHashORKadID;
+			listTrackedRequests.RemoveAt(pos);			
+		}else if(::GetTickCount() - sTrack.dwInserted >= PACKET_RESEND_INTERVAL){//resend packet
+			if(sTrack.nResendTimes > 0 && !sTrack.bRecv){
+				theApp.clientudp->SendPacket(sTrack.pPacket, ntohl(sTrack.dwIP), sTrack.nPort, true
+					, sTrack.pachTargetClientHashORKadID, true , sTrack.nReceiverVerifyKey);
+				sTrack.nResendTimes--;
+				sTrack.dwInserted = ::GetTickCount();
+				listTrackedRequestsTmp.AddHead(sTrack);
+				listTrackedRequests.RemoveAt(pos);
+			}
+		}else//these packets in front of this are not expired
 			break;
 	}
+
+	listTrackedRequests.AddHead(&listTrackedRequestsTmp);
+	listTrackedRequestsTmp.RemoveAll();
 }
 
 bool CPacketTracking::IsTrackedOutListRequestPacket(uint8 byOpcode) const
@@ -88,8 +125,14 @@
 #endif
 	for (POSITION pos = listTrackedRequests.GetHeadPosition(); pos != NULL; listTrackedRequests.GetNext(pos)){
 		if (listTrackedRequests.GetAt(pos).dwIP == dwIP && listTrackedRequests.GetAt(pos).byOpcode == byOpcode && ::GetTickCount() - listTrackedRequests.GetAt(pos).dwInserted < SEC2MS(180)){
-			if (!bDontRemove)
+			if (!bDontRemove){
+				delete listTrackedRequests.GetAt(pos).pPacket;
+				delete[] listTrackedRequests.GetAt(pos).pachTargetClientHashORKadID;
 				listTrackedRequests.RemoveAt(pos);
+			}
+			else{
+				listTrackedRequests.GetAt(pos).bRecv = true;
+			}
 			return true;
 		}
 	}
Only in srchybrid_withpatch/kademlia/net: PacketTracking.cpp.bak
diff -urB srchybrid/kademlia/net/PacketTracking.h srchybrid_withpatch/kademlia/net/PacketTracking.h
--- srchybrid/kademlia/net/PacketTracking.h	2008-08-30 12:12:52.000000000 +0800
+++ srchybrid_withpatch/kademlia/net/PacketTracking.h	2011-08-31 10:48:20.000000000 +0800
@@ -17,13 +17,23 @@
 
 #pragma once
 #include "../utils/UInt128.h"
+#include "../../ClientUDPSocket.h"
+#include "../../Packets.h"
 
 namespace Kademlia
 {
+#define PACKET_RESEND_TIMES			3
+#define PACKET_RESEND_INTERVAL		2000 //ms
 	struct TrackPackets_Struct{
+		Packet* pPacket;
 		uint32 dwIP;
+		uint16 nPort;
+		uchar* pachTargetClientHashORKadID;
+		uint32 nReceiverVerifyKey;
 		uint32 dwInserted;
 		uint8  byOpcode;
+		uint8 nResendTimes;
+		bool bRecv;//process multi-response packets
 	};
 
 	struct TrackChallenge_Struct{
@@ -53,10 +63,12 @@
 	{
 		public:
 			CPacketTracking();
+			void ResendPackets();
 			virtual ~CPacketTracking();
 
 		protected:
-			void AddTrackedOutPacket(uint32 dwIP, uint8 byOpcode);
+			//if return false, the opcode is wrong, so dont need send this packet
+			bool AddTrackedOutPacket(uint32 dwIP, uint16 nPort, const uchar* pachTargetClientHashORKadID, uint32 nReceiverVerifyKey, Packet* packet, uint8 byOpcode);
 			bool IsOnOutTrackList(uint32 dwIP, uint8 byOpcode, bool bDontRemove = false);
 			bool InTrackListIsAllowedPacket(uint32 uIP, uint8 byOpcode, bool bValidReceiverkey);
 			void InTrackListCleanup();
Only in srchybrid_withpatch/kademlia/net: PacketTracking.h.bak

0

#20 User is offline   liubingshuang 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 11
  • Joined: 31-August 11

Posted 03 September 2011 - 07:20 AM

Please ignore the "*.bak" file. :angelnot:

View Postsonoro, on 02 September 2011 - 08:04 PM, said:

diff -urB srchybrid/ClientUDPSocket.cpp srchybrid_withpatch/ClientUDPSocket.cpp
--- srchybrid/ClientUDPSocket.cpp	2009-02-22 19:36:56.000000000 +0800
+++ srchybrid_withpatch/ClientUDPSocket.cpp	2011-08-31 10:48:16.000000000 +0800
@@ -62,7 +62,8 @@
     POSITION pos = controlpacket_queue.GetHeadPosition();
 	while (pos){
 		UDPPack* p = controlpacket_queue.GetNext(pos);
-		delete p->packet;
+		if(!p->bKad)//delete kad packet in packet resend method
+			delete p->packet;
 		delete p;
 	}
 }
@@ -523,7 +524,8 @@
                 sentBytes += nLen; // ZZ:UploadBandWithThrottler (UDP)
 
 				controlpacket_queue.RemoveHead();
-				delete cur_packet->packet;
+				if(!cur_packet->bKad)//delete kad packet in packet resend method
+					delete cur_packet->packet;
 				delete cur_packet;
             }
 			delete[] sendbuffer;
@@ -531,7 +533,8 @@
 		else
 		{
 			controlpacket_queue.RemoveHead();
-			delete cur_packet->packet;
+			if(!cur_packet->bKad)//delete kad packet in packet resend method
+				delete cur_packet->packet;
 			delete cur_packet;
 		}
 	}
Only in srchybrid_withpatch/: ClientUDPSocket.cpp.bak
diff -urB srchybrid/kademlia/kademlia/Kademlia.cpp srchybrid_withpatch/kademlia/kademlia/Kademlia.cpp
--- srchybrid/kademlia/kademlia/Kademlia.cpp	2010-03-10 18:57:44.000000000 +0800
+++ srchybrid_withpatch/kademlia/kademlia/Kademlia.cpp	2011-08-31 10:48:18.000000000 +0800
@@ -315,8 +315,10 @@
 		delete pContact;
 	}
 
-	if (GetUDPListener() != NULL)
+	if (GetUDPListener() != NULL){
 		GetUDPListener()->ExpireClientSearch(); // function does only one compare in most cases, so no real need for a timer
+		GetUDPListener()->ResendPackets();//resend no reply packets here
+	}
 }
 
 void CKademlia::AddEvent(CRoutingZone *pZone)
Only in srchybrid_withpatch/kademlia/kademlia: Kademlia.cpp.bak
diff -urB srchybrid/kademlia/kademlia/Search.cpp srchybrid_withpatch/kademlia/kademlia/Search.cpp
--- srchybrid/kademlia/kademlia/Search.cpp	2010-04-05 12:39:52.000000000 +0800
+++ srchybrid_withpatch/kademlia/kademlia/Search.cpp	2011-08-31 10:48:20.000000000 +0800
@@ -361,15 +361,28 @@
 	//Find contact that is responding.
 	CUInt128 uFromDistance((ULONG)0);
 	CContact* pFromContact = NULL;
+	CUInt128 uWeakFromDistance((ULONG)0);
+	CContact* pWeakFromContact = NULL;
 	for (ContactMap::const_iterator itContactMap = m_mapTried.begin(); itContactMap != m_mapTried.end(); ++itContactMap)
 	{
 		CContact* pTmpContact = itContactMap->second;
-		if ((pTmpContact->GetIPAddress() == uFromIP) && (pTmpContact->GetUDPPort() == uFromPort))
+		if ((pTmpContact->GetIPAddress() == uFromIP) && (pTmpContact->GetUDPPort() == uFromPort))//first find ip and port
 		{
 			uFromDistance = itContactMap->first;
 			pFromContact = pTmpContact;
 			break;
 		}
+		//if there are more than one contact having the same ip in m_mapTried, we chose the farthest one.
+		if(pTmpContact->GetIPAddress() == uFromIP && m_mapResponded.count(itContactMap->first) == 0)//if not find, find only ip
+		{
+			uWeakFromDistance = itContactMap->first;
+			pWeakFromContact = pTmpContact;
+		}
+	}
+	if(pFromContact == NULL)
+	{
+			uFromDistance = uWeakFromDistance;
+			pFromContact = pWeakFromContact;
 	}
 	
 	// Make sure the node is not sending more results than we requested, which is not only a protocol vialoation
@@ -400,7 +413,8 @@
 		// Add contacts to the History for GUI purposes
 		for (ContactList::iterator itContactList = plistResults->begin(); itContactList != plistResults->end(); ++itContactList)
 		{			
-			CUInt128 uDistance(((CContact*)*itContactList)->GetClientID().Xor(m_uTarget));
+			//CUInt128 uDistance(((CContact*)*itContactList)->GetClientID().Xor(m_uTarget));//there modfy (*itContactList)'s clientID by mistake
+			CUInt128 uDistance(CUInt128(((CContact*)*itContactList)->GetClientID()).Xor(m_uTarget));
 			m_pLookupHistory->ContactReceived(*itContactList, pFromContact, uDistance, uDistance < uFromDistance, true);
 		}
 		theApp.emuledlg->kademliawnd->UpdateSearchGraph(m_pLookupHistory);
Only in srchybrid_withpatch/kademlia/kademlia: Search.cpp.bak
diff -urB srchybrid/kademlia/net/KademliaUDPListener.cpp srchybrid_withpatch/kademlia/net/KademliaUDPListener.cpp
--- srchybrid/kademlia/net/KademliaUDPListener.cpp	2010-04-05 09:47:30.000000000 +0800
+++ srchybrid_withpatch/kademlia/net/KademliaUDPListener.cpp	2011-08-31 10:48:18.000000000 +0800
@@ -42,8 +42,8 @@
 #include "../routing/RoutingZone.h"
 #include "../io/ByteIO.h"
 #include "../../emule.h"
-#include "../../ClientUDPSocket.h"
-#include "../../Packets.h"
+//#include "../../ClientUDPSocket.h"
+//#include "../../Packets.h"
 #include "../../emuledlg.h"
 #include "../../KadContactListCtrl.h"
 #include "../../kademliawnd.h"
@@ -1172,6 +1172,11 @@
 		strError.Format(_T("***NOTE: Received wrong size (%u) packet in %hs"), uLenPacket, __FUNCTION__);
 		throw strError;
 	}
+	else if (!IsOnOutTrackList(uIP, KADEMLIA_SEARCH_REQ, true)){
+		CString strError;
+		strError.Format(_T("***NOTE: Received unrequested response packet, size (%u) in %hs"), uLenPacket, __FUNCTION__);
+		throw strError;
+	}
 
 	// What search does this relate to
 	CByteIO byteIO(pbyPacketData, uLenPacket);
@@ -1212,6 +1217,12 @@
 // Used in Kad2.0 only
 void CKademliaUDPListener::Process_KADEMLIA2_SEARCH_RES (const byte *pbyPacketData, uint32 uLenPacket, CKadUDPKey /*senderUDPKey*/, uint32 uIP, uint16 uUDPPort)
 {
+	//there may be more than one response packet
+	if (!IsOnOutTrackList(uIP, KADEMLIA2_SEARCH_KEY_REQ, true) && !IsOnOutTrackList(uIP, KADEMLIA2_SEARCH_SOURCE_REQ, true)){
+		CString strError;
+		strError.Format(_T("***NOTE: Received unrequested response packet, size (%u) in %hs"), uLenPacket, __FUNCTION__);
+		throw strError;
+	}
 	CByteIO byteIO(pbyPacketData, uLenPacket);
 
 	// Who sent this packet.
@@ -1592,6 +1603,11 @@
 // Used only by Kad2.0
 void CKademliaUDPListener::Process_KADEMLIA2_SEARCH_NOTES_REQ (const byte *pbyPacketData, uint32 uLenPacket, uint32 uIP, uint16 uUDPPort, CKadUDPKey senderUDPKey)
 {
+	if (!IsOnOutTrackList(uIP, KADEMLIA2_SEARCH_NOTES_REQ, true)){
+		CString strError;
+		strError.Format(_T("***NOTE: Received unrequested response packet, size (%u) in %hs"), uLenPacket, __FUNCTION__);
+		throw strError;
+	}
 	CSafeMemFile fileIO(pbyPacketData, uLenPacket);
 	CUInt128 uTarget;
 	fileIO.ReadUInt128(&uTarget);
@@ -2046,7 +2062,6 @@
 		ASSERT(0);
 		return;
 	}
-	AddTrackedOutPacket(uDestinationHost, pbyData[1]);
 	Packet* pPacket = new Packet(OP_KADEMLIAHEADER);
 	pPacket->opcode = pbyData[1];
 	pPacket->pBuffer = new char[uLenData+8];
@@ -2055,6 +2070,10 @@
 	if( uLenData > 200 )
 		pPacket->PackPacket();
 	theStats.AddUpDataOverheadKad(pPacket->size);
+	bool bAdd = true;
+	bAdd = AddTrackedOutPacket(uDestinationHost, uDestinationPort, ((const uchar*) (uCryptTargetID != NULL) ? uCryptTargetID->GetData() : NULL), targetUDPKey.GetKeyValue(theApp.GetPublicIP(false)), pPacket, pbyData[1]);
+	if(!bAdd)
+		return;
 	theApp.clientudp->SendPacket(pPacket, ntohl(uDestinationHost), uDestinationPort, true
 		, (uCryptTargetID != NULL) ? uCryptTargetID->GetData() : NULL
 		, true , targetUDPKey.GetKeyValue(theApp.GetPublicIP(false)));
@@ -2062,7 +2081,6 @@
 
 void CKademliaUDPListener::SendPacket(const byte *pbyData, uint32 uLenData, byte byOpcode, uint32 uDestinationHost, uint16 uDestinationPort, CKadUDPKey targetUDPKey, const CUInt128* uCryptTargetID)
 {
-	AddTrackedOutPacket(uDestinationHost, byOpcode);
 	Packet* pPacket = new Packet(OP_KADEMLIAHEADER);
 	pPacket->opcode = byOpcode;
 	pPacket->pBuffer = new char[uLenData];
@@ -2071,6 +2089,10 @@
 	if( uLenData > 200 )
 		pPacket->PackPacket();
 	theStats.AddUpDataOverheadKad(pPacket->size);
+	bool bAdd = true;
+	bAdd = AddTrackedOutPacket(uDestinationHost, uDestinationPort, ((const uchar*) (uCryptTargetID != NULL) ? uCryptTargetID->GetData() : NULL), targetUDPKey.GetKeyValue(theApp.GetPublicIP(false)), pPacket, byOpcode);
+	if(!bAdd)
+		return;
 	theApp.clientudp->SendPacket(pPacket, ntohl(uDestinationHost), uDestinationPort, true
 		, (uCryptTargetID != NULL) ? uCryptTargetID->GetData() : NULL
 		, true , targetUDPKey.GetKeyValue(theApp.GetPublicIP(false)));
@@ -2078,12 +2100,15 @@
 
 void CKademliaUDPListener::SendPacket(CSafeMemFile *pbyData, byte byOpcode, uint32 uDestinationHost, uint16 uDestinationPort, CKadUDPKey targetUDPKey, const CUInt128* uCryptTargetID)
 {
-	AddTrackedOutPacket(uDestinationHost, byOpcode);
 	Packet* pPacket = new Packet(pbyData, OP_KADEMLIAHEADER);
 	pPacket->opcode = byOpcode;
 	if( pPacket->size > 200 )
 		pPacket->PackPacket();
 	theStats.AddUpDataOverheadKad(pPacket->size);
+	bool bAdd = true;
+	bAdd = AddTrackedOutPacket(uDestinationHost, uDestinationPort,  ((const uchar*) (uCryptTargetID != NULL) ? uCryptTargetID->GetData() : NULL), targetUDPKey.GetKeyValue(theApp.GetPublicIP(false)), pPacket, byOpcode);
+	if(!bAdd)
+		return;
 	theApp.clientudp->SendPacket(pPacket, ntohl(uDestinationHost), uDestinationPort, true
 		, (uCryptTargetID != NULL) ? uCryptTargetID->GetData() : NULL
 		, true , targetUDPKey.GetKeyValue(theApp.GetPublicIP(false)));
Only in srchybrid_withpatch/kademlia/net: KademliaUDPListener.cpp.bak
diff -urB srchybrid/kademlia/net/PacketTracking.cpp srchybrid_withpatch/kademlia/net/PacketTracking.cpp
--- srchybrid/kademlia/net/PacketTracking.cpp	2010-03-09 23:33:04.000000000 +0800
+++ srchybrid_withpatch/kademlia/net/PacketTracking.cpp	2011-08-31 10:48:20.000000000 +0800
@@ -37,24 +37,61 @@
 }
 
 CPacketTracking::~CPacketTracking(){
+	for (POSITION pos = listTrackedRequests.GetTailPosition(); pos != NULL; listTrackedRequests.GetPrev(pos)){
+		delete listTrackedRequests.GetAt(pos).pPacket;
+		delete[]  listTrackedRequests.GetAt(pos).pachTargetClientHashORKadID;
+	}
 	m_mapTrackPacketsIn.RemoveAll();
 	while (!m_liTrackPacketsIn.IsEmpty())
 		delete m_liTrackPacketsIn.RemoveHead();
 }
 
-void CPacketTracking::AddTrackedOutPacket(uint32 dwIP, uint8 byOpcode){
+bool CPacketTracking::AddTrackedOutPacket(uint32 dwIP, uint16 nPort, const uchar* pachTargetClientHashORKadID, uint32 nReceiverVerifyKey, Packet* packet, uint8 byOpcode){
 	// this tracklist tacks _outgoing_ request packets, to make sure incoming answer packets were requested
 	// only track packets which we actually check for later
-	if (!IsTrackedOutListRequestPacket(byOpcode))
-		return;
-	TrackPackets_Struct sTrack = {dwIP, ::GetTickCount(), byOpcode};
+	if (!IsTrackedOutListRequestPacket(byOpcode)){
+		delete packet;
+		return false;
+	}
+	uchar* pachTargetClientHashORKadIDTmp = NULL;
+	if( pachTargetClientHashORKadID != NULL){
+		pachTargetClientHashORKadIDTmp =  new uchar[32];
+		memcpy(pachTargetClientHashORKadIDTmp, pachTargetClientHashORKadID, 32);
+	}
+	TrackPackets_Struct sTrack = {packet, dwIP, nPort, pachTargetClientHashORKadIDTmp, nReceiverVerifyKey, ::GetTickCount(), byOpcode, PACKET_RESEND_TIMES, false};
 	listTrackedRequests.AddHead(sTrack);
-	while (!listTrackedRequests.IsEmpty()){
-		if (::GetTickCount() - listTrackedRequests.GetTail().dwInserted > SEC2MS(180))
-			listTrackedRequests.RemoveTail();
-		else
+	//while (!listTrackedRequests.IsEmpty()){
+	//	if (::GetTickCount() - listTrackedRequests.GetTail().dwInserted > SEC2MS(180))
+	//		listTrackedRequests.RemoveTail();
+	//	else
+	//		break;
+	//}
+	return true;
+}
+
+void CPacketTracking::ResendPackets(){
+	CList<TrackPackets_Struct> listTrackedRequestsTmp;
+	for (POSITION pos = listTrackedRequests.GetTailPosition(); pos != NULL; listTrackedRequests.GetPrev(pos)){
+		TrackPackets_Struct& sTrack = listTrackedRequests.GetAt(pos);
+		if (::GetTickCount() - sTrack.dwInserted > SEC2MS(180)){//clean expired packet after 180 seconds
+			delete sTrack.pPacket;
+			delete[] sTrack.pachTargetClientHashORKadID;
+			listTrackedRequests.RemoveAt(pos);			
+		}else if(::GetTickCount() - sTrack.dwInserted >= PACKET_RESEND_INTERVAL){//resend packet
+			if(sTrack.nResendTimes > 0 && !sTrack.bRecv){
+				theApp.clientudp->SendPacket(sTrack.pPacket, ntohl(sTrack.dwIP), sTrack.nPort, true
+					, sTrack.pachTargetClientHashORKadID, true , sTrack.nReceiverVerifyKey);
+				sTrack.nResendTimes--;
+				sTrack.dwInserted = ::GetTickCount();
+				listTrackedRequestsTmp.AddHead(sTrack);
+				listTrackedRequests.RemoveAt(pos);
+			}
+		}else//these packets in front of this are not expired
 			break;
 	}
+
+	listTrackedRequests.AddHead(&listTrackedRequestsTmp);
+	listTrackedRequestsTmp.RemoveAll();
 }
 
 bool CPacketTracking::IsTrackedOutListRequestPacket(uint8 byOpcode) const
@@ -88,8 +125,14 @@
 #endif
 	for (POSITION pos = listTrackedRequests.GetHeadPosition(); pos != NULL; listTrackedRequests.GetNext(pos)){
 		if (listTrackedRequests.GetAt(pos).dwIP == dwIP && listTrackedRequests.GetAt(pos).byOpcode == byOpcode && ::GetTickCount() - listTrackedRequests.GetAt(pos).dwInserted < SEC2MS(180)){
-			if (!bDontRemove)
+			if (!bDontRemove){
+				delete listTrackedRequests.GetAt(pos).pPacket;
+				delete[] listTrackedRequests.GetAt(pos).pachTargetClientHashORKadID;
 				listTrackedRequests.RemoveAt(pos);
+			}
+			else{
+				listTrackedRequests.GetAt(pos).bRecv = true;
+			}
 			return true;
 		}
 	}
Only in srchybrid_withpatch/kademlia/net: PacketTracking.cpp.bak
diff -urB srchybrid/kademlia/net/PacketTracking.h srchybrid_withpatch/kademlia/net/PacketTracking.h
--- srchybrid/kademlia/net/PacketTracking.h	2008-08-30 12:12:52.000000000 +0800
+++ srchybrid_withpatch/kademlia/net/PacketTracking.h	2011-08-31 10:48:20.000000000 +0800
@@ -17,13 +17,23 @@
 
 #pragma once
 #include "../utils/UInt128.h"
+#include "../../ClientUDPSocket.h"
+#include "../../Packets.h"
 
 namespace Kademlia
 {
+#define PACKET_RESEND_TIMES			3
+#define PACKET_RESEND_INTERVAL		2000 //ms
 	struct TrackPackets_Struct{
+		Packet* pPacket;
 		uint32 dwIP;
+		uint16 nPort;
+		uchar* pachTargetClientHashORKadID;
+		uint32 nReceiverVerifyKey;
 		uint32 dwInserted;
 		uint8  byOpcode;
+		uint8 nResendTimes;
+		bool bRecv;//process multi-response packets
 	};
 
 	struct TrackChallenge_Struct{
@@ -53,10 +63,12 @@
 	{
 		public:
 			CPacketTracking();
+			void ResendPackets();
 			virtual ~CPacketTracking();
 
 		protected:
-			void AddTrackedOutPacket(uint32 dwIP, uint8 byOpcode);
+			//if return false, the opcode is wrong, so dont need send this packet
+			bool AddTrackedOutPacket(uint32 dwIP, uint16 nPort, const uchar* pachTargetClientHashORKadID, uint32 nReceiverVerifyKey, Packet* packet, uint8 byOpcode);
 			bool IsOnOutTrackList(uint32 dwIP, uint8 byOpcode, bool bDontRemove = false);
 			bool InTrackListIsAllowedPacket(uint32 uIP, uint8 byOpcode, bool bValidReceiverkey);
 			void InTrackListCleanup();
Only in srchybrid_withpatch/kademlia/net: PacketTracking.h.bak

1

  • Member Options

  • (2 Pages)
  • +
  • 1
  • 2

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users