JMule project forum

JMule - Java file sharing client
 

It is currently Thu Nov 23, 2017 1:17 pm

Your Ad Here


Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2, 3
Author Message
Offline
 Post subject: Re: Kademlia
PostPosted: Tue May 24, 2011 8:14 am 
 Profile

Joined: Wed May 18, 2011 8:40 am
Posts: 7
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.


Top
 

Offline
 Post subject: Re: Kademlia
PostPosted: Wed May 25, 2011 7:34 am 
JMule staff member
JMule staff member
 WWW  Profile

Joined: Fri Jul 11, 2008 4:34 pm
Posts: 43
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();
            }
               


Top
 

Offline
 Post subject: Re: Kademlia
PostPosted: Wed May 25, 2011 8:07 am 
 Profile

Joined: Wed May 18, 2011 8:40 am
Posts: 7
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!


Top
 

Offline
 Post subject: Re: Kademlia
PostPosted: Wed May 25, 2011 6:49 pm 
JMule staff member
JMule staff member
 WWW  Profile

Joined: Fri Jul 11, 2008 4:34 pm
Posts: 43
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 ?


Top
 

Offline
 Post subject: Re: Kademlia
PostPosted: Thu May 26, 2011 6:42 am 
 Profile

Joined: Wed May 18, 2011 8:40 am
Posts: 7
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?


Top
 

Offline
 Post subject: Re: Kademlia
PostPosted: Thu May 26, 2011 12:31 pm 
JMule staff member
JMule staff member
User avatar
 Profile

Joined: Fri Jul 11, 2008 4:10 pm
Posts: 33
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));


Top
 

Offline
 Post subject: Re: Kademlia
PostPosted: Thu May 26, 2011 1:44 pm 
 Profile

Joined: Wed May 18, 2011 8:40 am
Posts: 7
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:


Top
 

Offline
 Post subject: Re: Kademlia
PostPosted: Thu May 26, 2011 4:01 pm 
JMule staff member
JMule staff member
User avatar
 Profile

Joined: Fri Jul 11, 2008 4:10 pm
Posts: 33
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'.


Top
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 28 posts ]  Go to page Previous  1, 2, 3


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Contact : jmule [at] jmule.org
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group