On Wed, 2 Aug 2000 hal at finney.org wrote:

> Bram writes:
> 
> > I'm trying to change the logic to decide which neigbor to send a file to
> > to be based on comparison in a ring - where's the code which does this? I
> > just spent a while trying to figure it out.
> 
> Changing the forwarding logic should not be done lightly, as it is important
> that all nodes use the same logic so that requests can find inserted data.
> 
> However, the basic function is findClosestKey in node/StandardDataStore.java.

The following is a patch to support/StringKey.java which makes all the
nodes get about the same number of blobs, fixing the problem that ones
whose ids are at the extremes get significantly fewer.

73c73,78
<               for (int x=0; true; x++)
---
>               int c0 = ringCharComp(this.charAt(0), 
> k1.charAt(0),k2.charAt(0));
>               if (c0 == 1)
>                       return true;
>               else if (c0 == -1)
>                       return false;
>               for (int x=1; true; x++)
87c92,109
<   
---
> 
>   private int ringCharComp(char c, char c1, char c2)
>     {
>       d1 = Math.abs(Character.getNumericValue(c) - 
>                   Character.getNumericValue(c1));
>       d2 = Math.abs(Character.getNumericValue(c) - 
>                   Character.getNumericValue(c2));
>       if (d1 > 128)
>         d1 = 128 - d1;
>       if (d2 > 128)
>         d2 = 128 - d2;
>       if (d1 < d2)
>         return 1;
>       if (d1 > d2)
>         return -1;
>       return 0;
>     }
> 

-Bram Cohen


_______________________________________________
Freenet-dev mailing list
Freenet-dev at lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/freenet-dev

Reply via email to