Skip to content

Commit

Permalink
v 0.7.8
Browse files Browse the repository at this point in the history
    - Added Additional BitTorrent Trackers to Client.
    - Updated ZeroNet Core Package.
  • Loading branch information
canewsin committed Dec 12, 2020
1 parent 5a26271 commit 90319a7
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 8 deletions.
4 changes: 2 additions & 2 deletions android/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
flutter.versionName=v 0.7.7
flutter.versionCode=25
flutter.versionName=v 0.7.8
flutter.versionCode=30
4 changes: 4 additions & 0 deletions lib/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import '../imports.dart';
abstract class Setting {
String name;
String description;
bool hidden = false;
Setting({
this.name,
this.description,
this.hidden,
});

Map toMap();
Expand All @@ -24,9 +26,11 @@ class ToggleSetting extends Setting {
this.name,
this.description,
this.value,
bool hidden = false,
}) : super(
name: name,
description: description,
hidden: hidden,
);

@override
Expand Down
18 changes: 18 additions & 0 deletions lib/others/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import '../imports.dart';
Directory appPrivDir;
Directory tempDir;
Directory metaDir = Directory(dataDir + '/meta');
Directory trackersDir = Directory(dataDir + '/trackers');
AndroidDeviceInfo deviceInfo;
bool isZeroNetInstalledm = false;
bool isZeroNetDownloadedm = false;
Expand All @@ -19,6 +20,7 @@ bool isExecPermitted = false;
bool debugZeroNetCode = false;
bool enableTorLogConsole = false;
bool vibrateonZeroNetStart = false;
bool enableZeroNetAddTrackers = false;
int downloadStatus = 0;
Map downloadsMap = {};
Map downloadStatusMap = {};
Expand All @@ -45,6 +47,10 @@ FlutterBackgroundService service;

String downloadLink(String item) =>
releases + 'Android_Module_Binaries/$item.zip';

String trackerRepo = 'https://cdn.jsdelivr.net/gh/ngosang/trackerslist/';
String downloadTrackerLink(String item) => trackerRepo + item;

bool isUsrBinExists() => Directory(dataDir + '/usr').existsSync();
bool isZeroNetExists() => Directory(dataDir + '/ZeroNet-py3').existsSync();
String downloadingMetaDir(String tempDir, String name, String key) =>
Expand All @@ -64,6 +70,17 @@ List<String> files(String arch) => [
'tor_$arch',
];

List<String> trackerFileNames = [
'trackers_best.txt',
'trackers_all.txt',
'trackers_all_udp.txt',
'trackers_all_http.txt',
'trackers_all_https.txt',
'trackers_all_ws.txt',
'trackers_best_ip.txt',
'trackers_all_ip.txt',
];

