## net.i2p.client.streaming
Class PacketHandler

    java.lang.Object
      net.i2p.client.streaming.PacketHandler

     class PacketHandler

extends Object

receive a packet and dispatch it correctly to the connection specified, the server socket, or queue a reply RST packet.

Constructor Summary
`PacketHandler(I2PAppContext ctx, ConnectionManager mgr)`

Method Summary
`(package private) void` `displayPacket(Packet packet, String prefix, String suffix)`

`(package private) void`

`receivePacket(Packet packet)`
private boolean choke(Packet packet) { if (true) return true; //if ( (_dropped == 0) && true ) { //&& (_manager.getSent() <= 0) ) { // _dropped++; // return false; //} if (true) { // artificial choke: 2% random drop and a 0-5s // random tiered delay from 0-30s if (_context.random().nextInt(100) >= 98) { displayPacket(packet, "DROP", null); return false; } else { // if (true) return true; // no lag, just drop // int delay = _context.random().nextInt(5*1000); int delay = _context.random().nextInt(1*1000); int delayFactor = _context.random().nextInt(100); if (delayFactor > 80) { if (delayFactor > 98) delay *= 5; else if (delayFactor > 95) delay *= 4; else if (delayFactor > 90) delay *= 3; else delay *= 2; } if (_context.random().nextInt(100) >= 20) delay = _lastDelay; _lastDelay = delay; SimpleTimer.getInstance().addEvent(new Reinject(packet, delay), delay); return false; } } else { return true; } } private class Reinject implements SimpleTimer.TimedEvent { private Packet _packet; private int _delay; public Reinject(Packet packet, int delay) { _packet = packet; _delay = delay; } public void timeReached() { _log.debug("Reinjecting after " + _delay + ": " + _packet); receivePacketDirect(_packet); } }

`(package private) void` `receivePacketDirect(Packet packet, boolean queueIfNoConn)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### PacketHandler

    public PacketHandler(I2PAppContext ctx,
                         ConnectionManager mgr)

Method Detail

### receivePacket

    void receivePacket(Packet packet)

  private boolean choke(Packet packet) { if (true) return true; //if ( (_dropped == 0) && true ) { //&& (_manager.getSent() <= 0) ) { // _dropped++; // return false; //} if (true) { // artificial choke: 2% random drop and a 0-5s // random tiered delay from 0-30s if (_context.random().nextInt(100) >= 98) { displayPacket(packet, "DROP", null); return false; } else { // if (true) return true; // no lag, just drop // int delay = _context.random().nextInt(5*1000); int delay = _context.random().nextInt(1*1000); int delayFactor = _context.random().nextInt(100); if (delayFactor > 80) { if (delayFactor > 98) delay *= 5; else if (delayFactor > 95) delay *= 4; else if (delayFactor > 90) delay *= 3; else delay *= 2; } if (_context.random().nextInt(100) >= 20) delay = _lastDelay; _lastDelay = delay; SimpleTimer.getInstance().addEvent(new Reinject(packet, delay), delay); return false; } } else { return true; } } private class Reinject implements SimpleTimer.TimedEvent { private Packet _packet; private int _delay; public Reinject(Packet packet, int delay) { _packet = packet; _delay = delay; } public void timeReached() { _log.debug("Reinjecting after " + _delay + ": " + _packet); receivePacketDirect(_packet); } }

### receivePacketDirect

    void receivePacketDirect(Packet packet,
                             boolean queueIfNoConn)

### displayPacket

    void displayPacket(Packet packet,
                       String prefix,
                       String suffix)