aMule Forum

English => en_Bugs => Topic started by: xsun on October 29, 2006, 01:51:10 AM

Title: Bug in CKademliaUDPListener::addContacts()
Post by: xsun on October 29, 2006, 01:51:10 AM
The following code is in KademliaUDPListener.cpp (aMule 2.1.3), which contains a bug:
...
void CKademliaUDPListener::addContacts( const byte *data, uint32 lenData, uint16 numContacts)
{
   CMemFile bio((byte*)data, lenData );
   CRoutingZone *routingZone = CKademlia::getRoutingZone();
   for (uint16 i=0; i      CUInt128 id = bio.ReadUInt128();
      uint32 ip = bio.ReadUInt32();
      ip = wxUINT32_SWAP_ALWAYS(ip);
      uint16 port = bio.ReadUInt16();
      uint16 tport = bio.ReadUInt16();
      byte type = bio.ReadUInt8();
      //AddDebugLogLineM(false, logKadMain, wxT("Adding contact(s) with ip ") + Uint32_16toStringIP_Port(wxUINT32_SWAP_ALWAYS(ip),port));
      if (IsGoodIPPort(wxUINT32_SWAP_ALWAYS(ip),port)) {
         routingZone->add(id, ip, port, tport, type);
      }
   }
}
 ...

Note that in the above code the statement
ip = wxUINT32_SWAP_ALWAYS(ip);
should be removed. Because the changing from network order to host order has already been done in bio.ReadUInt32():

//the following code is in SafeFile.cpp
uint32 CFileDataIO::ReadUInt32() const
{
   uint32 value = 0;
   Read(&value, 4);
   
   return ENDIAN_SWAP_32(value);
}

//the following code is in ArchSpecific.h
#define ENDIAN_SWAP_32(x) (wxUINT32_SWAP_ON_BE(x))

//the following code is in defs.h
#define wxUINT32_SWAP_ON_BE(val)  wxUINT32_SWAP_ALWAYS(val)
Title: Re: Bug in CKademliaUDPListener::addContacts()
Post by: Kry on October 29, 2006, 02:48:21 AM
Are you really, really sure? ;)
Title: Re: Bug in CKademliaUDPListener::addContacts()
Post by: xsun on October 29, 2006, 03:08:57 AM
Yes, because I've done some tests.. Also, please compare with the same addContacts() function in eMule.

Quote
Originally posted by Kry
Are you really, really sure? ;)
Title: Re: Bug in CKademliaUDPListener::addContacts()
Post by: xsun on October 29, 2006, 03:28:25 AM
More specifically, one test could be, whether we can talk to anyone we learned from the  KADEMLIA_BOOTSTRAP_RES messages. I tried to send KADEMLIA_HELLO_REQ to all nodes I had learned from KADEMLIA_BOOTSTRAP_RES messages, but none of them replied me. However after I commented the problmatic line,  I became able to get responses. I repeated several times the results are the same.

Quote
Originally posted by xsun
Yes, because I've done some tests.. Also, please compare with the same addContacts() function in eMule.

Quote
Originally posted by Kry
Are you really, really sure? ;)