ShareManager.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.furthurnet.furi |
![]() |
![]() |
Furthurnet |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* FURI - A distributed peer-to-peer file sharing system.
* Copyright (C) 2000-2002 William W. Wong, Furthur Network
* williamw@jps.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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.furthurnet.furi;
import java.util.Vector;
import org.furthurnet.datastructures.supporting.IntegerPointer;
import org.furthurnet.servergui.FileSetInfo;
import org.furthurnet.servergui.ServerGuiConstants;
import org.furthurnet.xmlparser.NetworkSpec;
import org.furthurnet.xmlparser.SearchParamSet;
import org.furthurnet.xmlparser.XmlObject;
public class ShareManager
{
private DataChanger mStatusChangedListener;
public ShareManager()
{
mStatusChangedListener = new DataChanger();
}
public void addStatusChangedListener(IDataChangedListener listener)
{
mStatusChangedListener.addListener(listener);
}
public int getFileCount()
{
// JMA - 9/01/01
//return mNumbersToFiles.size();
try
{
return ServiceManager.getManager().getMainFrame().mPcpShareTab.getRowCount();
}
catch (Exception e)
{
return 0;
}
}
public int getTotalFileSize()
{
// JMA - 9/01/01
//return mTotalFileSize;
try
{
return ServiceManager.getManager().getMainFrame().getTotalSharingSize();
}
catch (Exception e)
{
return 0;
}
}
// JMA - 8/27/01
// I changed this method to search the File Set list instead
public Vector searchFile(String searchStr, IntegerPointer isIdSearch) throws Exception
{
//jonco
//System.out.println("this is searchStr: "+searchStr);
Vector results = new Vector();
boolean onlyCheckFilesAlreadyServing = false;
boolean amIFirewall = ServiceManager.getManager().getMainFrame().isFirewall();
SearchParamSet params = XmlObject.getSearchParamSet(searchStr);
synchronized (params)
{
if (!params.isBandSearch() && ServiceManager.getManager().getMainFrame().maxServersReached())
{
// For a firewall box, don't respond to any search if
// uploading limit has been reached.
if (amIFirewall)
return results;
else
onlyCheckFilesAlreadyServing = true;
}
}
try
{
FileSetInfo[] mySharedFileSets = (FileSetInfo[])(ServiceManager.getManager().getMainFrame().mPcpShareTab.getArray());
int numSharedFileSets = ServiceManager.getManager().getMainFrame().mPcpShareTab.getRowCount();
synchronized (mySharedFileSets)
{
// Don't search without params, unless it is an id query.
if ((params.numParams == 0) && (params.objectID == null))
return results;
try
{
if (params.furthurVersion.compareTo("1.5.4") < 0)
return results;
}
catch (Exception e)
{
return results;
}
// don't respond if the query source is a firewall
// and I am a firewall
if ((params.firewall) && (amIFirewall))
return results;
NetworkSpec networkSpec = ServiceManager.getManager().getMainFrame().getNetworkSpec(params.networkType);
// compile a list of file sets that match
for (int i=0; i<numSharedFileSets; i++)
if ((params.networkType.equals(mySharedFileSets[i].networkType))
&& (mySharedFileSets[i].active)
&& (canServe(mySharedFileSets[i].getStatus()))
&& ((!amIFirewall) || (mySharedFileSets[i].pcpMonitor == null))
&& ((amIFirewall) || (mySharedFileSets[i].pcpMonitor == null) || (!mySharedFileSets[i].pcpMonitor.reachedMaxFirewallConnections()))
&& ((!onlyCheckFilesAlreadyServing) || (mySharedFileSets[i].pcpMonitor != null)))
{
if (params.objectID != null) // just searching on objectID
{
if (params.furthurVersion.compareTo("1.5.5") >= 0) // older clients can't understand the modified id response
isIdSearch.value = 1;
if (params.objectID.equals(mySharedFileSets[i].fileId))
{
//System.out.println("match:"+mySharedFileSets[i].fileSetName);
results.addElement(mySharedFileSets[i]);
}
}
else // searching on parameters
{
if (params.matchesAttributes(mySharedFileSets[i].getAttributes(), networkSpec))
results.addElement(mySharedFileSets[i]);
}
}
}
}
catch (Exception e)
{
if (e.getMessage().equals("Version"))
throw new Exception("Version");
}
return results;
}
//JMA
private boolean canServe(String status)
{
return status.equals(ServerGuiConstants.STATUS_SERVING) ||
status.equals(ServerGuiConstants.STATUS_NOT_SERVING);
}
// JMA - 8-27-01
public void saveSharingInfo()
{
ServiceManager.getManager().getMainFrame().saveSharingInfo();
}
}
The table below shows all metrics for ShareManager.java.




