(args)
Send a message over satellite
Send a message over satellite
Send a message over satellite
def send(args):
    """Send a message over satellite"""
    gnupghome = os.path.join(args.cfg_dir, args.gnupghome)
    server_addr = _get_server_addr(args.net, args.server)

    # Instantiate the GPG wrapper object if running with encryption or signing
    if (not args.plaintext or args.sign):
        gpg = Gpg(gnupghome, interactive=True)
        config_keyring(gpg)
    else:
        gpg = None

    # A passphrase is required if signing
    if (args.sign and (not args.no_password)):
        gpg.prompt_passphrase('Password to private key used for message '
                              'signing: ')

    # File or text message to send over satellite
    if (args.file is None):
        if (args.message is None):
            data = input("Type a message: ").encode()
            print()
        else:
            data = args.message.encode()
        basename = None
    else:
        basename = os.path.basename(args.file)
        with open(args.file, 'rb') as f:
            data = f.read()

    assert(len(data) > 0), \
        "Empty {}".format("file" if args.file else "message")

    # Put file or text within an API message
    msg = api_msg.generate(data,
                           filename=basename,
                           plaintext=args.plaintext,
                           encapsulate=(not args.send_raw),
                           sign=args.sign,
                           fec=args.fec,
                           gpg=gpg,
                           recipient=args.recipient,
                           trust=args.trust,
                           sign_key=args.sign_key,
                           fec_overhead=args.fec_overhead)

    # Actual number of bytes used for satellite transmission
    tx_len = calc_ota_msg_len(msg.get_length())
    logger.info("Satellite transmission will use %d bytes" % (tx_len))

    # Ask user for bid or take it from argument
    bid = args.bid if args.bid else bidding.ask_bid(tx_len)

    # API transmission order
    order = ApiOrder(server_addr, tls_cert=args.tls_cert, tls_key=args.tls_key)
    res = order.send(msg.get_data(), bid)
    print()

    # The API servers (except the gossip and btc-src instances) should return a
    # Lightning invoice for the transmission order
    if (server_addr != server_map['gossip']
            and server_addr != server_map['btc-src']):
        payreq = res["lightning_invoice"]["payreq"]

        # Print QR code
        try:
            qr = qrcode.QRCode()
            qr.add_data(payreq)
            qr.print_ascii()
        except UnicodeError:
            qr.print_tty()

        # Execute arbitrary command with the Lightning invoice
        if (args.invoice_exec):
            cmd = shlex.split(args.invoice_exec.replace("{}", payreq))
            logger.debug("Execute:\n> {}".format(" ".join(cmd)))
            subprocess.run(cmd)

    # Wait until the transmission completes (after the ground station confirms
    # reception). Stop if it is canceled.
    if (args.no_wait):
        return

    try:
        target_state = ['sent', 'cancelled']
        order.wait_state(target_state)
    except KeyboardInterrupt:
        pass
def send ( args ) : gnupghome = os . path . join ( args . cfg_dir , args . gnupghome ) server_addr = _get_server_addr ( args . net , args . server ) # Instantiate the GPG wrapper object if running with encryption or signing if ( not args . plaintext or args . sign ) : gpg = Gpg ( gnupghome , interactive = True ) config_keyring ( gpg ) else : gpg = None # A passphrase is required if signing if ( args . sign and ( not args . no_password ) ) : gpg . prompt_passphrase ( 'Password to private key used for message ' 'signing: ' ) # File or text message to send over satellite if ( args . file is None ) : if ( args . message is None ) : data = input ( "Type a message: " ) . encode ( ) print ( ) else : data = args . message . encode ( ) basename = None else : basename = os . path . basename ( args . file ) with open ( args . file , 'rb' ) as f : data = f . read ( ) assert ( len ( data ) > 0 ) , "Empty {}" . format ( "file" if args . file else "message" ) # Put file or text within an API message msg = api_msg . generate ( data , filename = basename , plaintext = args . plaintext , encapsulate = ( not args . send_raw ) , sign = args . sign , fec = args . fec , gpg = gpg , recipient = args . recipient , trust = args . trust , sign_key = args . sign_key , fec_overhead = args . fec_overhead ) # Actual number of bytes used for satellite transmission tx_len = calc_ota_msg_len ( msg . get_length ( ) ) logger . info ( "Satellite transmission will use %d bytes" % ( tx_len ) ) # Ask user for bid or take it from argument bid = args . bid if args . bid else bidding . ask_bid ( tx_len ) # API transmission order order = ApiOrder ( server_addr , tls_cert = args . tls_cert , tls_key = args . tls_key ) res = order . send ( msg . get_data ( ) , bid ) print ( ) # The API servers (except the gossip and btc-src instances) should return a # Lightning invoice for the transmission order if ( server_addr != server_map [ 'gossip' ] and server_addr != server_map [ 'btc-src' ] ) : payreq = res [ "lightning_invoice" ] [ "payreq" ] # Print QR code try : qr = qrcode . QRCode ( ) qr . add_data ( payreq ) qr . print_ascii ( ) except UnicodeError : qr . print_tty ( ) # Execute arbitrary command with the Lightning invoice if ( args . invoice_exec ) : cmd = shlex . split ( args . invoice_exec . replace ( "{}" , payreq ) ) logger . debug ( "Execute:\n> {}" . format ( " " . join ( cmd ) ) ) subprocess . run ( cmd ) # Wait until the transmission completes (after the ground station confirms # reception). Stop if it is canceled. if ( args . no_wait ) : return try : target_state = [ 'sent' , 'cancelled' ] order . wait_state ( target_state ) except KeyboardInterrupt : pass