aMule Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

We're back! (IN POG FORM)

Pages: [1] 2

Author Topic: nodes.dat self destructed  (Read 12430 times)

Stu Redman

  • Administrator
  • Hero Member
  • *****
  • Karma: 214
  • Offline Offline
  • Posts: 3739
  • Engines screaming
nodes.dat self destructed
« on: April 01, 2008, 12:06:28 AM »

I've seen a few times that aMule killed my nodes.dat.  :o  It was either completely empty (4 bytes), or very small, so that at the next start KAD boot failed.
So I added a sanity check: write file only if a minimum of 50 contacts is available. Maximum is 200, therefore I think 50 could be a sensible threshold.

To make the KAD boot really reliable more drastic measures would be necessary:
- for each contact, store date when it was first seen under that IP, and when last (change of file format!)
- prefer storing contacts with static adresses (available for a long time) to dynamic contacts. Don't drop static contacts at once if they were just one time not there.
I don't know if that's really necessary, but it might do away with the KAD booting problems.

Code: [Select]
Index: src/kademlia/routing/RoutingZone.cpp
===================================================================
--- src/kademlia/routing/RoutingZone.cpp (revision 8312)
+++ src/kademlia/routing/RoutingZone.cpp (working copy)
@@ -154,9 +154,11 @@
  unsigned int count = 0;
  CContact *c;
  CFile file;
- if (file.Open(m_filename, CFile::write)) {
- ContactList contacts;
- GetBootstrapContacts(&contacts, 200);
+ ContactList contacts;
+ int found = GetBootstrapContacts(&contacts, 200);
+ if ( found < 50) {
+ AddDebugLogLineM( false, logKadRouting, wxString::Format(wxT("Only %d contactsavailable, file not written."), count));
+ } else if (file.Open(m_filename, CFile::write)) {
  file.WriteUInt32((uint32)std::min((int)contacts.size(), CONTACT_FILE_LIMIT));
  ContactList::const_iterator it;
  for (it = contacts.begin(); it != contacts.end(); ++it) {
Logged
The image of mother goddess, lying dormant in the eyes of the dead, the sheaf of the corn is broken, end the harvest, throw the dead on the pyre -- Iron Maiden, Isle of Avalon

Kry

  • Ex-developer
  • Retired admin
  • Hero Member
  • *****
  • Karma: -665
  • Offline Offline
  • Posts: 5795
Re: nodes.dat self destructed
« Reply #1 on: April 01, 2008, 12:27:47 AM »

Format can't be changed.
Logged

Stu Redman

  • Administrator
  • Hero Member
  • *****
  • Karma: 214
  • Offline Offline
  • Posts: 3739
  • Engines screaming
Re: nodes.dat self destructed
« Reply #2 on: April 01, 2008, 11:26:53 PM »

Why ? It's not compatible with eMule anyway.  :P
Besides, the little patch above changes nothing in the format.

Code: [Select]
aMule:
file.WriteUInt32((uint32)std::min((int)contacts.size(), CONTACT_FILE_LIMIT));
ContactList::const_iterator it;
for (it = contacts.begin(); it != contacts.end(); ++it) {
count++;
c = *it;
file.WriteUInt128(c->GetClientID());
file.WriteUInt32(c->GetIPAddress());
file.WriteUInt16(c->GetUDPPort());
file.WriteUInt16(c->GetTCPPort());
file.WriteUInt8(c->GetType());
if (count == CONTACT_FILE_LIMIT) {
break;
}
}


eMule 0.48a:
// Start file with 0 to prevent older clients from reading it.
file.WriteUInt32(0);
// Now tag it with a version which happens to be 1.
file.WriteUInt32(1);
file.WriteUInt32((uint32)listContacts.size());
for (ContactList::const_iterator itContactList = listContacts.begin(); itContactList != listContacts.end(); ++itContactList)
{
CContact* pContact = *itContactList;
pContact->GetClientID(&uID);
file.WriteUInt128(&uID);
file.WriteUInt32(pContact->GetIPAddress());
file.WriteUInt16(pContact->GetUDPPort());
file.WriteUInt16(pContact->GetTCPPort());
file.WriteUInt8(pContact->GetVersion());
}



Logged
The image of mother goddess, lying dormant in the eyes of the dead, the sheaf of the corn is broken, end the harvest, throw the dead on the pyre -- Iron Maiden, Isle of Avalon

Kry

  • Ex-developer
  • Retired admin
  • Hero Member
  • *****
  • Karma: -665
  • Offline Offline
  • Posts: 5795
Re: nodes.dat self destructed
« Reply #3 on: April 02, 2008, 01:25:22 AM »

It is compatible with emule, actually. Kinda.
Logged

Stu Redman

  • Administrator
  • Hero Member
  • *****
  • Karma: 214
  • Offline Offline
  • Posts: 3739
  • Engines screaming
Re: nodes.dat self destructed
« Reply #4 on: April 02, 2008, 10:25:26 PM »

"Kinda" meaning, eMule can read aMule's nodes.dat and aMule can't read eMule's. Now I know what the nodes.dat posts in the problem forum are about.  ;D

I've extended the fix so aMule can now read eMule's nodes.dat too. Now the usability of downloaded nodes.dats should rise from 2% to 100%.  ;)
Still no change in the file format.
Logged
The image of mother goddess, lying dormant in the eyes of the dead, the sheaf of the corn is broken, end the harvest, throw the dead on the pyre -- Iron Maiden, Isle of Avalon

GonoszTopi

  • The current man in charge of most things.
  • Administrator
  • Hero Member
  • *****
  • Karma: 169
  • Offline Offline
  • Posts: 2685
Re: nodes.dat self destructed
« Reply #5 on: April 03, 2008, 11:47:54 PM »

Your patch makes aMule an incompatible client for the Kademlia network.

Sorry, but that's just not that easy.
Logged
concordia cum veritate

Stu Redman

  • Administrator
  • Hero Member
  • *****
  • Karma: 214
  • Offline Offline
  • Posts: 3739
  • Engines screaming
Re: nodes.dat self destructed
« Reply #6 on: April 04, 2008, 12:09:41 AM »

Huh ?  ???

There are two parts in the patch:
1) allow loading of nodes.dat in eMule format (and of course existing files from aMule)
2) adding sanity check before saving (of course you could lower the 50 contact limit I set)

