net.i2p.data.Hash.create()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(131)

本文整理了Java中net.i2p.data.Hash.create()方法的一些代码示例,展示了Hash.create()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hash.create()方法的具体详情如下:
包路径:net.i2p.data.Hash
类名称:Hash
方法名:create

Hash.create介绍

[英]Pull from cache or return new
[中]从缓存中提取或返回新的

代码示例

代码示例来源: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

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

public void readMessage(byte data[], int offset, int dataSize, int type) throws I2NPMessageException {
  if (type != MESSAGE_TYPE) throw new I2NPMessageException("Message type is incorrect for this message");
  int curIndex = offset;
  
  //byte keyData[] = new byte[Hash.HASH_LENGTH];
  //System.arraycopy(data, curIndex, keyData, 0, Hash.HASH_LENGTH);
  _key = Hash.create(data, curIndex);
  curIndex += Hash.HASH_LENGTH;
  //_key = new Hash(keyData);
  
  int num = data[curIndex] & 0xff;
  curIndex++;
  
  _peerHashes.clear();
  for (int i = 0; i < num; i++) {
    //byte peer[] = new byte[Hash.HASH_LENGTH];
    //System.arraycopy(data, curIndex, peer, 0, Hash.HASH_LENGTH);
    Hash p = Hash.create(data, curIndex);
    curIndex += Hash.HASH_LENGTH;
    addReply(p);
  }
    
  //byte from[] = new byte[Hash.HASH_LENGTH];
  //System.arraycopy(data, curIndex, from, 0, Hash.HASH_LENGTH);
  _from = Hash.create(data, curIndex);
  curIndex += Hash.HASH_LENGTH;
  //_from = new Hash(from);
  //_context.statManager().addRateData("netDb.searchReplyMessageReceive", num*32 + 64, 1);
}

代码示例来源:origin: i2p/i2p.i2p

private static Hash getHash(String filename, String prefix, String suffix) {
  try {
    String key = filename.substring(prefix.length());
    key = key.substring(0, key.length() - suffix.length());
    //Hash h = new Hash();
    //h.fromBase64(key);
    byte[] b = Base64.decode(key);
    if (b == null)
      return null;
    Hash h = Hash.create(b);
    return h;
  } catch (RuntimeException e) {
    // static
    //_log.warn("Unable to fetch the key from [" + filename + "]", e);
    return null;
  }
}

代码示例来源:origin: i2p/i2p.i2p

protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
  if (size == 0) {
    _dest = null;
    _hash = null;
  } else {
    try {
      if (size == Hash.HASH_LENGTH) {
        _hash = Hash.create(in);
      } else {
        _dest = Destination.create(in);
      }
    } catch (DataFormatException dfe) {
      _dest = null;
      _hash = null;
    }
  }
}

代码示例来源:origin: i2p/i2p.i2p

@Override
public void readBytes(InputStream in) throws DataFormatException, IOException {
  _gateway = Hash.create(in);
  // flags
  DataHelper.skip(in, 2);
  _type = in.read();
  _cost = in.read();
  _end = new Date(DataHelper.readLong(in, 4) * 1000);
}

代码示例来源:origin: i2p/i2p.i2p

/**
 * Calculate the hash and cache the result.
 * @param source what to hash
 */
public final Hash calculateHash(byte[] source, int start, int len) {
  MessageDigest digest = acquire();
  digest.update(source, start, len);
  byte rv[] = digest.digest();
  release(digest);
  return Hash.create(rv);
}

代码示例来源:origin: i2p/i2p.i2p

private Hash getHash(String name) {
  String key = name.substring(PREFIX.length());
  key = key.substring(0, 44);
  //Hash h = new Hash();
  try {
    //h.fromBase64(key);
    byte[] b = Base64.decode(key);
    if (b == null)
      return null;
    Hash h = Hash.create(b);
    return h;
  } catch (RuntimeException dfe) {
    _log.warn("Invalid base64 [" + key + "]", dfe);
    return null;
  }
}

代码示例来源:origin: i2p/i2p.i2p

