本文整理了Java中net.i2p.data.Hash
类的一些代码示例,展示了Hash
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hash
类的具体详情如下:
包路径:net.i2p.data.Hash
类名称:Hash
[英]Defines the hash as defined by the I2P data structure spec. A hash is the SHA-256 of some data, taking up 32 bytes.
[中]根据I2P数据结构规范定义哈希。哈希是某些数据的SHA-256,占用32字节。
代码示例来源:origin: i2p/i2p.i2p
/**
* @param target key to compare distances with
* @param avoidZeroHop if true, zero-hop tunnels will be put last
*/
public TunnelInfoComparator(Hash target, boolean avoidZeroHop) {
_base = target.getData();
_avoidZero = avoidZeroHop;
}
代码示例来源:origin: i2p/i2p.i2p
/**
* Copied/modded from PersistentDataStore
*/
private static String getRouterInfoName(Hash hash) {
String b64 = hash.toBase64();
return ROUTERINFO_PREFIX + b64 + ROUTERINFO_SUFFIX;
}
}
代码示例来源:origin: i2p/i2p.i2p
@Override
public boolean equals(Object obj) {
if (obj == null ||
!(obj instanceof PeerProfile))
return false;
PeerProfile prof = (PeerProfile)obj;
return _peer.equals(prof._peer);
}
代码示例来源:origin: i2p/i2p.i2p
/** not thread safe */
private HashComparator(Hash h) {
_hash = h;
tmp = new Hash(new byte[Hash.HASH_LENGTH]);
data = new byte[2*Hash.HASH_LENGTH];
System.arraycopy(_hash.getData(), 0, data, Hash.HASH_LENGTH, Hash.HASH_LENGTH);
}
代码示例来源:origin: i2p/i2p.i2p
public DataStructure createDataStructure() throws DataFormatException {
Hash hash = new Hash();
byte data[] = new byte[32];
for (int i = 0; i < data.length; i++)
data[i] = (byte)(i%16);
hash.setData(data);
return hash;
}
public DataStructure createStructureToRead() { return new Hash(); }
代码示例来源:origin: i2p/i2p.i2p
byte tunnelIds[][] = new byte[numHops][4];
for (int i = 0; i < numHops; i++) {
peers[i] = new Hash();
peers[i].setData(new byte[Hash.HASH_LENGTH]);
_context.random().nextBytes(peers[i].getData());
_context.random().nextBytes(tunnelIds[i]);
代码示例来源:origin: i2p/i2p.i2p
/**
* Read the next hop from the record. If this is the outbound tunnel endpoint, this specifies
* the gateway to which the reply should be sent.
*/
public Hash readNextIdentity() {
//byte rv[] = new byte[Hash.HASH_LENGTH];
//System.arraycopy(_data, OFF_SEND_IDENT, rv, 0, Hash.HASH_LENGTH);
//return new Hash(rv);
return Hash.create(_data, OFF_SEND_IDENT);
}
代码示例来源:origin: i2p/i2p.i2p
public DataStructure createStructureToRead() { return new Hash(); }
}
代码示例来源:origin: i2p/i2p.i2p
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("Transient DataStore: ").append(_data.size()).append("\nKeys: ");
for (Map.Entry<Hash, DatabaseEntry> e : _data.entrySet()) {
Hash key = e.getKey();
DatabaseEntry dp = e.getValue();
buf.append("\n\t*Key: ").append(key.toString()).append("\n\tContent: ").append(dp.toString());
}
buf.append("\n");
return buf.toString();
}
代码示例来源:origin: i2p/i2p.i2p
ByteArrayOutputStream baos = new ByteArrayOutputStream(datalen);
for (int i = 0; i < size; i++) {
_leases.get(i).getGateway().writeBytes(baos);
_leases.get(i).getTunnelId().writeBytes(baos);
for (int i = 0; i < size-1; i++) {
Lease l = new Lease();
Hash h = new Hash();
h.readBytes(bais);
l.setGateway(h);
TunnelId t = new TunnelId();
代码示例来源:origin: i2p/i2p.i2p
private void addRandom(int count) {
for (int i = 0; i < count; i++) {
byte val[] = new byte[Hash.HASH_LENGTH];
context.random().nextBytes(val);
Hash h = new Hash(val);
// in the highly unlikely chance we randomly generate a hash equal to us
assertTrue(set.add(h) || h.equals(usHash));
}
}
代码示例来源:origin: i2p/i2p.i2p
if (us == null)
return true;
boolean usf = from.equals(us);
if (usf && ctx.commSystem().isEstablished(to))
return true;
boolean ust = to.equals(us);
if (ust && ctx.commSystem().isEstablished(from))
return true;
if (!rv && log.shouldWarn()) {
log.warn("Cannot connect: " +
(usf ? "us" : from.toString()) + " with mask " + cf + "\nto " +
(ust ? "us" : to.toString()) + " with mask " + ct);
代码示例来源:origin: i2p/i2p.i2p
protected byte[] doWriteMessage() throws I2CPMessageException, IOException {
if (_hash == null)
throw new I2CPMessageException("Unable to write out the message as there is not enough data");
ByteArrayOutputStream os = new ByteArrayOutputStream(Hash.HASH_LENGTH);
try {
_hash.writeBytes(os);
} catch (DataFormatException dfe) {
throw new I2CPMessageException("Error writing out the hash", dfe);
}
return os.toByteArray();
}
代码示例来源:origin: i2p/i2p.i2p
/** @throws IllegalArgumentException if data is not 32 bytes (null is ok) */
public Hash(byte data[]) {
super();
setData(data);
}
代码示例来源:origin: i2p/i2p.i2p
byte tunnelIds[][] = new byte[numHops][4];
for (int i = 0; i < numHops; i++) {
peers[i] = new Hash();
peers[i].setData(new byte[Hash.HASH_LENGTH]);
_context.random().nextBytes(peers[i].getData());
_context.random().nextBytes(tunnelIds[i]);
代码示例来源:origin: i2p/i2p.i2p
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
//Hash h = new Hash();
try {
//h.readBytes(in);
_hash = Hash.create(in);
//} catch (DataFormatException dfe) {
} catch (IllegalArgumentException dfe) {
throw new I2CPMessageException("Unable to load the hash", dfe);
}
//_hash = h;
}
代码示例来源:origin: i2p/i2p.i2p
private static Hash generateRandomKey() {
byte hash[] = new byte[Hash.HASH_LENGTH];
RandomSource.getInstance().nextBytes(hash);
return new Hash(hash);
}
代码示例来源:origin: i2p/i2p.i2p
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
if (_dest != null)
buf.append(_dest.calculateHash().toString());
else
buf.append(_host);
buf.append(':');
buf.append(_port);
return buf.toString();
}
代码示例来源:origin: i2p/i2p.i2p
ByteArrayOutputStream baos = new ByteArrayOutputStream(datalen);
for (int i = 0; i < size; i++) {
_leases.get(i).getGateway().writeBytes(baos);
_leases.get(i).getTunnelId().writeBytes(baos);
Hash h = new Hash();
h.readBytes(bais);
_leases.get(i).setGateway(h);
TunnelId t = new TunnelId();
代码示例来源:origin: i2p/i2p.i2p
public DataStructure createDataStructure() throws DataFormatException {
DeliveryInstructions instructions = new DeliveryInstructions();
//instructions.setDelayRequested(true);
//instructions.setDelaySeconds(42);
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_TUNNEL);
// encryption key read/write disabled
//instructions.setEncrypted(true);
//SessionKey key = new SessionKey();
//byte keyData[] = new byte[SessionKey.KEYSIZE_BYTES];
//for (int i = 0; i < keyData.length; i++)
// keyData[i] = (byte)i;
//key.setData(keyData);
//instructions.setEncryptionKey(key);
Hash hash = new Hash();
byte hashData[] = new byte[32];
for (int i = 0; i < hashData.length; i++)
hashData[i] = (byte)(i%32);
hash.setData(hashData);
instructions.setRouter(hash);
TunnelId id = new TunnelId();
id.setTunnelId(666);
instructions.setTunnelId(id);
return instructions;
}
public DataStructure createStructureToRead() { return new DeliveryInstructions(); }
内容来源于网络,如有侵权,请联系作者删除!