simple_cluster module

Copyright (c) 2017 beyond-blockchain.org.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

NetworkDomain([network, config, domain_id, …]) Compose a simple core node cluster
class simple_cluster.NetworkDomain(network=None, config=None, domain_id=None, node_id=None, loglevel='all', logname=None)[source]

Bases: bbc1.core.bbc_network.DomainBase

Compose a simple core node cluster

add_peer_node(node_id, ip4, addr_info)[source]

(internal use) add node as a peer node

Parameters:
  • node_id
  • ip4
  • addr_info
Returns:

advertise_domain_info()[source]
alive_check()[source]
domain_manager_loop()[source]

maintain domain (e.g., updating peer list and topology)

Returns:
get_neighbor_nodes()[source]

Return neighbor nodes (for broadcasting message)

Returns:
get_resource(query_entry)[source]
print_peerlist()[source]

Print peer list

Returns:
process_REQUEST_FIND_VALUE(msg)[source]
process_REQUEST_STORE(msg)[source]
process_RESPONSE_FIND_VALUE(msg)[source]
process_message(ip4, from_addr, msg)[source]

process received message

Parameters:
  • ip4 – True (from IPv4) / False (from IPv6)
  • from_addr – sender address and port (None if TCP)
  • msg – the message body (already deserialized)
Returns:

purge_by_LRU()[source]

(internal use) purge cache entry by Least Recently Used algorithm

Returns:
put_resource(asset_group_id, resource_id, resource_type, resource)[source]
random_send(msg, count)[source]

(internal use) send data to randomly selected nodes

Parameters:
  • msg
  • count – number of nodes to send
Returns:

resend_resource(query_entry)[source]
resolve_accommodating_core_node(query_entry)[source]

Resolve which node the user connects to

Parameters:query_entry
Returns:
respond_find_node(target_id, nonce, asset_group_id=None, resource_id=None)[source]
respond_find_value(target_id, nonce, asset_group_id=None, resource_id=None, resource=None, resource_type=None)[source]
send_find_value(target_id, nonce, asset_group_id, resource_id, resource_type)[source]
send_p2p_message(query_entry)[source]

Send a message to another node

Parameters:query_entry
Returns:
send_peerlist(query_entry)[source]