On Tuesday 20 May 2008 21:24:40 alexlehm at freenetproject.org wrote:
> Author: alexlehm
> Date: 2008-05-20 20:24:40 +0000 (Tue, 20 May 2008)
> New Revision: 19976
>
> Modified:
> trunk/apps/Freemail/src/freemail/AccountManager.java
> trunk/apps/Freemail/src/freemail/AckProcrastinator.java
> trunk/apps/Freemail/src/freemail/InboundContact.java
> trunk/apps/Freemail/src/freemail/OutboundContact.java
> trunk/apps/Freemail/src/freemail/RTSFetcher.java
> trunk/apps/Freemail/src/freemail/RTSLog.java
> trunk/apps/Freemail/src/freemail/config/Configurator.java
> trunk/apps/Freemail/src/freemail/utils/PropsFile.java
> Log:
> 0002377: Parent issue for PropsFile conflicting writes problems.
(https://bugs.freenetproject.org/view.php?id=2377)
> resp the child issues
> 0002344 sending many mails immediately after each makes freemail loose some
slots
> 0002176 Messages are sometimes inserted more than once
> 0001989 Slot with SSK at key/null
>
> changed PropsFile to a factory with Eclipse, we only instantiate every
PropsFile once by filename, this should fix the conflicting write problems,
but creates a minor memory leak with temp files, as mentioned before. We will
fix this later.
>
> (Also, I fixed some typos in comments and message strings.)
Great stuff - thanks. I've just added a reaper method that gets called every
20 PropsFile creations which will address the memory leak issue.
Looks good though, thanks for that.
Dave
PS. You broke the build in r19979 - nothing major but try to be on IRC when
you commit things so you see FreenetLogBot's autobuild messge & we can shout
at you when it goes wrong. ;)
>
>
> Modified: trunk/apps/Freemail/src/freemail/AccountManager.java
> ===================================================================
> --- trunk/apps/Freemail/src/freemail/AccountManager.java 2008-05-20
> 16:30:25
UTC (rev 19975)
> +++ trunk/apps/Freemail/src/freemail/AccountManager.java 2008-05-20
> 20:24:40
UTC (rev 19976)
> @@ -183,7 +183,7 @@
> }
>
> private static PropsFile getAccountFile(File accdir) {
> - PropsFile accfile = new PropsFile(new File(accdir,
> ACCOUNT_FILE));
> + PropsFile accfile = PropsFile.createPropsFile(new File(accdir,
ACCOUNT_FILE));
>
> if (!accdir.exists() || !accfile.exists()) {
> return null;
> @@ -193,7 +193,7 @@
> }
>
> private static PropsFile newAccountFile(File accdir) {
> - PropsFile accfile = new PropsFile(new File(accdir,
> ACCOUNT_FILE));
> + PropsFile accfile = PropsFile.createPropsFile(new File(accdir,
ACCOUNT_FILE));
>
> if (accdir.exists() && !accfile.exists()) {
> initAccFile(accfile);
>
> Modified: trunk/apps/Freemail/src/freemail/AckProcrastinator.java
> ===================================================================
> --- trunk/apps/Freemail/src/freemail/AckProcrastinator.java 2008-05-20
16:30:25 UTC (rev 19975)
> +++ trunk/apps/Freemail/src/freemail/AckProcrastinator.java 2008-05-20
20:24:40 UTC (rev 19976)
> @@ -37,8 +37,8 @@
>
> /** Takes simple pieces of data to insert to keys and inserts them at some
point
> * randomly within a given time frame in order to disguise the time at
which messages
> - * were received. This is by no means infalliable, and will only work
effectively if
> - * Freemail is run more or less permanantly.
> + * were received. This is by no means infallible, and will only work
effectively if
> + * Freemail is run more or less permanently.
> */
> public class AckProcrastinator implements Runnable {
> /**
> @@ -78,7 +78,7 @@
>
> int i;
> for (i = 0; i < acks.length; i++) {
> - PropsFile ack = new PropsFile(acks[i]);
> + PropsFile ack =
> PropsFile.createPropsFile(acks[i]);
>
> String s_it = ack.get("nominalInsertTime");
> String key = ack.get("key");
> @@ -108,10 +108,10 @@
> FCPInsertErrorMessage err =
> fcpcli.put(bis, key);
> if (err == null) {
> acks[i].delete();
> - Logger.normal(this,"ACK
> insertion to "+key+" sucessful");
> + Logger.normal(this,"ACK
> insertion to "+key+" successful");
> } else if (err.errorcode ==
> FCPInsertErrorMessage.COLLISION) {
> acks[i].delete();
> - Logger.normal(this,"ACK
> insertion to "+key+" sucessful");
> + Logger.normal(this,"ACK
> insertion to "+key+" successful");
> }
> } catch (FCPBadFileException bfe) {
> // won't occur
> @@ -154,7 +154,7 @@
> long by = System.currentTimeMillis() + MAX_DELAY;
>
> try {
> - PropsFile ackfile= new
> PropsFile(File.createTempFile("delayed-ack", "",
getAckDir()));
> + PropsFile ackfile=
PropsFile.createPropsFile(File.createTempFile("delayed-ack", "",
getAckDir()));
>
> ackfile.put("key", key);
> if (data != null)
>
> Modified: trunk/apps/Freemail/src/freemail/InboundContact.java
> ===================================================================
> --- trunk/apps/Freemail/src/freemail/InboundContact.java 2008-05-20
> 16:30:25
UTC (rev 19975)
> +++ trunk/apps/Freemail/src/freemail/InboundContact.java 2008-05-20
> 20:24:40
UTC (rev 19976)
> @@ -58,7 +58,7 @@
> this.ibct_dir.mkdir();
> }
>
> - this.ibct_props = new PropsFile(new File(this.ibct_dir,
> IBCT_PROPSFILE));
> + this.ibct_props = PropsFile.createPropsFile(new
> File(this.ibct_dir,
IBCT_PROPSFILE));
> }
>
> public void setProp(String key, String val) {
> @@ -115,7 +115,7 @@
> Logger.normal(this,"Found a message!");
>
> // parse the Freemail header(s) out.
> - PropsFile msgprops = new PropsFile(msg, true);
> + PropsFile msgprops = PropsFile.createPropsFile(msg,
> true);
> String s_id = msgprops.get("id");
> if (s_id == null) {
> Logger.error(this,"Got a message with an
> invalid header. Discarding.");
> @@ -199,7 +199,7 @@
> public boolean validateFrom(EmailAddress from) throws IOException,
ConnectionTerminatedException {
> String sd = from.getSubDomain();
> if (sd == null) {
> - // well that's definately not valid. Piffle!
> + // well that's definitely not valid. Piffle!
> return false;
> }
>
>
> Modified: trunk/apps/Freemail/src/freemail/OutboundContact.java
> ===================================================================
> --- trunk/apps/Freemail/src/freemail/OutboundContact.java 2008-05-20
16:30:25 UTC (rev 19975)
> +++ trunk/apps/Freemail/src/freemail/OutboundContact.java 2008-05-20
20:24:40 UTC (rev 19976)
> @@ -139,7 +139,7 @@
> throw new IOException("Couldn't create outbound
> contact dir!");
> }
>
> - this.contactfile = new PropsFile(new File(obctdir,
> PROPSFILE_NAME));
> + this.contactfile = PropsFile.createPropsFile(new
> File(obctdir,
PROPSFILE_NAME));
> this.ctoutbox = new File(obctdir, OUTBOX_DIR);
> if (!this.ctoutbox.exists() && !this.ctoutbox.mkdir()) {
> throw new IOException("Couldn't create contact
> outbox!");
> @@ -152,7 +152,7 @@
> this.address = new EmailAddress();
> this.address.domain = ctdir.getName()+".freemail";
>
> - this.contactfile = new PropsFile(new File(ctdir,
> PROPSFILE_NAME));
> + this.contactfile = PropsFile.createPropsFile(new File(ctdir,
PROPSFILE_NAME));
>
> this.ctoutbox = new File(ctdir, OUTBOX_DIR);
> if (!this.ctoutbox.exists()) {
> @@ -540,7 +540,7 @@
>
> Logger.normal(this,"got mailsite");
>
> - PropsFile mailsite = new PropsFile(mailsite_file);
> + PropsFile mailsite = PropsFile.createPropsFile(mailsite_file);
>
> String rtsksk = mailsite.get("rtsksk");
> String keymod_str = mailsite.get("asymkey.modulus");
> @@ -834,7 +834,7 @@
> this.uid = uid;
> this.file = new File(ctoutbox, Integer.toString(uid));
>
> - this.index = new PropsFile(new File(ctoutbox,
> INDEX_FILE));
> + this.index = PropsFile.createPropsFile(file);
>
> this.slot = this.index.get(uid+".slot");
> String s_first = this.index.get(uid+".first_send_time");
>
> Modified: trunk/apps/Freemail/src/freemail/RTSFetcher.java
> ===================================================================
> --- trunk/apps/Freemail/src/freemail/RTSFetcher.java 2008-05-20 16:30:25 UTC
(rev 19975)
> +++ trunk/apps/Freemail/src/freemail/RTSFetcher.java 2008-05-20 20:24:40 UTC
(rev 19976)
> @@ -288,7 +288,7 @@
> return false;
> }
>
> - PropsFile rtsprops = new PropsFile(rtsfile);
> + PropsFile rtsprops = PropsFile.createPropsFile(rtsfile);
>
> try {
> validate_rts(rtsprops);
> @@ -335,7 +335,7 @@
> return false;
> }
>
> - PropsFile mailsite = new PropsFile(msfile);
> + PropsFile mailsite = PropsFile.createPropsFile(msfile);
> String their_exponent = mailsite.get("asymkey.pubexponent");
> String their_modulus = mailsite.get("asymkey.modulus");
>
>
> Modified: trunk/apps/Freemail/src/freemail/RTSLog.java
> ===================================================================
> --- trunk/apps/Freemail/src/freemail/RTSLog.java 2008-05-20 16:30:25 UTC
(rev 19975)
> +++ trunk/apps/Freemail/src/freemail/RTSLog.java 2008-05-20 20:24:40 UTC
(rev 19976)
> @@ -39,7 +39,7 @@
> private static String UNPROC_NEXTID = "unproc-nextid";
>
> public RTSLog(File f) {
> - this.logfile = new PropsFile(f);
> + this.logfile = PropsFile.createPropsFile(f);
> if (!this.logfile.exists()) {
> String birth = DateStringFactory.getOffsetKeyString(0);
> this.logfile.put("birth", birth);
>
> Modified: trunk/apps/Freemail/src/freemail/config/Configurator.java
> ===================================================================
> --- trunk/apps/Freemail/src/freemail/config/Configurator.java 2008-05-20
16:30:25 UTC (rev 19975)
> +++ trunk/apps/Freemail/src/freemail/config/Configurator.java 2008-05-20
20:24:40 UTC (rev 19976)
> @@ -35,7 +35,7 @@
> private final HashMap callbacks;
>
> public Configurator(File f) {
> - this.props = new PropsFile(f);
> + this.props = PropsFile.createPropsFile(f);
> this.props.setCommentPrefix("#");
> String ls = System.getProperty("line.separator");
> StringBuffer head = new StringBuffer();
>
> Modified: trunk/apps/Freemail/src/freemail/utils/PropsFile.java
> ===================================================================
> --- trunk/apps/Freemail/src/freemail/utils/PropsFile.java 2008-05-20
16:30:25 UTC (rev 19975)
> +++ trunk/apps/Freemail/src/freemail/utils/PropsFile.java 2008-05-20
20:24:40 UTC (rev 19976)
> @@ -31,8 +31,31 @@
> import java.util.Iterator;
> import java.util.Map;
> import java.util.Set;
> +import java.util.Hashtable;
>
> public class PropsFile {
> + // substitute static methods for constructor
> +
> + static Hashtable propsList=new Hashtable();
> +
> + public static PropsFile createPropsFile(File f, boolean stopAtBlank) {
> + String fn=f.getPath();
> +
> + PropsFile pf=(PropsFile)propsList.get(fn);
> +
> + if(pf!=null) {
> + return pf;
> + } else {
> + pf=new PropsFile(f, stopAtBlank);
> + propsList.put(fn, pf);
> + return pf;
> + }
> + }
> +
> + public static PropsFile createPropsFile(File f) {
> + return createPropsFile(f, false);
> + }
> +
> private final File file;
> private HashMap data;
> private BufferedReader bufrdr;
> @@ -43,7 +66,7 @@
> * a blank line. It's the the caller's responsibility to get
> * (using the getReader() method) the stream and close it properly.
> */
> - public PropsFile(File f, boolean stopAtBlank) {
> + private PropsFile(File f, boolean stopAtBlank) {
> this.file = f;
> this.data = null;
>
> @@ -57,10 +80,6 @@
> this.header = null;
> }
>
> - public PropsFile(File f) {
> - this(f, false);
> - }
> -
> public void setCommentPrefix(String cp) {
> this.commentPrefix = cp;
> }
>
> _______________________________________________
> Freemail mailing list
> Freemail at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/freemail
>