-
Notifications
You must be signed in to change notification settings - Fork 452
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
Added basic query functionality to bandwidth accounting #5689
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
[Unit] | ||
Description="Bandwidth crawler" | ||
After=network-online.target | ||
|
||
[Service] | ||
Type=simple | ||
User=crawler | ||
Group=crawler | ||
Restart=always | ||
Environment=PYTHONPATH=./src/pyipv8:./src/tribler-common:./src/tribler-core | ||
WorkingDirectory=/opt/tribler | ||
ExecStart=/usr/bin/python3 src/tribler-core/run_bandwidth_crawler.py --statedir /var/lib/crawler $EXTRA_CRAWLER_ARGS | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
""" | ||
This executable script starts a Tribler instance and joins the BandwidthAccountingCommunity. | ||
""" | ||
import argparse | ||
import sys | ||
from asyncio import ensure_future, get_event_loop | ||
from pathlib import Path | ||
|
||
from ipv8.loader import IPv8CommunityLoader | ||
|
||
from tribler_core.config.tribler_config import TriblerConfig | ||
from tribler_core.modules.bandwidth_accounting.database import BandwidthDatabase | ||
from tribler_core.modules.bandwidth_accounting.settings import BandwidthAccountingSettings | ||
from tribler_core.modules.ipv8_module_catalog import BandwidthCommunityLauncher | ||
from tribler_core.session import Session | ||
|
||
|
||
class PortAction(argparse.Action): | ||
def __call__(self, _, namespace, values, option_string=None): | ||
if not 0 < values < 2**16: | ||
raise argparse.ArgumentError(self, "Invalid port number") | ||
setattr(namespace, self.dest, values) | ||
|
||
|
||
class BandwidthCommunityCrawlerLauncher(BandwidthCommunityLauncher): | ||
|
||
def get_kwargs(self, session): | ||
settings = BandwidthAccountingSettings() | ||
settings.outgoing_query_interval = 5 | ||
database = BandwidthDatabase(session.config.get_state_dir() / "sqlite" / "bandwidth.db", | ||
session.trustchain_keypair.pub().key_to_bin(), store_all_transactions=True) | ||
|
||
return { | ||
"database": database, | ||
"settings": settings, | ||
"max_peers": -1 | ||
} | ||
|
||
|
||
async def start_crawler(tribler_config): | ||
session = Session(tribler_config) | ||
|
||
# We use our own community loader | ||
loader = IPv8CommunityLoader() | ||
session.ipv8_community_loader = loader | ||
loader.set_launcher(BandwidthCommunityCrawlerLauncher()) | ||
|
||
await session.start() | ||
|
||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description=('Start a crawler in the bandwidth accounting community')) | ||
parser.add_argument('--statedir', '-s', default='bw_crawler', type=str, help='Use an alternate statedir') | ||
parser.add_argument('--restapi', '-p', default=8085, type=str, help='Use an alternate port for the REST API', | ||
action=PortAction, metavar='{0..65535}') | ||
args = parser.parse_args(sys.argv[1:]) | ||
|
||
config = TriblerConfig(args.statedir, config_file=Path(args.statedir) / 'triblerd.conf') | ||
config.set_state_dir(Path(args.statedir).absolute()) | ||
config.set_tunnel_community_enabled(False) | ||
config.set_libtorrent_enabled(False) | ||
config.set_bootstrap_enabled(False) | ||
config.set_chant_enabled(False) | ||
config.set_torrent_checking_enabled(False) | ||
config.set_api_http_enabled(True) | ||
config.set_api_http_port(args.restapi) | ||
|
||
loop = get_event_loop() | ||
coro = start_crawler(config) | ||
ensure_future(coro) | ||
loop.run_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/tribler-core/tribler_core/modules/bandwidth_accounting/settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class BandwidthAccountingSettings: | ||
""" | ||
This class contains several settings related to the bandwidth accounting mechanism. | ||
""" | ||
outgoing_query_interval: int = 30 # The interval at which we send out queries to other peers, in seconds. | ||
max_tx_returned_in_query: int = 10 # The maximum number of bandwidth transactions to return in response to a query. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 for
argparse
usage!