EduSteem - IPFS support (Backend)

Repository

https://github.com/bflanagin/EduSteem

Screenshot from 2018-07-30 00-44-09.png

Images displayed in the screenshot above are pulled from the ipfs network.

New Feature: IPFS support

When creating any project we must consider how data is stored, what data is shared, and probably most importantly how others access this data. In eduSteem as with all my projects I take the local storage approach whenever possible. Having the data on site means that no matter how good or bad your connection to the internet is you can still use the software. Of course this has its own challenges, as you have to add extra steps to ensure that data is synchronized between client and server and that no matter what the outcome it does so with grace. So after considering my options i decided that a third party solution was needed. Enter IPFS a decentralized data store that uses block-chain methodologies to store and share data over its network.

Using IPFS eduSteem can now upload and download media assets without the need to host these files on our own servers. Which is the basis of most of the other feature updates in this post.

Implementation

ipfs is a standalone application that needs to be installed on the computer with eduSteem as I use a snap compatible Linux distribution it was as simple as running


$ sudo snap install ipfs
$ ipfs init

Once installed I need to launch and interact with the program from within eduSteem. For this I created a new header file called process.h. In process.h I created a public class called Process that allows me to launch and read what is sent to stdout if applicable. This code was influenced by several QProcess examples, and stripped down to just the parts I needed. Here is the header file in entirety.


#ifndef PROCESS_H
#define PROCESS_H

#endif // PROCESS_H

#include 
#include 

class Process : public QProcess {
    Q_OBJECT

public:
    Process(QObject *parent = 0) : QProcess(parent) { }

    Q_INVOKABLE void start(const QString &program, const QVariantList &arguments) {
        QStringList args;

        // convert QVariantList from QML to QStringList for QProcess

        for (int i = 0; i < arguments.length(); i++)
            args << arguments[i].toString();

        QProcess::start(program, args);
    }

    Q_INVOKABLE QByteArray readAll() {
        return QProcess::readAll();
    }
};

Once the header file was written I added it to the includes within main.cpp to register it for use in my qml files.


qmlRegisterType<Process>("Process", 1, 0, "Process");

Due to the way that ipfs works you must have it running on your computer as a daemon (service) given that ipfs won't allow multiple daemons to run I added a very simple process element called "ipfsdaemon" to start whenever eduSteem starts, and thankfully due to the way that QProcess works the daemon is closed after eduSteem is exited. (Note if you kill the eduSteem process it doesn't kill the daemon, only if you close it properly will it cleanly shutdown.

Launching ipfs is rather trivial requiring only these lines of code to ensure it is running when we need it.

   Process {
        id: ipfsdaemon
        onReadyRead: {
            console.log(readAll())
            ipfsDaemon = true
        }
    }

Then I simply call ipfsdaemon.start("ipfs", "daemon") once various checks are complete.

With the daemon process complete I simply create other similar processes to add files to the ipfs network whenever there is need to store media files. As these files are referenced via their hash I created a table called "Media" in my local database to store these hashes. This table also includes fields to associate the file with the school, the owner of the file, as well as the type of file. All these fields will be used in features in the future, but for now we use it for backup purposes as well as verification that our files are indeed making it where they need to go.

Banner.png

Find out more

eduSteem is going through a development sprint. These weekly updates, help keep me on track as well as giving those that are interested detailed reporting of my progress. The goal is to have it ready for use in a small school setting by the end of July. For further reading check out these other posts here on Steemit.

GitHub Account

https://github.com/bflanagin

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now