Changeset dfbf01d


Ignore:
Timestamp:
Jul 13, 2011 2:21:42 PM (9 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
857f0a0
Parents:
6886346
Message:
  • Blocklist:
    • Fix delayed lookup of reason from file
    • Tag strings for translation
    • Sort IPs on configpeer.jsp correctly
    • Cleanups
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • history.txt

    r6886346 rdfbf01d  
     12011-07-13 zzz
     2  * Blocklist:
     3    - Fix delayed lookup of reason from file
     4    - Tag strings for translation
     5    - Sort IPs on configpeer.jsp correctly
     6  * SummaryHelper: Fix NPE at startup (ticket #493)
     7
    182011-07-10 zzz
    29  * DH, YK:
  • router/java/src/net/i2p/router/Blocklist.java

    r6886346 rdfbf01d  
    3131import net.i2p.util.ConcurrentHashSet;
    3232import net.i2p.util.Log;
     33import net.i2p.util.Translate;
    3334
    3435/**
     
    6162public class Blocklist {
    6263    private final Log _log;
    63     private RouterContext _context;
     64    private final RouterContext _context;
    6465    private long _blocklist[];
    6566    private int _blocklistSize;
     
    7677   
    7778    /** only for testing with main() */
    78     public Blocklist() {
     79    private Blocklist() {
     80        _context = null;
    7981        _log = new Log(Blocklist.class);
    8082    }
     
    99101
    100102    private class ReadinJob extends JobImpl {
    101         private String _file;
     103        private final String _file;
    102104        public ReadinJob (String f) {
    103105            super(_context);
     
    262264
    263265    private static class Entry {
    264         String comment;
    265         byte ip1[];
    266         byte ip2[];
    267         Hash peer;
     266        final String comment;
     267        final byte ip1[];
     268        final byte ip2[];
     269        final Hash peer;
    268270
    269271        public Entry(String c, Hash h, byte[] i1, byte[] i2) {
     
    429431    }
    430432
    431     // Maintain a simple in-memory single-IP blocklist
    432     // This is used for new additions, NOT for the main list
    433     // of IP ranges read in from the file.
     433    /**
     434     * Maintain a simple in-memory single-IP blocklist
     435     * This is used for new additions, NOT for the main list
     436     * of IP ranges read in from the file.
     437     */
    434438    public void add(String ip) {
    435439        InetAddress pi;
     
    444448    }
    445449
     450    /**
     451     * Maintain a simple in-memory single-IP blocklist
     452     * This is used for new additions, NOT for the main list
     453     * of IP ranges read in from the file.
     454     */
    446455    public void add(byte ip[]) {
    447456        if (ip.length != 4)
     
    514523    }
    515524
    516     // calling this externally won't shitlist the peer, this is just an IP check
     525    /**
     526     * calling this externally won't shitlist the peer, this is just an IP check
     527     */
    517528    public boolean isBlocklisted(String ip) {
    518529        InetAddress pi;
     
    527538    }
    528539
    529     // calling this externally won't shitlist the peer, this is just an IP check
     540    /**
     541     * calling this externally won't shitlist the peer, this is just an IP check
     542     */
    530543    public boolean isBlocklisted(byte ip[]) {
    531544        if (ip.length != 4)
     
    631644    }
    632645
     646    /** IP to string */
    633647    public static String toStr(byte[] ip) {
    634648        return toStr(toInt(ip));
     
    668682        // Temporary reason, until the job finishes
    669683        _context.shitlist().shitlistRouterForever(peer, _x("IP banned"));
    670         if (! "true".equals( _context.getProperty(PROP_BLOCKLIST_DETAIL, "true")))
     684        if (!  _context.getBooleanPropertyDefaultTrue(PROP_BLOCKLIST_DETAIL))
    671685            return;
    672686        boolean shouldRunJob;
     
    678692        if (!shouldRunJob)
    679693            return;
    680         Job job = new ShitlistJob(peer);
     694        // get the IPs now because it won't be in the netdb by the time the job runs
     695        Job job = new ShitlistJob(peer, getAddresses(peer));
    681696        if (number > 0)
    682697            job.getTiming().setStartAfter(_context.clock().now() + (30*1000l * number));
     
    685700
    686701    private class ShitlistJob extends JobImpl {
    687         private Hash _peer;
    688         public ShitlistJob (Hash p) {
     702        private final Hash _peer;
     703        private final List<byte[]> _ips;
     704        public ShitlistJob (Hash p, List<byte[]> ips) {
    689705            super(_context);
    690706            _peer = p;
     707            _ips = ips;
    691708        }
    692709        public String getName() { return "Ban Peer by IP"; }
    693710        public void runJob() {
    694             shitlistForever(_peer);
     711            shitlistForever(_peer, _ips);
    695712            synchronized (_inProcess) {
    696713                _inProcess.remove(_peer);
     
    708725     *
    709726     */
    710     private synchronized void shitlistForever(Hash peer) {
     727    private synchronized void shitlistForever(Hash peer, List<byte[]> ips) {
    711728        String file = _context.getProperty(PROP_BLOCKLIST_FILE, BLOCKLIST_FILE_DEFAULT);
    712729        File BLFile = new File(file);
     
    720737
    721738        // look through the file for each address to find which one was the cause
    722         List ips = getAddresses(peer);
    723739        for (Iterator<byte[]> iter = ips.iterator(); iter.hasNext(); ) {
    724740            byte ip[] = iter.next();
     
    764780    private static final int MAX_DISPLAY = 1000;
    765781
    766     /** write directly to the stream so we don't OOM on a huge list */
     782    /**
     783     *  Write directly to the stream so we don't OOM on a huge list.
     784     *  Go through each list twice since we store out-of-order.
     785     */
    767786    public void renderStatusHTML(Writer out) throws IOException {
    768787        // move to the jsp
     
    771790        singles.addAll(_singleIPBlocklist);
    772791        if (!singles.isEmpty()) {
    773             out.write("<table><tr><td><b>Transient IPs</b></td></tr>");
    774             for (Iterator<Integer> iter = singles.iterator(); iter.hasNext(); ) {
    775                  int ip = iter.next().intValue();
    776                  out.write("<tr><td align=right>"); out.write(toStr(ip)); out.write("</td></tr>\n");
     792            out.write("<table><tr><th align=center colspan=2><b>");
     793            out.write(_("IPs Banned Until Restart"));
     794            out.write("</b></td></tr>");
     795            // first 0 - 127
     796            for (Integer ii : singles) {
     797                 int ip = ii.intValue();
     798                 if (ip < 0)
     799                     continue;
     800                 out.write("<tr><td align=center width=50%>");
     801                 out.write(toStr(ip));
     802                 out.write("</td><td width=50%>&nbsp;</td></tr>\n");
     803            }
     804            // then 128 - 255
     805            for (Integer ii : singles) {
     806                 int ip = ii.intValue();
     807                 if (ip >= 0)
     808                     break;
     809                 out.write("<tr><td align=center width=50%>");
     810                 out.write(toStr(ip));
     811                 out.write("</td><td width=50%>&nbsp;</td></tr>\n");
    777812            }
    778813            out.write("</table>");
    779814        }
    780815        if (_blocklistSize > 0) {
    781             out.write("<table><tr><th align=center colspan=2><b>IPs from Blocklist File</b></th></tr><tr><td align=center width=50%><b>From:</b></td><td align=center width=50%><b>To:</b></td></tr>");
     816            out.write("<table><tr><th align=center colspan=2><b>");
     817            out.write(_("IPs Permanently Banned"));
     818            out.write("</b></th></tr><tr><td align=center width=50%><b>");
     819            out.write(_("From"));
     820            out.write("</b></td><td align=center width=50%><b>");
     821            out.write(_("To"));
     822            out.write("</b></td></tr>");
    782823            int max = Math.min(_blocklistSize, MAX_DISPLAY);
     824            int displayed = 0;
     825            // first 0 - 127
    783826            for (int i = 0; i < max; i++) {
    784827                 int from = getFrom(_blocklist[i]);
     828                 if (from < 0)
     829                     continue;
    785830                 out.write("<tr><td align=center width=50%>"); out.write(toStr(from)); out.write("</td><td align=center width=50%>");
    786831                 int to = getTo(_blocklist[i]);
     
    789834                 } else
    790835                     out.write("&nbsp;</td></tr>\n");
     836                 displayed++;
     837            }
     838            // then 128 - 255
     839            for (int i = 0; i < max && displayed++ < max; i++) {
     840                 int from = getFrom(_blocklist[i]);
     841                 if (from >= 0)
     842                     break;
     843                 out.write("<tr><td align=center width=50%>"); out.write(toStr(from)); out.write("</td><td align=center width=50%>");
     844                 int to = getTo(_blocklist[i]);
     845                 if (to != from) {
     846                     out.write(toStr(to)); out.write("</td></tr>\n");
     847                 } else
     848                     out.write("&nbsp;</td></tr>\n");
    791849            }
    792850            if (_blocklistSize > MAX_DISPLAY)
     851                // very rare, don't bother translating
    793852                out.write("<tr><th colspan=2>First " + MAX_DISPLAY + " displayed, see the " +
    794853                          BLOCKLIST_FILE_DEFAULT + " file for the full list</th></tr>");
    795854            out.write("</table>");
    796855        } else {
    797             out.write("<br><i>No blocklist file entries.</i>");
     856            out.write("<br><i>");
     857            out.write(_("none"));
     858            out.write("</i>");
    798859        }
    799860        out.flush();
     
    808869    private static final String _x(String s) {
    809870        return s;
     871    }
     872
     873    private static final String BUNDLE_NAME = "net.i2p.router.web.messages";
     874
     875    /** translate */
     876    private String _(String key) {
     877        return Translate.getString(key, _context, BUNDLE_NAME);
    810878    }
    811879
  • router/java/src/net/i2p/router/RouterVersion.java

    r6886346 rdfbf01d  
    1919    public final static String ID = "Monotone";
    2020    public final static String VERSION = CoreVersion.VERSION;
    21     public final static long BUILD = 9;
     21    public final static long BUILD = 10;
    2222
    2323    /** for example "-test" */
Note: See TracChangeset for help on using the changeset viewer.