libpkg

1.0.8 • Public • Published


Library

Library is a set of tools that enables super fast streaming by combining torrenting protocols with WebRTC

How it works

Library speeds up the downloading process by taking the load one server would normally have, dividing it into 256 packets that are competitively bid on by individuals that will earn based upon how much they contribute to the total file. The process is first started with the requester minting a contract and sending it to a trusted node (dwey). Once the trusted node receives the contract, it publishes it to all the miners that are connected to its WebSocket channel. Then if the miner decides to accept the contract it checks if it has the requested file, collects the requester's webRTC connection information, and forwards its connection information to the requester through the trusted node. When the webRTC connection is finally made the peer sends the packet number it is currently on and the process continues from there where each miner connects and gets sent a packet. After they send the packet the requester sends them the next packet number until they receive all 256 packets it needs. Now that the requester has all the packets it sends on the last request that contains all the payment information. If the receiver fails to send this data it will be charged a fine of 10x the original payment amount to ensure there is no incentive to not pay the miners.

Install

Install

curl -sL https://raw.githubusercontent.com/llib-sh/library/master/install.sh | sh

If you already have NodeJS installed:

npm install libpkg -g

Library.js

<script src="https://unpkg.com/libpkg/dist/library.min.js"></script>

Usage

Library.js

Library.js is the client side framework of the network.

GET file

POST file

Api

lib = new Library(userId, offer, token)

Create a client connection to the network

userId: Id that the trusted node assigns to your account

offer: Offer to reward the nodes that server the file

token: Secret token you share with the trusted node

lib.get(fileName)

Retrive file from network and handle data

fileName: SHA256 hash of file (returned by "lib.post")

returns:

[Promise] Responce Object: Output is calculated as below

// file = "7dsa968d6a7s86d7ysa7d9..." (file data returned by nodes)

// Convert "file" to base64

return new Promise(async function(resolve, reject) {
  let b64 = btoa(file);
  // Attempt to find file format if possible
  let mime = detectMimeType(base64);
  // fetch base64 URL of the file data and return the promise
  resolve(fetch(`data:${mime};base64,${base64}`).catch(reject))
})
Responce Object Methods

res.text(): returns a promise the resolves with a plain text responce

res.json(): returns a promise the resolves with a parsed JSON responce

res.blob(): returns a promise the resolves with a blob of the provided data

res.arrayBuffer(): returns a promise the resolves with a ArrayBuffer of the provided data

res.clone(): returns a promise the resolves with a clone of the provided data

lib.post(fileData)

Publish file to the network

fileData: Any string that contains data you want to store on the network

NOTE: fileData must be a String, any other type will be rejected

returns:

[Promise] fileName : A SHA256 hash of the file, used as the fileId to retrive the file

Librarian

Librarian is the CLI node, below describes the usage of it.

Usage
librarian --f <files> -t <token> -a <user> -o <offer>
Display settings

-q, --quiet: [Boolean] Quiet mode

-f, --files: [String] Route to store hosted files

-t, --token: [String] Your unique token given at sign up

-u, --user: [String] Your user id given at sign up

-o, --offer: [Boolean] Your minimum accepted offer in cents USD

-l, --log: [Boolean] Optional, Enable logging

-q, --quiet: [Boolean] Optional, Quiet mode

-h, --host: [String] Optional, URL of your preferred trusted node. Defaults to "http://llib.sh/dwey"

Default layout

Readme

Keywords

none

Package Sidebar

Install

npm i libpkg

Weekly Downloads

0

Version

1.0.8

License

MIT

Unpacked Size

1.84 MB

Total Files

44

Last publish

Collaborators

  • m-a-s-o-n