On this page

latest contributor to this doc

Last Edit:

@gaeacodes

How to stream and playback a video file using the DEXP2P layer of a Smart Chain

This tech is in development. The DEX_streamsub method works well in small dedicated DEXP2P networks with fast nodes. It will be further developed to increase its reliability in larger networks. The specifics of the implementation are subject to change. This document is a Work In Progress.

The two methods DEX_stream and DEX_streamsub can be used to broadcast and download files from the "data mempool" of the DEXP2P network of a Smart Chain. Consult the RPC description pages for the two methods before going through this tutorial.

The DEX_stream method utilizes datablobs to

This datablob contains the DEX_pubkey of the sender, the name of the file published, its SHA256 hash, its size, number of datablobs that have been used to send all the data of the file to the network (fragments); the datablobs of this type can be found using their tagA, which is set to files.

Example:

Command to filter the datablobs to get information on all the slices published and available on the network

./komodo-cli -ac_name=DORN DEX_list 0 0 "slices"

The value of the key named "matches" is a JSON array. In it, we can see JSON of datablobs representing all the slices of different files available on the network . In each JSON, we can see that tagA is slices, which we filtered for. The rest of the relevant keys from the example are as follows

  • "tagB" set to "17-53-21.mkv"; it is the name of the file being streamed
  • "pubkey" set to "01e28518858aa3515163a67deee2b19f0d30e4fa237f0aec255e4c94db0fe8d063"; it is the DEX_pubkey of the streamer of the file
  • "decrypted" set to "f957d82bdd4fea7b38e28a2f949def308a4db4bcfa6eb9d30b6578c4709db615"; it is the SHA256 hash of the slice
  • "amountA" set to "0.00000000"; the value encodes the size of the file being streamed (in bytes) that exists before this slice
  • "amountB" set to "0.00000100"; the value encodes the number of datablobs used to broadcast the slice; to get the number, multiply the value with 10^8; this value is the same for all the slices

The method then splits the slice's data into fragments and broadcasts each fragment using a datablob. These datablobs have tagA as the filename and tagB as the word data

Example:

Command to filter the datablobs to get all the datablobs that contain the data of a published file whose name is 17-53-21.mkv

./komodo-cli -ac_name=DORN DEX_list 0 0 "17-53-21.mkv" "data"

The value of the key named "matches" is a JSON array. The length of the array must be a multiple of 100, as each slice is broken into 100 fragments as indicated by the previous datablob (slice info datablob). The datablob shown in the above example contains data from the published file. In the JSON that represents the datablob, we can see that tagA is the file name and tagB is the word data, which we filtered for. The rest of the relevant keys are as follows

  • "pubkey" set to "01e28518858aa3515163a67deee2b19f0d30e4fa237f0aec255e4c94db0fe8d063"; it is the DEX_pubkey of the publisher
  • the value of the key named "decrypted" contains the the actual data of the slice broadcasted using this datablob;
  • "amountA" set to "0.00000099"; the value encodes the fragment number of the data stored in this datablob; to get the fragment number, multiply the value with 10^8

This is done by broadcasting a datablob that contains this information. This datablob has tagA as the filename and tagB as the slice number

Example:

Command to filter the datablobs to get the datablob that contains the information about the ids of datablobs that contain the actual data of slice number 0 of a file being streamed whose name is 17-53-21.mkv

./komodo-cli -ac_name=DORN DEX_list 0 0 "17-53-21.mkv" "0"

The value of the key named "matches" is a JSON array. In it, we can see the datablob that contains the locators information about the published file. In the JSON that represents the datablob, we can see that tagA is the file name and tagB is the slice number, which we filtered for. The rest of the relevant keys are as follows

  • "pubkey" set to "01e28518858aa3515163a67deee2b19f0d30e4fa237f0aec255e4c94db0fe8d063"; it is the DEX_pubkey of the file streamer
  • the value of the key named "decrypted" contains the ids of all the datablobs that have the actual data of the slice;
  • "amountA" set to "0.01000000"; the value encodes the size of the slice; to get the size in bytes, multiply the value with 10^8; a slice is always 1 MB in size
  • "amountB" set to "0.00000100"; the value encodes the number of datablobs used to broadcast the slice; to get the number, multiply the value with 10^8

