Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First Credit mining prototype #2064

Merged
merged 24 commits into from
Jun 28, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7226455
Channel boosting implementation
Oct 9, 2013
168f7cc
sessioncalling arg was removed a while ago.
Aug 18, 2015
bd87ab1
Updates for API changes
Aug 18, 2015
897cdff
Add missing __init__.py
Aug 18, 2015
d713895
Don't fail when a torrent not in the download list finishes.
Aug 18, 2015
9d3201b
Remove DOS newlines from BoostingManager modifications.
Aug 18, 2015
24ebb7b
WIP commit
Aug 24, 2015
2184356
WIP commit
Aug 28, 2015
b7010d8
Fix initial work in BoostingManager that cannot work
ardhipoetra Jun 27, 2016
a31b923
Revamped creditmining GUI
ardhipoetra Jun 27, 2016
9a87521
Extract peerlist to its own function
ardhipoetra Mar 18, 2016
6600773
Create function to translate peers into health
ardhipoetra Jun 27, 2016
d7d9ccf
Create holder in GUI if credit mining is not ready yet
ardhipoetra Jun 27, 2016
ae7576c
Start boosting manager if ready only
ardhipoetra Jun 27, 2016
9b9c01a
Add dirdialog for convenience choosing source
ardhipoetra Jun 27, 2016
c2e894b
Prevent GUI to do task when quitting
ardhipoetra May 9, 2016
a33b4c7
Clean onexit in BoostingManager
ardhipoetra Jun 27, 2016
6cc9d7d
Add and clean documentation in some functions needed
ardhipoetra May 3, 2016
2310579
Add credit mining preferences by SessionConfig
ardhipoetra May 27, 2016
a85ab3c
Refactor policies, constant, and function to different file
ardhipoetra May 31, 2016
66eb87f
Fix resume data to use configparser
ardhipoetra Jun 27, 2016
57e8636
Add logger.conf, Delete bootstraptribler.txt and boostchannel.py
ardhipoetra Jun 14, 2016
b11fd65
Fix switch policy when loading config
ardhipoetra Jun 8, 2016
b9d1940
Credit mining testcase
ardhipoetra Jun 27, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Prevent GUI to do task when quitting
Squashed Commits:
- Fix resetting statistics data in list
- Loading credit mining GUI if necessary
- Enabling/Disabling feature credit mining in main
- Refactor to move credit mining instance to LaunchManyCore
- Remove singleton usage in GUI
- Disable credit mining by default on GUI
- Refactor GUI code to only provide RAW source
  • Loading branch information
ardhipoetra committed Jun 28, 2016
commit c2e894b2c98c151967860025da364f5a030621b0
155 changes: 91 additions & 64 deletions Tribler/Main/Dialogs/BoostingDialogs.py
Original file line number Diff line number Diff line change
@@ -1,130 +1,157 @@
# Written by Egbert Bouman
"""
This module contains wx dialog gui for adding/removing boosting source

Written by Egbert Bouman and Ardhi Putra Pratama H
"""

import wx

from Tribler.Main.Utility.GuiDBHandler import startWorker, GUI_PRI_DISPERSY
from Tribler.Main.vwxGUI.GuiUtility import GUIUtility
from Tribler.Policies.BoostingManager import BoostingManager, ChannelSource
from Tribler.Policies.BoostingManager import ChannelSource


class AddBoostingSource(wx.Dialog):
"""
Class for adding the source for credit mining
"""

def __init__(self, parent):
wx.Dialog.__init__(self, parent, -1, 'Add boosting source', size=(275, 275), name="AddBoostingSourceDialog")
wx.Dialog.__init__(self, parent, -1, 'Add boosting source', size=(475, 275), name="AddBoostingSourceDialog")

self.guiutility = GUIUtility.getInstance()
self.channels = []
self.source = ''

