Daemon 0.21 updates #223

Merged
akinwale merged 5 commits from daemon-components into master 2018-08-13 08:12:14 +02:00
11 changed files with 109 additions and 64 deletions

View file

@ -10,9 +10,8 @@ import {
NativeModules NativeModules
} from 'react-native'; } from 'react-native';
import { createStore, applyMiddleware, compose, combineReducers } from 'redux'; import { createStore, applyMiddleware, compose, combineReducers } from 'redux';
import { import { createLogger } from 'redux-logger';
StackNavigator, addNavigationHelpers import { StackNavigator, addNavigationHelpers } from 'react-navigation';
} from 'react-navigation';
import { AppNavigator } from './component/AppNavigator'; import { AppNavigator } from './component/AppNavigator';
import AppWithNavigationState from './component/AppNavigator'; import AppWithNavigationState from './component/AppNavigator';
import { persistStore, autoRehydrate } from 'redux-persist'; import { persistStore, autoRehydrate } from 'redux-persist';
@ -80,6 +79,7 @@ const reducers = combineReducers({
}); });
const bulkThunk = createBulkThunkMiddleware(); const bulkThunk = createBulkThunkMiddleware();
const logger = createLogger({ collapsed: true });
const middleware = [thunk, bulkThunk, reactNavigationMiddleware]; const middleware = [thunk, bulkThunk, reactNavigationMiddleware];
// eslint-disable-next-line no-underscore-dangle // eslint-disable-next-line no-underscore-dangle

View file