init() async {
getArch();
kIsPlayStoreInstall = await isPlayStoreInstall();
Expand All @@ -75,6 +92,7 @@ init() async {
if (isZeroNetInstalledm) {
varStore.isZeroNetInstalled(isZeroNetInstalledm);
checkForAppUpdates();
downloadTrackerFiles();
runZeroNetService(
autoStart: (varStore.settings[autoStartZeroNet] as ToggleSetting).value,
);
Expand Down
8 changes: 8 additions & 0 deletions lib/others/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ const String enableZeroNetConsoleDes =
const String enableZeroNetFilters = 'Enable ZeroNet Filters';
const String enableZeroNetFiltersDes =
'Enabling ZeroNet Filters blocks known ametuer content sites and spam users.';
const String enableAdditionalTrackers = 'Additional BitTorrent Trackers';
const String enableAdditionalTrackersDes =
'Enabling External/Additional BitTorrent Trackers will give more ZeroNet Site Seeders or Clients.';
const String pluginManager = 'Plugin Manager';
const String pluginManagerDes = 'Enable/Disable ZeroNet Plugins';
const String vibrateOnZeroNetStart = 'Vibrate on ZeroNet Start';
Expand Down Expand Up @@ -217,6 +220,11 @@ class Utils {
description: batteryOptimisationDes,
value: false,
),
enableAdditionalTrackers: ToggleSetting(
name: enableAdditionalTrackers,
description: enableAdditionalTrackersDes,
value: true,
),
enableZeroNetFilters: ToggleSetting(
name: enableZeroNetFilters,
description: enableZeroNetFiltersDes,
Expand Down
26 changes: 26 additions & 0 deletions lib/others/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,29 @@ installPlugin(File file) async {
),
);
}

void downloadTrackerFiles() async {
DateTime pastTime;
int hrs = -1;
File timestamp = File(trackersDir.path + '/timestamp');
if (timestamp.existsSync()) {
int epoch = int.parse(timestamp.readAsStringSync());
pastTime = DateTime.fromMillisecondsSinceEpoch(epoch);
hrs = pastTime.difference(DateTime.now()).inHours;
} else {
timestamp.createSync(recursive: true);
timestamp.writeAsStringSync('${DateTime.now().millisecondsSinceEpoch}');
}
if (hrs == -1 || hrs > 24) {
await FlutterDownloader.initialize();
for (var item in trackerFileNames) {
await FlutterDownloader.enqueue(
url: downloadTrackerLink(item),
savedDir: trackersDir.path,
showNotification: false,
openFileFromNotification: false,
);
}
timestamp.writeAsStringSync('${DateTime.now().millisecondsSinceEpoch}');
}
}
25 changes: 19 additions & 6 deletions lib/others/zeronet_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ Future checkInitStatus() async {
zeroNetUrl = defZeroNetUrl;
varStore.zeroNetWrapperKey = key;
uiStore.setZeroNetStatus(ZeroNetStatus.RUNNING);
ZeroNet.instance.connect(
zeroNetIPwithPort(defZeroNetUrl),
Utils.urlZeroNetMob,
);
ZeroNet.instance
.connect(
zeroNetIPwithPort(defZeroNetUrl),
Utils.urlZeroNetMob,
)
.catchError((onError) => printToConsole(onError));
service.sendData({'notification': 'ZeroNetStatus.RUNNING'});
testUrl();
} catch (e) {
Expand Down Expand Up @@ -109,6 +111,7 @@ runZeroNet() {
service.sendData({'console': startZeroNetLog + '\n'});
var python = zeroNetNativeDir + '/libpython3.8.so';
var openssl = zeroNetNativeDir + '/libopenssl.so';
var trackerFile = trackersDir.path + '/${trackerFileNames[7]}';

if (File(python).existsSync()) {
Process.start('$python', [
Expand All @@ -117,7 +120,9 @@ runZeroNet() {
"--start_dir",
zeroNetDir,
"--openssl_bin_file",
openssl
openssl,
if (enableZeroNetAddTrackers) '--trackers_file',
if (enableZeroNetAddTrackers) trackerFile,
], environment: {
"LD_LIBRARY_PATH": "$libDir:$libDir64:/system/lib64",
'PYTHONHOME': '$dataDir/usr',
Expand Down Expand Up @@ -160,9 +165,10 @@ void runZeroNetService({bool autoStart = false}) async {
? true
: (varStore.settings[autoStartZeroNetonBoot] as ToggleSetting).value;
bool filtersEnabled =
(varStore.settings[enableZeroNetFilters] as ToggleSetting).value;
(varStore.settings[enableZeroNetFilters] as ToggleSetting).value ?? true;
if (filtersEnabled) await activateFilters();
printToConsole(startZeroNetLog);
//TODO?: Check for Bugs Here.
if (await FlutterBackgroundService().isServiceRunning())
FlutterBackgroundService.initialize(
runBgIsolate,
Expand Down Expand Up @@ -193,6 +199,9 @@ void runBgIsolate() {
(varStore.settings[debugZeroNet] as ToggleSetting).value;
enableTorLogConsole =
(varStore.settings[enableTorLog] as ToggleSetting).value;
enableZeroNetAddTrackers =
(varStore.settings[enableAdditionalTrackers] as ToggleSetting)
.value;
vibrateonZeroNetStart =
(varStore.settings[vibrateOnZeroNetStart] as ToggleSetting).value;
runZeroNet();
Expand Down Expand Up @@ -220,6 +229,7 @@ void onBgServiceDataReceivedForIsolate(Map<String, dynamic> data) {
enableTorLogConsole = initMap['enableTorLog'];
zeroNetStartedFromBoot = initMap['zeroNetStartedFromBoot'];
vibrateonZeroNetStart = initMap['vibrateOnZeroNetStart'];
enableZeroNetAddTrackers = initMap['enableAdditionalTrackers'];
setBgServiceRunningNotification();
} else if (data.keys.first == 'notification') {
if (data.values.first == 'ZeroNetStatus.RUNNING') {
Expand Down Expand Up @@ -257,6 +267,9 @@ void onBgServiceDataReceived(Map<String, dynamic> data) {
(varStore.settings[enableTorLog] as ToggleSetting).value,
'vibrateOnZeroNetStart':
(varStore.settings[vibrateOnZeroNetStart] as ToggleSetting).value,
'enableAdditionalTrackers':
(varStore.settings[enableAdditionalTrackers] as ToggleSetting)
.value,
}
});
if (zeroNetNativeDir.isEmpty || zeroNetNativeDir == null) {
Expand Down

0 comments on commit 90319a7

Please sign in to comment.