Example #1
0
    def __init__(self,
                 bc_id,
                 full_url,
                 agent,
                 look_back_count=5,
                 validator=None):
        self.validator = validator
        self.bc_id = bc_id
        self.url = full_url
        self.agent = agent
        self.name = "block_client_{0}".format(bc_id)
        self.bc_state = "UNKNWN"
        self.responding = None

        self.validator_comm = ValidatorCommunications(self.agent) \
            if agent is not None else None

        self.new_blocks = []
        self.last_block_id = GENESIS_PREVIOUS_BLOCK_ID
        self.last_block_num = -1
        self.last_block_previous_block_id = None
        self.lb_count = look_back_count
        self.current_branch = None
        self.no_response_reason = None
        self.path = None
    def __init__(self, urls):
        self.validator_contact_attempted = False
        self.validator_responded = False
        self.recent_validator_responded = False

        self.endpoint_urls = list(urls)
        self.endpoints = {}

        self.contact_list = None

        self.validator_comm = ValidatorCommunications()
class StatsClient(object):
    def __init__(self, val_id, fullurl):
        self.val_id = val_id
        self.url = fullurl
        self.name = "validator_{0}".format(val_id)

        self.validator_state = "UNKNWN"

        self.ledgerstats = {}
        self.nodestats = {}

        self.vsm = ValidatorStatsManager()

        self.responding = False
        self.no_response_reason = ""

        self.request_start = 0.0
        self.request_complete = 0.0
        self.response_time = 0.0

        self.validator_comm = ValidatorCommunications(Agent(reactor))
        self.path = self.url + "/statistics/all"

    def stats_request(self):
        # request stats from specified validator url
        self.request_start = time.clock()
        # self.path = self.url + "/statistics/all"
        self.validator_comm.get_request(
            self.path,
            self._stats_completion,
            self._stats_error)

    def _stats_completion(self, json_stats, response_code):
        self.request_complete = time.clock()
        self.response_time = self.request_complete - self.request_start
        self.validator_state = "RESP_{}".format(response_code)
        if response_code is 200:
            self.vsm.update_stats(
                json_stats, True, self.request_start,
                self.request_complete)
            self.responding = True
        else:
            self.responding = False
            self.no_response_reason = ""

    def _stats_error(self, failure):
        self.vsm.update_stats(self.ledgerstats, False, 0, 0)
        self.responding = False
        self.validator_state = "NO_RESP"
        self.no_response_reason = failure.type.__name__
        return
Example #4
0
class StatsClient(object):
    def __init__(self, val_id, fullurl):
        self.val_id = val_id
        self.url = fullurl
        self.name = "validator_{0}".format(val_id)

        self.state = "UNKNWN"

        self.ledgerstats = {}
        self.nodestats = {}

        self.validator_stats = ValidatorStats()

        self.responding = False
        self.no_response_reason = ""

        self.request_start = 0.0
        self.request_complete = 0.0
        self.response_time = 0.0

        self.validator_comm = ValidatorCommunications()

        self.path = None

    def stats_request(self):
        # request stats from specified validator url
        self.request_start = time.clock()
        self.path = self.url + "/statistics/all"
        self.validator_comm.get_request(self.path, self._stats_completion,
                                        self._stats_error)

    def _stats_completion(self, json_stats, response_code):
        self.request_complete = time.clock()
        self.response_time = self.request_complete - self.request_start
        self.state = "RESP_{}".format(response_code)
        if response_code is 200:
            self.validator_stats.update_stats(json_stats, self.request_start,
                                              self.request_complete)
            self.responding = True
        else:
            self.responding = False
            self.no_response_reason = ""

    def _stats_error(self, failure):
        self.validator_stats.update_stats(self.ledgerstats, 0, 0)
        self.responding = False
        self.state = "NO_RESP"
        self.no_response_reason = failure.type.__name__
        return
    def __init__(self, urls):
        self.validator_contact_attempted = False
        self.validator_responded = False
        self.recent_validator_responded = False

        self.endpoint_urls = list(urls)
        self.endpoints = {}

        self.contact_list = None

        self.validator_comm = ValidatorCommunications()
