On this page

latest contributor to this doc

Last Edit:

@gaeacodes

How to publish and download files using the DEXP2P layer

The two methods DEX_publish and DEX_subscribe can be used to broadcast and download files from the "data mempool" of the DEXP2P network of a Smart Chain.

The DEX_publish 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 files published and available on the network

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

The value of the key named "matches" is a JSON array. In it, we can see only one JSON. It means that, there is only 1 file that is currently published and available on the network. In that JSON, we can see that tagA is files, which we filtered for. The rest of the relevant keys are as follows

  • "tagB" set to "roadmap2020.pdf"; it is the name of the file
  • "pubkey" set to "01e28518858aa3515163a67deee2b19f0d30e4fa237f0aec255e4c94db0fe8d063"; it is the DEX_pubkey of the publisher
  • "decrypted" set to "8ed81c26721dcce7bfd1a811f301ec84a2f79389ab86cb45e481ab3f5f40f85d"; it is the SHA256 hash of the file
  • "amountA" set to "0.02049320"; the value encodes the size of the file; to get the size in bytes, multiply the value with 10^8
  • "amountB" set to "0.00000205"; the value encodes the number of datablobs used to broadcast the file; to get the number, multiply the value with 10^8

The method then splits the file'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 the datablobs that contains the data of a published file whose name is roadmap2020.pdf

./komodo-cli -ac_name=DORN DEX_list 0 0 "roadmap2020.pdf" "data"

node.position.start.linenode.position.start.line The value of the key named "matches" is a JSON array. The length of the array is 205, same as the number of fragments as indicated by the previous datablob (file info datablob). In it, we can see a datablob that 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 file broadcasted using this datablob;
  • "amountA" set to "0.00000201"; 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 word locators

Example:

Command to filter the datablobs to get the datablob that contains the locators information of a published file whose name is roadmap2020.pdf

./komodo-cli -ac_name=DORN DEX_list 0 0 "roadmap2020.pdf" "locators"

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 word locators, 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 ids of all the datablobs that have the actual data of the file;
  • "amountA" set to "0.02049320"; the value encodes the size of the file; to get the size in bytes, multiply the value with 10^8
  • "amountB" set to "0.00000205"; the value encodes the number of datablobs used to broadcast the file; to get the number, multiply the value with 10^8

After a file is published, any node on the network can issue the DEX_subscribe RPC to construct the file from the datablobs available in its RAM

  • Follow the installation instructions here to install Komodo
  • Navigate to the directory komodo/src and launch the Smart Chain to be used to Publish the file

Example:

./komodod -ac_name=DORN -ac_cc=2 -ac_supply=1000000 -ac_reward=100000000 -addnode=136.243.58.134 -dexp2p=2
  • Copy and Paste the file that needs to be published into the directory where the komodod binary used to launch the Smart Chain is present
  • Make sure the file's name is less than 15 characters
  • Open another terminal and issue the following command to publish the file
./komodo-cli -ac_name=<Smart Chain Name> DEX_publish <file name> 0
  • In the above command, replace the text <Smart Chain Name> with the name of the Smart Chain and the text <file name> with the name of the file to be published
  • Wait for the prompt to be freed and available to you; you have successfully published a file to the DEXP2P network of your desired Smart Chain

  • Follow the installation instructions here to install Komodo
  • Navigate to the directory komodo/src and launch the Smart Chain from whose DEXP2P network a file needs to be downloaded.

Example:

./komodod -ac_name=DORN -ac_cc=2 -ac_supply=1000000 -ac_reward=100000000 -addnode=136.243.58.134 -dexp2p=2
  • Wait a little while after launching the chain to give your node time to synchronise with the network and receive datablobs. You can check if your node is receiving datablobs by using the DEX_stats command
  • Open another terminal and issue the following command to get a list of all the files available
./komodo-cli -ac_name=<Smart Chain Name> DEX_list 0 0 "files"
  • In the above command, replace the text <Smart Chain Name> with the name of the Smart Chain
  • Observe the key named "matches" in the response. Its value is an array of JSON that represent datablobs that contain the details necessary to download the files. Each datablob will have the information needed to download one file
  • the tagB of a datablob is the file's name and pubkey is the pubkey of the sender
  • these two details can be used to download the corresponding file
./komodo-cli -ac_name=DORN DEX_subscribe "<file name>" 0 0 <sender pubkey>
  • In the above command, replace the text <file name> with the name of the file (tagB from the previous DEX_list response) and the text <sender pubkey> with the sender's pubkey (pubkey from the previous DEX_list response)
  • The file will be downloaded to the directory where the komodod binary used to launch the Smart Chain is present