public synchronized void tick() {


        if (unchoked.size() == maxUnchoked && interested.size() > maxUnchoked) {
            long now = System.currentTimeMillis();
            Peer slowest = null;
            for (Map.Entry<Peer, Long> e : unchoked.entrySet()) {

                if (now - e.getValue() > 10000) {
                    if (slowest == null) {
                        slowest = e.getKey();
                    } else {
                        if ((float) slowest.getDownloaded() / (now - unchoked.get(slowest)) >
                                (float) e.getKey().getDownloaded() / (now - e.getValue())) {
                            slowest = e.getKey();
                        }
                    }
                }
            }

            if (slowest != null) {
                slowest.setIsChoked(true);
                unchoked.remove(slowest);

                List<Peer> interestedChoked = new LinkedList<Peer>(interested);
                interestedChoked.removeAll(unchoked.keySet());

                Peer newUnchoked = interestedChoked.get(new Random().nextInt(interestedChoked.size()));
                newUnchoked.setIsChoked(false);
                unchoked.put(newUnchoked, now);
            }

        }

    }