text = wx.StaticText(self, -1, 'Please enter a RSS feed URL or directory to start boosting swarms:')
# self.channel_radio = wx.RadioButton(self, -1, 'Subscribed Channel:', style=wx.RB_GROUP)
# self.channel_choice = wx.Choice(self, -1)
# self.channel_choice.Bind(wx.EVT_CHOICE, lambda evt: self.channel_radio.SetValue(True))

self.rss_feed_radio = wx.RadioButton(self, -1, 'RSS feed:')
self.rss_feed_edit = wx.TextCtrl(self, -1)
self.rss_feed_edit.Bind(wx.EVT_TEXT, lambda evt: self.rss_feed_radio.SetValue(True))

self.rss_dir_radio = wx.RadioButton(self, -1, 'RSS dir:')
self.rss_dir_radio = wx.RadioButton(self, -1, 'Torrents local directory:')
self.rss_dir_edit = wx.TextCtrl(self, -1)
self.rss_dir_edit.Bind(wx.EVT_TEXT, lambda evt: self.rss_dir_radio.SetValue(True))
self.rss_dir_edit.Bind(wx.EVT_LEFT_DOWN, self.OnDir)
self.rss_dir_edit.Bind(wx.EVT_LEFT_DOWN, self.on_open_dir)

self.archive_check = wx.CheckBox(self, -1, "Archive mode")
ok_btn = wx.Button(self, -1, "OK")
ok_btn.Bind(wx.EVT_BUTTON, self.OnOK)
ok_btn.Bind(wx.EVT_BUTTON, self.on_added_source)
cancel_btn = wx.Button(self, -1, "Cancel")
cancel_btn.Bind(wx.EVT_BUTTON, self.OnCancel)