Now how does this make aMule an incompatible client for the Kademlia network? It is connecting fine to Kad here with the patch.

as it is now
1) aMule doesn't load nodes.dat from eMule (no of entries is wrongly interpreted as 0)
2) aMule happily writes empty nodes.dat under some conditions (like after startup with a hung up router and a quick exit). THIS effectively cuts the client off Kad, and 1) makes it very hard to get back because downloading a nodes.dat is pointless.

If I'm overlooking something please point it out for me. Just "breaks aMule" is not helpful, no matter how often you repeat it.  ::)
Logged
The image of mother goddess, lying dormant in the eyes of the dead, the sheaf of the corn is broken, end the harvest, throw the dead on the pyre -- Iron Maiden, Isle of Avalon

GonoszTopi

  • The current man in charge of most things.
  • Administrator
  • Hero Member
  • *****
  • Karma: 169
  • Offline Offline
  • Posts: 2685
Re: nodes.dat self destructed
« Reply #7 on: April 04, 2008, 12:19:17 AM »

Ok, then after being able to read the file, aMule must also be able to interpret its contents properly. That's what is missing from your patch.
Logged
concordia cum veritate

Stu Redman

  • Administrator
  • Hero Member
  • *****
  • Karma: 214
  • Offline Offline
  • Posts: 3739
  • Engines screaming
Re: nodes.dat self destructed
« Reply #8 on: April 04, 2008, 12:38:33 AM »

The content is identical (see comparison of sources above), except that the new eMule Format has a leading 00000000 00000001.
The code of the patch is original eMule code.
I have run patched aMule with eMule nodes.dat RIGHT NOW and it read the contacts and connected just fine.

I am still not getting your point.
Logged
The image of mother goddess, lying dormant in the eyes of the dead, the sheaf of the corn is broken, end the harvest, throw the dead on the pyre -- Iron Maiden, Isle of Avalon

GonoszTopi

  • The current man in charge of most things.
  • Administrator
  • Hero Member
  • *****
  • Karma: 169
  • Offline Offline
  • Posts: 2685
Re: nodes.dat self destructed
« Reply #9 on: April 04, 2008, 01:44:18 AM »

