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
This commit is contained in:
jrandom
2006-03-25 23:50:48 +00:00
committed by zzz
parent d489caa88c
commit b5c0d77c69
9 changed files with 116 additions and 18 deletions

View File

@ -633,11 +633,11 @@ public class Snark
boolean allocating = false; boolean allocating = false;
public void storageCreateFile(Storage storage, String name, long length) public void storageCreateFile(Storage storage, String name, long length)
{ {
if (allocating) //if (allocating)
System.out.println(); // Done with last file. // System.out.println(); // Done with last file.
System.out.print("Creating file '" + name //System.out.print("Creating file '" + name
+ "' of length " + length + ": "); // + "' of length " + length + ": ");
allocating = true; allocating = true;
} }
@ -647,10 +647,10 @@ public class Snark
public void storageAllocated(Storage storage, long length) public void storageAllocated(Storage storage, long length)
{ {
allocating = true; allocating = true;
System.out.print("."); //System.out.print(".");
allocated += length; allocated += length;
if (allocated == meta.getTotalLength()) //if (allocated == meta.getTotalLength())
System.out.println(); // We have all the disk space we need. // System.out.println(); // We have all the disk space we need.
} }
boolean allChecked = false; boolean allChecked = false;
@ -664,10 +664,10 @@ public class Snark
// Use the MetaInfo from the storage since our own might not // Use the MetaInfo from the storage since our own might not
// yet be setup correctly. // yet be setup correctly.
MetaInfo meta = storage.getMetaInfo(); MetaInfo meta = storage.getMetaInfo();
if (meta != null) //if (meta != null)
System.out.print("Checking existing " // System.out.print("Checking existing "
+ meta.getPieces() // + meta.getPieces()
+ " pieces: "); // + " pieces: ");
checking = true; checking = true;
} }
if (!checking) if (!checking)
@ -677,8 +677,8 @@ public class Snark
public void storageAllChecked(Storage storage) public void storageAllChecked(Storage storage)
{ {
if (checking) //if (checking)
System.out.println(); // System.out.println();
allChecked = true; allChecked = true;
checking = false; checking = false;
@ -688,7 +688,7 @@ public class Snark
{ {
Snark.debug("Completely received " + torrent, Snark.INFO); Snark.debug("Completely received " + torrent, Snark.INFO);
//storage.close(); //storage.close();
System.out.println("Completely received: " + torrent); //System.out.println("Completely received: " + torrent);
if (completeListener != null) if (completeListener != null)
completeListener.torrentComplete(this); completeListener.torrentComplete(this);
} }

View File

@ -6,6 +6,7 @@ import java.text.*;
import net.i2p.I2PAppContext; import net.i2p.I2PAppContext;
import net.i2p.data.*; import net.i2p.data.*;
import net.i2p.syndie.data.*; import net.i2p.syndie.data.*;
import net.i2p.util.FileUtil;
import net.i2p.util.Log; import net.i2p.util.Log;
/** /**
@ -332,6 +333,15 @@ public class Archive {
return rv; 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) { public boolean storeEntry(EntryContainer container) {
if (container == null) return false; if (container == null) return false;
BlogURI uri = container.getURI(); BlogURI uri = container.getURI();

View File

@ -1060,4 +1060,49 @@ public class BlogManager {
return true; return true;
return false; 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();
}
} }

View File

@ -46,6 +46,7 @@ public class AddressesServlet extends BaseServlet {
public static final String ACTION_DELETE_BLOG = "Delete author"; public static final String ACTION_DELETE_BLOG = "Delete author";
public static final String ACTION_UPDATE_BLOG = "Update author"; public static final String ACTION_UPDATE_BLOG = "Update author";
public static final String ACTION_ADD_BLOG = "Add 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_DELETE_ARCHIVE = "Delete archive";
public static final String ACTION_UPDATE_ARCHIVE = "Update 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)) { if (pn.isMember(FilteredThreadIndex.GROUP_IGNORE)) {
out.write("Ignored? <input type=\"checkbox\" name=\"" + PARAM_IGNORE out.write("Ignored? <input type=\"checkbox\" name=\"" + PARAM_IGNORE
+ "\" checked=\"true\" value=\"true\" title=\"If true, their threads are hidden\" /> "); + "\" checked=\"true\" value=\"true\" title=\"If true, their threads are hidden\" /> ");
if (BlogManager.instance().authorizeRemote(user))
out.write("<input type=\"submit\" name=\"" + PARAM_ACTION + "\" value=\"" + ACTION_PURGE_AND_BAN_BLOG + "\" /> ");
} else { } else {
out.write("Ignored? <input type=\"checkbox\" name=\"" + PARAM_IGNORE out.write("Ignored? <input type=\"checkbox\" name=\"" + PARAM_IGNORE
+ "\" value=\"true\" title=\"If true, their threads are hidden\" /> "); + "\" value=\"true\" title=\"If true, their threads are hidden\" /> ");

View File

@ -329,6 +329,34 @@ public abstract class BaseServlet extends HttpServlet {
(AddressesServlet.ACTION_UPDATE_OTHER.equals(action)) || (AddressesServlet.ACTION_UPDATE_OTHER.equals(action)) ||
(AddressesServlet.ACTION_UPDATE_PEER.equals(action)) ) { (AddressesServlet.ACTION_UPDATE_PEER.equals(action)) ) {
return updateAddress(user, req); 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)) || } else if ( (AddressesServlet.ACTION_DELETE_ARCHIVE.equals(action)) ||
(AddressesServlet.ACTION_DELETE_BLOG.equals(action)) || (AddressesServlet.ACTION_DELETE_BLOG.equals(action)) ||
(AddressesServlet.ACTION_DELETE_EEPSITE.equals(action)) || (AddressesServlet.ACTION_DELETE_EEPSITE.equals(action)) ||

View File

@ -62,6 +62,8 @@ public class RemoteArchiveBean {
} }
private boolean ignoreBlog(User user, Hash blog) { private boolean ignoreBlog(User user, Hash blog) {
if (BlogManager.instance().isBanned(blog))
return true;
PetNameDB db = user.getPetNameDB(); PetNameDB db = user.getPetNameDB();
PetName pn = db.getByLocation(blog.toBase64()); PetName pn = db.getByLocation(blog.toBase64());
return ( (pn!= null) && (pn.isMember("Ignore")) ); return ( (pn!= null) && (pn.isMember("Ignore")) );

View File

@ -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 2006-03-24 jrandom
* Try to desync tunnel building near startup (thanks Complication!) * Try to desync tunnel building near startup (thanks Complication!)

View File

@ -238,6 +238,7 @@ class RouterThrottleImpl implements RouterThrottle {
} }
private static final int DEFAULT_MESSAGES_PER_TUNNEL_ESTIMATE = 600; // 1KBps 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 * with bytesAllocated already accounted for across the numTunnels existing
@ -279,7 +280,7 @@ class RouterThrottleImpl implements RouterThrottle {
return true; return true;
} else { } else {
double probAllow = availBps / (allocatedBps + availBps); double probAllow = availBps / (allocatedBps + availBps);
boolean allow = _context.random().nextDouble() <= probAllow; boolean allow = (availBps > MIN_AVAILABLE_BPS) && (_context.random().nextDouble() <= probAllow);
if (allow) { if (allow) {
if (_log.shouldLog(Log.INFO)) if (_log.shouldLog(Log.INFO))
_log.info("Probabalistically allowing the tunnel w/ " + (pctFull*100d) + "% of our " + availBps _log.info("Probabalistically allowing the tunnel w/ " + (pctFull*100d) + "% of our " + availBps

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
* *
*/ */
public class RouterVersion { 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 String VERSION = "0.6.1.12";
public final static long BUILD = 16; public final static long BUILD = 17;
public static void main(String args[]) { public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD); System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID); System.out.println("Router ID: " + RouterVersion.ID);