Example #6
0
    def __init__(self, bc_id, full_url, look_back_count=5, validator=None):
        self.validator = validator
        self.bc_id = bc_id
        self.url = full_url
        self.name = "block_client_{0}".format(bc_id)

        self.responding = False
        self.bc_state = "WAITING"
        self.bc_response_status = " - First Contact"

        self.validator_comm = ValidatorCommunications()

        self.new_blocks = []
        self.last_block_id = GENESIS_PREVIOUS_BLOCK_ID
        self.last_block_num = -1
        self.last_block_previous_block_id = None
        self.lb_count = look_back_count
        self.current_branch = None

        self.path = None
    def __init__(self, val_id, fullurl):
        self.val_id = val_id
        self.url = fullurl
        self.name = "validator_{0}".format(val_id)

        self.ledgerstats = {}
        self.nodestats = {}

        self.validator_stats = ValidatorStats()

        self.responding = False
        self.state = "WAITING"
        self.response_status = "- First Contact"

        self.request_start = 0.0
        self.request_complete = 0.0
        self.response_time = 0.0

        self.validator_comm = ValidatorCommunications()

        self.path = None
 def __init__(self):
     self.error_count = 0
     self.no_endpoint_responders = False
     self.initial_discovery = True
     self.endpoint_urls = []
     self.endpoints = {}  # None
     self.validator_comm = ValidatorCommunications(Agent(reactor))
     self.contact_list = None
     self.endpoint_completion_cb = None
     self.initial_url = None
     self.init_path = None
     self.endpoint_completion_cb_args = None
Example #9
0
    def __init__(self, val_id, fullurl):
        self.val_id = val_id
        self.url = fullurl
        self.name = "validator_{0}".format(val_id)

        self.state = "UNKNWN"

        self.ledgerstats = {}
        self.nodestats = {}

        self.validator_stats = ValidatorStats()

        self.responding = False
        self.no_response_reason = ""

        self.request_start = 0.0
        self.request_complete = 0.0
        self.response_time = 0.0

        self.validator_comm = ValidatorCommunications()

        self.path = None
Example #10
0
    def __init__(self, val_id, fullurl):
        self.val_id = val_id
        self.url = fullurl
        self.name = "validator_{0}".format(val_id)

        self.validator_state = "UNKNWN"

        self.ledgerstats = {}
        self.nodestats = {}

        self.vsm = ValidatorStatsManager()

        self.responding = False
        self.no_response_reason = ""

        self.request_start = 0.0
        self.request_complete = 0.0
        self.response_time = 0.0

        self.validator_comm = ValidatorCommunications(Agent(reactor))
        self.path = self.url + "/statistics/all"
    def __init__(self, val_id, fullurl):
        self.val_id = val_id
        self.url = fullurl
        self.name = "validator_{0}".format(val_id)

        self.ledgerstats = {}
        self.nodestats = {}

        self.validator_stats = ValidatorStats()

        self.responding = False
        self.state = "WAITING"
        self.response_status = "- First Contact"

        self.request_start = 0.0
        self.request_complete = 0.0
        self.response_time = 0.0

        self.validator_comm = ValidatorCommunications()

        self.path = None
class EndpointManager(object):
    def __init__(self, urls):
        self.validator_contact_attempted = False
        self.validator_responded = False
        self.recent_validator_responded = False

        self.endpoint_urls = list(urls)
        self.endpoints = {}

        self.contact_list = None

        self.validator_comm = ValidatorCommunications()

    def endpoint_discovery_loop(self):
        self.contact_list = list(self.endpoint_urls)
        url = self.contact_list.pop()
        path = url + "/store/{0}/*".format('EndpointRegistryTransaction')
        self.validator_comm.get_request(path,
                                        self._endpoint_discovery_response,
                                        self._update_endpoint_continue)

    def _endpoint_discovery_response(self, results, response_code):
        # response has been received
        # if response OK, then get host url & port number of each validator
        # if response not OK, then validator must be busy,
        # try another validator
        if response_code is 200:
            updated_endpoint_urls = []
            self.endpoints = results
            for endpoint in results.values():
                updated_endpoint_urls.append('http://{0}:{1}'.format(
                    endpoint["Host"], endpoint["HttpPort"]))
            self.endpoint_urls = updated_endpoint_urls
            # if contact is successful, then...
            self.validator_contact_attempted = True
            self.validator_responded = True
            self.recent_validator_responded = True
        else:
            self._update_endpoint_continue(None)

    def _update_endpoint_continue(self, failure):
        # if no response (or did not respond with 200 - see above),
        # then try with another url from the contact list
        if len(self.contact_list) > 0:
            url = self.contact_list.pop()
            path = url + "/store/{0}/*".format('EndpointRegistryTransaction')
            self.validator_comm.get_request(path,
                                            self._endpoint_discovery_response,
                                            self._update_endpoint_continue)
        else:
            # contact with all validators has been attempted
            # no validator has responded
            self.validator_contact_attempted = True
            self.recent_validator_responded = False

    def endpoint_loop_stop(self, reason):
        print("handling endpoint loop stop")
        return reason

    def update_endpoint_loop_error(self, reason):
        print("handling endpoint loop error")
        return reason
