Exemplo n.º 1
0
 def __create_new_income(self, task_id, node_id, value, expected_value,
                         state):
     with db.transaction():
         ReceivedPayment.create(from_node_id=node_id,
                                task=task_id,
                                val=value,
                                expected_val=expected_value,
                                state=state)
Exemplo n.º 2
0
def increase_negative_resource(node_id, trust_mod):
    try:
        with db.transaction():
            LocalRank.create(node_id=node_id, negative_resource=trust_mod)
    except IntegrityError:
        LocalRank.update(negative_resource=LocalRank.negative_resource + trust_mod,
                         modified_date=str(datetime.datetime.now())) \
            .where(LocalRank.node_id == node_id).execute()
Exemplo n.º 3
0
def increase_positive_payment(node_id, trust_mod):
    try:
        with db.transaction():
            LocalRank.create(node_id=node_id, positive_payment=trust_mod)
    except IntegrityError:
        LocalRank.update(positive_payment=LocalRank.positive_payment + trust_mod,
                         modified_date=str(datetime.datetime.now())) \
            .where(LocalRank.node_id == node_id).execute()
Exemplo n.º 4
0
def increase_wrong_computed(node_id, trust_mod):
    try:
        with db.transaction():
            LocalRank.create(node_id=node_id, wrong_computed=trust_mod)
    except IntegrityError:
        LocalRank.update(wrong_computed=LocalRank.wrong_computed + trust_mod,
                         modified_date=str(datetime.datetime.now())) \
            .where(LocalRank.node_id == node_id).execute()
Exemplo n.º 5
0
def upsert_global_rank(node_id, comp_trust, req_trust, comp_weight, req_weight):
    try:
        with db.transaction():
            GlobalRank.create(node_id=node_id, requesting_trust_value=req_trust, computing_trust_value=comp_trust,
                              gossip_weight_computing=comp_weight, gossip_weight_requesting=req_weight)
    except IntegrityError:
        GlobalRank.update(requesting_trust_value=req_trust, computing_trust_value=comp_trust,
                          gossip_weight_computing=comp_weight, gossip_weight_requesting=req_weight,
                          modified_date=str(datetime.datetime.now())) \
            .where(GlobalRank.node_id == node_id).execute()
Exemplo n.º 6
0
def upsert_neighbour_loc_rank(neighbour_id, about_id, loc_rank):
    try:
        if neighbour_id == about_id:
            logger.warning("Removing {} self trust".format(about_id))
            return
        with db.transaction():
            NeighbourLocRank.create(node_id=neighbour_id, about_node_id=about_id,
                                    requesting_trust_value=loc_rank[1], computing_trust_value=loc_rank[0])
    except IntegrityError:
        NeighbourLocRank.update(requesting_trust_value=loc_rank[1], computing_trust_value=loc_rank[0]) \
            .where(
            (NeighbourLocRank.about_node_id == about_id) & (NeighbourLocRank.node_id == neighbour_id)).execute()
Exemplo n.º 7
0
    def add_known_peer(self, node, ip_address, port, metadata=None):
        is_seed = node.is_super_node() if node else False

        try:
            with db.transaction():
                host, _ = KnownHosts.get_or_create(
                    ip_address=ip_address,
                    port=port,
                    defaults={'is_seed': is_seed})
                host.last_connected = time.time()
                host.metadata = metadata or {}
                host.save()

            self.__remove_redundant_hosts_from_db()
            self._sync_seeds()

        except Exception as err:
            logger.error("Couldn't add known peer %r:%r : %s", ip_address,
                         port, err)
Exemplo n.º 8
0
    def add_known_peer(self, node, ip_address, port):
        is_seed = node.is_super_node() if node else False

        try:
            with db.transaction():
                KnownHosts.delete().where((KnownHosts.ip_address == ip_address)
                                          &
                                          (KnownHosts.port == port)).execute()

                KnownHosts.insert(ip_address=ip_address,
                                  port=port,
                                  last_connected=time.time(),
                                  is_seed=is_seed).execute()

            self.__remove_redundant_hosts_from_db()
            self.__sync_seeds()

        except Exception as err:
            logger.error("Couldn't add known peer %r:%r : %s", ip_address,
                         port, err)