Author: bback
Date: 2006-02-11 19:40:07 +0000 (Sat, 11 Feb 2006)
New Revision: 8020
Removed:
trunk/apps/frost-0.7/source/frost/fileTransfer/GetRequestsThread.java
trunk/apps/frost-0.7/source/frost/messages/FECRedirectFileObject.java
trunk/apps/frost-0.7/source/frost/messages/RedirectFileObject.java
trunk/apps/frost-0.7/source/frost/threads/GetFriendsRequestsThread.java
Log:
remove old files
Deleted: trunk/apps/frost-0.7/source/frost/fileTransfer/GetRequestsThread.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/fileTransfer/GetRequestsThread.java
2006-02-11 19:38:11 UTC (rev 8019)
+++ trunk/apps/frost-0.7/source/frost/fileTransfer/GetRequestsThread.java
2006-02-11 19:40:07 UTC (rev 8020)
@@ -1,284 +0,0 @@
-/*
- GetRequestsThread.java / Frost
- Copyright (C) 2001 Jan-Thomas Czornack <jantho at users.sourceforge.net>
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-package frost.fileTransfer;
-
-import java.io.File;
-import java.util.*;
-import java.util.logging.*;
-
-import frost.*;
-import frost.fcp.FcpRequest;
-import frost.fileTransfer.upload.*;
-import frost.identities.FrostIdentities;
-/**
- * Downloads file requests
- */
-
-public class GetRequestsThread extends Thread
-{
- private UploadModel model;
-
- private FrostIdentities identities;
-
- static java.util.ResourceBundle LangRes =
- java.util.ResourceBundle.getBundle("res.LangRes");
-
- private static Logger logger =
Logger.getLogger(GetRequestsThread.class.getName());
-
- //public FrostBoardObject board;
- private int downloadHtl;
- private String keypool;
- private String destination;
- private String fileSeparator = System.getProperty("file.separator");
- private String date;
-
- /*public int getThreadType()
- {
- return BoardUpdateThread.BOARD_FILE_UPLOAD;
- }*/
-
- public void run() {
- System.out.println("Getrequests thread is started");
- //first, start today's thread.
- if (DateFun.getDate().compareTo(date) != 0) {
-
- GetRequestsThread todaysRequests =
- new GetRequestsThread(
- downloadHtl,
- keypool,
- model,
- DateFun.getDate(),
- identities);
- todaysRequests.start();
- try {
- todaysRequests.join();
- } catch (InterruptedException e) {
- logger.log(Level.SEVERE, "Exception thrown in
run()", e);
- }
- }
- // notifyThreadStarted(this);
- try {
-
- // Wait some random time to speed up the update of the
TOF table
- // ... and to not to flood the node
- int waitTime = (int) (Math.random() * 5000);
- // wait a max. of 5 seconds between start of threads
- Mixed.wait(waitTime);
-
- GregorianCalendar cal = new GregorianCalendar();
- cal.setTimeZone(TimeZone.getTimeZone("GMT"));
-
- String dirdate = date;
-
- /*destination = new StringBuffer().append(keypool)
-
.append(board.getBoardFilename()).append(fileSeparator)
-
.append(dirdate).append(fileSeparator).toString();*/
-
- //yes mister spammer, this is a special for you!
- destination =
- new StringBuffer()
- .append("requests")
- .append(fileSeparator)
-
.append(Mixed.makeFilename(identities.getMyId().getUniqueName()))
- .toString();
-
- File makedir = new File(destination);
- if (!makedir.exists()) {
- logger.info(
- Thread.currentThread().getName() + ":
Creating directory: " + destination);
- makedir.mkdirs();
- }
-
- if (isInterrupted()) {
- //notifyThreadFinished(this);
- return;
- }
-
- //start the request loop
- Mixed.wait(60 * 1000); // wait 1 min before first start
- boolean firstRun = true;
- while (true) {
- dirdate = date;
- if (firstRun) {
- firstRun = false;
- } else {
- Mixed.wait(15 * 60 * 1000);
- }
- if (Core.getMyBatches().isEmpty())
- continue;
- //do not start requesting until the user has
shared something
- try {
- Iterator it =
Core.getMyBatches().keySet().iterator();
- while (it.hasNext()) {
- String currentBatch = (String)
it.next();
- int index = 0;
- int failures = 0;
- int maxFailures = 3;
- // increased, skips now up to 3
request indicies (in case if gaps occured)
- while (failures < maxFailures) {
- String val =
- new
StringBuffer()
-
.append(destination)
-
.append(fileSeparator)
-
.append(currentBatch.trim())
-
.append("-")
-
.append(dirdate)
-
.append("-")
-
.append(index)
-
.append(".req.sha")
-
.toString();
- File testMe = new
File(val);
- boolean justDownloaded
= false;
-
- // already downloaded ?
- if (testMe.length() >
0) {
- index++;
- failures = 0;
- continue;
- } else {
- String tmp =
- new
StringBuffer()
-
.append("GetRequestsThread.run, file = ")
-
.append(testMe.getName())
-
.append(", failures = ")
-
.append(failures)
-
.toString();
-
logger.fine(tmp);
-
-
FcpRequest.getFile(
- "KSK at
frost/request/"
-
+ MainFrame.frostSettings.getValue("messageBase")
-
+ "/"
-
+ Mixed.makeFilename(identities.getMyId().getUniqueName())
-
+ "-"
-
+ testMe.getName(),
- null,
- testMe,
-
downloadHtl,
- false);
- justDownloaded
= true;
- }
-
- // Download successful?
- if (testMe.length() > 0
/* && justDownloaded */
- ) {
- logger.fine(
-
Thread.currentThread().getName()
-
+ " Received request "
-
+ testMe.getName());
-// TODO: read multiple requests
- String content
= (FileAccess.readFile(testMe)).trim();
-
logger.fine("Request content is " + content);
- int rowCount =
model.getItemCount();
-
- for (int i = 0;
i < rowCount; i++) {
-
FrostUploadItem ulItem =
-
(FrostUploadItem) model.getItemAt(i);
- String
SHA1 = ulItem.getSHA1();
- if
(SHA1 == null)
-
continue;
- else
-
SHA1 = SHA1.trim();
-
//Core.getOut().println("comparing requested "+content + " with "+SHA1);
- if
(SHA1.equals(content)) {
-
logger.fine("content matched!");
-
// ? is'nt it possible to use uploadItem.getLastUploadData for this?
-
// probably, this .lck thing is jantho's style
-
File requestLock = new File(destination + SHA1 + ".lck");
-
if (!requestLock.exists()) {
-
// for handling of ENCODING state see ulItem.getNextState() javadoc
-
// changing state ENCODING_REQUESTED to REQUESTED is ok!
-
if (ulItem.getState()
-
!= FrostUploadItem.STATE_UPLOADING
-
&& ulItem.getState()
-
!= FrostUploadItem.STATE_PROGRESS)
-
//TOTHINK: this is optional
-
{
-
logger.fine("Request matches row " + i);
-
if (ulItem.getState()
-
== FrostUploadItem.STATE_ENCODING) {
-
ulItem.setNextState(
-
FrostUploadItem.STATE_REQUESTED);
-
} else {
-
ulItem.setState(
-
FrostUploadItem.STATE_REQUESTED);
-
}
-
} else
-
logger.fine("file was in state uploading/progress");
-
} else {
-
logger.info(
-
"File with hash "
-
+ SHA1
-
+ " was requested, but already uploaded today");
-
}
- }
//else Core.getOut().println("content didn't match");
- }
- index++;
- failures = 0;
- } else {
- index++;
- // this now
skips gaps in requests, but gives each download only 1 try
- failures++;
- }
- if (isInterrupted()) {
- break;
- }
- }
-
- }
-
- } catch (ConcurrentModificationException e) {
- continue;
- }
- }
- } //people with nice ides can refactor :-P
- catch (Throwable t) {
- logger.log(
- Level.SEVERE,
- Thread.currentThread().getName() + ": Oo.
EXCEPTION in GetRequestsThread:",
- t);
- }
-
- //notifyThreadFinished(this);
- }
-
- /**Constructor*/
- public GetRequestsThread(
- int dlHtl,
- String kpool,
- UploadModel newModel,
- FrostIdentities newIdentities) {
-
- this(dlHtl, kpool, newModel, DateFun.getDate(1), newIdentities);
- }
- public GetRequestsThread(
- int htl,
- String newKeypool,
- UploadModel newModel,
- String newDate,
- FrostIdentities newIdentities) {
-
- downloadHtl = htl;
- keypool = newKeypool;
- model = newModel;
- date = newDate;
- identities = newIdentities;
- }
-
-}
Deleted: trunk/apps/frost-0.7/source/frost/messages/FECRedirectFileObject.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/messages/FECRedirectFileObject.java
2006-02-11 19:38:11 UTC (rev 8019)
+++ trunk/apps/frost-0.7/source/frost/messages/FECRedirectFileObject.java
2006-02-11 19:40:07 UTC (rev 8020)
@@ -1,84 +0,0 @@
-/*
- * Created on Nov 17, 2003
- *
- * To change the template for this generated file go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-package frost.messages;
-
-import java.io.File;
-
-import org.w3c.dom.CDATASection;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.xml.sax.SAXException;
-
-import frost.XMLTools;
-import frost.gui.objects.Board;
-
-/**
- * @author zlatinb
- *
- * represents a fileObject holding a FEC redirect
- */
-public class FECRedirectFileObject extends RedirectFileObject {
-
- String redirect;
-
- /* (non-Javadoc)
- * @see frost.messages.RedirectFileObject#getRedirectType()
- */
- public int getRedirectType() {
- return FEC_REDIRECT;
- }
-
- public Element getXMLElement(Document doc) {
- // TODO Auto-generated method stub
- Element el = super.getXMLElement(doc);
- Element el2 = doc.createElement("redirect");
- CDATASection cdata = doc.createCDATASection(redirect);
- el2.appendChild(cdata);
- el.appendChild(el2);
- el.setAttribute("redirect","FEC");
- return el;
- }
-
- public void loadXMLElement(Element current) throws SAXException {
- assert current.getAttribute("redirect").equals("FEC") &&
-
XMLTools.getChildElementsByTagName(current,"redirect").size()>0 :
- "fec redirect not present in file";
- super.loadXMLElement(current);
- redirect =
XMLTools.getChildElementsCDATAValue(current,"redirect");
- }
-
- /**
- * @return Returns the redirect.
- */
- public String getRedirect() {
- return redirect;
- }
-
- /**
- * @param redirect The redirect to set.
- */
- public void setRedirect(String redirect) {
- this.redirect = redirect;
- }
-
- /**
- * @param file
- * @param board
- */
- public FECRedirectFileObject(File file, Board board) {
- super(file, board);
- redirect = null;
- }
-
-
-
- public FECRedirectFileObject() {
- super();
- redirect = null;
- }
-
-}
Deleted: trunk/apps/frost-0.7/source/frost/messages/RedirectFileObject.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/messages/RedirectFileObject.java
2006-02-11 19:38:11 UTC (rev 8019)
+++ trunk/apps/frost-0.7/source/frost/messages/RedirectFileObject.java
2006-02-11 19:40:07 UTC (rev 8020)
@@ -1,70 +0,0 @@
-/*
- * Created on Nov 17, 2003
- *
- * To change the template for this generated file go to
- * Window>Preferences>Java>Code Generation>Code and Comments
- */
-package frost.messages;
-
-import java.io.File;
-
-import org.w3c.dom.Element;
-import org.xml.sax.SAXException;
-
-import frost.gui.objects.Board;
-import frost.*;
-
-
-/**
- * @author zlatinb
- *
- * represents a fileObject that also contains a redirect in it.
- */
-public abstract class RedirectFileObject extends SharedFileObject {
-
- public static final int FEC_REDIRECT = 1;
-
- public abstract int getRedirectType();
-
- /* (non-Javadoc)
- * @see frost.XMLizable#loadXMLElement(org.w3c.dom.Element)
- */
- public void loadXMLElement(Element current) throws SAXException {
-
- assert current.getAttribute("redirect").length()>0 :
- "redirect attribute not found!";
-
- super.loadXMLElement(current);
- }
-
- /**
- * @param file
- * @param board
- */
- public RedirectFileObject(File file, Board board) {
- super(file, board);
- }
-
- /**
- *
- */
- public RedirectFileObject() {
- super();
- }
-
-
- public abstract String getRedirect();
-
- public static SharedFileObject getRedirectInstance(Element e) throws
SAXException{
- assert e.getAttribute("redirect").length() > 0 &&
- XMLTools.getChildElementsByTagName(e,"redirect").size() > 0:
"element does not contain redirect";
-
- SharedFileObject result = null;
- if (e.getAttribute("redirect").equals("FEC")) {
- result = new FECRedirectFileObject();
- result.loadXMLElement(e);
-
- }
- return result;
- }
-}
Deleted: trunk/apps/frost-0.7/source/frost/threads/GetFriendsRequestsThread.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/threads/GetFriendsRequestsThread.java
2006-02-11 19:38:11 UTC (rev 8019)
+++ trunk/apps/frost-0.7/source/frost/threads/GetFriendsRequestsThread.java
2006-02-11 19:40:07 UTC (rev 8020)
@@ -1,164 +0,0 @@
-/*
- GetFriendsRequestsThread.java / Frost
- Copyright (C) 2003 Jan-Thomas Czornack <jantho at users.sourceforge.net>
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-package frost.threads;
-
-import java.io.*;
-import java.util.*;
-import java.util.logging.*;
-
-import frost.*;
-
-import frost.fcp.*;
-import frost.fileTransfer.*;
-import frost.identities.*;
-import frost.messages.*;
-
-public class GetFriendsRequestsThread extends TimerTask {
-
- private FrostIdentities identities;
- private RequestThread runner = null;
-
- private static Logger logger =
Logger.getLogger(GetFriendsRequestsThread.class.getName());
-
- public GetFriendsRequestsThread(FrostIdentities newIdentities) {
- super();
- identities = newIdentities;
- }
-
- private class RequestThread extends Thread {
- public void run() {
- doRequests();
- runner = null;
- }
- }
-
- public void run() {
- // we start and maintain a single thread here to be able to return
quickly
- // in the timertask. otherwise we block other tasks.
- if( runner == null ) {
- runner = new RequestThread();
- runner.start();
- }
- }
-
- private Set generatePrefixes() {
-
- Set prefixes = new HashSet();
-
- // process all index files
- File keypool = new File(MainFrame.keypool);
- File[] boardDirs = keypool.listFiles();
- for (int i = 0; i < boardDirs.length; i++) {
- if (boardDirs[i].isDirectory()) {
- File current = new File(boardDirs[i].getPath() +
File.separator + "files.xml");
- if (!current.isFile()) {
- continue;
- }
- FrostIndex frostIndex = null;
- Index idx = Index.getInstance();
- synchronized(idx) {
- frostIndex = idx.readKeyFile(current);
- }
- if( frostIndex != null ) {
- Collection c = frostIndex.getFilesMap().values();
- addToPrefixes(c, prefixes);
- }
- }
- }
- boardDirs = null;
- System.gc();
- return prefixes;
- }
-
- private void addToPrefixes(Collection c, Set prefixes) {
- for(Iterator it = c.iterator(); it.hasNext(); ) {
- SharedFileObject current = (SharedFileObject) it.next();
- if (current.getOwner() == null) {
- continue; //do not request anonymous files
- }
- Identity id = identities.getIdentity(current.getOwner());
- if( id == null ) {
- continue;
- }
- if
(current.getOwner().compareTo(identities.getMyId().getUniqueName()) != 0 &&
//not me
- id.getState() == FrostIdentities.FRIEND ) //marked to be helped
- {
- String newPrefix = new StringBuffer()
- .append("KSK at frost/request/")
- .append(Core.frostSettings.getValue("messageBase"))
- .append("/")
- .append(Mixed.makeFilename(current.getOwner()))
- .append("-")
- .append(current.getBatch()).toString();
-
- prefixes.add(newPrefix);
- }
- }
- }
-
- private void doRequests() {
- logger.info("starting to request requests for friends");
-
- Set prefixes = generatePrefixes();
-
- logger.info("Will help a total of " + prefixes.size() + "
batches");
- File tempFile = new File("requests" + File.separator +
"helper.tmp");
- for(Iterator it = prefixes.iterator(); it.hasNext(); ) {
- String currentPrefix = (String)it.next();
- it.remove(); // remove currentPrefix to free mem
-
- //request until a DNF - we're doing this for other
people so we don't really care
- //and its ok to request the same keys again the next
time around
-
- String date = DateFun.getDate();
- int index = -1;
- String slot;
-
- //TODO make work
-
- do {
- index++;
- slot = new StringBuffer()
- .append(currentPrefix)
- .append("-")
- .append(date)
- .append("-")
- .append(index)
- .append(".req.sha").toString();
- logger.fine("friend's request address is " +
slot);
- tempFile.delete();
-
- // sleep 1 second between requests to not hurt the node to much
- try { Thread.sleep(1000); }
- catch(Exception ex) { }
-
- } while(FcpRequest.getFile(slot,
- null,
- tempFile,
- 21,
- true, //do redirect
- false) //deep request
- != null ); //break when dnfs
-
- logger.fine("batch of " + currentPrefix + " had " +
index + " requests");
- }
- tempFile.delete();
- logger.info("finishing requesting friend's requests");
- }
-}