~10 lines below the first fragment you changed (reading the file):
Code: [Select]
uint8 uContactVersion = 0;
byte byType = 0;
if(uVersion == 1)
uContactVersion = file.ReadUInt8();
else
byType = file.ReadUInt8();
and everything that it implies.
« Last Edit: April 04, 2008, 01:45:50 AM by GonoszTopi »
Logged
concordia cum veritate

Stu Redman

  • Administrator
  • Hero Member
  • *****
  • Karma: 214
  • Offline Offline
  • Posts: 3739
  • Engines screaming
Re: nodes.dat self destructed
« Reply #10 on: April 04, 2008, 10:48:26 PM »

You are right. Well, you could have explained the problem in your first post instead of sphinxing around the way you did.  ::)

Back to post one. You implemented the nodes.dat loader, but the WriteFile is still without sanity check.
Logged
The image of mother goddess, lying dormant in the eyes of the dead, the sheaf of the corn is broken, end the harvest, throw the dead on the pyre -- Iron Maiden, Isle of Avalon

Stu Redman

  • Administrator
  • Hero Member
  • *****
  • Karma: 214
  • Offline Offline
  • Posts: 3739
  • Engines screaming
Re: nodes.dat self destructed
« Reply #11 on: April 06, 2008, 07:12:24 PM »

Anyway, the important bug fixing here is on part 2:
Yes.

Sturednan , could you post a stripped version of you patch fixing sanity checks on nodes.dat file writes only?
I believe GonoszTopy shouldn't be against committing that.

It's in the first post of the thread. And if anybody agreed with us and found it worth commiting, they would have done it.  :-X
Logged
The image of mother goddess, lying dormant in the eyes of the dead, the sheaf of the corn is broken, end the harvest, throw the dead on the pyre -- Iron Maiden, Isle of Avalon

GonoszTopi

  • The current man in charge of most things.
  • Administrator
  • Hero Member
  • *****
  • Karma: 169
  • Offline Offline
  • Posts: 2685
Re: nodes.dat self destructed
« Reply #12 on: April 14, 2008, 01:27:58 AM »

BtW: it just wrote a 12 byte nodes.dat AGAIN.  Do you like it that way ? ::)

Do you like to store dead contacts?
Logged
concordia cum veritate

mr_hyde

  • Global Moderator
  • Full Member
  • *****
  • Karma: 12
  • Offline Offline
  • Posts: 105
Re: nodes.dat self destructed
« Reply #13 on: April 14, 2008, 08:55:10 AM »

Noticed the same problem: only 12 bytes of nodes.dat (I suppose the 12 bytes of header).

Probably it should be better to understand WHY the contacts list becomes empty.

In the meanwhile, IMHO,  it's "preferable" to have a OLD nodes.dat file (even if it contains dead contacts) instead of a zero contact file: the zero contact file (12 bytes only nodes.dat) causes to my aMule to remain in "Contacting..." status.

Bye,
  Mr Hyde
Logged

Stu Redman

  • Administrator
  • Hero Member
  • *****
  • Karma: 214
  • Offline Offline
  • Posts: 3739
  • Engines screaming
Re: nodes.dat self destructed
« Reply #14 on: April 14, 2008, 09:07:04 PM »

Do you like to store dead contacts?
No. But how do you get the idea they are "dead" ?
I tell you what I did. I started aMule twice, each time checking the directory tree in the settings menu, and then closed it again. Each time KAD connected fine meanwhile. Third time I started it, it did NOT connect at all (Kad Graph stayed at zero), and nodes.dat was empty.
Do you truely want to consider any contact as "dead" after only 30s of uptime ?

I don't know what exactly causes this misconsideration, but writing a zero file just makes no sense. I'd go as far to rather keep 3k of "dead" contacts along with 1k of "live" ones than just the live ones. Maybe they are really just fine and just a half hung up router caused them to be considered as dead.

As it is now, every user has to manually back up his nodes.dat (the LOG of all things is backed up, but not the nodes.dat  ::) ) or risk being cut off and go hunting for a download (which at least works now again). I call this a flaw.
Logged
The image of mother goddess, lying dormant in the eyes of the dead, the sheaf of the corn is broken, end the harvest, throw the dead on the pyre -- Iron Maiden, Isle of Avalon
Pages: [1] 2