@ -17,6 +17,9 @@ class SettingsPage extends React.PureComponent {
setClientSetting setClientSetting
} = this.props; } = this.props;
// default to true if the setting is null or undefined
const actualKeepDaemonRunning = (keepDaemonRunning === null || keepDaemonRunning === undefined) ? true : keepDaemonRunning;
return ( return (
<View> <View>
<PageHeader title={"Settings"} <PageHeader title={"Settings"}
@ -47,7 +50,7 @@ class SettingsPage extends React.PureComponent {
<Text style={settingsStyle.description}>Enable this option for quicker app launch and to keep the synchronisation with the blockchain up to date.</Text> <Text style={settingsStyle.description}>Enable this option for quicker app launch and to keep the synchronisation with the blockchain up to date.</Text>
</View> </View>
<View style={settingsStyle.switchContainer}> <View style={settingsStyle.switchContainer}>
<Switch value={keepDaemonRunning} onValueChange={(value) => { <Switch value={actualKeepDaemonRunning} onValueChange={(value) => {
setClientSetting(SETTINGS.KEEP_DAEMON_RUNNING, value); setClientSetting(SETTINGS.KEEP_DAEMON_RUNNING, value);
if (NativeModules.DaemonServiceControl) { if (NativeModules.DaemonServiceControl) {
NativeModules.DaemonServiceControl.setKeepDaemonRunning(value); NativeModules.DaemonServiceControl.setKeepDaemonRunning(value);

View file

@ -26,7 +26,6 @@ class SplashScreen extends React.PureComponent {
isRunning: false, isRunning: false,
isLagging: false, isLagging: false,
launchUrl: null, launchUrl: null,
didDownloadHeaders: false,
isDownloadingHeaders: false, isDownloadingHeaders: false,
headersDownloadProgress: 0 headersDownloadProgress: 0
}); });
@ -55,7 +54,9 @@ class SplashScreen extends React.PureComponent {
_updateStatusCallback(status) { _updateStatusCallback(status) {
const startupStatus = status.startup_status; const startupStatus = status.startup_status;
if (startupStatus.code == 'started') { // At the minimum, wallet should be started and blocks_behind equal to 0 before calling resolve
const hasStarted = startupStatus.wallet && status.wallet.blocks_behind <= 0;
if (hasStarted) {
// Wait until we are able to resolve a name before declaring // Wait until we are able to resolve a name before declaring
// that we are done. // that we are done.
// TODO: This is a hack, and the logic should live in the daemon // TODO: This is a hack, and the logic should live in the daemon
@ -88,37 +89,33 @@ class SplashScreen extends React.PureComponent {
return; return;
neb-b commented 2018-08-13 04:53:00 +02:00 (Migrated from github.com)
Review

Aren't the headers not downloaded at this point?
blockchainHeaders.download_progress < 100
Then didDownloadHeaders is set to true

Aren't the headers not downloaded at this point? `blockchainHeaders.download_progress < 100` Then `didDownloadHeaders` is set to `true`
akinwale commented 2018-08-13 07:31:08 +02:00 (Migrated from github.com)
Review

I'm supposed to remove this setState call as it's not needed anymore. The check is also supposed to be if (blockchainHeaders && blockchainHeaders.downloading_headers).

I'm supposed to remove this `setState` call as it's not needed anymore. The check is also supposed to be `if (blockchainHeaders && blockchainHeaders.downloading_headers)`.
} }
const blockchainStatus = status.blockchain_status; const blockchainHeaders = status.blockchain_headers;
if (blockchainStatus) { const walletStatus = status.wallet;
if (blockchainHeaders) {
this.setState({ this.setState({
isDownloadingHeaders: blockchainStatus.is_downloading_headers, isDownloadingHeaders: blockchainHeaders.downloading_headers,
headersDownloadProgress: blockchainStatus.headers_download_progress headersDownloadProgress: blockchainHeaders.download_progress
}); });
} }
if (blockchainStatus && (blockchainStatus.is_downloading_headers || if (blockchainHeaders && blockchainHeaders.downloading_headers) {
(this.state.didDownloadHeaders && 'loading_wallet' === startupStatus.code))) { const downloadProgress = blockchainHeaders.download_progress ? blockchainHeaders.download_progress : 0;
if (!this.state.didDownloadHeaders) {
this.setState({ didDownloadHeaders: true });
}
this.setState({ this.setState({
message: 'Blockchain Sync', message: 'Blockchain Sync',
details: `Catching up with the blockchain (${blockchainStatus.headers_download_progress}%)`, details: `Catching up with the blockchain (${downloadProgress}%)`,
isLagging: startupStatus.is_lagging
}); });
} else if (blockchainStatus && blockchainStatus.blocks_behind > 0) { } else if (walletStatus && walletStatus.blocks_behind > 0) {
const behind = blockchainStatus.blocks_behind; const behind = walletStatus.blocks_behind;
const behindText = behind + ' block' + (behind == 1 ? '' : 's') + ' behind'; const behindText = behind + ' block' + (behind == 1 ? '' : 's') + ' behind';
this.setState({ this.setState({
message: 'Blockchain Sync', message: 'Blockchain Sync',
details: behindText, details: behindText,
isLagging: startupStatus.is_lagging,
}); });
} else { } else {
this.setState({ this.setState({
message: 'Network Loading', message: 'Network Loading',
details: startupStatus.message + (startupStatus.is_lagging ? '' : '...'), details: 'Initializing LBRY service...'
isLagging: startupStatus.is_lagging,
}); });
} }
setTimeout(() => { setTimeout(() => {

View file

@ -1,22 +1,10 @@
import { AsyncStorage } from 'react-native'; import { AsyncStorage } from 'react-native';
import { ACTIONS, SETTINGS } from 'lbry-redux'; import { ACTIONS } from 'lbry-redux';
getAsyncStorageItem = key => {
return AsyncStorage.getItem(key).then(value => {
if (['true', 'false'].indexOf(value) > -1) {
return value === 'true';
}
return value;
});
};
const reducers = {}; const reducers = {};
const defaultState = { const defaultState = {
clientSettings: { clientSettings: {}
backgroundPlayEnabled: getAsyncStorageItem(SETTINGS.BACKGROUND_PLAY_ENABLED),
keepDaemonRunning: getAsyncStorageItem(SETTINGS.KEEP_DAEMON_RUNNING),
showNsfw: getAsyncStorageItem(SETTINGS.SHOW_NSFW)
}
}; };
reducers[ACTIONS.CLIENT_SETTING_CHANGED] = (state, action) => { reducers[ACTIONS.CLIENT_SETTING_CHANGED] = (state, action) => {
@ -24,13 +12,13 @@ reducers[ACTIONS.CLIENT_SETTING_CHANGED] = (state, action) => {
const clientSettings = Object.assign({}, state.clientSettings); const clientSettings = Object.assign({}, state.clientSettings);
clientSettings[key] = value; clientSettings[key] = value;
AsyncStorage.setItem(key, String(value));
return Object.assign({}, state, { return Object.assign({}, state, {
clientSettings, clientSettings,
}); });
}; };
export default function reducer(state = defaultState, action) { export default function reducer(state = defaultState, action) {
const handler = reducers[action.type]; const handler = reducers[action.type];
if (handler) return handler(state, action); if (handler) return handler(state, action);

View file

@ -36,7 +36,7 @@ version.filename = %(source.dir)s/main.py
# (list) Application requirements # (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy # comma seperated e.g. requirements = sqlite3,kivy
requirements = openssl, sqlite3, hostpython2, android, distro, pyjnius, certifi==2018.4.16, constantly, incremental, functools32, miniupnpc==1.9, gmpy==1.17, twisted==16.6.0, appdirs==1.4.3, argparse==1.2.1, docopt==0.6.2, base58==0.2.2, colorama==0.3.7, dnspython==1.12.0, ecdsa==0.13, envparse==0.2.0, jsonrpc==1.2, jsonrpclib==0.1.7, jsonschema==2.5.1, pbkdf2==1.3, pyyaml==3.12, qrcode==5.2.2, requests==2.9.1, seccure==0.3.1.3, attrs==18.1.0, pyasn1, pyasn1-modules, service_identity==16.0.0, six==1.9.0, slowaes==0.1a1, txJSON-RPC==0.5, wsgiref==0.1.2, zope.interface==4.3.3, protobuf==3.2.0, keyring==10.4.0, git+https://github.com/lbryio/lbryschema.git@v0.0.16#egg=lbryschema, git+https://github.com/lbryio/lbryum.git#egg=lbryum, git+https://github.com/lbryio/lbry.git@v0.20.4#egg=lbrynet, asn1crypto, cryptography==2.2.2, pyopenssl==17.4.0, treq==17.8.0, funcsigs, mock, pbr, unqlite requirements = openssl, sqlite3, hostpython2, android, distro, pyjnius, certifi==2018.4.16, constantly, incremental, functools32, miniupnpc==1.9, gmpy==1.17, twisted==16.6.0, appdirs==1.4.3, argparse==1.2.1, docopt==0.6.2, base58==0.2.2, colorama==0.3.7, dnspython==1.12.0, ecdsa==0.13, envparse==0.2.0, jsonrpc==1.2, jsonrpclib==0.1.7, jsonschema==2.5.1, pbkdf2==1.3, pyyaml==3.12, qrcode==5.2.2, requests==2.9.1, seccure==0.3.1.3, attrs==18.1.0, pyasn1, pyasn1-modules, service_identity==16.0.0, six==1.9.0, slowaes==0.1a1, txJSON-RPC==0.5, wsgiref==0.1.2, zope.interface==4.3.3, protobuf==3.2.0, keyring==10.4.0, netifaces, txupnp==0.0.1a10, git+https://github.com/lbryio/lbryschema.git@v0.0.16#egg=lbryschema, git+https://github.com/lbryio/lbryum.git#egg=lbryum, git+https://github.com/lbryio/lbry.git#egg=lbrynet, asn1crypto, cryptography==2.2.2, pyopenssl==17.4.0, treq==17.8.0, funcsigs, mock, pbr, unqlite
# (str) Custom source folders for requirements # (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes # Sets custom source for any requirements with recipes

View file

@ -36,7 +36,7 @@ version.filename = %(source.dir)s/main.py
# (list) Application requirements # (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy # comma seperated e.g. requirements = sqlite3,kivy
requirements = openssl, sqlite3, hostpython2, android, distro, pyjnius, certifi==2018.4.16, constantly, incremental, functools32, miniupnpc==1.9, gmpy==1.17, twisted==16.6.0, appdirs==1.4.3, argparse==1.2.1, docopt==0.6.2, base58==0.2.2, colorama==0.3.7, dnspython==1.12.0, ecdsa==0.13, envparse==0.2.0, jsonrpc==1.2, jsonrpclib==0.1.7, jsonschema==2.5.1, pbkdf2==1.3, pyyaml==3.12, qrcode==5.2.2, requests==2.9.1, seccure==0.3.1.3, attrs==18.1.0, pyasn1, pyasn1-modules, service_identity==16.0.0, six==1.9.0, slowaes==0.1a1, txJSON-RPC==0.5, wsgiref==0.1.2, zope.interface==4.3.3, protobuf==3.2.0, keyring==10.4.0, git+https://github.com/lbryio/lbryschema.git@v0.0.16#egg=lbryschema, git+https://github.com/lbryio/lbryum.git#egg=lbryum, git+https://github.com/lbryio/lbry.git@v0.20.4#egg=lbrynet, asn1crypto, cryptography==2.2.2, pyopenssl==17.4.0, treq==17.8.0, funcsigs, mock, pbr, unqlite requirements = openssl, sqlite3, hostpython2, android, distro, pyjnius, certifi==2018.4.16, constantly, incremental, functools32, miniupnpc==1.9, gmpy==1.17, twisted==16.6.0, appdirs==1.4.3, argparse==1.2.1, docopt==0.6.2, base58==0.2.2, colorama==0.3.7, dnspython==1.12.0, ecdsa==0.13, envparse==0.2.0, jsonrpc==1.2, jsonrpclib==0.1.7, jsonschema==2.5.1, pbkdf2==1.3, pyyaml==3.12, qrcode==5.2.2, requests==2.9.1, seccure==0.3.1.3, attrs==18.1.0, pyasn1, pyasn1-modules, service_identity==16.0.0, six==1.9.0, slowaes==0.1a1, txJSON-RPC==0.5, wsgiref==0.1.2, zope.interface==4.3.3, protobuf==3.2.0, keyring==10.4.0, netifaces, txupnp==0.0.1a10, git+https://github.com/lbryio/lbryschema.git@v0.0.16#egg=lbryschema, git+https://github.com/lbryio/lbryum.git#egg=lbryum, git+https://github.com/lbryio/lbry.git#egg=lbrynet, asn1crypto, cryptography==2.2.2, pyopenssl==17.4.0, treq==17.8.0, funcsigs, mock, pbr, unqlite
# (str) Custom source folders for requirements # (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes # Sets custom source for any requirements with recipes

View file

@ -36,7 +36,7 @@ version.filename = %(source.dir)s/main.py
# (list) Application requirements # (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy # comma seperated e.g. requirements = sqlite3,kivy
requirements = openssl, sqlite3, hostpython2, android, distro, pyjnius, certifi==2018.4.16, constantly, incremental, functools32, miniupnpc==1.9, gmpy==1.17, twisted==16.6.0, appdirs==1.4.3, argparse==1.2.1, docopt==0.6.2, base58==0.2.2, colorama==0.3.7, dnspython==1.12.0, ecdsa==0.13, envparse==0.2.0, jsonrpc==1.2, jsonrpclib==0.1.7, jsonschema==2.5.1, pbkdf2==1.3, pyyaml==3.12, qrcode==5.2.2, requests==2.9.1, seccure==0.3.1.3, attrs==18.1.0, pyasn1, pyasn1-modules, service_identity==16.0.0, six==1.9.0, slowaes==0.1a1, txJSON-RPC==0.5, wsgiref==0.1.2, zope.interface==4.3.3, protobuf==3.2.0, keyring==10.4.0, git+https://github.com/lbryio/lbryschema.git@v0.0.16#egg=lbryschema, git+https://github.com/lbryio/lbryum.git#egg=lbryum, git+https://github.com/lbryio/lbry.git@v0.20.4#egg=lbrynet, asn1crypto, cryptography==2.2.2, pyopenssl==17.4.0, treq==17.8.0, funcsigs, mock, pbr, unqlite requirements = openssl, sqlite3, hostpython2, android, distro, pyjnius, certifi==2018.4.16, constantly, incremental, functools32, miniupnpc==1.9, gmpy==1.17, twisted==16.6.0, appdirs==1.4.3, argparse==1.2.1, docopt==0.6.2, base58==0.2.2, colorama==0.3.7, dnspython==1.12.0, ecdsa==0.13, envparse==0.2.0, jsonrpc==1.2, jsonrpclib==0.1.7, jsonschema==2.5.1, pbkdf2==1.3, pyyaml==3.12, qrcode==5.2.2, requests==2.9.1, seccure==0.3.1.3, attrs==18.1.0, pyasn1, pyasn1-modules, service_identity==16.0.0, six==1.9.0, slowaes==0.1a1, txJSON-RPC==0.5, wsgiref==0.1.2, zope.interface==4.3.3, protobuf==3.2.0, keyring==10.4.0, netifaces, txupnp==0.0.1a10, git+https://github.com/lbryio/lbryschema.git@v0.0.16#egg=lbryschema, git+https://github.com/lbryio/lbryum.git#egg=lbryum, git+https://github.com/lbryio/lbry.git#egg=lbrynet, asn1crypto, cryptography==2.2.2, pyopenssl==17.4.0, treq==17.8.0, funcsigs, mock, pbr, unqlite
# (str) Custom source folders for requirements # (str) Custom source folders for requirements
# Sets custom source for any requirements with recipes # Sets custom source for any requirements with recipes

View file

@ -0,0 +1,25 @@
import glob
from pythonforandroid.toolchain import CompiledComponentsPythonRecipe, Recipe
from os.path import join
import sh
class NetifacesRecipe(CompiledComponentsPythonRecipe):
version = '0.10.7'
url = 'https://files.pythonhosted.org/packages/81/39/4e9a026265ba944ddf1fea176dbb29e0fe50c43717ba4fcf3646d099fe38/netifaces-{version}.tar.gz'
depends = ['python2', 'setuptools']
call_hostpython_via_targetpython = False
def get_recipe_env(self, arch):
env = super(NetifacesRecipe, self).get_recipe_env(arch)
target_python = Recipe.get_recipe('python2', self.ctx).get_build_dir(arch.arch)
env['PYTHON_ROOT'] = join(target_python, 'python-install')
env['LDSHARED'] = env['CC'] + ' -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions'
env['CFLAGS'] += ' -I' + env['PYTHON_ROOT'] + '/include/python2.7'
env['LDFLAGS'] += ' -L' + env['PYTHON_ROOT'] + '/lib' + ' -lpython2.7'
return env
recipe = NetifacesRecipe()

View file

@ -0,0 +1,11 @@
LOCAL_PATH := $(call my-dir)/..
include $(CLEAR_VARS)
LOCAL_SRC_FILES := sqlite3.c
LOCAL_MODULE := sqlite3
LOCAL_CFLAGS := -DSQLITE_ENABLE_FTS4
include $(BUILD_SHARED_LIBRARY)

View file

@ -0,0 +1,32 @@
from pythonforandroid.toolchain import NDKRecipe, shprint, shutil, current_directory
from os.path import join, exists
import sh
class Sqlite3Recipe(NDKRecipe):
version = '3.24.0'
# Don't forget to change the URL when changing the version
url = 'https://www.sqlite.org/2018/sqlite-amalgamation-3240000.zip'
generated_libraries = ['sqlite3']
def should_build(self, arch):
return not self.has_libs(arch, 'libsqlite3.so')
def prebuild_arch(self, arch):
super(Sqlite3Recipe, self).prebuild_arch(arch)
# Copy the Android make file
sh.mkdir('-p', join(self.get_build_dir(arch.arch), 'jni'))
shutil.copyfile(join(self.get_recipe_dir(), 'Android.mk'),
join(self.get_build_dir(arch.arch), 'jni/Android.mk'))
def build_arch(self, arch, *extra_args):
super(Sqlite3Recipe, self).build_arch(arch)
# Copy the shared library
shutil.copyfile(join(self.get_build_dir(arch.arch), 'libs', arch.arch, 'libsqlite3.so'),
join(self.ctx.get_libs_dir(arch.arch), 'libsqlite3.so'))
def get_recipe_env(self, arch):
env = super(Sqlite3Recipe, self).get_recipe_env(arch)
env['NDK_PROJECT_PATH'] = self.get_build_dir(arch.arch)
return env
recipe = Sqlite3Recipe()

View file

@ -81,8 +81,8 @@ from jsonrpc.proxy import JSONRPCProxy
from lbrynet import analytics from lbrynet import analytics
from lbrynet import conf from lbrynet import conf
from lbrynet.core import utils, system_info from lbrynet.core import utils, system_info
from lbrynet.daemon.auth.client import LBRYAPIClient from lbrynet.daemon.Components import PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT
from lbrynet.daemon.DaemonServer import DaemonServer from lbrynet.daemon.Daemon import Daemon
# https certificate verification # https certificate verification
# TODO: this is bad. Need to find a way to properly verify https requests # TODO: this is bad. Need to find a way to properly verify https requests
@ -124,33 +124,22 @@ def start():
lbrynet_log = conf.settings.get_log_filename() lbrynet_log = conf.settings.get_log_filename()
log_support.configure_logging(lbrynet_log, True, []) log_support.configure_logging(lbrynet_log, True, [])
log.debug('Final Settings: %s', conf.settings.get_current_settings_dict())
# TODO: specify components, initialise auth
conf.settings.update({
'components_to_skip': [PEER_PROTOCOL_SERVER_COMPONENT, REFLECTOR_COMPONENT],
'concurrent_announcers': 0
})
log.info('Final Settings: %s', conf.settings.get_current_settings_dict())
log.info("Starting lbrynet-daemon") log.info("Starting lbrynet-daemon")
if test_internet_connection(): if test_internet_connection():
analytics_manager = analytics.Manager.new_instance() daemon = Daemon()
start_server_and_listen(False, analytics_manager) daemon.start_listening()
reactor.run() reactor.run()
else: else:
log.info("Not connected to internet, unable to start") log.info("Not connected to the Internet. Unable to start.")
@defer.inlineCallbacks
def start_server_and_listen(use_auth, analytics_manager, max_tries=5):
"""The primary entry point for launching the daemon.
Args:
use_auth: set to true to enable http authentication
analytics_manager: to send analytics
"""
analytics_manager.send_server_startup()
daemon_server = DaemonServer(analytics_manager)
try:
yield daemon_server.start(use_auth)
analytics_manager.send_server_startup_success()
except Exception as e:
log.exception('Failed to startup')
yield daemon_server.stop()
analytics_manager.send_server_startup_error(str(e))
reactor.fireSystemEvent("shutdown")
if __name__ == '__main__': if __name__ == '__main__':