class EndpointManager(object):
    def __init__(self, urls):
        self.validator_contact_attempted = False
        self.validator_responded = False
        self.recent_validator_responded = False

        self.endpoint_urls = list(urls)
        self.endpoints = {}

        self.contact_list = None

        self.validator_comm = ValidatorCommunications()

    def endpoint_discovery_loop(self):
        self.contact_list = list(self.endpoint_urls)
        url = self.contact_list.pop()
        path = url + "/store/{0}/*".format('EndpointRegistryTransaction')
        self.validator_comm.get_request(
            path, self._endpoint_discovery_response,
            self._update_endpoint_continue)

    def _endpoint_discovery_response(self, results, response_code):
        # response has been received
        # if response OK, then get host url & port number of each validator
        # if response not OK, then validator must be busy,
        # try another validator
        if response_code is 200:
            updated_endpoint_urls = []
            self.endpoints = results
            for endpoint in results.values():
                updated_endpoint_urls.append(
                    'http://{0}:{1}'.format(
                        endpoint["Host"], endpoint["HttpPort"]))
            self.endpoint_urls = updated_endpoint_urls
            # if contact is successful, then...
            self.validator_contact_attempted = True
            self.validator_responded = True
            self.recent_validator_responded = True
        else:
            self._update_endpoint_continue(None)

    def _update_endpoint_continue(self, failure):
        # if no response (or did not respond with 200 - see above),
        # then try with another url from the contact list
        if len(self.contact_list) > 0:
            url = self.contact_list.pop()
            path = url + "/store/{0}/*".format('EndpointRegistryTransaction')
            self.validator_comm.get_request(
                path, self._endpoint_discovery_response,
                self._update_endpoint_continue)
        else:
            # contact with all validators has been attempted
            # no validator has responded
            self.validator_contact_attempted = True
            self.recent_validator_responded = False

    def endpoint_loop_stop(self, reason):
        print("handling endpoint loop stop")
        return reason

    def update_endpoint_loop_error(self, reason):
        print("handling endpoint loop error")
        return reason
