-Pause all fix
-Smartproxy optimization
-Kalam light
This commit is contained in:
tonikelope 2019-06-20 14:17:04 +02:00
parent 3a3aa37804
commit c5dcaf631b
12 changed files with 77 additions and 134 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tonikelope</groupId>
<artifactId>MegaBasterd</artifactId>
<version>6.12</version>
<version>6.13</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
@ -29,6 +29,11 @@
<version>2.9.9</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-collections4</artifactId>
<version>4.3</version>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

View File

@ -20,7 +20,7 @@ import java.util.logging.Logger;
*/
public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
public static final double SLOW_PROXY_PERC = 0.5;
public static final double SLOW_PROXY_PERC = 0.1;
private final int _id;
private final Download _download;
private volatile boolean _exit;
@ -248,7 +248,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
byte[] buffer = new byte[DEFAULT_BYTE_BUFFER_SIZE];
while (!_exit && !_download.isStopped() && !_download.getChunkmanager().isExit() && chunk_reads < chunk_size && (reads = is.read(buffer, 0, Math.min((int) (chunk_size - chunk_reads), buffer.length))) != -1) {
while (!_exit && !slow_proxy && !_download.isStopped() && !_download.getChunkmanager().isExit() && chunk_reads < chunk_size && (reads = is.read(buffer, 0, Math.min((int) (chunk_size - chunk_reads), buffer.length))) != -1) {
tmp_chunk_file_os.write(buffer, 0, reads);
@ -268,19 +268,24 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
paused += System.currentTimeMillis() - pause_init_time;
} else if (!_download.isPaused() && _download.getMain_panel().getDownload_manager().isPaused_all()) {
_download.pause();
_download.pause_worker();
pause_init_time = System.currentTimeMillis();
secureWait();
paused += System.currentTimeMillis() - pause_init_time;
}
if (current_smart_proxy != null) {
long avg_chunk_speed = _download.getMain_panel().getGlobal_dl_speed().getAvg_chunk_speed();
if (avg_chunk_speed != -1) {
//Proxy speed benchmark
long chunk_speed = Math.round(chunk_reads / (((double) (System.currentTimeMillis() - init_chunk_time - paused)) / 1000));
if (chunk_speed < Math.round(avg_chunk_speed * SLOW_PROXY_PERC)) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Worker WARNING -> PROXY {1} CHUNK DOWNLOAD SPEED: {2}/s IS VERY SLOW (average is {3}/s)", new Object[]{_id, current_smart_proxy, formatBytes(chunk_speed), formatBytes(avg_chunk_speed)});
slow_proxy = true;
}
}
}
}
finish_chunk_time = System.currentTimeMillis();
@ -320,20 +325,15 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
http_error = 0;
_download.getChunkmanager().secureNotify();
if (current_smart_proxy != null) {
if (current_smart_proxy != null && finish_chunk_time != -1) {
//Update average chunk download speed using SmartProxy
long chunk_speed = Math.round(chunk_size / (((double) (finish_chunk_time - init_chunk_time - paused)) / 1000));
_download.getMain_panel().getGlobal_dl_speed().update_avg_chunk_speed(chunk_speed);
//Proxy speed benchmark
long chunk_speed = Math.round(chunk_size / ((double) (finish_chunk_time - init_chunk_time - paused) / 1000));
if (chunk_speed < Math.round(((double) _download.getMain_panel().getGlobal_dl_speed().getMaxAvgGlobalSpeed() / _download.getMain_panel().getDownload_manager().calcTotalSlotsCount()) * SLOW_PROXY_PERC)) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Worker WARNING -> PROXY SPEED: {1}/s is SLOW", new Object[]{_id, formatBytes(chunk_speed)});
slow_proxy = true;
}
}
_download.getChunkmanager().secureNotify();
}
}

View File

@ -184,13 +184,6 @@ public class ChunkUploader implements Runnable, SecureSingleThreadNotifiable {
secureWait();
} else if (!_upload.isPaused() && _upload.getMain_panel().getUpload_manager().isPaused_all()) {
_upload.pause();
_upload.pause_worker();
secureWait();
}
}
}

View File

