Search in sources :

Example 11 with LogAlert

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

the class ClientRestarterImpl method runUpdateProcess.

private boolean runUpdateProcess(boolean update_only, boolean no_wait) throws CoreException {
    PluginInterface pi = core.getPluginManager().getPluginInterfaceByID("azupdater");
    if (pi == null) {
        Logger.log(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_ERROR, "Can't update/restart, mandatory plugin 'azupdater' not found"));
        throw (new CoreException("mandatory plugin 'azupdater' not found"));
    }
    String updater_dir = pi.getPluginDirectoryName();
    classpath_prefix = updater_dir + File.separator + UPDATER_JAR;
    String app_path = SystemProperties.getApplicationPath();
    while (app_path.endsWith(File.separator)) {
        app_path = app_path.substring(0, app_path.length() - 1);
    }
    String user_path = SystemProperties.getUserPath();
    while (user_path.endsWith(File.separator)) {
        user_path = user_path.substring(0, user_path.length() - 1);
    }
    String config_override = System.getProperty(SystemProperties.SYS_PROP_CONFIG_OVERRIDE);
    if (config_override == null) {
        config_override = "";
    }
    String[] parameters = { update_only ? "updateonly" : "restart", app_path, user_path, config_override };
    FileOutputStream fos = null;
    try {
        Properties update_properties = new Properties();
        long max_mem = Runtime.getRuntime().maxMemory();
        update_properties.put("max_mem", "" + max_mem);
        update_properties.put("app_name", SystemProperties.getApplicationName());
        update_properties.put("app_entry", SystemProperties.getApplicationEntryPoint());
        if (System.getProperty(SystemProperties.SYSPROP_NATIVELAUNCHER) != null || Constants.isOSX) {
            try {
                String cmd = PlatformManagerFactory.getPlatformManager().getApplicationCommandLine();
                if (cmd != null) {
                    update_properties.put("app_cmd", cmd);
                }
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
        if (no_wait) {
            update_properties.put("no_wait", "1");
        }
        update_properties.put("instance_port", String.valueOf(Constants.INSTANCE_PORT));
        fos = new FileOutputStream(new File(user_path, UPDATE_PROPERTIES));
        // this handles unicode chars by writing \\u escapes
        update_properties.store(fos, "BiglyBT restart properties");
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    } finally {
        if (fos != null) {
            try {
                fos.close();
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
    }
    String[] properties = { "-Duser.dir=\"" + app_path + "\"" };
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    boolean res = restartApp(new PrintWriter(os) {

        @Override
        public void println(String str) {
            // we intercept these logs and log immediately
            Logger.log(new LogEvent(LOGID, str));
        }
    }, MAIN_CLASS, properties, parameters, update_only);
    // just check if any non-logged data exists
    byte[] bytes = os.toByteArray();
    if (bytes.length > 0) {
        Logger.log(new LogEvent(LOGID, "BiglyBTUpdater: extra log - " + new String(bytes)));
    }
    return (res);
}
Also used : LogEvent(com.biglybt.core.logging.LogEvent) PluginInterface(com.biglybt.pif.PluginInterface) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SystemProperties(com.biglybt.core.util.SystemProperties) Properties(java.util.Properties) LogAlert(com.biglybt.core.logging.LogAlert) CoreException(com.biglybt.core.CoreException) FileOutputStream(java.io.FileOutputStream) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 12 with LogAlert

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

the class AEDiagnostics method startup.

public static synchronized void startup(boolean _enable_pending) {
    if (started_up) {
        return;
    }
    started_up = true;
    enable_pending_writes = _enable_pending;
    try {
        // Minimize risk of loading to much when in transitory startup mode
        boolean transitoryStartup = System.getProperty("transitory.startup", "0").equals("1");
        if (transitoryStartup) {
            // no xxx_?.log logging for you!
            loggers_enabled = false;
            return;
        }
        debug_dir = FileUtil.getUserFile("logs");
        debug_save_dir = new File(debug_dir, "save");
        COConfigurationManager.addAndFireParameterListeners(new String[] { "Logger.Enabled", "Logger.DebugFiles.Enabled", "Logger.DebugFiles.SizeKB" }, new ParameterListener() {

            @Override
            public void parameterChanged(String parameterName) {
                logging_enabled = COConfigurationManager.getBooleanParameter("Logger.Enabled");
                loggers_enabled = logging_enabled && COConfigurationManager.getBooleanParameter("Logger.DebugFiles.Enabled");
                if (!loggers_enabled) {
                    boolean skipCVSCheck = System.getProperty("skip.loggers.enabled.cvscheck", "0").equals("1");
                    loggers_enabled = (!skipCVSCheck && Constants.IS_CVS_VERSION) || COConfigurationManager.getBooleanParameter("Logger.DebugFiles.Enabled.Force");
                }
                if (System.getProperty("diag.logsize", null) == null) {
                    int kb = COConfigurationManager.getIntParameter("Logger.DebugFiles.SizeKB", 0) * 1024;
                    if (kb > 0) {
                        MAX_FILE_SIZE_ACTUAL[0] = kb;
                    }
                }
            }
        });
        boolean was_tidy = COConfigurationManager.getBooleanParameter(CONFIG_KEY);
        new AEThread2("asyncify", true) {

            @Override
            public void run() {
                SimpleTimer.addEvent("AEDiagnostics:logCleaner", SystemTime.getCurrentTime() + 60000 + RandomUtils.nextInt(15000), new TimerEventPerformer() {

                    @Override
                    public void perform(TimerEvent event) {
                        cleanOldLogs();
                    }
                });
            }
        }.start();
        if (debug_dir.exists()) {
            boolean save_logs = System.getProperty("az.logging.save.debug", "true").equals("true");
            long now = SystemTime.getCurrentTime();
            File[] files = debug_dir.listFiles();
            if (files != null) {
                boolean file_found = false;
                for (int i = 0; i < files.length; i++) {
                    File file = files[i];
                    if (file.isDirectory()) {
                        continue;
                    }
                    if (!was_tidy) {
                        file_found = true;
                        if (save_logs) {
                            if (!debug_save_dir.exists()) {
                                debug_save_dir.mkdir();
                            }
                            FileUtil.copyFile(file, new File(debug_save_dir, now + "_" + file.getName()));
                        }
                    }
                }
                if (file_found) {
                    Logger.logTextResource(new LogAlert(LogAlert.UNREPEATABLE, LogAlert.AT_WARNING, "diagnostics.log_found"), new String[] { debug_save_dir.toString() });
                }
            }
        } else {
            debug_dir.mkdir();
        }
        AEJavaManagement.initialise();
    } catch (Throwable e) {
        if (!(e instanceof NoClassDefFoundError)) {
            Debug.printStackTrace(e);
        }
    } finally {
        startup_complete = true;
    }
}
Also used : LogAlert(com.biglybt.core.logging.LogAlert) ParameterListener(com.biglybt.core.config.ParameterListener)

Example 13 with LogAlert

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

the class AEDiagnostics method analyseDump.

protected static void analyseDump(File file) {
    System.out.println("Analysing " + file);
    try {
        LineNumberReader lnr = new LineNumberReader(new FileReader(file));
        try {
            boolean float_excep = false;
            boolean swt_crash = false;
            boolean browser_crash = false;
            String[] bad_dlls_uc = new String[bad_dlls.length];
            for (int i = 0; i < bad_dlls.length; i++) {
                String dll = bad_dlls[i][0];
                bad_dlls_uc[i] = (dll + ".dll").toUpperCase();
            }
            String alcohol_dll = "AxShlex";
            List<String> matches = new ArrayList<>();
            while (true) {
                String line = lnr.readLine();
                if (line == null) {
                    break;
                }
                line = line.toUpperCase();
                if (line.contains("EXCEPTION_FLT")) {
                    float_excep = true;
                } else {
                    if (line.startsWith("# C") && line.contains("[SWT-WIN32")) {
                        swt_crash = true;
                    } else if (line.contains("CURRENT THREAD") && line.contains("SWT THREAD")) {
                        swt_crash = true;
                    } else if (line.startsWith("# C") && (line.contains("[IEFRAME") || line.contains("[JSCRIPT") || line.contains("[FLASH") || line.contains("[MSHTML"))) {
                        swt_crash = browser_crash = true;
                    } else if ((line.startsWith("J ") && line.contains("SWT.BROWSER")) || (line.startsWith("C ") && line.contains("[IEFRAME")) || (line.startsWith("C ") && line.contains("[MSHTML")) || (line.startsWith("C ") && line.contains("[FLASH")) || (line.startsWith("C ") && line.contains("[JSCRIPT"))) {
                        browser_crash = true;
                    }
                    for (int i = 0; i < bad_dlls_uc.length; i++) {
                        String b_uc = bad_dlls_uc[i];
                        if (line.contains(b_uc)) {
                            String dll = bad_dlls[i][0];
                            if (dll.equals(alcohol_dll)) {
                                if (float_excep) {
                                    matches.add(dll);
                                }
                            } else {
                                matches.add(dll);
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < matches.size(); i++) {
                String dll = matches.get(i);
                String detail = MessageText.getString("platform.win32.baddll." + dll);
                Logger.logTextResource(new LogAlert(LogAlert.REPEATABLE, LogAlert.AT_WARNING, "platform.win32.baddll.info"), new String[] { dll + ".dll", detail });
            }
            if (swt_crash && browser_crash) {
                if (Constants.isWindows) {
                    if (!COConfigurationManager.getBooleanParameter("browser.internal.disable", false)) {
                        COConfigurationManager.setParameter("browser.internal.disable", true);
                        COConfigurationManager.save();
                        Logger.logTextResource(new LogAlert(LogAlert.REPEATABLE, LogAlert.AT_WARNING, "browser.internal.auto.disabled"));
                    }
                }
            }
        } finally {
            lnr.close();
        }
    } catch (Throwable e) {
        Debug.printStackTrace(e);
    }
}
Also used : LogAlert(com.biglybt.core.logging.LogAlert)

Example 14 with LogAlert

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

the class VersionCheckClient method preProcessReply.

protected void preProcessReply(Map reply, final boolean v6) {
    NetworkAdmin admin = NetworkAdmin.getSingleton();
    try {
        byte[] address = (byte[]) reply.get("source_ip_address");
        if (address != null) {
            InetAddress my_ip = InetAddress.getByName(new String(address));
            NetworkAdminASN old_asn = admin.getCurrentASN();
            NetworkAdminASN new_asn = admin.lookupCurrentASN(my_ip);
            if (!new_asn.sameAs(old_asn)) {
                if (!secondary_check_done) {
                    secondary_check_done = true;
                    new AEThread("Secondary version check", true) {

                        @Override
                        public void runSupport() {
                            getVersionCheckInfoSupport(REASON_SECONDARY_CHECK, false, true, v6);
                        }
                    }.start();
                }
            }
        }
    } catch (Throwable e) {
        if (!Debug.containsException(e, UnknownHostException.class)) {
            Debug.printStackTrace(e);
        }
    }
    Long as_advice = (Long) reply.get("as_advice");
    if (as_advice != null) {
        NetworkAdminASN current_asn = admin.getCurrentASN();
        String asn = current_asn.getASName();
        if (asn != null) {
            long advice = as_advice.longValue();
            if (advice != 0) {
                // require crypto
                String done_asn = COConfigurationManager.getStringParameter("ASN Advice Followed", "");
                if (!done_asn.equals(asn)) {
                    COConfigurationManager.setParameter("ASN Advice Followed", asn);
                    boolean change = advice == 1 || advice == 2;
                    boolean alert = advice == 1 || advice == 3;
                    if (!COConfigurationManager.getBooleanParameter("network.transport.encrypted.require")) {
                        if (change) {
                            COConfigurationManager.setParameter("network.transport.encrypted.require", true);
                        }
                        if (alert) {
                            String msg = MessageText.getString("crypto.alert.as.warning", new String[] { asn });
                            Logger.log(new LogAlert(false, LogAlert.AT_WARNING, msg));
                        }
                    }
                }
            }
        }
    }
    // set ui.toolbar.uiswitcher based on instructions from tracker
    // Really shouldn't be in VersionCheck client, but instead have some
    // listener and have the code elsewhere.  Simply calling
    // getVersionCheckInfo from "code elsewhere" (to get the cached result)
    // caused a deadlock at startup.
    Long lEnabledUISwitcher = (Long) reply.get("ui.toolbar.uiswitcher");
    if (lEnabledUISwitcher != null) {
        COConfigurationManager.setBooleanDefault("ui.toolbar.uiswitcher", lEnabledUISwitcher.longValue() == 1);
    }
}
Also used : NetworkAdmin(com.biglybt.core.networkmanager.admin.NetworkAdmin) NetworkAdminASN(com.biglybt.core.networkmanager.admin.NetworkAdminASN) LogAlert(com.biglybt.core.logging.LogAlert)

Example 15 with LogAlert

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

the class TrackerListURLConnection method readList.

private static synchronized String readList(String url_str) throws IOException {
    if (url_str.contains("info_hash=")) {
        throw (new IOException("Tracker list URLs can't be directly used as announce URLs"));
    }
    String key = "tl_" + Base32.encode(url_str.getBytes("UTF-8")) + ".txt";
    long now = SystemTime.getMonotonousTime();
    URL url = new URL(url_str);
    boolean do_cache = !url.getProtocol().equals("file");
    File cache_dir = new File(SystemProperties.getUserPath(), "cache");
    if (!cache_dir.exists()) {
        cache_dir.mkdirs();
    }
    File cache_file = new File(cache_dir, key);
    if (do_cache) {
        long cache_time = cache_file.exists() ? 60 * 60 * 1000 : 5 * 60 * 1000;
        Long last = last_downloads.get(key);
        if (last != null && now - last < cache_time) {
            if (cache_file.exists()) {
                try {
                    String result = FileUtil.readFileAsString(cache_file, 32 * 1024, "UTF-8");
                    return (result);
                } catch (Throwable e) {
                    cache_file.delete();
                }
            } else {
                return ("");
            }
        }
        last_downloads.put(key, now);
    }
    try {
        ResourceDownloader rd = ResourceDownloaderFactoryImpl.getSingleton().create(url);
        rd.setProperty("URL_Connect_Timeout", 20 * 1000);
        rd.setProperty("URL_Read_Timeout", 10 * 1000);
        InputStream is = rd.download();
        try {
            String result = FileUtil.readInputStreamAsString(is, 32 * 1024, "UTF-8");
            if (do_cache) {
                FileUtil.writeStringAsFile(cache_file, result);
            }
            return (result);
        } finally {
            is.close();
        }
    } catch (Throwable e) {
        Logger.log(new LogAlert(true, LogAlert.AT_ERROR, "Failed to load Tracker List from  '" + url_str + "'", e));
        if (do_cache && cache_file.exists()) {
            try {
                String result = FileUtil.readFileAsString(cache_file, 32 * 1024, "UTF-8");
                return (result);
            } catch (Throwable f) {
                cache_file.delete();
            }
        }
        if (e instanceof IOException) {
            throw ((IOException) e);
        } else {
            throw (new IOException(Debug.getNestedExceptionMessage(e)));
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) ResourceDownloader(com.biglybt.pif.utils.resourcedownloader.ResourceDownloader) File(java.io.File) URL(java.net.URL) LogAlert(com.biglybt.core.logging.LogAlert)

Aggregations

LogAlert (com.biglybt.core.logging.LogAlert)72 File (java.io.File)21 LogEvent (com.biglybt.core.logging.LogEvent)20 URL (java.net.URL)7 Core (com.biglybt.core.Core)5 ParameterListener (com.biglybt.core.config.ParameterListener)5 DownloadManager (com.biglybt.core.download.DownloadManager)5 TOTorrent (com.biglybt.core.torrent.TOTorrent)5 UIFunctions (com.biglybt.ui.UIFunctions)5 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 VuzeFile (com.biglybt.core.vuzefile.VuzeFile)4 PlatformManagerException (com.biglybt.pif.platform.PlatformManagerException)4 Method (java.lang.reflect.Method)4 CoreRunningListener (com.biglybt.core.CoreRunningListener)3 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)3 URLClassLoader (java.net.URLClassLoader)3 CoreException (com.biglybt.core.CoreException)2 CacheFile (com.biglybt.core.diskmanager.cache.CacheFile)2 DownloadManagerInitialisationAdapter (com.biglybt.core.download.DownloadManagerInitialisationAdapter)2