[Core] Replace deprecated lt.fingerprint with peer_fingerprint setting

This commit is contained in:
Calum Lind 2016-11-17 20:49:06 +00:00
parent fc902af10c
commit 089c0be89b
1 changed files with 19 additions and 28 deletions

View File

@ -48,34 +48,21 @@ class Core(component.Component):
log.debug('Core init...') log.debug('Core init...')
component.Component.__init__(self, 'Core') component.Component.__init__(self, 'Core')
# These keys will be dropped from the set_config() RPC and are deluge_version = deluge.common.get_version()
# configurable from the command-line. split_version = deluge.common.VersionSplit(deluge_version).version
self.read_only_config_keys = read_only_config_keys while len(split_version) < 4:
log.debug('read_only_config_keys: %s', read_only_config_keys) split_version.append(0)
# Create the client fingerprint deluge_fingerprint = lt.generate_fingerprint('DE', *split_version)
client_id = 'DE' user_agent = 'Deluge/{} libtorrent/{}'.format(deluge_version, self.get_libtorrent_version())
client_version = deluge.common.VersionSplit(deluge.common.get_version()).version
while len(client_version) < 4:
client_version.append(0)
# Start the libtorrent session # Start the libtorrent session.
log.info('Starting libtorrent %s (%s, %s) session...', lt.__version__, client_id, client_version) log.debug('Starting session (fingerprint: %s, user_agent: %s)', deluge_fingerprint, user_agent)
self.session = lt.session(lt.fingerprint(client_id, *client_version), flags=0) settings_pack = {'peer_fingerprint': deluge_fingerprint, 'user_agent': user_agent}
self.session = lt.session(settings_pack, flags=0)
# Load the session state if available # Load the settings, if available.
self.__load_session_state() self._load_session_state()
# Apply session settings
self.apply_session_setting(
'user_agent',
'Deluge/%(deluge_version)s libtorrent/%(lt_version)s' % {
'deluge_version': deluge.common.get_version(),
'lt_version': self.get_libtorrent_version().rpartition('.')[0]}
)
# No SSL torrent support in code so disable the listen port.
self.apply_session_setting('ssl_listen', 0)
# Enable libtorrent extensions # Enable libtorrent extensions
# Allows peers to download the metadata from the swarm directly # Allows peers to download the metadata from the swarm directly
@ -179,13 +166,18 @@ class Core(component.Component):
shutil.move(filepath_bak, filepath) shutil.move(filepath_bak, filepath)
def __load_session_state(self): def __load_session_state(self):
"""Loads the libtorrent session state""" """Loads the libtorrent session state
Returns:
dict: A libtorrent sesion state, empty dict if unable to load it.
"""
filename = 'session.state' filename = 'session.state'
filepath = get_config_dir(filename) filepath = get_config_dir(filename)
filepath_bak = filepath + '.bak' filepath_bak = filepath + '.bak'
for _filepath in (filepath, filepath_bak): for _filepath in (filepath, filepath_bak):
log.info('Opening %s for load: %s', filename, _filepath) log.debug('Opening %s for load: %s', filename, _filepath)
try: try:
with open(_filepath, 'rb') as _file: with open(_filepath, 'rb') as _file:
state = lt.bdecode(_file.read()) state = lt.bdecode(_file.read())
@ -194,7 +186,6 @@ class Core(component.Component):
else: else:
log.info('Successfully loaded %s: %s', filename, _filepath) log.info('Successfully loaded %s: %s', filename, _filepath)
self.session.load_state(state) self.session.load_state(state)
return
def get_new_release(self): def get_new_release(self):
log.debug('get_new_release') log.debug('get_new_release')