|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectoogp2p.pastry.PastryLocation
Represents a Pastry identifier for a node, object or key. A single identifier and the bit length for Ids is stored in this class. Ids are stored little endian.
| Nested Class Summary | |
static class |
PastryLocation.Distance
A class for representing and manipulating the distance between two Ids on the circle. |
| Field Summary | |
static int[] |
Half
|
protected int[] |
Id
|
static int |
IdBitLength
This is the bit length of the node ids. |
private java.lang.String |
IPaddr
|
protected static java.security.MessageDigest |
md
|
static int[] |
NegOne
|
protected static int |
nlen
|
static int[] |
Null
|
static int[] |
One
|
| Constructor Summary | |
PastryLocation()
Constructor. |
|
PastryLocation(byte[] material)
Constructor. |
|
PastryLocation(int[] material)
Constructor. |
|
PastryLocation(java.lang.String str)
|
|
PastryLocation(java.lang.String IP,
int port)
Creates a new PastryLocation from a given IP and port. |
|
| Method Summary | |
private int[] |
absDistance(PastryLocation nid)
Returns the absolute numerical distance between a pair of Ids. |
PastryLocation |
add(PastryLocation.Distance offset)
Returns an Id corresponding to this Id plus a given distance |
PastryLocation |
addToId(PastryLocation.Distance offset)
Returns an Id corresponding to this Id plus a given distance |
void |
blit(byte[] target)
Blits the Id into a target array. |
boolean |
checkBit(int i)
Checks if the ith bit is flipped. |
boolean |
clockwise(PastryLocation nid)
Checks to see if the Id nid is clockwise or counterclockwise from this, on the ring. |
int |
compareTo(java.lang.Object obj)
Comparison operator for Ids. |
byte[] |
copy()
Copy the Id into a freshly generated array. |
PastryLocation.Distance |
distance(PastryLocation nid)
Returns the shorter numerical distance on the ring between a pair of Ids. |
PastryLocation.Distance |
distanceFromId(PastryLocation nid)
Returns the shorter numerical distance on the ring between a pair of Ids. |
boolean |
equals(java.lang.Object obj)
Equality operator for Ids. |
boolean |
equals(PastryLocation nid)
Equivalence relation for Ids. |
protected void |
generateFromBytes(byte[] material)
Generates the pastry location information given the hash in byte array form. |
PastryLocation |
getAlternateId(int num,
int b,
int i)
produces a set of ids (keys) that are evenly distributed around the id ring. |
PastryLocation |
getCCW()
gets the Id just counterclockwise from this |
PastryLocation |
getCW()
gets the Id just clockwise from this |
int |
getDigit(int i,
int b)
Gets the ith digit in base 2^b. |
PastryLocation |
getDomainPrefix(int row,
int column,
int suffixDigit,
int b)
produces a Id whose prefix up to row is identical to this, followed by a digit with value column, followed by a suffix of digits with value suffixDigits. |
static byte[] |
getHash(java.lang.String str)
Hashes a string. |
int[] |
getID()
|
java.net.InetAddress |
getIP()
|
int |
hashCode()
Hash codes for Ids. |
int |
indexOfMSDB(PastryLocation nid)
Returns the index of the most significant differing bit (MSDB). |
int |
indexOfMSDD(PastryLocation nid,
int base)
Returns the index of the most significant different digit (MSDD) in a given base. |
private void |
invert(int[] dist)
inverts the distance value stored in an integer array (computes 0-value) |
boolean |
isBetween(PastryLocation ccw,
PastryLocation cw)
Checks if this Id is between two given ids ccw (inclusive) and cw (exclusive) on the circle |
PastryLocation.Distance |
longDistance(PastryLocation nid)
Returns the longer numerical distance on the ring between a pair of Ids. |
PastryLocation.Distance |
longDistanceFromId(PastryLocation nid)
Returns the longer numerical distance on the ring between a pair of Ids. |
static PastryLocation |
makeRandomId(java.util.Random rng)
Creates a random Id. |
static int |
numDigits(int base)
return the number of digits in a given base |
void |
setBit(int i,
int v)
Sets the ith bit to a given value i = 0 is the least significant bit. |
void |
setDigit(int i,
int v,
int b)
Sets the ith digit in base 2^b. |
byte[] |
toByteArray()
Returns the byte array representation of this Id |
java.lang.String |
toString()
Returns a string representation of the Id in base 16. |
java.lang.String |
toStringFull()
Returns the complete represntation of this Id, in hex. |
void |
xor(PastryLocation otherId)
Xor operator for Ids. |
| Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
private java.lang.String IPaddr
protected static java.security.MessageDigest md
public static final int[] Null
public static final int[] One
public static final int[] NegOne
public static final int[] Half
public static final int IdBitLength
protected static final int nlen
protected int[] Id
| Constructor Detail |
public PastryLocation(byte[] material)
material - an array of length at least IdBitLength/8 containing raw Id material.public PastryLocation(int[] material)
material - an array of length at least IdBitLength/32 containing raw Id material.
public PastryLocation(java.lang.String IP,
int port)
IP - string ip in address (not hostname) formport - public PastryLocation(java.lang.String str)
public PastryLocation()
| Method Detail |
public static byte[] getHash(java.lang.String str)
str - -- str to be hashed
protected void generateFromBytes(byte[] material)
material - -- hash value in byte arraypublic static int numDigits(int base)
base - the number of bits in the base
public static PastryLocation makeRandomId(java.util.Random rng)
rng - random number generator
public java.net.InetAddress getIP()
public int[] getID()
public PastryLocation getCW()
public PastryLocation getCCW()
public boolean isBetween(PastryLocation ccw,
PastryLocation cw)
ccw - the counterclockwise idcw - the clockwise id
public int getDigit(int i,
int b)
i - which digit to get.b - which power of 2 is the base to get it in.
public PastryLocation getDomainPrefix(int row,
int column,
int suffixDigit,
int b)
row - the length of the prefixcolumn - the value of the following digitsuffixDigit - the value of the suffix digitsb - power of 2 of the base
public PastryLocation getAlternateId(int num,
int b,
int i)
num - the number of Ids in the set (must be <= 2^b)b - the routing base (as a power of 2)i - the index of the requested member of the set (0<=i
public void setBit(int i,
int v)
i - which bit to set.v - new value of bit
public void setDigit(int i,
int v,
int b)
i - which digit to get.v - the new value of the digitb - which power of 2 is the base to get it in.public void blit(byte[] target)
target - an array of length at least IdBitLength/8 for the Id to be stored in.public byte[] copy()
public boolean equals(java.lang.Object obj)
obj - a Id object
public int compareTo(java.lang.Object obj)
obj - the Id to compare with.
public byte[] toByteArray()
public int hashCode()
public PastryLocation add(PastryLocation.Distance offset)
offset - the distance to add
public PastryLocation.Distance distance(PastryLocation nid)
nid - the other node id.
public PastryLocation.Distance longDistance(PastryLocation nid)
nid - the other node id.
public void xor(PastryLocation otherId)
otherId - a Id objectpublic boolean equals(PastryLocation nid)
nid - the other node id.
public boolean clockwise(PastryLocation nid)
nid - The Id we are comparing to
public boolean checkBit(int i)
i - which bit to check.
public int indexOfMSDB(PastryLocation nid)
nid - another node id to compare with.
public int indexOfMSDD(PastryLocation nid,
int base)
nid - another node id to compare with.base - the base (as a power of two) to compare in.
public java.lang.String toString()
public java.lang.String toStringFull()
public PastryLocation addToId(PastryLocation.Distance offset)
offset - the distance to add
public PastryLocation.Distance distanceFromId(PastryLocation nid)
nid - the other node id.
public PastryLocation.Distance longDistanceFromId(PastryLocation nid)
nid - the other node id.
private int[] absDistance(PastryLocation nid)
nid - the other node id.
private void invert(int[] dist)
dist - the distance value
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||