Skip to content
Snippets Groups Projects
README.md 6.96 KiB
Newer Older
  • Learn to ignore specific revisions
  • # DRIP and Iroha scripts
    
    This repository contains various scripts to help register and simulate a UA that is compliant with the DRIP protocol. Hyperledger Iroha blockchain framework is used as a registry for DRIP.
    
    ## drippy
    
    drippy is a python package containing modules to read host identity protocol xml files, create self attestation authentication messages, and interact with the blockchain.
    
    ## bluetooth
    
    `beacon.py` is used to broadcast legacy bluetooth frames for ASTM F3411-19 basic ID, location and authentication messages. It uses drippy to read host identity files, from which an identity will be used for the basic ID messages. If an iroha private key file is specified, then it will also attempt to send location updates to the blockchain. Type `python beacon.py -h` for more information on how to use the script. Note that sudo priviledges will be required to run the hci commands in the script.
    
    ## iroha
    
    Contains various scripts and files to help build the Iroha blockchain registry. See setup for how to use the relevant scripts.
    
    ## flight_path
    
    Contains scripts to extract a flight path (list of coordinates) from the Iroha blockchain, and display it on google maps using Jupyter.
    
    ## keys
    
    Contains the iroha private/public keypair used for querying the blockchain in the [android application](https://gitlab.liu.se/drip_iroha/dronehit_android).
    
    # Setup
    
    ## Prerequisites
    
    Make sure to create a python virtual environment and install the required packages in `requirements.txt`. A venv folder is assumed to be installed in the root directory of this repository for the instructions. All commands (except for those in the Iroha section) are executed from the root directory.
    
    create venv: `python3 -m venv venv`
    activate venv:
    <ol>
        <li>On windows: <code>venv\Scripts\activate</code></li>
        <li>On linux: <code>source venv/bin/activate</code></li>
    </ol>
    
    install requirements: `pip install -r requirements`
    
    In case of docker permission errors:
    
        sudo groupadd docker
        sudo usermod -aG docker $USER
        newgrp docker
    
    If above does not work, try restarting. You can check that user is part of docker group using command `groups`.
    
    ### Iroha
    
    
    The first way: you need to first compile [my version of Iroha 1.2.0](https://gitlab.liu.se/drip_iroha/iroha-1.2.0-drip), as that version contains other regex validation for account id that allows some characters contained in a HHIT. Instructions to compile can be found [here](https://iroha.readthedocs.io/en/main/build/index.html).
    
    Try this when the first way is hard and complex to achieve:
    The second way is to use command "pip install iroha" on Linux (the newest version of iroha on 5th/Dec/2022 is 1.4.1.1). Additionally, to run the code, the version of package named "protobuf" needs to be downgrade to the version <= 3.20.1 (just use 3.20.1), by using command "pip install protobuf==3.20.1". Other than that, you may also meet the problem of lacking packages "gps" and "dotenv", theses can be installed by using "pip install gps" and "pip install python-dotenv", the newest version will be auto installed.
    
    
    
    Once it's compiled, you would need to start it with the correct configurations. These can be found in iroha/node_config (in this repository). In the same folder where you have compiled the iroha binaries (usually in `build/bin`), copy over the configration files and run:
    
    `./irohad -genesis_block genesis.json -config config.json -keypair_name node_0`
    
    If you want to use separate configuration files for iroha, then see [here](https://iroha.readthedocs.io/en/main/configure/index.html) for instructions. Make sure to change the host and port in the `.env` file.
    
    If you have decided to use my configuration files, then continue with running (in this repo) `python iroha/setup_iroha_drip_scenario.py`. This will store self attestations and certificates for the identities in use, currently only one admin account and one drone account.
    
    ### Drone
    
    Assuming you have a gps module installed on your drone device, you can run `sudo venv/bin/python bluetooth/beacon.py -f identities/drone/drone_identities.xml --gps`. This will start sending bluetooth advertisements using the gps data from the gps module. There is an [app](https://gitlab.liu.se/drip_iroha/dronehit_android) that can be used to capture these advertisements.
    
    If you want to send gps location updates to the blockchain as well, you need to specify a file with the correct private key for the iroha account that belongs to the same host identity specified. For the drone identity included, run `sudo venv/bin/python bluetooth/beacon.py -f identities/drone/drone_identitites.xml -i identitites/drone/200100250b3fa14c1cee522e25add5b0.priv --gps`
    
    A flight_id in hexadecimal string can be specified with the `--flight_id` option. This option is only used when sending location updates to the blockchain in order to identify the current flight path a UA takes. If no flight_id is specified, one will be generated for you. The flight_id is printed in the terminal, save the flight_id somewhere if you want to query the correct flight path later. Note that the flight_id has to be exactly 32 bytes, or 64 characters long when specified with hexstring.
    
    ### Recreate drone path
    
    If you have sent location updates to the blockchain, you can recreate the path taken by the UA with the scripts in the flight_path directory. First run `generate_flight_path.py`. You need to specify the host identity file for for an admin account, with the corresponding iroha private key, and the output file name:
    
    `python flight_path/generate_flight_path.py -f identities/admin/admin_identitites.xml -i identitites/admin/200100250b3fa14c422d977815e6912e.priv -o coords.json`
    
    The script will prompt you for the iroha account you want to query, as well as the flight id. Here you should input the UA account id. Note that this script will fetch blocks from the blockchain, meaning the query account needs the correct permissions to succesfully fetch them. Make sure to specify a host identity file and iroha private key for an account that has these permissions, such as the admin account specified in the command above.
    
    Next, you need to run `plot_flight_path.ipynb` with Jupyter. This file uses google maps api, so we need to enable the correct jupyter extensions (these should already be included in requirements.txt). Run these commands:
    
    `jupyter nbextension enable --py --sys-prefix widgetsnbextension`
    `jupyter nbextension enable --py --sys-prefix gmaps`
    
    Since we are using google maps api, you also need to make sure that there is a `maps_api_key.txt` file in the same directory that should contain your google maps api key. If it's in place, just run:
    
    `jupyter-notebook flight_path/plot_flight_path.ipynb`
    
    Run the code cell in the jupyter notebook, and if all is correct, a flight path should be displayed on a google maps frame.
    
    ### [Iroha drone tracker](https://github.com/soupracer/iroha_drone_tracker)
    
    You can use my Iroha drone tracker web application in case you don't want to use jupyter. The web application can also track current UA position by querying the blockchain.