2009-10-30 02:06:04: Wrote 2 contacts to file. 2009-10-30 02:06:04: Wrote 2 contacts to file. 2009-10-30 02:06:04: Kad merged 1 Zones
^^ I've been noticing for quite a time that a nodes.dat containing 200 nodes is overwritten with just 1 or 2 nodes occasionally. The mule is running 24/7 and this has been happening after approximately 24h. Recently I've discovered it can happen a bit earlier too. Normally this is not a problem as a more functional nodes.dat will be saved when KAD is stopped or eMule is closed. But if something happens in between so that eMule is not closed properly, you'll end up with a bit short nodes.dat. With just one or two nodes the chances is high that you can't connect to the network and IMO it's better to not touch the old one as it can be used for many months. Especially the special nodes.dat.
After checking the KAD source I think I've found what's causing this behaviour.
The root zone (CRoutingZone::CRoutingZone()) is initialized when Kademlia is started with it's m_pSuperZone set to NULL (Init(NULL, 0, CUInt128((ULONG)0))), which is also one of the conditions for reading the nodes.dat (CRoutingZone::Init) and written to it (CRoutingZone::~CRoutingZone())
CRoutingZone::~CRoutingZone()
{
// Root node is processed first so that we can write our contact list and delete all branches.
if ((m_pSuperZone == NULL) && (m_sFilename.GetLength() > 0))
{
// Hide contacts in the GUI
theApp.emuledlg->kademliawnd->HideContacts();
WriteFile();
}
// If this zone is a leaf, delete our contact bin.
if (IsLeaf())
delete m_pBin;
else
(..)
}This makes me believe that the intention is that nodes.dat should be read when the root zone is created and written to when the root zone is destroyed.
But in (CRoutingZone::Consolidate()), which is called from CKademlia::Process() every 45 minutes, under a certain condition two subzones's superzone's are set to Null before the subzones are destructed which if I have got it right explains why only a few nodes is saved in nodes.dat.
uint32 CRoutingZone::Consolidate()
{
(..)
if( m_pSubZones[0]->IsLeaf() && m_pSubZones[1]->IsLeaf() && GetNumContacts() < K/2 )
{
(..)
m_pSubZones[0]->m_pSuperZone = NULL; // <-- Can safely be removed ?
m_pSubZones[1]->m_pSuperZone = NULL; // <-- ditto
m_pSubZones[0]->m_pBin->m_bDontDeleteContacts = true;
m_pSubZones[1]->m_pBin->m_bDontDeleteContacts = true;
delete m_pSubZones[0]; // <-- destroyed when it's m_pSuperZone == NULL
delete m_pSubZones[1]; // <-- destroyed when it's m_pSuperZone == NULL
m_pSubZones[0] = NULL;
m_pSubZones[1] = NULL;
(..)
}I'm running a test now that will confirm my thoughts - I hope..
This post has been edited by Nissenice: 15 November 2009 - 06:50 PM










Sign In
Register