@ -50,7 +50,7 @@ import javax.swing.UIManager;
*/
public final class MainPanel {
public static final String VERSION = "6.12";
public static final String VERSION = "6.13";
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
public static final int STREAMER_PORT = 1337;
@ -58,7 +58,7 @@ public final class MainPanel {
public static final int DEFAULT_MEGA_PROXY_PORT = 9999;
public static final String DEFAULT_LANGUAGE = "EN";
public static final boolean DEFAULT_SMART_PROXY = true;
public static Font DEFAULT_FONT = createAndRegisterFont("/fonts/Kalam-Regular.ttf");
public static Font DEFAULT_FONT = createAndRegisterFont("/fonts/Kalam-Light.ttf");
public static final float ZOOM_FACTOR = 1.0f;
public static final String DEFAULT_USER_AGENT = "Mozilla/5.0 (X11; Linux x86_64; rv:61.0) Gecko/20100101 Firefox/61.0";
public static final String ICON_FILE = "/images/mbasterd_32.png";
@ -599,16 +599,16 @@ public final class MainPanel {
if (_font != null) {
if (_font.equals("DEFAULT")) {
DEFAULT_FONT = createAndRegisterFont("/fonts/Kalam-Regular.ttf");
DEFAULT_FONT = createAndRegisterFont("/fonts/Kalam-Light.ttf");
} else {
DEFAULT_FONT = createAndRegisterFont("/fonts/NotoSansCJKtc-Regular.otf");
DEFAULT_FONT = createAndRegisterFont("/fonts/NotoSansCJK-Regular.ttc");
}
} else {
DEFAULT_FONT = createAndRegisterFont("/fonts/Kalam-Regular.ttf");
DEFAULT_FONT = createAndRegisterFont("/fonts/Kalam-Light.ttf");
}
String def_slots = selectSettingValue("default_slots_down");

View File

@ -1266,7 +1266,7 @@ public final class MiscTools {
} catch (MegaAPIException exception) {
if (exception.getCode() == -6) {
JOptionPane.showMessageDialog((Frame) container.getParent(), LabelTranslatorSingleton.getInstance().translate("You've tried to login too many times. Wait an hour."), "Error", JOptionPane.ERROR_MESSAGE);
JOptionPane.showMessageDialog(container.getParent(), LabelTranslatorSingleton.getInstance().translate("You've tried to login too many times. Wait an hour."), "Error", JOptionPane.ERROR_MESSAGE);
}
throw exception;

View File

@ -19,7 +19,7 @@ import java.util.logging.Logger;
public final class SmartMegaProxyManager {
public static String DEFAULT_SMART_PROXY_URL = "https://raw.githubusercontent.com/tonikelope/megabasterd/proxy_list/proxy_list.txt";
public static final int BLOCK_TIME = 600;
public static final int BLOCK_TIME = 300;
private volatile String _proxy_list_url;
private final LinkedHashMap<String, Long> _proxy_list;
private final MainPanel _main_panel;
@ -40,9 +40,11 @@ public final class SmartMegaProxyManager {
Set<String> keys = _proxy_list.keySet();
Long current_time = System.currentTimeMillis();
for (String k : keys) {
if (_proxy_list.get(k) < System.currentTimeMillis()) {
if (_proxy_list.get(k) < current_time) {
return k;
}
@ -105,10 +107,12 @@ public final class SmartMegaProxyManager {
_proxy_list.clear();
Long current_time = System.currentTimeMillis();
for (String proxy : proxy_list) {
if (proxy.trim().matches(".+?:[0-9]{1,5}")) {
_proxy_list.put(proxy, System.currentTimeMillis());
_proxy_list.put(proxy, current_time);
}
}
}

View File

@ -2,12 +2,14 @@ package com.tonikelope.megabasterd;
import static com.tonikelope.megabasterd.MiscTools.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import org.apache.commons.collections4.queue.CircularFifoQueue;
/**
*
@ -16,6 +18,7 @@ import javax.swing.JLabel;
public final class SpeedMeter implements Runnable {
public static final int SLEEP = 3000;
public static final int CHUNK_SPEED_QUEUE_MAX_SIZE = 5;
private final JLabel _speed_label;
private final JLabel _rem_label;
private final TransferenceManager _trans_manager;
@ -23,21 +26,52 @@ public final class SpeedMeter implements Runnable {
private long _speed_counter;
private long _speed_acumulator;
private volatile long _max_avg_global_speed;
private volatile long _avg_chunk_speed;
private final CircularFifoQueue _chunk_speed_queue;
SpeedMeter(TransferenceManager trans_manager, JLabel sp_label, JLabel rem_label) {
_speed_label = sp_label;
_rem_label = rem_label;
_trans_manager = trans_manager;
_transferences = new ConcurrentHashMap<>();
_chunk_speed_queue = new CircularFifoQueue(CHUNK_SPEED_QUEUE_MAX_SIZE);
_speed_counter = 0L;
_speed_acumulator = 0L;
_max_avg_global_speed = 0L;
_avg_chunk_speed = -1;
}
private long _getAvgGlobalSpeed() {
return Math.round((double) _speed_acumulator / _speed_counter);
}
public void setAvg_chunk_speed(long _avg_chunk_speed) {
this._avg_chunk_speed = _avg_chunk_speed;
}
public long getAvg_chunk_speed() {
return _avg_chunk_speed;
}
public void update_avg_chunk_speed(long speed) {
synchronized (this._chunk_speed_queue) {
this._chunk_speed_queue.add(speed);
long acumulador = 0;
Iterator i = this._chunk_speed_queue.iterator();
while (i.hasNext()) {
acumulador += (long) i.next();
}
this._avg_chunk_speed = Math.round(((double) acumulador) / this._chunk_speed_queue.size());
}
}
public void attachTransference(Transference transference) {
HashMap<String, Object> properties = new HashMap<>();

Binary file not shown.

View File

@ -1,93 +0,0 @@
Copyright (c) 2014, Indian Type Foundry (info@indiantypefoundry.com).
This Font Software is licensed under the SIL Open Font License, Version 1.1.
This license is copied below, and is also available with a FAQ at:
http://scripts.sil.org/OFL
-----------------------------------------------------------
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
-----------------------------------------------------------
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting -- in part or in whole -- any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 177 KiB

After

Width:  |  Height:  |  Size: 185 KiB