def init(port=None): global _WebSocketListener global _AllAPIMethods global _APILogFileEnabled _APILogFileEnabled = settings.config.conf().getBool('logs/api-enabled') if _WebSocketListener is not None: lg.warn('_WebSocketListener already initialized') return if not port: port = settings.DefaultWebSocketPort() try: ws = BitDistWrappedWebSocketFactory(BitDustWebSocketFactory()) _WebSocketListener = listen("tcp:%d" % port, ws) except: lg.exc() return _AllAPIMethods = set(dir(api)) _AllAPIMethods.difference_update([ # TODO: keep that list up to date when changing the api 'on_api_result_prepared', 'Deferred', 'ERROR', 'Failure', 'OK', 'RESULT', '_Debug', '_DebugLevel', 'strng', 'sys', 'time', 'gc', 'map', 'os', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'absolute_import', 'driver', 'filemanager', 'jsn', 'lg', 'event_listen', 'message_receive', 'process_debug', ]) if _Debug: lg.out(_DebugLevel, 'api_web_socket.init _WebSocketListener=%r with %d methods' % ( _WebSocketListener, len(_AllAPIMethods))) read_api_secret() events.add_subscriber(on_event, event_id='*')
def start(self): from twisted.internet import reactor # @UnresolvedImport from twisted.internet.defer import Deferred from logs import lg from transport.proxy import proxy_interface from transport import network_transport from transport import gateway from services import driver from main import events from main.config import conf if len(self._available_transports()) == 0: lg.warn('no transports available') return False events.add_subscriber(self._on_dht_layer_connected, 'dht-layer-connected') self._check_reset_original_identity() self.starting_deferred = Deferred() self.transport = network_transport.NetworkTransport( 'proxy', proxy_interface.GateInterface()) conf().addConfigNotifier('services/proxy-transport/enabled', self._on_enabled_disabled) conf().addConfigNotifier('services/proxy-transport/sending-enabled', self._on_sending_enabled_disabled) conf().addConfigNotifier('services/proxy-transport/receiving-enabled', self._on_receiving_enabled_disabled) if driver.is_on('service_entangled_dht'): self._do_join_proxy_routers_dht_layer() else: self.transport.automat( 'init', (gateway.listener(), self._on_transport_state_changed)) reactor.callLater(0, self.transport.automat, 'start') # @UndefinedVariable return self.starting_deferred
def start(self): from twisted.internet.defer import Deferred from logs import lg from main.config import conf from main import events from raid import eccmap from services import driver from customer import fire_hire self.starting_deferred = Deferred() self.starting_deferred.addErrback( lambda err: lg.warn('service %r was not started: %r' % (self.service_name, err.getErrorMessage() if err else 'unknown reason'))) self.all_suppliers_hired_event_sent = False if driver.is_on('service_entangled_dht'): self._do_join_suppliers_dht_layer() eccmap.Update() fire_hire.A('init') fire_hire.A().addStateChangedCallback(self._on_fire_hire_ready, None, 'READY') conf().addConfigNotifier('services/customer/suppliers-number', self._on_suppliers_number_modified) conf().addConfigNotifier('services/customer/needed-space', self._on_needed_space_modified) events.add_subscriber(self._on_supplier_modified, 'supplier-modified') events.add_subscriber(self._on_dht_layer_connected, event_id='dht-layer-connected') if fire_hire.IsAllHired(): self.starting_deferred.callback(True) self.starting_deferred = None lg.info('all my suppliers are already hired') return True fire_hire.A('restart') return self.starting_deferred
def start(self): from twisted.internet.defer import Deferred from transport import callback from main import events from main import listeners from p2p import online_status from p2p import p2p_service from p2p import p2p_connector from p2p import network_connector from p2p import ratings p2p_service.init() online_status.init() ratings.init() self._starting_defer = Deferred() p2p_connector.A('init') p2p_connector.A().addStateChangedCallback( self._on_p2p_connector_switched) network_connector.A().addStateChangedCallback( self._on_network_connector_switched) callback.append_inbox_callback(self._on_inbox_packet_received) callback.append_inbox_callback(p2p_service.inbox) events.add_subscriber(self._on_identity_url_changed, 'identity-url-changed') events.add_subscriber(self._on_my_identity_url_changed, 'my-identity-url-changed') if listeners.is_populate_requered('online_status'): listeners.populate_later().remove('online_status') online_status.populate_online_statuses() return True
def start(self): from storage import backup_fs from storage import backup_control from storage import backup_matrix from storage import backup_monitor from main.config import conf from main import control from main import events from transport import callback from p2p import p2p_connector backup_fs.init() backup_control.init() backup_matrix.init() backup_matrix.SetBackupStatusNotifyCallback(control.on_backup_stats) backup_matrix.SetLocalFilesNotifyCallback(control.on_read_local_files) backup_monitor.A('init') backup_monitor.A('restart') conf().addConfigNotifier('services/backups/keep-local-copies-enabled', self._on_keep_local_copies_modified) conf().addConfigNotifier('services/backups/wait-suppliers-enabled', self._on_wait_suppliers_modified) p2p_connector.A().addStateChangedCallback( self._on_p2p_connector_state_changed, 'INCOMMING?', 'CONNECTED') p2p_connector.A().addStateChangedCallback( self._on_p2p_connector_state_changed, 'MY_IDENTITY', 'CONNECTED') callback.append_inbox_callback(self._on_inbox_packet_received) events.add_subscriber(self._on_my_identity_rotated, 'my-identity-rotated') events.add_subscriber(self._on_key_erased, 'key-erased') return True
def start(self): from logs import lg from userid import my_id from main.config import conf my_id.loadLocalIdentity() if my_id._LocalIdentity is None: lg.warn( 'Loading local identity failed - need to create an identity first' ) return False from main import events from contacts import identitycache from userid import known_servers from p2p import propagate from contacts import contactsdb identitycache.init() d = contactsdb.init() propagate.init() conf().addConfigNotifier('services/identity-propagate/known-servers', self._on_known_servers_changed) lg.info('known ID servers are : %r' % known_servers.by_host()) events.add_subscriber(self._on_local_identity_modified, 'local-identity-modified') events.add_subscriber(self._on_my_identity_rotated, 'my-identity-rotated') return d
def init(self): self.last_time_saw_files = -1 self.ping_required = True events.add_subscriber(self._on_my_identity_rotated, 'my-identity-rotated') events.add_subscriber(self._on_supplier_connected, 'supplier-connected')
def start(self): from main import events from contacts import contactsdb from coins import customer_contract_executor for supplier_idurl in contactsdb.suppliers(): customer_contract_executor.init_contract(supplier_idurl) events.add_subscriber(self._on_supplier_modified, 'supplier-modified') return True
def _init_modules(self): """ Finish initialization part, run delayed methods. """ lg.out(2, "initializer._init_modules") from updates import git_proc git_proc.init() events.add_subscriber(self._on_software_code_updated, 'source-code-fetched')
def start(self): from main import events from chat import message_database from chat import message_keeper message_database.init() message_keeper.init() events.add_subscriber(self._on_my_keys_synchronized, 'my-keys-synchronized') return True
def start(self): from main import events from stream import message_peddler message_peddler.A('start') self._do_connect_message_brokers_dht_layer() events.add_subscriber(self._on_dht_layer_connected, 'dht-layer-connected') events.add_subscriber(self._on_my_identity_url_changed, 'my-identity-url-changed') return True
def init(self): self.target_customer_idurl = None self.result_defer = None self.critical_suppliers_number = 0 self.last_time_saw_files = {} self.ping_required = True self.received_lf_counter = 0 self.requested_lf_packet_ids = set() events.add_subscriber(self._on_my_identity_rotated, 'my-identity-rotated') events.add_subscriber(self._on_supplier_connected, 'supplier-connected')
def start(self): from main import events from services import driver from access import groups groups.init() events.add_subscriber(self._on_supplier_modified, 'supplier-modified') events.add_subscriber(self._on_dht_layer_connected, event_id='dht-layer-connected') if driver.is_on('service_entangled_dht'): self._do_join_message_brokers_dht_layer() return True
def start(self): from twisted.internet import task from main import events from p2p import network_connector network_connector.A('init') self.task = task.LoopingCall(self._do_check_network_interfaces) self.task.start(20, now=False) events.add_subscriber(self._on_my_identity_rotate_complete, 'my-identity-rotate-complete') events.add_subscriber(self._on_my_external_ip_changed, 'my-external-ip-changed') return True
def start(self): from customer import fire_hire from main.config import conf from main import events from raid import eccmap eccmap.Update() fire_hire.A('init') conf().addCallback('services/customer/suppliers-number', self._on_suppliers_number_modified) conf().addCallback('services/customer/needed-space', self._on_needed_space_modified) events.add_subscriber(self._on_supplier_modified, 'supplier-modified') self._do_cleanup_dht_suppliers() return True
def start(self): from transport import callback from main import events from contacts import contactsdb from storage import accounting callback.append_inbox_callback(self._on_inbox_packet_received) events.add_subscriber(self._on_customer_accepted, 'existing-customer-accepted') events.add_subscriber(self._on_customer_accepted, 'new-customer-accepted') events.add_subscriber(self._on_customer_terminated, 'existing-customer-denied') events.add_subscriber(self._on_customer_terminated, 'existing-customer-terminated') space_dict = accounting.read_customers_quotas() for customer_idurl in contactsdb.customers(): known_customer_meta_info = contactsdb.get_customer_meta_info( customer_idurl) events.send('existing-customer-accepted', data=dict( idurl=customer_idurl, allocated_bytes=space_dict.get(customer_idurl), ecc_map=known_customer_meta_info.get('ecc_map'), position=known_customer_meta_info.get('position'), )) return True
def start(self): from logs import lg from services import driver from main import events from transport.proxy import proxy_router proxy_router.A('init') proxy_router.A('start') if driver.is_on('service_entangled_dht'): self._do_connect_proxy_routers_dht_layer() else: lg.warn('service service_entangled_dht is OFF') events.add_subscriber(self._on_dht_layer_connected, 'dht-layer-connected') return True
def start(self): from logs import lg from customer import fire_hire if not fire_hire.IsAllHired(): lg.warn('service_data_motion() can not start right now, not all suppliers hired yet') return False from main import events from stream import io_throttle from stream import data_sender from stream import data_receiver io_throttle.init() data_sender.A('init') data_receiver.A('init') events.add_subscriber(self._on_identity_url_changed, 'identity-url-changed') return True
def start(self): from contacts import contactsdb from customer import supplier_connector from userid import my_id from main import events for _, supplier_idurl in enumerate(contactsdb.suppliers()): if supplier_idurl and not supplier_connector.by_idurl( supplier_idurl, customer_idurl=my_id.getLocalID()): supplier_connector.create( supplier_idurl=supplier_idurl, customer_idurl=my_id.getLocalID(), ) events.add_subscriber(self._on_my_keys_synchronized, 'my-keys-synchronized') events.add_subscriber(self._on_identity_url_changed, 'identity-url-changed') # TODO: read from dht and connect to other suppliers - from other customers who shared data to me return True
def start(self): from twisted.internet import reactor # @UnresolvedImport from userid import id_url from main import events from supplier import customer_assistant from contacts import contactsdb from transport import callback for customer_idurl in contactsdb.customers(): if id_url.is_cached(customer_idurl): if customer_idurl and not customer_assistant.by_idurl( customer_idurl): ca = customer_assistant.create(customer_idurl) reactor.callLater(0, ca.automat, 'init') # @UndefinedVariable events.add_subscriber(self._on_identity_url_changed, 'identity-url-changed') callback.add_outbox_callback(self._on_outbox_packet_sent) callback.append_inbox_callback(self._on_inbox_packet_received) return True
def start(self): from logs import lg from main import events from contacts import contactsdb from supplier import family_member from transport import callback # TODO: check all imports.! my_id must be loaded latest as possible! from userid import my_id callback.append_inbox_callback(self._on_inbox_packet_received) for customer_idurl in contactsdb.customers(): if not customer_idurl: continue if customer_idurl == my_id.getLocalIDURL(): lg.warn('skipping my own identity') continue fm = family_member.by_customer_idurl(customer_idurl) if not fm: fm = family_member.create_family(customer_idurl) fm.automat('init') local_customer_meta_info = contactsdb.get_customer_meta_info(customer_idurl) fm.automat('family-join', { 'supplier_idurl': my_id.getLocalIDURL(), 'ecc_map': local_customer_meta_info.get('ecc_map'), 'position': local_customer_meta_info.get('position', -1), 'family_snapshot': local_customer_meta_info.get('family_snapshot'), }) events.add_subscriber(self._on_existing_customer_accepted, 'existing-customer-accepted') events.add_subscriber(self._on_new_customer_accepted, 'new-customer-accepted') events.add_subscriber(self._on_existing_customer_terminated, 'existing-customer-terminated') return True
def start(self): from main import events from transport import callback callback.append_inbox_callback(self._on_inbox_packet_received) events.add_subscriber(self._on_supplier_modified, 'supplier-modified') events.add_subscriber(self._on_my_list_files_refreshed, 'my-list-files-refreshed') events.add_subscriber(self._on_key_erased, 'key-erased') self._do_open_known_shares() return True
def start(self): from transport import callback from main import events from contacts import contactsdb callback.append_inbox_callback(self._on_inbox_packet_received) events.add_subscriber(self._on_customer_accepted, 'existing-customer-accepted') events.add_subscriber(self._on_customer_accepted, 'new-customer-accepted') events.add_subscriber(self._on_customer_terminated, 'existing-customer-denied') events.add_subscriber(self._on_customer_terminated, 'existing-customer-terminated') for customer_idurl in contactsdb.customers(): events.send('existing-customer-accepted', data=dict(idurl=customer_idurl)) return True
def start(self): import os from twisted.internet import reactor # @UnresolvedImport from main import config from main import settings from main import events from blockchain import pybc_service self.flag_public_key_registered = False self.flag_public_key_transaction_sent = False pybc_home = settings.BlockchainDir() seeds = config.conf().getString('services/blockchain/seeds') if seeds: seed_nodes = [( i.split(':')[0], int(i.split(':')[1]), ) for i in seeds.split(',')] else: seed_nodes = pybc_service.seed_nodes() pybc_service.init( host=config.conf().getData('services/blockchain/host'), port=config.conf().getInt('services/blockchain/port'), seed_nodes=seed_nodes, blockstore_filename=os.path.join(pybc_home, 'blocks'), keystore_filename=os.path.join(pybc_home, 'keys'), peerstore_filename=os.path.join(pybc_home, 'peers'), minify=None, loglevel='DEBUG', logfilepath=os.path.join(pybc_home, 'log'), stats_filename=None, ) if config.conf().getBool('services/blockchain/explorer/enabled'): pybc_service.start_block_explorer( config.conf().getInt('services/blockchain/explorer/port'), pybc_service.node()) if config.conf().getBool('services/blockchain/wallet/enabled'): pybc_service.start_wallet( config.conf().getInt('services/blockchain/wallet/port'), pybc_service.node(), pybc_service.wallet()) if config.conf().getBool('services/blockchain/miner/enabled'): reactor.callFromThread( pybc_service.generate_block, json_data={}, with_inputs=True, repeat=True, ) events.add_subscriber(self._on_local_identity_modified, 'local-identity-modified') events.add_subscriber(self._on_blockchain_forward, 'blockchain-forward') events.add_subscriber(self._on_blockchain_sync, 'blockchain-sync') reactor.callLater(0, self._do_check_register_my_identity) return True
def start(self): from main import events from transport import callback from stream import message from chat import nickname_holder message.init() nickname_holder.A('set') callback.append_inbox_callback(self._on_inbox_packet_received) events.add_subscriber(self._on_identity_url_changed, 'identity-url-changed') events.add_subscriber(self._on_user_connected, 'node-connected') events.add_subscriber(self._on_user_disconnected, 'node-disconnected') return True
def start(self): from main import events from services import driver from access import groups from access import group_member groups.init() events.add_subscriber(self._on_supplier_modified, 'supplier-modified') events.add_subscriber(self._on_dht_layer_connected, 'dht-layer-connected') if driver.is_on('service_entangled_dht'): self._do_join_message_brokers_dht_layer() group_member.start_group_members() events.add_subscriber(groups.on_identity_url_changed, 'identity-url-changed') return True
def start(self): from twisted.internet.task import LoopingCall from main import events from dht import dht_service events.add_subscriber(self._on_new_customer_accepted, 'new-customer-accepted') events.add_subscriber(self._on_existing_customer_accepted, 'existing-customer-accepted') events.add_subscriber(self._on_existing_customer_terminated, 'existing-customer-terminated') self.refresh_task = LoopingCall(self._do_refresh_dht_records) self.refresh_task.start(dht_service.KEY_EXPIRE_MIN_SECONDS * 2, now=False) return True
def start(self): from twisted.internet import reactor # @UnresolvedImport from logs import lg from main import events from contacts import contactsdb from userid import id_url from supplier import family_member from transport import callback from userid import my_id callback.append_inbox_callback(self._on_inbox_packet_received) for customer_idurl in contactsdb.customers(): if not customer_idurl: continue if not id_url.is_cached(customer_idurl): continue if customer_idurl == my_id.getLocalID(): lg.warn('skipping my own identity') continue fm = family_member.by_customer_idurl(customer_idurl) if not fm: fm = family_member.create_family(customer_idurl) fm.automat('init') local_customer_meta_info = contactsdb.get_customer_meta_info( customer_idurl) reactor.callLater(0, fm.automat, 'family-join', { # @UndefinedVariable 'supplier_idurl': my_id.getLocalID().to_bin(), 'ecc_map': local_customer_meta_info.get('ecc_map'), 'position': local_customer_meta_info.get('position', -1), 'family_snapshot': id_url.to_bin_list(local_customer_meta_info.get('family_snapshot')), }) events.add_subscriber(self._on_identity_url_changed, 'identity-url-changed') events.add_subscriber(self._on_existing_customer_accepted, 'existing-customer-accepted') events.add_subscriber(self._on_new_customer_accepted, 'new-customer-accepted') events.add_subscriber(self._on_existing_customer_terminated, 'existing-customer-terminated') return True
def start(self): from dht import dht_relations from contacts import contactsdb from userid import my_id from main import events events.add_subscriber(self._on_new_customer_accepted, 'new-customer-accepted') events.add_subscriber(self._on_existing_customer_accepted, 'existing-customer-accepted') events.add_subscriber(self._on_existing_customer_terminated, 'existing-customer-terminated') for customer_idurl in contactsdb.customers(): dht_relations.publish_customer_supplier_relation(customer_idurl) dht_relations.scan_customer_supplier_relations(my_id.getLocalID()) return True
def start(self): from chat import message_database from chat import message_keeper from main import events from main import listeners message_database.init() message_keeper.init() events.add_subscriber(self.on_key_registered, 'key-registered') events.add_subscriber(self.on_key_renamed, 'key-renamed') events.add_subscriber(self.on_key_generated, 'key-generated') if listeners.is_populate_requered('conversation'): listeners.populate_later().remove('conversation') message_database.populate_conversations() if listeners.is_populate_requered('message'): listeners.populate_later().remove('message') message_database.populate_messages() return True