sourceGrid = wx.FlexGridSizer(2, 2, 0, 0)
sourceGrid.AddGrowableCol(1)
sourceGrid.Add(self.rss_feed_radio, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT | wx.TOP, 5)
sourceGrid.Add(self.rss_feed_edit, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5)
sourceGrid.Add(self.rss_dir_radio, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT | wx.TOP, 5)
sourceGrid.Add(self.rss_dir_edit, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
btnSizer.Add(ok_btn, 0, wx.RIGHT | wx.TOP | wx.BOTTOM, 5)
btnSizer.Add(cancel_btn, 0, wx.ALL, 5)
vSizer = wx.BoxSizer(wx.VERTICAL)
vSizer.Add(text, 0, wx.EXPAND | wx.ALL, 5)
vSizer.Add(sourceGrid, 0, wx.EXPAND | wx.ALL, 5)
vSizer.AddSpacer((-1, 5))
vSizer.Add(self.archive_check, 0, wx.LEFT | wx.RIGHT, 10)
vSizer.AddStretchSpacer()
vSizer.Add(btnSizer, 0, wx.EXPAND | wx.ALL, 5)
self.SetSizer(vSizer)

def OnOK(self, event):
cancel_btn.Bind(wx.EVT_BUTTON, self.on_cancel)

source_grid = wx.FlexGridSizer(2, 2, 0, 0)
source_grid.AddGrowableCol(1)
source_grid.Add(self.rss_feed_radio, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT | wx.TOP, 5)
source_grid.Add(self.rss_feed_edit, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5)
source_grid.Add(self.rss_dir_radio, 0, wx.ALIGN_CENTER_VERTICAL | wx.LEFT | wx.RIGHT | wx.TOP, 5)
source_grid.Add(self.rss_dir_edit, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5)
btn_sizer = wx.BoxSizer(wx.HORIZONTAL)
btn_sizer.Add(ok_btn, 0, wx.RIGHT | wx.TOP | wx.BOTTOM, 5)
btn_sizer.Add(cancel_btn, 0, wx.ALL, 5)
v_sizer = wx.BoxSizer(wx.VERTICAL)
v_sizer.Add(text, 0, wx.EXPAND | wx.ALL, 5)
v_sizer.Add(source_grid, 0, wx.EXPAND | wx.ALL, 5)
v_sizer.AddSpacer((-1, 5))
v_sizer.Add(self.archive_check, 0, wx.LEFT | wx.RIGHT, 10)
v_sizer.AddStretchSpacer()
v_sizer.Add(btn_sizer, 0, wx.EXPAND | wx.ALL, 5)
self.SetSizer(v_sizer)

def on_added_source(self, _):
"""
this function called when user clicked 'OK' button for adding source
"""
if self.rss_feed_radio.GetValue():
self.source = self.rss_feed_edit.GetValue()
else:
self.source = self.rss_dir_edit.GetValue()

self.guiutility.Notify(
GUIUtility.getInstance().Notify(
"Successfully add source for credit mining %s" % self.source)

self.EndModal(wx.ID_OK)

def OnCancel(self, event):
def on_cancel(self, _):
"""
this function called when user clicked 'Cancel' button when adding source
thus, cancelled
"""
self.EndModal(wx.ID_CANCEL)

def GetValue(self):
def get_value(self):
"""
get the value of new source
"""
return self.source, self.archive_check.GetValue()

def OnDir(self,event):
self.rss_dir_dialog = wx.DirDialog(self, "Choose a directory:",
style=wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)
def on_open_dir(self, event):
"""
opening local directory for choosing directory source
"""
rss_dir_dialog = wx.DirDialog(self, "Choose a directory:",
style=wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST)

if self.rss_dir_dialog.ShowModal() == wx.ID_OK:
self.rss_dir_edit.SetValue(self.rss_dir_dialog.GetPath())
if rss_dir_dialog.ShowModal() == wx.ID_OK:
self.rss_dir_edit.SetValue(rss_dir_dialog.GetPath())


class RemoveBoostingSource(wx.Dialog):

"""
Class for adding the source for credit mining
"""
def __init__(self, parent):
wx.Dialog.__init__(self, parent, -1, 'Remove boosting source', size=(475, 135), name="RemoveBoostingSourceDialog")
wx.Dialog.__init__(self, parent, -1, 'Remove boosting source', size=(475, 135),
name="RemoveBoostingSourceDialog")

self.guiutility = GUIUtility.getInstance()
self.boosting_manager = BoostingManager.get_instance()
self.boosting_manager = self.guiutility.utility.session.lm.boosting_manager
self.sources = []
self.source = ''

text = wx.StaticText(self, -1, 'Please select the boosting source you wish to remove:')
self.source_label = wx.StaticText(self, -1, 'Source:')
self.source_choice = wx.Choice(self, -1)
ok_btn = wx.Button(self, -1, "OK")
ok_btn.Bind(wx.EVT_BUTTON, self.OnOK)
ok_btn.Bind(wx.EVT_BUTTON, self.on_remove_source)
cancel_btn = wx.Button(self, -1, "Cancel")
cancel_btn.Bind(wx.EVT_BUTTON, self.OnCancel)

sourceSizer = wx.BoxSizer(wx.HORIZONTAL)
sourceSizer.Add(self.source_label, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5)
sourceSizer.Add(self.source_choice, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
btnSizer.Add(ok_btn, 0, wx.RIGHT | wx.TOP | wx.BOTTOM, 5)
btnSizer.Add(cancel_btn, 0, wx.ALL, 5)
vSizer = wx.BoxSizer(wx.VERTICAL)
vSizer.Add(text, 0, wx.EXPAND | wx.ALL, 5)
vSizer.Add(sourceSizer, 0, wx.EXPAND | wx.ALL, 5)
vSizer.AddStretchSpacer()
vSizer.Add(btnSizer, 0, wx.EXPAND | wx.ALL, 5)
self.SetSizer(vSizer)

channels = []
cancel_btn.Bind(wx.EVT_BUTTON, self.on_cancel)

sourcesizer = wx.BoxSizer(wx.HORIZONTAL)
sourcesizer.Add(self.source_label, 0, wx.ALIGN_CENTER_VERTICAL | wx.RIGHT | wx.TOP, 5)
sourcesizer.Add(self.source_choice, 1, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 5)
btnsizer = wx.BoxSizer(wx.HORIZONTAL)
btnsizer.Add(ok_btn, 0, wx.RIGHT | wx.TOP | wx.BOTTOM, 5)
btnsizer.Add(cancel_btn, 0, wx.ALL, 5)
vsizer = wx.BoxSizer(wx.VERTICAL)
vsizer.Add(text, 0, wx.EXPAND | wx.ALL, 5)
vsizer.Add(sourcesizer, 0, wx.EXPAND | wx.ALL, 5)
vsizer.AddStretchSpacer()
vsizer.Add(btnsizer, 0, wx.EXPAND | wx.ALL, 5)
self.SetSizer(vsizer)

# retrieve all source except channel source
self.sources = [s.getSource() for s in self.boosting_manager.boosting_sources.values()
self.sources = [s.get_source_text() for s in self.boosting_manager.boosting_sources.values()
if not isinstance(s, ChannelSource)]

self.source_choice.SetItems(self.sources)

def OnOK(self, event):
def on_remove_source(self, _):
"""
this function called when user clicked 'OK' button for removing source
"""
selection = self.source_choice.GetSelection()
if selection < len(self.sources):
self.source = self.sources[selection]
self.EndModal(wx.ID_OK)

def OnCancel(self, event):
def on_cancel(self, _):
"""
this function called when user clicked 'Cancel' button when adding source
thus, cancelled
"""
self.EndModal(wx.ID_CANCEL)

def GetValue(self):
def get_value(self):
"""
get value when removing source
"""
return self.source
20 changes: 4 additions & 16 deletions Tribler/Main/tribler_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# see LICENSE.txt for license information
#
from Tribler.Core.Modules.process_checker import ProcessChecker
from Tribler.Policies.BoostingManager import BoostingManager
from Tribler.Main.Dialogs.NewVersionDialog import NewVersionDialog

try:
Expand All @@ -28,7 +27,6 @@
import tempfile
import traceback
import urllib2
import shutil
from collections import defaultdict
from random import randint
from traceback import print_exc
Expand Down Expand Up @@ -399,8 +397,6 @@ def PostInit2(self):
# TODO(emilon): Use the LogObserver I already implemented
# self.dispersy.callback.attach_exception_handler(self.frame.exceptionHandler)

startWorker(None, self.loadSessionCheckpoint, delay=5.0, workerType="ThreadPool")

@forceWxThread
def sesscb_ntfy_myprefupdates(self, subject, changeType, objectID, *args):
if self._frame_and_ready():
Expand Down Expand Up @@ -686,8 +682,9 @@ def sesscb_ntfy_torrentupdates(self, events):
manager = self.frame.librarylist.GetManager()
manager.torrentsUpdated(infohashes)

manager = self.frame.creditminingpanel.cmlist.GetManager()
manager.torrentsUpdated(infohashes)
if self.utility.session.get_creditmining_enable():
manager = self.frame.creditminingpanel.cmlist.GetManager()
manager.torrents_updated(infohashes)

from Tribler.Main.Utility.GuiDBTuples import CollectedTorrent

Expand All @@ -710,7 +707,7 @@ def sesscb_ntfy_torrentfinished(self, subject, changeType, objectID, *args):
if self._frame_and_ready():
infohash = objectID
torrent = self.guiUtility.torrentsearch_manager.getTorrentByInfohash(infohash)
# Check if we got the actual torrent as the bandwith investor
# Check if we got the actual torrent as the bandwidth investor
# downloads aren't going to be there.
if torrent:
self.guiUtility.library_manager.addDownloadState(torrent)
Expand Down Expand Up @@ -823,15 +820,6 @@ def OnExit(self):
self.webUI.stop()
self.webUI.delInstance()

if self.boosting_manager:

#remove credit mining data
#TODO(ardhi) : not persistent mode only
import shutil; shutil.rmtree(self.boosting_manager.credit_mining_path, ignore_errors=True)

self.boosting_manager.shutdown()
self.boosting_manager.del_instance()

if self.frame:
self.frame.Destroy()
self.frame = None
Expand Down
Loading