JMule project forum
http://forum.jmule.org/

Kademlia
http://forum.jmule.org/viewtopic.php?f=7&t=15
Page 3 of 3

Author:  bimmel [ Tue May 24, 2011 8:14 am ]
Post subject:  Re: Kademlia

And thanks one more time.

But I have one more question :P

I have experimented with publishing notes. Well, publishing notes works. I can see them with my ordinary eMule client. But searching notes with the JMule code doesn't work for me (I get no results). Have you ever tried this? Unfortunately I didn't find a code sample for searching notes.

Author:  javajox [ Wed May 25, 2011 7:34 am ]
Post subject:  Re: Kademlia

This functionality is implemented at the core level only. We didn't build a GUI for it (you could implement it in GUI if you want, and we'll add you code to the main code-base :) ).
Here is an example how it works :
Code:
    byte[] bhash = org.jmule.core.utils.Convert.hexStringToByte("55221c0d118ad84db3733d889d924d62");
        try {
                    jkad.getSearch().searchNotes(new Int128(bhash), new SearchResultListener() {
                       
                        @Override
                        public void searchStarted() {
                            System.out.println("searchStarted");
                        }
                       
                        @Override
                        public void searchFinished() {
                            System.out.println("searchFinished");
                        }
                       
                        @Override
                        public void processNewResults(List<Source> result) {
                            System.out.println("Results...");
                            for(Source s : result) {
                                System.out.println(s.getTagList());
                            }
                        }
                    }, 1732292);
            } catch (JKadException e) {
                  e.printStackTrace();
            }
               

Author:  bimmel [ Wed May 25, 2011 8:07 am ]
Post subject:  Re: Kademlia

Sorry, but I am not a GUI expert.

Great, your example works fine. But why doesn't it work if I create the Int128 Object in this way? (This was the way I tried it):

Code:
new Int128(new FileHash("55221c0d118ad84db3733d889d924d62")


This is also the way I use to publish a note and in this direction it works.

Many Thanks!

Author:  javajox [ Wed May 25, 2011 6:49 pm ]
Post subject:  Re: Kademlia

I don't know, probably you missed something. Or that filehash hasn't associated any notes ? Or that filehash does not exist in the network, or a lot of other things... Did you specified the correct file size ?

Author:  bimmel [ Thu May 26, 2011 6:42 am ]
Post subject:  Re: Kademlia

Yes, I am sure the note is published. I publish it with the same hash before and can see it with my eMule client. And if I create the Int128 object from a byte array (as you did) instead of a FileHash object, the search is successful. So, is there any difference whether I create an Int128 object from a byte array or from a FileHash object? But it doesn't really mater. I can just use the byte array way :). At the moment I use

Code:
new Int128(new FileHash("55221c0d118ad84db3733d889d924d62"))


to publish the note. But

Code:
byte[] bhash = org.jmule.core.utils.Convert.hexStringToByte("55221c0d118ad84db3733d889d924d62");
Int128 fileHash = new Int128(bhash);


to search it. This works for me. I think the problem is that I don't understand why this

Code:
String hashString = "16F7712E5863F2759C55901BA8036F5D";
byte[] bhash = org.jmule.core.utils.Convert.hexStringToByte(hashString);
Int128 fileHash1 = new Int128(bhash);
Int128 fileHash2 = new Int128(new FileHash(hashString));
System.out.println(fileHash1.equals(fileHash2));


is false. JavaDoc says something about byte reverse in the Int128(FileHash fileHash) constructor. But why don't you do this if the Int128 object is created from a FileHash object?

Author:  binary256 [ Thu May 26, 2011 12:31 pm ]
Post subject:  Re: Kademlia

In eMule file hash is used and stored as sequence of 16 bytes, in Kad file hash is used as sequence of 16 bytes but is stored into 4 integers(little endian encoding), example :
Code:
File hash : 20 99 5A 92  7D 44 FD 10  2E 23 88 32  3F 11 88 81
Stored as : 92 5A 99 20  10 FD 44 7D  32 88 23 2E  81 88 11 3F
So if you want to create file hash for Kad you must reverse bytes with org.jmule.core.utils.reverseArray() :
Code:
       String hashString = "16F7712E5863F2759C55901BA8036F5D";
      byte[] bhash = org.jmule.core.utils.Convert.hexStringToByte(hashString);
      Int128 fileHash1 = new Int128(bhash);
         
      ByteBuffer reversed = Misc.getByteBuffer(16);
      ByteBuffer tmp = Misc.getByteBuffer(4);
      for(int i = 0;i<16;i+=4) {
         tmp.clear();
         tmp.put(bhash, i, 4);
         reversed.put(Convert.reverseArray(tmp.array()));
      }
      
      Int128 fileHash2 = new Int128(new FileHash(reversed.array()));
      System.out.println(fileHash1.equals(fileHash2));

Author:  bimmel [ Thu May 26, 2011 1:44 pm ]
Post subject:  Re: Kademlia

ah OK. Things are different in eMule and KAD. I think I got this point now :).

But now you made me curious. What is the reason why I have to publish the note with a non reversed fileId

Code:
publisher.publishNote(new Int128(new FileHash(hashString)),
new PublishItem(new FileHash(hashString), tagList));


but search it with a reversed one? Is it because of the distance calculation in the LookupTask (ClientID is non reversed)?

Quote:
this.targetDistance = Utils.XOR(targetID, _jkad_manager.getClientID());


and in the Search class in the searchNotes() method you reverse again?

Code:
Convert.updateSearchID(t);


Sorry for my silly questions. It is a little bit confusing if you don't know the code a goog as you do. But I think I understand it now :geek:

Author:  binary256 [ Thu May 26, 2011 4:01 pm ]
Post subject:  Re: Kademlia

all Int128(ClientID) are reversed and processed in sequence order. Search, Lookup, Publisher etc.converts automatically file hash to Int128 and reverse.
You just try to mix elements from different subsystems : Int128 is used internally in 'Kad' and FileHash in 'eMule'.

Page 3 of 3 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/