Exemple #1
0
 def fetch_buffer(self, message: Message, identifier: bytes = b'') -> bytes:
     """From Message - fetch bin buffer"""
     # TODO
     # identifier = NodeManager.identifierForIpAddress(self.ip);
     self.send(message.get_bytes_for_transmission())
     response = self.receive()
     return response
Exemple #2
0
 def fetch(self,
           message: Message,
           identifier: bytes = b'') -> MessageObject:
     """Fetch then decode"""
     buffer = self.fetch_buffer(message, identifier)
     return Message.from_bytes(
         buffer,
         b'').get_content()  # self.ip, but convert or use str for ips?
Exemple #3
0
def status(ctx):
    """Get Status of distant server"""
    connect(ctx)
    if VERBOSE:
        app_log.info(f"Connected to {ctx.obj['host']}:{ctx.obj['port']}")
    empty = EmptyMessageObject(app_log=app_log)
    message = Message(MessageType.StatusRequest17, empty, app_log=app_log)
    res = ctx.obj['connection'].fetch(message)
    print(res.to_json())
Exemple #4
0
def status(ctx):
    """Get Status of distant server"""
    # ex : python3 Nyzocli.py  -j status 159.69.216.65
    connect(ctx, ctx.obj['verifier_ip'])
    if VERBOSE:
        app_log.info(f"Connected to {ctx.obj['verifier_ip']}")
    empty = EmptyMessageObject(app_log=app_log)
    message = Message(MessageType.StatusRequest17, empty, app_log=app_log)
    res = ctx.obj['verifier_connection'].fetch(message)
    print(res.to_json())
Exemple #5
0
    def call(target_ip):
        private_key = None
        username = None

        rres = load_from_data(socks_host)
        if rres is None:
            res = assign_to_ip(socks_host)
            username = res['name']
            private_key = res['private_key']
        elif rres is None and get_count_active() > max_ips_vps:
            print('We have {} IPs, no need to add this to our server'.format(
                max_ips_vps))
        else:
            username = rres['name']
            private_key = rres['private_key']

        # print(private_key)
        if get_count_active() <= max_ips_vps:
            verbose = True
            target_port = 9444

            config.load()
            connection_args_dict = dict(verbose=verbose)
            message_args_dict = dict(app_log=app_log)

            message_args_dict.update({
                'timestamp': int(time() * 1000)
                # 'sourceNodePrivateKey': private_key
            })

            if (socks_host is None
                    and socks_port is not None) or (socks_host is not None
                                                    and socks_port is None):
                raise Exception('Socks port or socks host is not provided')

            if socks_host is not None:
                connection_args_dict.update({
                    'socks_host': socks_host,
                    'socks_port': socks_port
                })

            print('Propagating to {}:{}'.format(socks_host, socks_port))

            try:
                connection = Connection(target_ip, **connection_args_dict)

                request = NodeJoin(target_port, username, app_log=app_log)
                message = Message(MessageType.NodeJoin3, private_key, request,
                                  **message_args_dict)
                res = connection.fetch(message)
                print(res.to_json())
            except Exception as e:
                print('Skipped {}, {}'.format(target_ip, e))
                pass
Exemple #6
0
def block(ctx, block_number):
    """Get a block detail"""
    connect(ctx, ctx.obj['verifier_ip'])
    if VERBOSE:
        app_log.info(f"Connected to {ctx.obj['verifier_ip']}:9444")
        app_log.info(f"block {block_number}")
    req = BlockRequest(start_height=block_number,
                       end_height=block_number,
                       include_balance_list=False,
                       app_log=app_log)
    message = Message(MessageType.BlockRequest11, req, app_log=app_log)
    res = ctx.obj['verifier_connection'].fetch(message)
    print(res.to_json())
