Search in sources :

Example 61 with LogEvent

use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.

the class IpFilterAutoLoaderImpl method getP2BFileVersion.

private int getP2BFileVersion(InputStream is) {
    try {
        // first 4 are 255
        for (int i = 0; i < 4; i++) {
            int byteRead = is.read();
            if (byteRead != 255) {
                return -1;
            }
        }
        // next 'P2B'
        byte[] MAGIC = new byte[] { 'P', '2', 'B' };
        for (int i = 0; i < MAGIC.length; i++) {
            byte b = MAGIC[i];
            if (b != is.read()) {
                return -1;
            }
        }
        // next: version no
        int p2bVersion = is.read();
        Logger.log(new LogEvent(LOGID, "Log Filter: loading p2b version " + p2bVersion));
        return p2bVersion;
    } catch (IOException e) {
        Debug.out(e);
    }
    return -1;
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent)

Example 62 with LogEvent

use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.

the class IpFilterAutoLoaderImpl method downloadFiltersAsync.

/**
 * @param url
 *
 * @since 3.0.1.5
 */
void downloadFiltersAsync(URL url) {
    ResourceDownloader rd = ResourceDownloaderFactoryImpl.getSingleton().create(url);
    // old dl exists, load old one while new one downloads async
    rd.addListener(new ResourceDownloaderAdapter() {

        // @see com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter#reportPercentComplete(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader, int)
        @Override
        public void reportPercentComplete(ResourceDownloader downloader, int percentage) {
        }

        @Override
        public boolean completed(ResourceDownloader downloader, InputStream data) {
            try {
                setNextAutoDownload(true);
                Logger.log(new LogEvent(LOGID, "downloaded..waiting"));
                // since this is a different thread, we can use class_mon as
                // a cheap semaphore to wait until previous load completes
                class_mon.enter();
                Logger.log(new LogEvent(LOGID, "downloaded.. copying"));
                try {
                    FileUtil.copyFile(data, FileUtil.getUserFile("ipfilter.dl"));
                    AEThread thread = new AEThread("reload ipfilters", true) {

                        @Override
                        public void runSupport() {
                            try {
                                UIFunctions uif = UIFunctionsManager.getUIFunctions();
                                if (uif != null) {
                                    uif.setStatusText("reloading.filters");
                                }
                                ipFilter.reload(false);
                                if (uif != null) {
                                    uif.setStatusText(null);
                                }
                            } catch (Exception e) {
                                Debug.out(e);
                            }
                        }
                    };
                    thread.setPriority(Thread.NORM_PRIORITY - 1);
                    thread.start();
                } catch (Exception e) {
                    Debug.out(e);
                }
            } finally {
                class_mon.exit();
            }
            return true;
        }
    });
    rd.asyncDownload();
}
Also used : ResourceDownloaderAdapter(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderAdapter) LogEvent(com.biglybt.core.logging.LogEvent) GZIPInputStream(java.util.zip.GZIPInputStream) ZipInputStream(java.util.zip.ZipInputStream) UIFunctions(com.biglybt.ui.UIFunctions) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) MalformedURLException(java.net.MalformedURLException) ResourceDownloaderException(com.biglybt.pif.utils.resourcedownloader.ResourceDownloaderException)

Example 63 with LogEvent

use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.

the class IpFilterImpl method loadFilters.

private void loadFilters(boolean allowAsyncDownloading, boolean loadOldWhileAsyncDownloading) throws Exception {
    long startTime = System.currentTimeMillis();
    ipFilterAutoLoader.loadOtherFilters(allowAsyncDownloading, loadOldWhileAsyncDownloading);
    if (getNbRanges() > 0) {
        Logger.log(new LogEvent(LOGID, (System.currentTimeMillis() - startTime) + "ms for " + getNbRanges() + ". now loading norm"));
    }
    try {
        class_mon.enter();
        List new_ipRanges = new ArrayList(1024);
        FileInputStream fin = null;
        BufferedInputStream bin = null;
        try {
            // open the file
            File filtersFile = FileUtil.getUserFile("filters.config");
            if (filtersFile.exists()) {
                fin = new FileInputStream(filtersFile);
                bin = new BufferedInputStream(fin, 16384);
                Map map = BDecoder.decode(bin);
                List list = (List) map.get("ranges");
                if (list == null) {
                    return;
                }
                Iterator iter = list.listIterator();
                while (iter.hasNext()) {
                    Map range = (Map) iter.next();
                    String description = new String((byte[]) range.get("description"), "UTF-8");
                    String startIp = new String((byte[]) range.get("start"));
                    String endIp = new String((byte[]) range.get("end"));
                    IpRangeImpl ipRange = new IpRangeImpl(description, startIp, endIp, false);
                    ipRange.setAddedToRangeList(true);
                    new_ipRanges.add(ipRange);
                }
            }
        } finally {
            if (bin != null) {
                try {
                    bin.close();
                } catch (Throwable e) {
                }
            }
            if (fin != null) {
                try {
                    fin.close();
                } catch (Throwable e) {
                }
            }
            Iterator it = new_ipRanges.iterator();
            while (it.hasNext()) {
                ((IpRange) it.next()).checkValid();
            }
            markAsUpToDate();
        }
    } finally {
        class_mon.exit();
    }
    Logger.log(new LogEvent(LOGID, (System.currentTimeMillis() - startTime) + "ms to load all IP Filters"));
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) File(java.io.File)

