ChordID.getDistance() returns negative value

Home Forums PeerfactSim Forum ChordID.getDistance() returns negative value

This topic contains 2 replies, has 1 voice, and was last updated by  Dennis 3 years, 2 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #915

    Dennis

    I stumple accross some unusual behavior. I pretty sure it is a bug,
    but I need confirmation 🙂

    The distance method of the chord node class is defined as followed:

    public int getDistance(ChordID id) {
    BigInteger oid = id.getValue();
    return this.id.subtract(oid).abs().intValue();
    }

    I assumed that abs() is returning the absolute value of the BigInteger
    oid as explained in the corresponding javadoc. Therefore I thought
    that the distance is always positive. But my debugging showed that
    this is not the case.
    Is this a bug?

    P.S.: I helped myself by using Math.abs() on the return value.

    #916

    Matthias Feldotto

    I think there is a bigger problem. The method abs() of BigInteger
    should work correctly. The problem occurs by using the method
    intValue().

    BigInteger can contain values which do not fit into a normal integer.
    Because of the overflow you get negative values.

    To work with it correctly, change the return type of the method to
    BigInteger and remove the call of intValue() at the end. You only have
    to make two self-explanatory changes in other classes
    (de.tud.kom.p2psim.impl.overlay.dht.chord.base.components.AbstractChordContact
    and
    de.tud.kom.p2psim.impl.overlay.dht.chord.rechord.components.ChordRoutingTable)
    to make the code compile clean.

    The bug will be fixed in the next simulator version for all users.

    #917

    Dennis

    you are right. the problem lies in the intValue() function. Although
    it is quite difficult to express the difference of two 160bit numbers
    in a 32bit number… most of the time this won’t work.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.

Comments are closed