def __init__(self, url=common.DEFAULT_URL, debug=False, quiet=False, use_folder_tree=False, max_size=common.DEFAULT_MAX_SIZE, store_path=common.DEFAULT_STORE_PATH, config_path=common.DEFAULT_CONFIG_PATH, connection_retry_limit=common.DEFAULT_CONNECTION_RETRY_LIMIT, connection_retry_delay=common.DEFAULT_CONNECTION_RETRY_DELAY): debug = deserialize.flag(debug) quiet = deserialize.flag(quiet) self.url = deserialize.url(url) self.use_folder_tree = deserialize.flag(use_folder_tree) self.max_size = deserialize.byte_count(max_size) self.messenger = None # lazy self.btctxstore = BtcTxStore() self.retry_limit = deserialize.positive_integer(connection_retry_limit) self.retry_delay = deserialize.positive_integer(connection_retry_delay) # paths self.cfg_path = os.path.realpath(config_path) control.util.ensure_path_exists(os.path.dirname(self.cfg_path)) self.store_path = os.path.realpath(store_path) control.util.ensure_path_exists(self.store_path) # check for vfat partions if control.util.get_fs_type(self.store_path) == "vfat": self.use_folder_tree = True self.cfg = control.config.get(self.btctxstore, self.cfg_path)
def __init__(self, url=common.DEFAULT_URL, debug=False, quiet=False, use_folder_tree=False, max_size=common.DEFAULT_MAX_SIZE, store_path=common.DEFAULT_STORE_PATH, config_path=common.DEFAULT_CONFIG_PATH, connection_retry_limit=common.DEFAULT_CONNECTION_RETRY_LIMIT, connection_retry_delay=common.DEFAULT_CONNECTION_RETRY_DELAY): debug = deserialize.flag(debug) quiet = deserialize.flag(quiet) self.url = deserialize.url(url) self.use_folder_tree = deserialize.flag(use_folder_tree) self.max_size = deserialize.byte_count(max_size) self.messenger = None # lazy self.btctxstore = BtcTxStore() self.retry_limit = deserialize.positive_integer(connection_retry_limit) self.retry_delay = deserialize.positive_integer(connection_retry_delay) # paths self.cfg_path = os.path.realpath(config_path) control.util.ensure_path_exists(os.path.dirname(self.cfg_path)) self.store_path = os.path.realpath(store_path) control.util.ensure_path_exists(self.store_path) # check for vfat partions fstype = control.util.get_fs_type(self.store_path) if fstype == "vfat": logger.info("Detected vfat partition, using folder tree.") self.use_folder_tree = True if fstype is None: msg = "Couldn't detected partition type for '{0}'" logger.warning(msg.format(self.store_path)) self.cfg = control.config.get(self.btctxstore, self.cfg_path)
def __init__(self, url=common.DEFAULT_URL, debug=False, max_size=common.DEFAULT_MAX_SIZE, store_path=common.DEFAULT_STORE_PATH, config_path=common.DEFAULT_CONFIG_PATH, set_master_secret=None, set_payout_address=None, connection_retry_limit=common.DEFAULT_CONNECTION_RETRY_LIMIT, connection_retry_delay=common.DEFAULT_CONNECTION_RETRY_DELAY): # FIXME validate master_secret self.url = url self.config = None # lazy self.messanger = None # lazy self.debug = debug # TODO validate self.retry_limit = deserialize.positive_integer(connection_retry_limit) self.retry_delay = deserialize.positive_integer(connection_retry_delay) self.max_size = deserialize.byte_count(max_size) # paths self.config_path = os.path.realpath(config_path) # TODO validate self._ensure_path_exists(os.path.dirname(self.config_path)) self.store_path = os.path.realpath(store_path) self._ensure_path_exists(self.store_path) # validate payout address self.btctxstore = BtcTxStore() if set_payout_address and (not self.btctxstore.validate_address(set_payout_address)): raise exceptions.InvalidAddress(set_payout_address) self._initialize_config(set_master_secret, set_payout_address)
def __init__(self, url=common.DEFAULT_URL, debug=False, quiet=False, use_folder_tree=False, max_size=common.DEFAULT_MAX_SIZE, min_free_size=common.DEFAULT_MIN_FREE_SIZE, store_path=common.DEFAULT_STORE_PATH, config_path=common.DEFAULT_CONFIG_PATH, connection_retry_limit=common.DEFAULT_CONNECTION_RETRY_LIMIT, connection_retry_delay=common.DEFAULT_CONNECTION_RETRY_DELAY, nop2p=True): debug = deserialize.flag(debug) quiet = deserialize.flag(quiet) self.storjnode = None self.nop2p = nop2p self.url = deserialize.url(url) self.use_folder_tree = deserialize.flag(use_folder_tree) self.max_size = deserialize.byte_count(max_size) self.min_free_size = deserialize.byte_count(min_free_size) self.messenger = None # lazy self.btctxstore = BtcTxStore() self.retry_limit = deserialize.positive_integer(connection_retry_limit) self.retry_delay = deserialize.positive_integer(connection_retry_delay) # paths self.cfg_path = os.path.realpath(config_path) storjnode.util.ensure_path_exists(os.path.dirname(self.cfg_path)) self.store_path = os.path.realpath(store_path) storjnode.util.ensure_path_exists(self.store_path) # check for vfat partions try: fstype = storjnode.util.get_fs_type(self.store_path) # FileNotFoundError: [Errno 2] No such file or directory: '/etc/mtab' # psutil: https://code.google.com/p/psutil/issues/detail?id=434 except EnvironmentError as e: logger.warning(e) fstype = None if fstype == "vfat": logger.info("Detected vfat partition, using folder tree.") self.use_folder_tree = True if fstype is None: msg = "Couldn't detected partition type for '{0}'" logger.warning(msg.format(self.store_path)) self.cfg = storjnode.config.get(self.btctxstore, self.cfg_path)
def poll(self, delay=common.DEFAULT_DELAY, limit=None): """Attempt continuous keep-alive with the server. :param delay: Delay in seconds per ping of the server. :param limit: Number of seconds in the future to stop polling. :return: True, if limit is reached. None, if otherwise. """ delay = deserialize.positive_integer(delay) stop_time = None if limit is not None: stop_time = datetime.now() + timedelta(seconds=int(limit)) # start storjnode in background if not self.nop2p: # start node self.storjnode = storjnode.network.Node(self.cfg["wallet"]) print("Running storj dht node on port {port} with id {id}".format( id=binascii.hexlify(self.storjnode.get_id()), port=self.storjnode.port )) # add message handler (prints to stdout) def message_handler(source, message): print("Received message: %s" % json.dumps(message)) self.storjnode.add_message_handler(message_handler) while True: # ping the server every X seconds self.ping() if stop_time and datetime.now() >= stop_time: return True time.sleep(int(delay))
def poll(self, delay=common.DEFAULT_DELAY, limit=None): """Attempt continuous keep-alive with the server. :param delay: Delay in seconds per ping of the server. :param limit: Number of seconds in the future to stop polling. :return: True, if limit is reached. None, if otherwise. """ delay = deserialize.positive_integer(delay) stop_time = None if limit is not None: stop_time = datetime.now() + timedelta(seconds=int(limit)) # start storjnode in background if not self.nop2p: # start node self.storjnode = storjnode.network.Node(self.cfg["wallet"]) print("Running storj dht node on port {port} with id {id}".format( id=binascii.hexlify(self.storjnode.get_id()), port=self.storjnode.port)) # add message handler (prints to stdout) def message_handler(source, message): print("Received message: %s" % json.dumps(message)) self.storjnode.add_message_handler(message_handler) while True: # ping the server every X seconds self.ping() if stop_time and datetime.now() >= stop_time: return True time.sleep(int(delay))
def __init__(self, url=common.DEFAULT_URL, debug=False, max_size=common.DEFAULT_MAX_SIZE, store_path=common.DEFAULT_STORE_PATH, config_path=common.DEFAULT_CONFIG_PATH, connection_retry_limit=common.DEFAULT_CONNECTION_RETRY_LIMIT, connection_retry_delay=common.DEFAULT_CONNECTION_RETRY_DELAY): self.url = url self.messanger = None # lazy self.debug = debug self.btctxstore = BtcTxStore() self.retry_limit = deserialize.positive_integer(connection_retry_limit) self.retry_delay = deserialize.positive_integer(connection_retry_delay) self.max_size = deserialize.byte_count(max_size) # paths self.cfg_path = os.path.realpath(config_path) self._ensure_path_exists(os.path.dirname(self.cfg_path)) self.store_path = os.path.realpath(store_path) self._ensure_path_exists(self.store_path) self.cfg = config.get(self.btctxstore, self.cfg_path)
def audit(self, delay=common.DEFAULT_AUDIT_DELAY, limit=None): self._init_messenger() # Initialize builder and audit shards bldr = builder.Builder(address=self.cfg["payout_address"], shard_size=common.SHARD_SIZE, max_size=self.max_size, min_free_size=self.min_free_size, use_folder_tree=self.use_folder_tree) delay = deserialize.positive_integer(delay) stop_time = None if limit is not None: stop_time = datetime.now() + timedelta(seconds=int(limit)) btc_index = 0 while True: btc_block = bldr.btc_last_confirmed_block( min_confirmations=common.DEFAULT_MIN_CONFIRMATIONS ) if btc_block['block_no'] != btc_index: btc_hash = btc_block['blockhash'] btc_index = btc_block['block_no'] logger.debug("Using bitcoin block {0} hash {1}.".format( btc_index, btc_hash)) wif = self.btctxstore.get_key(self.cfg["wallet"]) address = self.btctxstore.get_address(wif) response_data = address + btc_hash + str(bldr.audit( self.store_path, btc_block['block_no'], btc_block['blockhash'])) response = hashlib.sha256( response_data.encode('utf-8') ).hexdigest() # New Dataserv Server version is needed self.messenger.audit(btc_block['block_no'], response) else: msg = "Bitcoin block {0} already used. Waiting for new block." logger.debug(msg.format(btc_index)) if stop_time and datetime.now() >= stop_time: return True time.sleep(int(delay))
def poll(self, delay=common.DEFAULT_DELAY, limit=None): """Attempt continuous keep-alive with the server. :param delay: Delay in seconds per ping of the server. :param limit: Number of seconds in the future to stop polling. :return: True, if limit is reached. None, if otherwise. """ delay = deserialize.positive_integer(delay) stop_time = None if limit is not None: stop_time = datetime.now() + timedelta(seconds=int(limit)) while True: # ping the server every X seconds self.ping() if stop_time and datetime.now() >= stop_time: return True time.sleep(int(delay))