org.klomp.snark
Class PeerID

java.lang.Object
  extended by org.klomp.snark.PeerID
All Implemented Interfaces:
java.lang.Comparable

public class PeerID
extends java.lang.Object
implements java.lang.Comparable


Constructor Summary
PeerID(BDecoder be)
          Creates a PeerID from a BDecoder.
PeerID(byte[] id, Destination address)
           
PeerID(java.util.Map m)
          Creates a PeerID from a Map containing BEncoded peer id, ip and port.
 
Method Summary
 int compareTo(java.lang.Object o)
          Compares port, address and id.
 boolean equals(java.lang.Object o)
          Two PeerIDs are equal when they have the same id, address and port.
 Destination getAddress()
           
 byte[] getID()
           
 int getPort()
           
 int hashCode()
          The hash code of a PeerID is the exclusive or of all id bytes.
static java.lang.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 20 bytes as ID.
 java.lang.String toString()
          Returns the String "id@address" where id is the base64 encoded id and address is 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
 

Constructor Detail

PeerID

public PeerID(byte[] id,
              Destination address)

PeerID

public PeerID(BDecoder be)
       throws java.io.IOException
Creates a PeerID from a BDecoder.

Throws:
java.io.IOException

PeerID

public PeerID(java.util.Map m)
       throws InvalidBEncodingException,
              java.net.UnknownHostException
Creates a PeerID from a Map containing BEncoded peer id, ip and port.

Throws:
InvalidBEncodingException
java.net.UnknownHostException
Method Detail

getID

public byte[] getID()

getAddress

public Destination getAddress()

getPort

public int getPort()

hashCode

public int hashCode()
The hash code of a PeerID is the exclusive or of all id bytes.

Overrides:
hashCode in class java.lang.Object

sameID

public boolean sameID(PeerID pid)
Returns true if and only if this peerID and the given peerID have the same 20 bytes as ID.


equals

public boolean equals(java.lang.Object o)
Two PeerIDs are equal when they have the same id, address and port.

Overrides:
equals in class java.lang.Object

compareTo

public int compareTo(java.lang.Object o)
Compares port, address and id.

Specified by:
compareTo in interface java.lang.Comparable

toString

public java.lang.String toString()
Returns the String "id@address" where id is the base64 encoded id and address is 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 java.lang.Object

idencode

public static java.lang.String idencode(byte[] bs)
Encode an id as a hex encoded string and remove leading zeros.