Exemple #7
0
def vbalance(ctx, address):
    """Get balance of an ADDRESS from a verifier (Uses the one from localhost by default)
    """
    connect(ctx, ctx.obj['verifier_ip'])
    if address == '':
        address = config.PUBLIC_KEY.to_bytes().hex()
    else:
        id__address, address = normalize_address(address, asHex=True)

    if VERBOSE:
        app_log.info(f"Get vbalance for address {address}")
    assert (len(address) == 64)  # TODO: better user warning

    if VERBOSE:
        app_log.info(f"Connected to {ctx.obj['verifier_ip']}")
        app_log.info(f"address {address}")
    empty = EmptyMessageObject()
    message = Message(MessageType.StatusRequest17, empty, app_log=app_log)
    res = ctx.obj['verifier_connection'].fetch(message)
    status = res.get_lines()
    frozen = int(extract_status_lines(status, "frozen edge")[0])
    if VERBOSE:
        app_log.info(f"Frozen Edge: {frozen}")

    reconnect(ctx)

    req = BlockRequest(start_height=frozen,
                       end_height=frozen,
                       include_balance_list=True,
                       app_log=app_log)
    message2 = Message(MessageType.BlockRequest11, req, app_log=app_log)
    res = ctx.obj['verifier_connection'].fetch(message2)
    # Wow, this is quite heavy. move some logic the pynyzo
    # Also list is *supposed* to be sorted, can help find faster
    bin_address = bytes.fromhex(address)
    for item in res.get_initial_balance_list().get_items():
        if item.get_identifier() == bin_address:
            if ctx.obj['json']:
                print(
                    json.dumps({
                        "block": frozen,
                        "balance": item.get_balance(),
                        "blocks_until_fee": item.get_blocks_until_fee(),
                        "address": address
                    }))
            else:
                print(f"At block: {frozen}")
                print(f"Your Balance is: {item.get_balance()/1000000}")
                print(f"Blocks until fee: {item.get_blocks_until_fee()}")
            return (item.get_balance(), item.get_blocks_until_fee())

    # Address Not found
    if ctx.obj['json']:
        print(
            json.dumps({
                "block": frozen,
                "balance": 0,
                "blocks_until_fee": None,
                "address": address
            }))
    else:
        print(f"At block: {frozen}")
        print(f"Your Balance is: N/A")
        print(f"Blocks until fee: N/A")
    return 0, 0
Exemple #8
0
def main():
    parser = argparse.ArgumentParser(description='Nyzo node join test')
    parser.add_argument("-I",
                        "--ip",
                        type=str,
                        default='127.0.0.1',
                        help="IP to query (default 127.0.0.1)")
    parser.add_argument("-p",
                        "--port",
                        type=int,
                        default=9444,
                        help='Port to query')
    parser.add_argument("-u", "--user", type=str, help='Username')
    parser.add_argument("-v",
                        "--verbose",
                        action="count",
                        default=True,
                        help='Be verbose.')
    parser.add_argument("-sh", "--socks_host", type=str, help='Socks5 host')
    parser.add_argument("-sp", "--socks_port", type=int, help='Socks5 port')
    parser.add_argument("-i",
                        "--identifier",
                        type=str,
                        help='Source node identifier')
    parser.add_argument("-s",
                        "--signature",
                        type=str,
                        help='Source node signature')
    parser.add_argument("-sip",
                        "--source_ip",
                        type=int,
                        help='Source ip address')
    parser.add_argument("-pkey",
                        "--private_key",
                        type=str,
                        help='Private key string')
    args = parser.parse_args()

    app_log = tornado_logger()

    config.load()
    connection_args_dict = dict(verbose=args.verbose)
    message_args_dict = dict(app_log=app_log)
    if args.identifier is not None:
        if args.signature is None:
            raise Exception('Signature data should be provided as well')
        try:
            message_args_dict.update({
                'timestamp':
                int(time() * 1000),
                'sourceNodeIdentifier':
                args.identifier.encode(),
                'sourceNodeSignature':
                args.signature.encode()
            })
        except Exception:
            raise Exception(
                "Provided data in the arguments for identifier or signature are not correct"
            )

    message_args_dict['sourceNodePrivateKey'] = args.private_key

    if (args.socks_host is None
            and args.socks_port is not None) or (args.socks_host is not None
                                                 and args.socks_port is None):
        raise Exception('Socks port or socks host is not provided')

    if args.socks_host is not None:
        connection_args_dict.update({
            'socks_host': args.socks_host,
            'socks_port': args.socks_port
        })
    connection = Connection(args.ip, **connection_args_dict)

    request = NodeJoin(args.port, args.user, app_log=app_log)
    message = Message(MessageType.NodeJoin3, request, **message_args_dict)
    res = connection.fetch(message)
    print(res.to_json())
Exemple #9
0
                        default=False,
                        help='Be verbose.')
    parser.add_argument("-a",
                        "--action",
                        type=str,
                        default='status',
                        help='Action (status, block)')
    args = parser.parse_args()

    app_log = tornado_logger()

    config.load()

    connection = Connection(args.ip, app_log=app_log, verbose=args.verbose)

    if args.action == 'status':
        empty = EmptyMessageObject(app_log=app_log)
        message = Message(MessageType.StatusRequest17, empty, app_log=app_log)
        res = connection.fetch(message)
        print(res.to_json())
    elif args.action == 'block':
        # test. Use a block high enough so it's not frozen.
        # TODO: get last block from  reference verifiers
        request = BlockRequest(start_height=1695400,
                               end_height=1695400 + 2,
                               include_balance_list=True,
                               app_log=app_log)
        message = Message(MessageType.BlockRequest11, request, app_log=app_log)
        res = connection.fetch(message)
        print(res.to_json())