EduSteem - IPFS support (Backend)

in #utopian-io6 years ago

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 <QProcess>
#include <QVariant>

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

Sort:  

Hi again,
Another use of IPFS, that's a good call for hosting images ;)

Let's go for the review:

It's really great that you're using IPFS but you should have added a bit more stuff before submitting a contribution in my opinion.

Your contribution has been evaluated according to Utopian policies and guidelines, as well as a predefined set of questions pertaining to the category.

To view those questions and the relevant answers related to your post, click here.


Need help? Write a ticket on https://support.utopian.io/.
Chat with us on Discord.
[utopian-moderator]

lol, just can't win can I? I put in 3 or 4 features and get the same amount of payout as I get when when I put in 1. Sometimes its due to merit, but most of the time it seems to be on a per moderator basis. I'm planning on writing the "frontend" post today.

I agree about the localhost not needing to be hard coded I'm working on a settings page where people would be able to set those options. I am under the impression that you can ensure the media is locally cached by calling the local ipfs service to fetch the content. I could be wrong about this, so I'll do more reading.

Hey @gregory.latinier
Here's a tip for your valuable feedback! @Utopian-io loves and incentivises informative comments.

Contributing on Utopian
Learn how to contribute on our website.

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Hey @bflanagin
Thanks for contributing on Utopian.
We’re already looking forward to your next contribution!

Want to chat? Join us on Discord https://discord.gg/h52nFrV.

Vote for Utopian Witness!

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.034
BTC 63900.40
ETH 3140.82
USDT 1.00
SBD 3.98