After the streaming of a file is started, any node on the network can issue the DEX_streamsub RPC repeatedly to assemble the file from the datablobs available in its RAM

In this section, we will describe how to stream a video file using the DEXP2P layer. You can use an alternative setup, but we describe what we have tested and works.

We need a software that can record video with either the webcam or your desktop as the source. We chose OBS as it is multi platform, easy to use and most importantly, open source

You can install OBS for your OS by following the instructions here: https://obsproject.com/download

Once it is installed, launch the program and set the output format of a recording to mkv from Settings > Output > Recording > Recording Format > mkv

In the same tab, set the "Recording path" to the directory your Komodo daemon that will be used to launch the Smart Chain is present. If you have compiled it yourself, the Komodo daemon should be present in the directory komodo/src

Also, tick the checkbox that says "Generate File Name without Space"

obs-studio-recording

The final settings should look similar to the ones in the above image.

After that, navigate to Settings > Advanced > Recording > Filename Formatting and change the format to one that will produce file names that are less than 15 characters in length. We recommend you to use %hh-%mm-%ss, it sets the name of the file as the time (in hour-minute-seconds format) at which the recording was started.

obs-studio-advanced

The settings should look similar to the ones in the above image.

In the directory where the Komodo daemon is located, create a script named stream.sh with the following contents and save the file.

#!/bin/bash

while true; do
  ./komodo-cli -ac_name=$1 DEX_stream $2 2
  sleep 1
done

Make the file executable by issuing the following command

chmod +x stream.sh

Launch the Smart Chain designated for DEXP2P streaming. Installation instructions are here

Example:

./komodod -ac_name=DORN -ac_cc=2 -ac_supply=1000000 -ac_reward=100000000 -addnode=136.243.58.134 -dexp2p=2

Open OBS and select a source to record. To start recording, click the "Start Recording button". This should result in a file being created in the same directory the Komodo daemon is present. This file should be increasing in size as more data is recorded into it.

obs

Start the stream.sh script with the Smart Chain's name and the file's name as arguments

./stream.sh <SMART CHAIN NAME> <FILE NAME>

You should see slices of the file being published as they become available. You can ignore the warnings that say "Not enough data to extend the stream". Hit CTRL + C in the same terminal to exit the script and stop streaming.

To watch a stream, you must launch the same Smart Chain whose DEXP2P network is being used to broadcast it. So, find the details from the streamer.

In the directory where the Komodo daemon is located, create a script named streamsub.sh with the following contents and save the file.

#!/bin/bash

while true; do
  ./komodo-cli -ac_name=$1 DEX_streamsub $2 5 $3
  sleep 1
done

Make the file executable by issuing the following command

chmod +x streamsub.sh

You can either get the details from the streamer directly or you can use the DEX_list command to filter all the datablobs available to find the details of the stream you are interested in.

To find all the streams being broadcast right now, issue the following command:

./komodo-cli -ac_name=<SMART CHAIN NAME> DEX_list 0 0 "slices" ""

In the matches, the values of tagB of each JSON is the mae of the file. If you know the DEX_pubkey but not the file name, you can use the following command to display the files published by your favorite streamer

./komodo-cli -ac_name=<SMART CHAIN NAME> DEX_list 0 0 "slices" "" <DEX_pubkey of streamer>

Once you know the DEX_pubkey of the publisher and the file' name you can start the streamsub.sh script with the Smart Chain's name, the file's name and the DEX_pubkey of the streamer as arguments

./streamsub.sh <SMART CHAIN NAME> <FILE NAME> <DEX_pubkey of streamer>

You should see slices of the file being downloaded as they become available. The file will be downloaded and assembled in the same directory the Komodo daemon is located .You can ignore the warnings that say "id not found" or similar as long as the file being downloaded is increasing in size. Hit CTRL + C in the same terminal to exit the script and stop downloading.

The file can be played while it is increasing in size using the VLC media player. You might use another video player if it supports playing a file that is increasing in size.