bbc_app 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.

BBcAppClient([host, port, logname, loglevel])
class bbc_app.BBcAppClient(host='127.0.0.1', port=9000, logname='-', loglevel='none')[source]

Bases: object

broadcast_peerlist_to_all_neighbors(domain_id)[source]

Request bbc_core to broadcast peerlist to all its neighbors :param domain_id: :return:

domain_setup(domain_id, module_name=None, storage_type=1, storage_path=None)[source]

Set up domain with the specified network module and storage (maybe used by a system administrator)

Parameters:
  • domain_id
  • module_name
  • storage_type – StorageType value
  • storage_path
Returns:

gather_signatures(tx_obj, reference_obj=None, destinations=None, asset_files=None)[source]

Request to gather signatures from the specified user_ids

Parameters:
  • tx_obj
  • reference_obj – BBcReference object
  • destinations – list of destination user_ids
  • asset_files – dictionary of {asset_id: file_content}
Returns:

get_bbc_config()[source]

Get config file of bbc_core (maybe used by a system administrator)

Returns:
get_cross_refs(asset_group_id, number)[source]

Get cross_refs

Parameters:
  • asset_group_id
  • number
Returns:

get_domain_list()[source]

Get domain_id list in bbc_core (maybe used by a system administrator)

Returns:
get_domain_peerlist(domain_id)[source]

Get peer list of the domain from the core node (maybe used by a system administrator)

Parameters:domain_id
Returns:
get_stats()[source]

Get statistics of bbc_core :return:

insert_transaction(tx_obj)[source]

Request to insert a legitimate transaction

Parameters:
  • asset_group_id
  • tx_obj – Transaction object (not deserialized one)
Returns:

make_message_structure(cmd)[source]

(internal use) make a base message structure for sending to the core node

Parameters:cmd
Returns:
manipulate_ledger_subsystem(enable=False, domain_id=None)[source]

start/stop ledger_subsystem on the bbc_core (maybe used by a system administrator)

Parameters:
  • enable – True->start, False->stop
  • domain_id
Returns:

ping_to_all_neighbors(domain_id)[source]

Request bbc_core to send ping to all its neighbors :param domain_id: :return:

receiver_loop()[source]
register_in_ledger_subsystem(asset_group_id, transaction_id)[source]

Register transaction_id in the ledger_subsystem

Parameters:
  • asset_group_id
  • transaction_id
Returns:

register_to_core()[source]

Register the client (user_id) to the core node. After that, the client can communicate with the core node

Returns:
request_insert_completion_notification(asset_group_id, flag)[source]

Request notification when a transaction has been inserted (as a copy of transaction) :param asset_group_id: :param flag: :return:

search_asset(asset_group_id, asset_id)[source]

Search request for the specified asset. This would return transaction_data (and asset_file file content)

Parameters:
  • asset_group_id
  • asset_id
Returns:

search_transaction(transaction_id)[source]

Search request for transaction_data

Parameters:transaction_id
Returns:
search_transaction_by_userid(asset_group_id, user_id)[source]

Search request for transaction_data by user_id

Parameters:
  • asset_group_id
  • user_id – user_id of the asset owner
Returns:

The transaction_data that includes asset with the specified user_id

send_domain_ping(domain_id, ipv4=None, ipv6=None, port=6641)[source]

Send domain ping to notify the existence of the node (maybe used by a system administrator)

Parameters:
  • domain_id
  • ipv4
  • ipv6
  • port
Returns:

send_message(msg, dst_user_id)[source]

Send peer-to-peer message to the specified user_id

Parameters:
  • msg
  • dst_user_id
Returns:

send_msg(dat)[source]

(internal use) send the message to the core node

Parameters:dat
Return query_id or None:
 
sendback_denial_of_sign(dst, reason_text, query_id=None)[source]

Send back the denial of sign the transaction

Parameters:
  • dst
  • reason_text
  • query_id
Returns:

sendback_signature(dst, ref_index, sig, query_id=None)[source]

Send back the signed transaction to the source

Parameters:
  • dst
  • ref_index – Which reference in transaction the signature is for
  • sig
  • query_id
Returns:

set_callback(callback_obj)[source]

Set callback object that implements message processing functions

Parameters:callback_obj
Returns:
set_domain_id(domain_id)[source]

set domain_id to this client to include it in all messages

Parameters:domain_id
Returns:
set_domain_static_node(domain_id, node_id, ipv4, ipv6, port)[source]

Set static node to the core node (maybe used by a system administrator)

Parameters:
  • domain_id
  • node_id
  • ipv4
  • ipv6
  • port
Returns:

set_user_id(identifier)[source]

Set user_id of the object

Parameters:identifier
Returns:
start_receiver_loop()[source]
unregister_from_core()[source]

Unregister and disconnect from the core node

Returns:
verify_in_ledger_subsystem(asset_group_id, transaction_id)[source]

Verify transaction_id in the ledger_subsystem

Parameters:
  • asset_group_id
  • transaction_id
Returns:

class bbc_app.Callback(log=None)[source]

Bases: object

Set of callback functions for processing received message

create_queue(query_id)[source]
destroy_queue(query_id)[source]
dispatch(dat, payload_type)[source]
proc_cmd_sign_request(dat)[source]
proc_notify_inserted(dat)[source]
proc_resp_cross_ref(dat)[source]
proc_resp_domain_setup(dat)[source]
proc_resp_gather_signature(dat)[source]
proc_resp_get_config(dat)[source]
proc_resp_get_domainlist(dat)[source]

Return domain_ids

Parameters:dat
Returns:list of domain_id
proc_resp_get_peerlist(dat)[source]

Return node info

Parameters:dat
Returns:list of node info (the first one is that of the connecting core)
proc_resp_get_stats(dat)[source]
proc_resp_insert(dat)[source]
proc_resp_ledger_subsystem(dat)[source]
proc_resp_register_hash(dat)[source]
proc_resp_search_asset(dat)[source]
proc_resp_search_by_userid(dat)[source]
proc_resp_search_transaction(dat)[source]
proc_resp_set_peer(dat)[source]
proc_resp_sign_request(dat)[source]
proc_resp_verify_hash(dat)[source]
proc_user_message(dat)[source]
set_logger(log)[source]
sync_by_queryid(query_id, timeout=None)[source]

Wait for message with specified query_id

Parameters:
  • query_id
  • timeout – timeout second for waiting
Returns:

synchronize(timeout=None)[source]

Wait for receiving message

Parameters:timeout – timeout second for waiting
Returns:
bbc_app.get_id_from_mappings(name, asset_group_id)[source]
bbc_app.get_list_from_mappings(asset_group_id)[source]
bbc_app.remove_id_mappings(name, asset_group_id)[source]
bbc_app.store_id_mappings(name, asset_group_id, transaction_id=None, asset_ids=None)[source]