mirror of
https://github.com/i2p/i2p.i2p.git
synced 2026-06-03 17:31:25 +00:00
Console: Limit banlist output, add page links
Fix concurrent mod exception rendering banlist caused by switch to LHM
This commit is contained in:
@@ -25,30 +25,63 @@ import net.i2p.router.web.Messages;
|
||||
* Moved from Banlist.java
|
||||
*/
|
||||
class BanlistRenderer {
|
||||
static final int PAGE_SIZE = 2048;
|
||||
private int _pageSize = PAGE_SIZE;
|
||||
private int _page;
|
||||
|
||||
private final RouterContext _context;
|
||||
|
||||
public BanlistRenderer(RouterContext context) {
|
||||
_context = context;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param page 0-based
|
||||
* @since 0.9.69
|
||||
*/
|
||||
public void setPage(int page) {
|
||||
_page = page;
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.69
|
||||
*/
|
||||
public void setPageSize(int ps) {
|
||||
_pageSize = ps;
|
||||
}
|
||||
|
||||
public void renderStatusHTML(Writer out) throws IOException {
|
||||
StringBuilder buf = new StringBuilder(2048);
|
||||
Map<Hash, Banlist.Entry> entries = new TreeMap<Hash, Banlist.Entry>(HashComparator.getInstance());
|
||||
|
||||
entries.putAll(_context.banlist().getEntries());
|
||||
_context.banlist().getEntries(entries);
|
||||
buf.append("<h3 id=\"bannedpeers\">").append(_t("Banned Peers"));
|
||||
if (entries.isEmpty()) {
|
||||
int sz = entries.size();
|
||||
if (sz == 0) {
|
||||
buf.append("</h3><i>").append(_t("none")).append("</i>");
|
||||
out.append(buf);
|
||||
return;
|
||||
} else {
|
||||
buf.append(" (").append(entries.size()).append(")</h3>");
|
||||
buf.append(" (").append(sz).append(")</h3>");
|
||||
}
|
||||
|
||||
boolean morePages = false;
|
||||
int toSkip = _pageSize * _page;
|
||||
int last = Math.min(toSkip + _pageSize, sz);
|
||||
if (last < sz)
|
||||
morePages = true;
|
||||
if (_page > 0 || morePages)
|
||||
outputPageLinks(buf, _page, _pageSize, morePages);
|
||||
|
||||
buf.append("<ul id=\"banlist\">");
|
||||
|
||||
String unban = _t("unban now");
|
||||
int i = 0;
|
||||
for (Map.Entry<Hash, Banlist.Entry> e : entries.entrySet()) {
|
||||
if (i++ < toSkip)
|
||||
continue;
|
||||
if (i > last)
|
||||
break;
|
||||
Hash key = e.getKey();
|
||||
Banlist.Entry entry = e.getValue();
|
||||
long expires = entry.expireOn-_context.clock().now();
|
||||
@@ -85,10 +118,33 @@ class BanlistRenderer {
|
||||
}
|
||||
}
|
||||
buf.append("</ul>\n");
|
||||
if (_page > 0 || morePages)
|
||||
outputPageLinks(buf, _page, _pageSize, morePages);
|
||||
out.append(buf);
|
||||
out.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.69
|
||||
*/
|
||||
private void outputPageLinks(StringBuilder buf, int page, int pageSize, boolean morePages) {
|
||||
buf.append("<div class=\"netdbnotfound\">");
|
||||
if (page > 0) {
|
||||
buf.append("<a href=\"/profiles?f=3&pg=").append(page)
|
||||
.append("&ps=").append(pageSize).append("\">");
|
||||
buf.append(_t("Previous Page"));
|
||||
buf.append("</a> ");
|
||||
}
|
||||
buf.append(_t("Page")).append(' ').append(page + 1);
|
||||
if (morePages) {
|
||||
buf.append(" <a href=\"/profiles?f=3&pg=").append(page + 2)
|
||||
.append("&ps=").append(pageSize).append("\">");
|
||||
buf.append(_t("Next Page"));
|
||||
buf.append("</a>");
|
||||
}
|
||||
buf.append("</div>");
|
||||
}
|
||||
|
||||
/** translate a string */
|
||||
private String _t(String s) {
|
||||
return Messages.getString(s, _context);
|
||||
|
||||
@@ -38,6 +38,8 @@ public class PeerHelper extends HelperBase {
|
||||
private String _urlBase;
|
||||
private String _transport;
|
||||
private boolean _graphical;
|
||||
private int _pageSize = BanlistRenderer.PAGE_SIZE;
|
||||
private int _page;
|
||||
|
||||
private static final String titles[] = {
|
||||
_x("Status"),
|
||||
@@ -80,6 +82,31 @@ public class PeerHelper extends HelperBase {
|
||||
/** @since 0.9.38 */
|
||||
public void setTransport(String t) { _transport = t; }
|
||||
|
||||
/**
|
||||
* @param page 1-based
|
||||
* @since 0.9.69
|
||||
*/
|
||||
public void setPage(String page) {
|
||||
if (page != null) {
|
||||
try {
|
||||
_page = Integer.parseInt(page) - 1;
|
||||
if (_page < 0)
|
||||
_page = 0;
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.69
|
||||
*/
|
||||
public void setPageSize(String ps) {
|
||||
if (ps != null) {
|
||||
try {
|
||||
_pageSize = Integer.parseInt(ps);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* call for non-text-mode browsers
|
||||
* @since 0.9.38
|
||||
@@ -164,6 +191,8 @@ public class PeerHelper extends HelperBase {
|
||||
_context.commSystem().renderStatusHTML(_out, _urlBase, _sortFlags);
|
||||
} else if ("banned".equals(_transport)) {
|
||||
BanlistRenderer br = new BanlistRenderer(_context);
|
||||
br.setPage(_page);
|
||||
br.setPageSize(_pageSize);
|
||||
br.renderStatusHTML(_out);
|
||||
} else if (_transport != null) {
|
||||
boolean rendered = false;
|
||||
|
||||
@@ -8,6 +8,8 @@ import net.i2p.router.web.HelperBase;
|
||||
public class ProfilesHelper extends HelperBase {
|
||||
private int _full;
|
||||
private boolean _graphical;
|
||||
private int _pageSize = BanlistRenderer.PAGE_SIZE;
|
||||
private int _page;
|
||||
|
||||
private static final String titles[] =
|
||||
{_x("High Capacity"), // 0
|
||||
@@ -31,6 +33,31 @@ public class ProfilesHelper extends HelperBase {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param page 1-based
|
||||
* @since 0.9.69
|
||||
*/
|
||||
public void setPage(String page) {
|
||||
if (page != null) {
|
||||
try {
|
||||
_page = Integer.parseInt(page) - 1;
|
||||
if (_page < 0)
|
||||
_page = 0;
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @since 0.9.69
|
||||
*/
|
||||
public void setPageSize(String ps) {
|
||||
if (ps != null) {
|
||||
try {
|
||||
_pageSize = Integer.parseInt(ps);
|
||||
} catch (NumberFormatException nfe) {}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* call for non-text-mode browsers
|
||||
* @since 0.9.1
|
||||
@@ -69,6 +96,8 @@ public class ProfilesHelper extends HelperBase {
|
||||
public String getBanlistSummary() {
|
||||
try {
|
||||
BanlistRenderer rend = new BanlistRenderer(_context);
|
||||
rend.setPage(_page);
|
||||
rend.setPageSize(_pageSize);
|
||||
rend.renderStatusHTML(_out);
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
|
||||
Reference in New Issue
Block a user