Dev:HexHash

Aus YaCyWiki
Wechseln zu: Navigation, Suche

HexHash

The hexhash of a peer hash is an encoding of the 12 characters in Enhanced-Base64 encoding from the 72-bit hash into a representation using only hexadecimal values. The 12-charcter hash is first decoded into a set of 9 8-bit bytes and then encoded to hex. This results in 18 hex characters for an initial 12-character base64 String.

The following methods may illustrate how the hexhash is computed:

public static String b64Hash2hexHash(final String b64Hash) {
    // the hash string represents 12 * 6 bit = 72 bits.
    return Digest.encodeHex(Base64Order.enhancedCoder.decode(b64Hash));
}
public static String encodeHex(final byte[] in) {
    final StringBuilder result = new StringBuilder(in.length * 2);
    for (final byte element : in) {
        if ((0Xff & element) < 16) result.append('0');
        result.append(Integer.toHexString(0Xff & element));
    }
    return result.toString();
}

The hexhash is used mainly if a YaCy peer contacts another peer and addresses the remote peer (additionally) using the HTTP/1.1 Host-Attribute inside the http header. A typical header line for the 'Host' attribute using a hexhash host name looks like this:

Host: d7841c7477a57de875.yacyh