org.klomp.snark

## Class PeerID

- java.lang.Object
- - org.klomp.snark.PeerID

- All Implemented Interfaces:
    Comparable<PeerID>

      public class PeerID
      extends Object
      implements Comparable<PeerID>

  Store the address information about a peer. Prior to 0.8.1, an instantiation required a peer ID, and full Destination address. Starting with 0.8.1, to support compact tracker responses, a PeerID can be instantiated with a Destination Hash alone. The full destination lookup is deferred until getAddress() is called, and the PeerID is not required. Equality is now determined solely by the dest hash.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PeerID(BDecoder be)` Creates a PeerID from a BDecoder.
    `PeerID(byte[] id, Destination address)`
    `PeerID(byte[] dest_hash, I2PSnarkUtil util)` Creates a PeerID from a destHash
    `PeerID(Map<String,BEValue> m)` Creates a PeerID from a Map containing BEncoded peer id, ip and port.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `equals(Object o)` Two PeerIDs are equal when they have the same dest hash
    `Destination` | `getAddress()` Get the destination.
    `byte[]` | `getDestHash()`
    `byte[]` | `getID()`
    `int` | `getPort()`
    `int` | `hashCode()` The hash code of a PeerID is the hashcode of the desthash
    `static String` | `idencode(byte[] bs)` Encode an id as a hex encoded string and remove leading zeros.
    `boolean` | `sameID(PeerID pid)` Returns true if and only if this peerID and the given peerID have the same destination hash
    `void` | `setID(byte[] xid)` for connecting out to peer based on desthash @since 0.8.1
    `String` | `toString()` Returns the String "id@address" where id is the first 4 chars of the base64 encoded id and address is the first 6 chars of the base64 dest (was the base64 hash of the dest) which should match what the bytemonsoon tracker reports on its web pages.

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

    - ### Methods inherited from interface java.lang.Comparable

      `compareTo`

- - ### Constructor Detail

    - #### PeerID

          public PeerID(BDecoder be)
                 throws IOException

      Creates a PeerID from a BDecoder.
      Throws:
        `IOException`

    - #### PeerID

          public PeerID(byte[] id,
                        Destination address)

    - #### PeerID

          public PeerID(byte[] dest_hash,
                        I2PSnarkUtil util)
                 throws InvalidBEncodingException

      Creates a PeerID from a destHash
      Parameters:
        `util` - for eventual destination lookup
      Throws:
        `InvalidBEncodingException`

    - #### PeerID

          public PeerID(Map<String,BEValue> m)
                 throws InvalidBEncodingException,
                        UnknownHostException

      Creates a PeerID from a Map containing BEncoded peer id, ip and port.
      Throws:
        `InvalidBEncodingException`
        `UnknownHostException`

  - ### Method Detail

    - #### equals

          public boolean equals(Object o)

      Two PeerIDs are equal when they have the same dest hash
      Overrides:
        `equals` in class `Object`

    - #### getAddress

          public Destination getAddress()

      Get the destination. If this PeerId was instantiated with a destHash, and we have not yet done so, lookup the full destination, which may take up to 10 seconds.
      Returns:
        Dest or null if unknown

    - #### getDestHash

          public byte[] getDestHash()

    - #### getID

          public byte[] getID()

    - #### getPort

          public int getPort()

    - #### hashCode

          public int hashCode()

      The hash code of a PeerID is the hashcode of the desthash
      Overrides:
        `hashCode` in class `Object`

    - #### idencode

          public static String idencode(byte[] bs)

      Encode an id as a hex encoded string and remove leading zeros.

    - #### sameID

          public boolean sameID(PeerID pid)

      Returns true if and only if this peerID and the given peerID have the same destination hash

    - #### setID

          public void setID(byte[] xid)

      for connecting out to peer based on desthash @since 0.8.1

    - #### toString

          public String toString()

      Returns the String "id@address" where id is the first 4 chars of the base64 encoded id and address is the first 6 chars of the base64 dest (was the base64 hash of the dest) which should match what the bytemonsoon tracker reports on its web pages.
      Overrides:
        `toString` in class `Object`