byte[] b = Base32.decode(nlc.substring(0, 52));
if (b != null && b.length == Hash.HASH_LENGTH) {
  h = Hash.create(b);
  name = null;

代码示例来源:origin: i2p/i2p.i2p

@Override
public void readBytes(InputStream in) throws DataFormatException, IOException {
  _gateway = Hash.create(in);
  _tunnelId = new TunnelId();
  _tunnelId.readBytes(in);
  _end = new Date(DataHelper.readLong(in, 4) * 1000);
}

代码示例来源:origin: i2p/i2p.i2p

/**
 * No Destination yet available
 * @param compactInfo 20 byte node ID, 32 byte destHash, 2 byte port
 * @param offset starting at this offset in compactInfo
 * @throws IllegalArgumentException
 * @throws ArrayIndexOutOfBoundsException
 */
public NodeInfo(byte[] compactInfo, int offset) {
  super();
  byte[] d = new byte[LENGTH];
  System.arraycopy(compactInfo, offset, d, 0, LENGTH);
  setData(d);
  byte[] ndata = new byte[NID.HASH_LENGTH];
  System.arraycopy(d, 0, ndata, 0, NID.HASH_LENGTH);
  this.nID = new NID(ndata);
  this.hash = Hash.create(d, NID.HASH_LENGTH);
  this.port = (int) DataHelper.fromLong(d, NID.HASH_LENGTH + Hash.HASH_LENGTH, 2);
  if (port <= 0 || port >= 65535)
    throw new IllegalArgumentException("Bad port");
  verify();
}

代码示例来源:origin: i2p/i2p.i2p

public void readBytes(InputStream in) throws DataFormatException, IOException {
  //_gateway = new Hash();
  //_gateway.readBytes(in);
  _gateway = Hash.create(in);
  _tunnelId = new TunnelId();
  _tunnelId.readBytes(in);
  _end = DataHelper.readDate(in);
}

代码示例来源:origin: i2p/i2p.i2p

byte[] b = Base64.decode(peer);
if (b != null && b.length == Hash.HASH_LENGTH)
  return Hash.create(b);
byte[] b = Base64.decode(peer.substring(0, 44));
if (b != null && b.length == Hash.HASH_LENGTH)
  return Hash.create(b);
byte[] b = Base32.decode(peer.substring(0, 52));
if (b != null && b.length == Hash.HASH_LENGTH)
  return Hash.create(b);
byte[] b = Base32.decode(peer);
if (b != null && b.length == Hash.HASH_LENGTH)
  return Hash.create(b);

代码示例来源:origin: i2p/i2p.i2p

/**
 *  rcv 32 byte Hashes, return as a List
 *  @throws NPE, IllegalArgumentException, and others too
 */
private List<Hash> receivePeers(NodeInfo nInfo, List<BEValue> peers) throws InvalidBEncodingException {
  if (_log.shouldLog(Log.INFO))
     _log.info("Rcvd peers from: " + nInfo);
  int max = Math.min(MAX_WANT * 2, peers.size());
  List<Hash> rv = new ArrayList<Hash>(max);
  for (BEValue bev : peers) {
    byte[] b = bev.getBytes();
    if (b.length != Hash.HASH_LENGTH) {
      if (_log.shouldWarn())
        _log.info("Bad peers entry from: " + nInfo);
      continue;
    }
    //Hash h = new Hash(b);
    Hash h = Hash.create(b);
    rv.add(h);
    if (rv.size() >= max)
      break;
  }
  if (_log.shouldLog(Log.INFO))
     _log.info("Rcvd " + peers.size() + " peers from: " + nInfo + ": " + DataHelper.toString(rv));
  return rv;
}

代码示例来源:origin: i2p/i2p.i2p

Hash key = Hash.create(h);
Destination rv = null;
I2PClient client = new I2PSimpleClient();

代码示例来源:origin: i2p/i2p.i2p

@Override
protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
  try {
    _sessionId = new SessionId();
    _sessionId.readBytes(in);
    int numTunnels = (int) DataHelper.readLong(in, 1);
    _endpoints.clear();
    for (int i = 0; i < numTunnels; i++) {
      //Hash router = new Hash();
      //router.readBytes(in);
      Hash router = Hash.create(in);
      TunnelId tunnel = new TunnelId();
      tunnel.readBytes(in);
      _endpoints.add(new TunnelEndpoint(router, tunnel));
    }
    _end = DataHelper.readDate(in);
  } catch (DataFormatException dfe) {
    throw new I2CPMessageException("Unable to load the message data", dfe);
  }
}

代码示例来源:origin: i2p/i2p.i2p

if (b != null) {
  Hash h = Hash.create(b);
  if (_log.shouldLog(Log.INFO))
    _log.info("Using existing session for lookup of " + ip);

代码示例来源:origin: i2p/i2p.i2p

protected void doReadMessage(InputStream in, int size) throws I2CPMessageException, IOException {
  try {
    _sessionId = new SessionId();
    _sessionId.readBytes(in);
    _reqID = DataHelper.readLong(in, 4);
    _timeout = DataHelper.readLong(in, 4);
    _lookupType = (int) DataHelper.readLong(in, 1);
    if (_lookupType == LOOKUP_HASH) {
      _hash = Hash.create(in);
    } else if (_lookupType == LOOKUP_HOST) {
      _host = DataHelper.readString(in);
      if (_host.length() == 0)
        throw new I2CPMessageException("bad host");
    } else {
      throw new I2CPMessageException("bad type");
    }
  } catch (DataFormatException dfe) {
    throw new I2CPMessageException("bad data", dfe);
  }
}

代码示例来源:origin: i2p/i2p.i2p

/**
 * Create from persistent storage string.
 * Format: NID:Hash:Destination:port
 * First 3 in base 64; Destination may be empty string
 * @throws IllegalArgumentException
 */
public NodeInfo(String s) throws DataFormatException {
  super();
  String[] parts = DataHelper.split(s, ":", 4);
  if (parts.length != 4)
    throw new DataFormatException("Bad format");
  byte[] nid = Base64.decode(parts[0]);
  if (nid == null || nid.length != NID.HASH_LENGTH)
    throw new DataFormatException("Bad NID");
  nID = new NID(nid);
  byte[] h = Base64.decode(parts[1]);
  if (h == null || h.length != Hash.HASH_LENGTH)
    throw new DataFormatException("Bad hash");
  //hash = new Hash(h);
  hash = Hash.create(h);
  if (parts[2].length() > 0)
    dest = new Destination(parts[2]);
  try {
    port = Integer.parseInt(parts[3]);
  } catch (NumberFormatException nfe) {
    throw new DataFormatException("Bad port", nfe);
  }
  initialize();
}

代码示例来源:origin: i2p/i2p.i2p

byte[] b = Base32.decode(nlc.substring(0, 52));
if (b != null && b.length == Hash.HASH_LENGTH) {
  h = Hash.create(b);

相关文章