Example #14
0
class EndpointManager(object):
    def __init__(self):
        self.error_count = 0
        self.no_endpoint_responders = False
        self.initial_discovery = True
        self.endpoint_urls = []
        self.endpoints = {}  # None
        self.validator_comm = ValidatorCommunications(Agent(reactor))
        self.contact_list = None
        self.endpoint_completion_cb = None
        self.initial_url = None
        self.init_path = None
        self.endpoint_completion_cb_args = None

    def initialize_endpoint_discovery(self, url, init_cb, init_args=None):
        # initialize endpoint urls from specified validator url
        self.initial_url = url
        self.endpoint_completion_cb = init_cb
        self.endpoint_completion_cb_args = init_args or {}
        path = url + "/store/{0}/*".format('EndpointRegistryTransaction')
        self.init_path = path
        self.validator_comm.get_request(
            path,
            self.endpoint_discovery_response,
            self._init_terminate)

    def update_endpoint_discovery(self, update_cb):
        # initiates update of endpoint urls
        self.endpoint_completion_cb = update_cb
        self.endpoint_completion_cb_args = {}
        self.contact_list = list(self.endpoint_urls)
        url = self.contact_list.pop()
        path = url + "/store/{0}/*".format('EndpointRegistryTransaction')
        self.validator_comm.get_request(
            path, self.endpoint_discovery_response,
            self._update_endpoint_continue)

    def endpoint_discovery_response(self, results, response_code):
        # response has been received
        # if response OK, then get host url & port number of each validator
        # if response not OK, then validator must be busy,
        # if initial discovery, try again, else try another validator
        if response_code is 200:
            updated_endpoint_urls = []
            self.endpoints = results
            for endpoint in results.values():
                updated_endpoint_urls.append(
                    'http://{0}:{1}'.format(
                        endpoint["Host"], endpoint["HttpPort"]))
            self.endpoint_urls = updated_endpoint_urls
            self.endpoint_completion_cb(self.endpoints,
                                        **self.endpoint_completion_cb_args)
            self.initial_discovery = False
            self.no_endpoint_responders = False
        else:
            if self.initial_discovery is True:
                print "endpoint discovery: " \
                      "validator response not 200 - retrying"
                self.contact_list = [self.initial_url]

            self._update_endpoint_continue(None)

    def _update_endpoint_continue(self, failure):
        # if no response (or did not respond with 200 - see above),
        # then try with another url from the contact list
        # if all urls have been tried, set "no update" flag and be done
        if len(self.contact_list) > 0:
            url = self.contact_list.pop()
            path = url + "/store/{0}/*".format('EndpointRegistryTransaction')
            self.validator_comm.get_request(
                path, self.endpoint_discovery_response,
                self._update_endpoint_continue)
        else:
            self.no_endpoint_responders = True

    def update_endpoint_loop_done(self, result):
        reactor.stop()

    def update_endpoint_loop_error(self, failure):
        print "update endpoint loop error: "
        print failure
        reactor.stop()

    def _init_terminate(self, failure):
        print "failure during initial endpoint discovery"
        print "request to {} returned {}".format(
            self.init_path, failure.type.__name__)
        print "error message: "
        print failure.getErrorMessage()
        print "stopping stats client"
        reactor.stop()
        return
class StatsClient(object):
    def __init__(self, val_id, fullurl):
        self.val_id = val_id
        self.url = fullurl
        self.name = "validator_{0}".format(val_id)

        self.ledgerstats = {}
        self.nodestats = {}

        self.validator_stats = ValidatorStats()

        self.responding = False
        self.state = "WAITING"
        self.response_status = "- First Contact"

        self.request_start = 0.0
        self.request_complete = 0.0
        self.response_time = 0.0

        self.validator_comm = ValidatorCommunications()

        self.path = None

    def stats_request(self):
        # request stats from specified validator url
        self.request_start = time.clock()
        self.path = self.url + "/statistics/all"
        self.validator_comm.get_request(
            self.path,
            self._stats_completion,
            self._stats_error)

    def _stats_completion(self, json_stats, response_code):
        self.request_complete = time.clock()
        self.response_time = self.request_complete - self.request_start
        self.state = "RESP_{}".format(response_code)
        self._update_status(response_code)

        if response_code is 200:
            self.responding = True
            self.validator_stats.update_stats(self.responding, json_stats,
                                              self.request_start,
                                              self.request_complete)
        else:
            self.responding = False
            self.validator_stats.update_stats(self.responding, None,
                                              self.request_start,
                                              self.request_complete)

    def _stats_error(self, failure):
        self.request_complete = time.clock()
        self.response_time = self.request_complete - self.request_start
        self.state = "NO_RESP"
        self.responding = False
        self.response_status = failure.type.__name__
        self.validator_stats.update_stats(self.responding, None,
                                          self.request_start,
                                          self.request_complete)

        return

    def _update_status(self, response_code):
        response_codes = ["Informational", "Successful but not expected 200",
                          "Redirection", "Client Error", "Server Error"]
        if response_code is 200:
            self.response_status = "Successful"
        elif response_code in range(100, 600):
            index = response_code / 100 - 1
            self.response_status = response_codes[index]
        else:
            self.response_status = "Response Code Unknown"