Example 64 with LogEvent

use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.

the class IpFilterImpl method addExcludedHash.

@Override
public void addExcludedHash(byte[] hash) {
    synchronized (this) {
        if (excluded_hashes.containsKey(hash)) {
            return;
        }
        ByteArrayHashMap<String> copy = new ByteArrayHashMap<>();
        for (byte[] k : excluded_hashes.keys()) {
            copy.put(k, "");
        }
        copy.put(hash, "");
        excluded_hashes = copy;
    }
    markAsUpToDate();
    Logger.log(new LogEvent(LOGID, "Added " + ByteFormatter.encodeString(hash) + " to excluded set"));
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent)

Example 65 with LogEvent

use of com.biglybt.core.logging.LogEvent in project BiglyBT by BiglySoftware.

the class PEPieceImpl method checkRequests.

/**
 * This will scan each block looking for requested blocks. For each one, it'll verify
 * if the PEPeer for it still exists and is still willing and able to upload data.
 * If not, it'll unmark the block as requested.
 * @return int of how many were cleared (0 to nbBlocks)
 */
/*
	public int checkRequests()
	{
        if (getTimeSinceLastActivity() <30 *1000)
            return 0;
		int cleared =0;
		boolean nullPeer =false;
		for (int i =0; i <nbBlocks; i++)
		{
			if (!downloaded[i] &&!dmPiece.isWritten(i))
			{
				final String			requester =requested[i];
				final PEPeerTransport	pt;
				if (requester !=null)
				{
					pt =manager.getTransportFromAddress(requester);
					if (pt !=null)
					{
						pt.setSnubbed(true);
						if (!pt.isDownloadPossible())
						{
                            clearRequested(i);
							cleared++;
						}
					} else
					{
						nullPeer =true;
                        clearRequested(i);
						cleared++;
					}
				}
			}
		}
		if (cleared >0)
		{
			dmPiece.clearRequested();
            if (Logger.isEnabled())
                Logger.log(new LogEvent(dmPiece.getManager().getTorrent(), LOGID, LogEvent.LT_WARNING,
                        "checkRequests(): piece #" +getPieceNumber()+" cleared " +cleared +" requests."
                        + (nullPeer ?" Null peer was detected." :"")));
		}
		return cleared;
	}
	*/
/*
		 * Parg: replaced above commented out checking with one that verifies that the
		 * requests still exist. As piece-picker activity and peer disconnect logic is multi-threaded
		 * and full of holes, this is a stop-gap measure to prevent a piece from being left with
		 * requests that no longer exist
		 */
public void checkRequests() {
    if (getTimeSinceLastActivity() < 30 * 1000) {
        return;
    }
    int cleared = 0;
    PEPeerManager manager = piecePicker.getPeerManager();
    for (int i = 0; i < nbBlocks; i++) {
        if (!downloaded[i] && !dmPiece.isWritten(i)) {
            final String requester = requested[i];
            if (requester != null) {
                if (!manager.requestExists(requester, getPieceNumber(), i * DiskManager.BLOCK_SIZE, getBlockSize(i))) {
                    clearRequested(i);
                    cleared++;
                }
            }
        }
    }
    if (cleared > 0) {
        if (Logger.isEnabled())
            Logger.log(new LogEvent(dmPiece.getManager().getTorrent(), LOGID, LogEvent.LT_WARNING, "checkRequests(): piece #" + getPieceNumber() + " cleared " + cleared + " requests"));
    } else {
        if (fully_requested && getNbUnrequested() > 0) {
            if (Logger.isEnabled())
                Logger.log(new LogEvent(dmPiece.getManager().getTorrent(), LOGID, LogEvent.LT_WARNING, "checkRequests(): piece #" + getPieceNumber() + " reset fully requested"));
            fully_requested = false;
        }
    }
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) PEPeerManager(com.biglybt.core.peer.PEPeerManager)

Aggregations

LogEvent (com.biglybt.core.logging.LogEvent)172 LogAlert (com.biglybt.core.logging.LogAlert)20 IOException (java.io.IOException)14 File (java.io.File)11 URL (java.net.URL)11 ArrayList (java.util.ArrayList)9 InetSocketAddress (java.net.InetSocketAddress)8 InputStream (java.io.InputStream)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 ZipInputStream (java.util.zip.ZipInputStream)7 CacheFileManagerException (com.biglybt.core.diskmanager.cache.CacheFileManagerException)6 TOTorrent (com.biglybt.core.torrent.TOTorrent)6 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)6 ResourceDownloader (com.biglybt.pif.utils.resourcedownloader.ResourceDownloader)6 UIFunctions (com.biglybt.ui.UIFunctions)6 SocketChannel (java.nio.channels.SocketChannel)6 Iterator (java.util.Iterator)6 ConnectionEndpoint (com.biglybt.core.networkmanager.ConnectionEndpoint)5 ClientIDException (com.biglybt.pif.clientid.ClientIDException)5 ParameterListener (com.biglybt.core.config.ParameterListener)4