From b5c0d77c69d505744d9d7a7d2d085e8403fbcc72 Mon Sep 17 00:00:00 2001 From: jrandom Date: Sat, 25 Mar 2006 23:50:48 +0000 Subject: [PATCH] 2006-03-25 jrandom * Added a simple purge and ban of syndie authors, shown as the "Purge and ban" button on the addressbook for authors that are already on the ignore list. All of their entries and metadata are deleted from the archive, and the are transparently filtered from any remote syndication (so no user on the syndie instance will pull any new posts from them) * More strict tunnel join throtting when congested --- .../java/src/org/klomp/snark/Snark.java | 28 ++++++------ .../java/src/net/i2p/syndie/Archive.java | 10 +++++ .../java/src/net/i2p/syndie/BlogManager.java | 45 +++++++++++++++++++ .../net/i2p/syndie/web/AddressesServlet.java | 3 ++ .../src/net/i2p/syndie/web/BaseServlet.java | 28 ++++++++++++ .../net/i2p/syndie/web/RemoteArchiveBean.java | 2 + history.txt | 11 ++++- .../net/i2p/router/RouterThrottleImpl.java | 3 +- .../src/net/i2p/router/RouterVersion.java | 4 +- 9 files changed, 116 insertions(+), 18 deletions(-) diff --git a/apps/i2psnark/java/src/org/klomp/snark/Snark.java b/apps/i2psnark/java/src/org/klomp/snark/Snark.java index 82b197a344..8b8d202e94 100644 --- a/apps/i2psnark/java/src/org/klomp/snark/Snark.java +++ b/apps/i2psnark/java/src/org/klomp/snark/Snark.java @@ -633,11 +633,11 @@ public class Snark boolean allocating = false; public void storageCreateFile(Storage storage, String name, long length) { - if (allocating) - System.out.println(); // Done with last file. + //if (allocating) + // System.out.println(); // Done with last file. - System.out.print("Creating file '" + name - + "' of length " + length + ": "); + //System.out.print("Creating file '" + name + // + "' of length " + length + ": "); allocating = true; } @@ -647,10 +647,10 @@ public class Snark public void storageAllocated(Storage storage, long length) { allocating = true; - System.out.print("."); + //System.out.print("."); allocated += length; - if (allocated == meta.getTotalLength()) - System.out.println(); // We have all the disk space we need. + //if (allocated == meta.getTotalLength()) + // System.out.println(); // We have all the disk space we need. } boolean allChecked = false; @@ -664,10 +664,10 @@ public class Snark // Use the MetaInfo from the storage since our own might not // yet be setup correctly. MetaInfo meta = storage.getMetaInfo(); - if (meta != null) - System.out.print("Checking existing " - + meta.getPieces() - + " pieces: "); + //if (meta != null) + // System.out.print("Checking existing " + // + meta.getPieces() + // + " pieces: "); checking = true; } if (!checking) @@ -677,8 +677,8 @@ public class Snark public void storageAllChecked(Storage storage) { - if (checking) - System.out.println(); + //if (checking) + // System.out.println(); allChecked = true; checking = false; @@ -688,7 +688,7 @@ public class Snark { Snark.debug("Completely received " + torrent, Snark.INFO); //storage.close(); - System.out.println("Completely received: " + torrent); + //System.out.println("Completely received: " + torrent); if (completeListener != null) completeListener.torrentComplete(this); } diff --git a/apps/syndie/java/src/net/i2p/syndie/Archive.java b/apps/syndie/java/src/net/i2p/syndie/Archive.java index 0664ba2ea3..cdba757701 100644 --- a/apps/syndie/java/src/net/i2p/syndie/Archive.java +++ b/apps/syndie/java/src/net/i2p/syndie/Archive.java @@ -6,6 +6,7 @@ import java.text.*; import net.i2p.I2PAppContext; import net.i2p.data.*; import net.i2p.syndie.data.*; +import net.i2p.util.FileUtil; import net.i2p.util.Log; /** @@ -332,6 +333,15 @@ public class Archive { return rv; } + public synchronized void delete(Hash blog) { + if (blog == null) return; + File blogDir = new File(_rootDir, blog.toBase64()); + boolean deleted = FileUtil.rmdir(blogDir, false); + File cacheDir = new File(_cacheDir, blog.toBase64()); + deleted = FileUtil.rmdir(cacheDir, false) && deleted; + _log.info("Deleted blog " + blog.toBase64() + " completely? " + deleted); + } + public boolean storeEntry(EntryContainer container) { if (container == null) return false; BlogURI uri = container.getURI(); diff --git a/apps/syndie/java/src/net/i2p/syndie/BlogManager.java b/apps/syndie/java/src/net/i2p/syndie/BlogManager.java index 4e78f9aafd..f0e2cfdc37 100644 --- a/apps/syndie/java/src/net/i2p/syndie/BlogManager.java +++ b/apps/syndie/java/src/net/i2p/syndie/BlogManager.java @@ -1060,4 +1060,49 @@ public class BlogManager { return true; return false; } + + public boolean isBanned(Hash blog) { + if (blog == null) return false; + String str = blog.toBase64(); + String banned = System.getProperty("syndie.bannedBlogs", ""); + return (banned.indexOf(str) >= 0); + } + + public String[] getBannedBlogs() { + List blogs = new ArrayList(); + String str = System.getProperty("syndie.bannedBlogs", ""); + StringTokenizer tok = new StringTokenizer(str, ","); + while (tok.hasMoreTokens()) { + String blog = tok.nextToken(); + try { + Hash h = new Hash(); + h.fromBase64(blog); + blogs.add(blog); // the base64 string, but verified + } catch (DataFormatException dfe) { + // ignored + } + } + String rv[] = new String[blogs.size()]; + for (int i = 0; i < blogs.size(); i++) + rv[i] = (String)blogs.get(i); + return rv; + } + + /** + * Delete the blog from the archive completely, and ban them from ever being added again + */ + public void purgeAndBan(Hash blog) { + String banned[] = getBannedBlogs(); + StringBuffer buf = new StringBuffer(); + String str = blog.toBase64(); + buf.append(str); + for (int i = 0; banned != null && i < banned.length; i++) { + if (!banned[i].equals(str)) + buf.append(",").append(banned[i]); + } + System.setProperty("syndie.bannedBlogs", buf.toString()); + writeConfig(); + _archive.delete(blog); + _archive.regenerateIndex(); + } } diff --git a/apps/syndie/java/src/net/i2p/syndie/web/AddressesServlet.java b/apps/syndie/java/src/net/i2p/syndie/web/AddressesServlet.java index d11843d144..628344479c 100644 --- a/apps/syndie/java/src/net/i2p/syndie/web/AddressesServlet.java +++ b/apps/syndie/java/src/net/i2p/syndie/web/AddressesServlet.java @@ -46,6 +46,7 @@ public class AddressesServlet extends BaseServlet { public static final String ACTION_DELETE_BLOG = "Delete author"; public static final String ACTION_UPDATE_BLOG = "Update author"; public static final String ACTION_ADD_BLOG = "Add author"; + public static final String ACTION_PURGE_AND_BAN_BLOG = "Purge and ban author"; public static final String ACTION_DELETE_ARCHIVE = "Delete archive"; public static final String ACTION_UPDATE_ARCHIVE = "Update archive"; @@ -128,6 +129,8 @@ public class AddressesServlet extends BaseServlet { if (pn.isMember(FilteredThreadIndex.GROUP_IGNORE)) { out.write("Ignored? "); + if (BlogManager.instance().authorizeRemote(user)) + out.write(" "); } else { out.write("Ignored? "); diff --git a/apps/syndie/java/src/net/i2p/syndie/web/BaseServlet.java b/apps/syndie/java/src/net/i2p/syndie/web/BaseServlet.java index 7d22dbfb37..690dafe7a1 100644 --- a/apps/syndie/java/src/net/i2p/syndie/web/BaseServlet.java +++ b/apps/syndie/java/src/net/i2p/syndie/web/BaseServlet.java @@ -329,6 +329,34 @@ public abstract class BaseServlet extends HttpServlet { (AddressesServlet.ACTION_UPDATE_OTHER.equals(action)) || (AddressesServlet.ACTION_UPDATE_PEER.equals(action)) ) { return updateAddress(user, req); + } else if (AddressesServlet.ACTION_PURGE_AND_BAN_BLOG.equals(action)) { + String name = req.getParameter(AddressesServlet.PARAM_NAME); + PetName pn = user.getPetNameDB().getByName(name); + if (pn != null) { + boolean purged = false; + if (BlogManager.instance().authorizeRemote(user)) { + Hash h = null; + BlogURI uri = new BlogURI(pn.getLocation()); + if (uri.getKeyHash() != null) { + h = uri.getKeyHash(); + } + if (h == null) { + byte b[] = Base64.decode(pn.getLocation()); + if ( (b != null) && (b.length == Hash.HASH_LENGTH) ) + h = new Hash(b); + } + if (h != null) { + BlogManager.instance().purgeAndBan(h); + purged = true; + } + } + if (purged) // force a new thread index + return true; + else + return false; + } else { + return false; + } } else if ( (AddressesServlet.ACTION_DELETE_ARCHIVE.equals(action)) || (AddressesServlet.ACTION_DELETE_BLOG.equals(action)) || (AddressesServlet.ACTION_DELETE_EEPSITE.equals(action)) || diff --git a/apps/syndie/java/src/net/i2p/syndie/web/RemoteArchiveBean.java b/apps/syndie/java/src/net/i2p/syndie/web/RemoteArchiveBean.java index 92d2a15782..9c5f929078 100644 --- a/apps/syndie/java/src/net/i2p/syndie/web/RemoteArchiveBean.java +++ b/apps/syndie/java/src/net/i2p/syndie/web/RemoteArchiveBean.java @@ -62,6 +62,8 @@ public class RemoteArchiveBean { } private boolean ignoreBlog(User user, Hash blog) { + if (BlogManager.instance().isBanned(blog)) + return true; PetNameDB db = user.getPetNameDB(); PetName pn = db.getByLocation(blog.toBase64()); return ( (pn!= null) && (pn.isMember("Ignore")) ); diff --git a/history.txt b/history.txt index ab27b10ce8..5a74175ad7 100644 --- a/history.txt +++ b/history.txt @@ -1,4 +1,13 @@ -$Id: history.txt,v 1.437 2006/03/21 18:11:33 jrandom Exp $ +$Id: history.txt,v 1.438 2006/03/24 15:53:31 jrandom Exp $ + +2006-03-25 jrandom + * Added a simple purge and ban of syndie authors, shown as the + "Purge and ban" button on the addressbook for authors that are already + on the ignore list. All of their entries and metadata are deleted from + the archive, and the are transparently filtered from any remote + syndication (so no user on the syndie instance will pull any new posts + from them) + * More strict tunnel join throtting when congested 2006-03-24 jrandom * Try to desync tunnel building near startup (thanks Complication!) diff --git a/router/java/src/net/i2p/router/RouterThrottleImpl.java b/router/java/src/net/i2p/router/RouterThrottleImpl.java index 19b214f928..705adf83d8 100644 --- a/router/java/src/net/i2p/router/RouterThrottleImpl.java +++ b/router/java/src/net/i2p/router/RouterThrottleImpl.java @@ -238,6 +238,7 @@ class RouterThrottleImpl implements RouterThrottle { } private static final int DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE = 600; // 1KBps + private static final int MIN_AVAILABLE_BPS = 4*1024; // always leave at least 4KBps free when allowing /** * with bytesAllocated already accounted for across the numTunnels existing @@ -279,7 +280,7 @@ class RouterThrottleImpl implements RouterThrottle { return true; } else { double probAllow = availBps / (allocatedBps + availBps); - boolean allow = _context.random().nextDouble() <= probAllow; + boolean allow = (availBps > MIN_AVAILABLE_BPS) && (_context.random().nextDouble() <= probAllow); if (allow) { if (_log.shouldLog(Log.INFO)) _log.info("Probabalistically allowing the tunnel w/ " + (pctFull*100d) + "% of our " + availBps diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 2196b2b142..e6256cfbac 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -15,9 +15,9 @@ import net.i2p.CoreVersion; * */ public class RouterVersion { - public final static String ID = "$Revision: 1.378 $ $Date: 2006/03/21 18:13:09 $"; + public final static String ID = "$Revision: 1.379 $ $Date: 2006/03/24 15:53:30 $"; public final static String VERSION = "0.6.1.12"; - public final static long BUILD = 16; + public final static long BUILD = 17; public static void main(String args[]) { System.out.println("I2P Router version: " + VERSION + "-" + BUILD); System.out.println("Router ID: " + RouterVersion.ID);