Example #16
0
class BlockClient(object):
    def __init__(self, bc_id, full_url, look_back_count=5, validator=None):
        self.validator = validator
        self.bc_id = bc_id
        self.url = full_url
        self.name = "block_client_{0}".format(bc_id)

        self.responding = False
        self.bc_state = "WAITING"
        self.bc_response_status = " - First Contact"

        self.validator_comm = ValidatorCommunications()

        self.new_blocks = []
        self.last_block_id = GENESIS_PREVIOUS_BLOCK_ID
        self.last_block_num = -1
        self.last_block_previous_block_id = None
        self.lb_count = look_back_count
        self.current_branch = None

        self.path = None

    def blocks_request(self):
        # request block info for 5 newest blocks from specified validator url
        if self.validator_comm is not None:
            self.path = self.url + "/block?info=1&blockcount=5"
            self.validator_comm.get_request(self.path, self._blocks_completion,
                                            self._blocks_error)

    def _blocks_completion(self, block_response, response_code):
        self.bc_state = "RESP_{}".format(response_code)
        if response_code is 200:
            self.responding = True
            self.bc_response_status = "Response code = 200"
            self.update(block_response)
        else:
            self.responding = False
            self.bc_response_status = "Response code not 200"

    def _blocks_error(self, failure):
        self.responding = False
        self.bc_state = "NO_RESP"
        self.bc_response_status = failure.type.__name__
        return

    def update(self, block_response):
        block_id = block_response["head"]
        blocks = block_response["blocks"]
        block = blocks.get(block_id)
        # return if same block id and number as last time,
        # no new blocks available
        if block["BlockNum"] == self.last_block_num and \
                block_id == self.last_block_id:
            return
        newest_block_id = block_id
        newest_block_num = block["BlockNum"]
        while True:
            block = blocks.get(block_id, None)
            # break if end of block sequence
            if block is None:
                break
            block["Identifier"] = block_id
            self.new_blocks.append(block)
            # break if block immediately follows last block;
            # no further blocks required
            if block["BlockNum"] == self.last_block_num + 1 and \
                    block["PreviousBlockID"] == self.last_block_id:
                break
            block_id = block["PreviousBlockID"]
        self.last_block_id = newest_block_id
        self.last_block_num = newest_block_num

    def get_new_blocks(self):
        new_blocks = list(self.new_blocks)
        self.new_blocks = []
        return new_blocks
class StatsClient(object):
    def __init__(self, val_id, fullurl):
        self.val_id = val_id
        self.url = fullurl
        self.name = "validator_{0}".format(val_id)

        self.ledgerstats = {}
        self.nodestats = {}

        self.validator_stats = ValidatorStats()

        self.responding = False
        self.state = "WAITING"
        self.response_status = "- First Contact"

        self.request_start = 0.0
        self.request_complete = 0.0
        self.response_time = 0.0

        self.validator_comm = ValidatorCommunications()

        self.path = None

    def stats_request(self):
        # request stats from specified validator url
        self.request_start = time.clock()
        self.path = self.url + "/statistics/all"
        self.validator_comm.get_request(self.path, self._stats_completion,
                                        self._stats_error)

    def _stats_completion(self, json_stats, response_code):
        self.request_complete = time.clock()
        self.response_time = self.request_complete - self.request_start
        self.state = "RESP_{}".format(response_code)
        self._update_status(response_code)

        if response_code is 200:
            self.responding = True
            self.validator_stats.update_stats(self.responding, json_stats,
                                              self.request_start,
                                              self.request_complete)
        else:
            self.responding = False
            self.validator_stats.update_stats(self.responding, None,
                                              self.request_start,
                                              self.request_complete)

    def _stats_error(self, failure):
        self.request_complete = time.clock()
        self.response_time = self.request_complete - self.request_start
        self.state = "NO_RESP"
        self.responding = False
        self.response_status = failure.type.__name__
        self.validator_stats.update_stats(self.responding, None,
                                          self.request_start,
                                          self.request_complete)

        return

    def _update_status(self, response_code):
        response_codes = [
            "Informational", "Successful but not expected 200", "Redirection",
            "Client Error", "Server Error"
        ]
        if response_code is 200:
            self.response_status = "Successful"
        elif response_code in range(100, 600):
            index = response_code / 100 - 1
            self.response_status = response_codes[index]
        else:
            self.response_status = "Response Code Unknown"