/** * @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; }
/** * Copied/modded from PersistentDataStore */ private static String getRouterInfoName(Hash hash) { String b64 = hash.toBase64(); return ROUTERINFO_PREFIX + b64 + ROUTERINFO_SUFFIX; } }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof PeerProfile)) return false; PeerProfile prof = (PeerProfile)obj; return _peer.equals(prof._peer); }
/** * 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); }
public DataStructure createStructureToRead() { return new Hash(); } }
@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(); }
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();
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);
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(); }
/** @throws IllegalArgumentException if data is not 32 bytes (null is ok) */ public Hash(byte data[]) { super(); setData(data); }
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; }
private static Hash generateRandomKey() { byte hash[] = new byte[Hash.HASH_LENGTH]; RandomSource.getInstance().nextBytes(hash); return new Hash(hash); }
@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(); }
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();
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(); }