Beispiel #1
0
 def wait_for_pattern_end(self):
     messages = self.communicator.receive()
     for message in messages:
         if not message["type"] == SIGNAL_SUCCESS:
             logger.error(("Received unexpected "
                           "message type: {:}").format(message["type"]))
             sys.exit(6)
Beispiel #2
0
 def wait_for_start(self):
     message = self.communicator.receive()[0]
     if not message["type"] == SIGNAL_START:
         logger.error(("Received unexpected "
                       "message type: {:}").format(message["type"]))
         sys.exit(6)
     else:
         self.start_block = message["payload"]
Beispiel #3
0
 def start_communicator(self, key):
     # check connection to satellite systems
     try:
         self.communicator = Communicator(self.args.sat, self.args.port,
                                          key)
     except Exception as err:
         logger.error(err)
         logger.error(("Could not connect to other sbt processes. "
                       "Make sure they are running and can be reached."))
         sys.exit(3)
Beispiel #4
0
 def get_pattern(self):
     message = self.communicator.receive()[0]
     if message["type"] == PATTERN:
         node_id, value, pattern = message["payload"]
         self.simulator.value = value
         self.simulator.node_id = node_id
         self.simulator.set_pattern(pattern)
     else:
         logger.error(("Received unexpected "
                       "message type: {:}").format(message["type"]))
         sys.exit(6)
Beispiel #5
0
 def wait_for_report(self):
     reports = []
     messages = self.communicator.receive()
     for message in messages:
         if message["type"] == REPORT:
             reports.append(message["payload"])
         else:
             logger.error(("Received unexpected"
                           "message type: {:}").format(message["type"]))
             sys.exit(6)
     return reports
Beispiel #6
0
 def get_addresses(self):
     message = self.communicator.receive()[0]
     if message["type"] == ADDRESS_REQUEST:
         node_id, address_count = message["payload"]
         self.simulator.node_id = node_id
         addresses = self.syscoin.generate_addresses(address_count)
         message = self.communicator.create_message(ADDRESS_RESPONSE,
                                                    (node_id, addresses))
         self.communicator.send(message)
         return addresses
     else:
         logger.error(("Received unexpected "
                       "message type: {:}").format(message["type"]))
         sys.exit(6)
Beispiel #7
0
 def check_funds(self):
     # check balance in address against fee and token projection
     sys_have = self.syscoin.get_sys_balance()
     sys_need = self.simulator.get_gas_cost()
     sys_difference = sys_need - sys_have
     if sys_difference > 0:
         logger.error(("Not enough SYS in given address. {:.2f} more SYS "
                       "required.").format(sys_difference))
         sys.exit(4)
     tokens_have = self.syscoin.get_token_balance(self.args.addr)
     tokens_need = self.simulator.get_required_tokens()
     token_difference = tokens_need - tokens_have
     if token_difference > 0:
         logger.error(("Not enough tokens in given address. {:.2f} more "
                       "tokens required.").format(token_difference))
         sys.exit(5)
Beispiel #8
0
def ask_user(question):
    reply = str(raw_input("{:} (Y/n): ".format(question))).lower().strip()
    try:
        if reply == 'y' or reply == 'yes':
            return True
        if reply == 'n' or reply == 'no':
            return False
        if not reply:
            return True
        else:
            logger.error('Invalid Input')
            return ask_user(question)
    except Exception as error:
        logger.warning("Please enter valid inputs")
        print(error)
        return ask_user(question)
Beispiel #9
0
 def start_pattern(self, patterns, connections):
     for index in range(len(patterns)):
         message = self.communicator.create_single_message(
             PATTERN, connections[index],
             (index, self.simulator.value, patterns[index]))
         self.communicator.send(message)
     messages = self.communicator.receive()
     for message in messages:
         if not message["type"] == SIGNAL_READY:
             logger.error(("Received unexpected "
                           "message type: {:}").format(message["type"]))
             sys.exit(6)
     raw_input("Should I go on?")
     message = self.communicator.create_message(
         SIGNAL_START,
         self.syscoin.get_blockheight() + 1)
     self.communicator.send(message)
Beispiel #10
0
 def start_simulator(self):
     try:
         with open(self.args.pattern) as pattern_file:
             self.simulator = Simulator(self.syscoin,
                                        json.load(pattern_file),
                                        float(self.args.value),
                                        len(self.args.sat),
                                        float(self.args.fee),
                                        int(self.args.token),
                                        self.args.addr)
     except Exception as err:
         if isinstance(self, Satellite):
             self.simulator = Simulator(self.syscoin, {}, 0, 0, 0,
                                        int(self.args.token),
                                        self.args.addr)
         else:
             logger.error(err)
             sys.exit(1)
Beispiel #11
0
 def get_addresses(self, totals):
     if self.simulator.node_count != len(self.communicator.connection_list):
         logger.error("Satellite Connection count mismatch")
         sys.exit(7)
     for index in range(len(totals)):
         message = self.communicator.create_single_message(
             ADDRESS_REQUEST, self.communicator.connection_list[index],
             (index, totals[index]))
         self.communicator.send(message)
     messages = self.communicator.receive()
     all_addresses = {}
     for message in messages:
         if message["type"] == ADDRESS_RESPONSE:
             node_id, addresses = message["payload"]
             all_addresses[node_id] = addresses
         else:
             logger.error(("Received unexpected "
                           "message type: {:}").format(message["type"]))
             sys.exit(6)
     return all_addresses
        help='Funding address')
    parser.add_argument('--pattern', default="pattern.json",
                        help='path to JSON file containing traffic pattern')
    parser.add_argument('--token', default="1533716253", help='Token ID')
    parser.add_argument('--value', default=1,
                        help='Average transaction value')
    parser.add_argument('--sat', default=[],
                        help='List of satellite system IPs')
    parser.add_argument('--port', default=9999, help='The port to use')
    parser.add_argument('--fee', default=0.0001,
                        help='Transaction fee per kilobyte')
    parser.add_argument('--prefund', default=False, action="store_true",
                        help='Distribute coins')
    parser.add_argument('--addrfile', default="main-addr.json",
                        help='File containing addresses')

    args = parser.parse_args()
    # account for argparse inability to create a list of strings
    args.sat = args.sat if isinstance(args.sat, list) else args.sat.split(",")

    try:
        syscoin = Syscoin(args.token)
    except Exception as err:
        logger.error(err)
        logger.error(("Could not connect to syscoind. "
                      "Make sure syscoin is running and "
                      "this user has access to the rpc port."))
        sys.exit(2)
    state_machine = StateMachine(syscoin, args)
    state_machine.start()