public TunnelId getTunnelIdObj() { if (_tunnelIdObj == null) _tunnelIdObj = new TunnelId(_tunnelId); // not thread safe, but immutable, so who cares return _tunnelIdObj; }
/** * (correctly) Invalidates stored checksum */ public void setTunnelId(TunnelId id) { _hasChecksum = false; _tunnelIdObj = id; _tunnelId = id.getTunnelId(); }
public DataStructure createDataStructure() throws DataFormatException { TunnelId id = new TunnelId(); id.setTunnelId(42); return id; } public DataStructure createStructureToRead() { return new TunnelId(); }
for (int i = 0; i < size; i++) { _leases.get(i).getGateway().writeBytes(baos); _leases.get(i).getTunnelId().writeBytes(baos); h.readBytes(bais); l.setGateway(h); TunnelId t = new TunnelId(); t.readBytes(bais); l.setTunnelId(t); l.setEndDate(_leases.get(i).getEndDate());
int curIndex = offset; _tunnelId = new TunnelId(DataHelper.fromLong(data, curIndex, 4)); curIndex += 4; if (_tunnelId.getTunnelId() <= 0) throw new I2NPMessageException("Invalid tunnel Id " + _tunnelId);
/** * @param id 1 to 0xffffffff * @throws IllegalArgumentException if less than or equal to zero or greater than max value */ public TunnelId(long id) { setTunnelId(id); }
@Override public boolean equals(Object obj) { if (obj == null || !(obj instanceof ReplyTunnel)) return false; return this.h.equals(((ReplyTunnel)obj).h) && this.id.equals(((ReplyTunnel)obj).id); }
@Override public void writeBytes(OutputStream out) throws DataFormatException, IOException { if ((_gateway == null) || (_tunnelId == null)) throw new DataFormatException("Not enough data to write out a Lease"); _gateway.writeBytes(out); _tunnelId.writeBytes(out); DataHelper.writeLong(out, 4, _end.getTime() / 1000); }
@Override public int hashCode() { return this.h.hashCode() ^ this.id.hashCode(); } }
for (int i = 0; i < size; i++) { _leases.get(i).getGateway().writeBytes(baos); _leases.get(i).getTunnelId().writeBytes(baos); h.readBytes(bais); _leases.get(i).setGateway(h); TunnelId t = new TunnelId(); t.readBytes(bais); _leases.get(i).setTunnelId(t);
public TunnelInfo getTunnel(TunnelId gatewayId) { synchronized (_tunnels) { for (int i = 0; i < _tunnels.size(); i++) { TunnelInfo info = _tunnels.get(i); if (_settings.isInbound()) { if (info.getReceiveTunnelId(0).equals(gatewayId)) return info; } else { if (info.getSendTunnelId(0).equals(gatewayId)) return info; } } } return null; }
public void writeBytes(OutputStream out) throws DataFormatException, IOException { if ((_gateway == null) || (_tunnelId == null)) throw new DataFormatException("Not enough data to write out a Lease"); _gateway.writeBytes(out); _tunnelId.writeBytes(out); DataHelper.writeDate(out, _end); }
private static TunnelId getTunnel(byte id[]) { if (id == null) return null; else return new TunnelId(DataHelper.fromLong(id, 0, id.length)); }
@Override public int hashCode() { return (int) _end.getTime() ^ DataHelper.hashCode(_gateway) ^ (int) _tunnelId.getTunnelId(); } }
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(); }
@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); } }
if (_lease.getTunnelId().equals(lease.getTunnelId()) && _lease.getGateway().equals(lease.getGateway())) { if (_log.shouldLog(Log.INFO))
@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if (_sessionId == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); ByteArrayOutputStream os = new ByteArrayOutputStream(256); try { _sessionId.writeBytes(os); DataHelper.writeLong(os, 1, _endpoints.size()); for (int i = 0; i < _endpoints.size(); i++) { Hash router = getRouter(i); router.writeBytes(os); TunnelId tunnel = getTunnelId(i); tunnel.writeBytes(os); } DataHelper.writeDate(os, _end); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }