This is example of API for target developers who can integrate velas distributed resources with their apps.
Last active
March 19, 2020 15:13
-
-
Save askucher/1255aede5b26d418ada5a08cbd021110 to your computer and use it in GitHub Desktop.
VELAS SPHERE ANN
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//2 | |
import VelasSchere from 'velas-sphere'; | |
import distributedFunction from './distributedFunction.js'; | |
const options = { | |
timeout: 100000, //= > this timer is connected to deposited balance of the user into velas-sphere. | |
limitWrite: "2mb", | |
params: {}, //=> distributedFunction.js obtains it as input params | |
type: 'javascript', | |
pool: 0, | |
places: 0 | |
} | |
const distributedTask = VelasSchere.CPUTask(distributedFunction, options); | |
const privateKey = "..."; | |
const signedTask = VelasSchere.sign(distributedTask, privateKey); | |
const taskHash = await VelasSchere.publish(signedTask); | |
const results = await VelasSchere.getResultLength(taskHash); | |
if (result.err === "task not found") return console.log(err); | |
console.log(results.length); | |
const result = await VelasSchere.getResult(taskHash, 0); | |
if (result.err === "task not found") return console.log(err); | |
if (result.err === "error during execution") return console.log(VelasSchere.decrypt(result.body, privateKey)); | |
//all information should be encrypted with public key. Only requester can descript and check the result | |
//here is example how to encrypt and decrypt the message https://ethereum.stackexchange.com/questions/3092/how-to-encrypt-a-message-with-the-public-key-of-an-ethereum-address | |
console.log(VelasSchere.decrypt(result.body, privateKey)); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//1 | |
//VELAS SPHERE API | |
import VelasSchere from 'velas-sphere'; | |
import readFileSync from 'fs' | |
const options = { | |
timeout: 100000, //= > this timer is connected to deposited balance of the user into velas-sphere. | |
params: {}, //=> distributedFunction obtains it as input params | |
type: 'python' //=> need to discuss how to implement horovod https://github.com/horovod/horovod/blob/master/examples/tensorflow2_mnist.py | |
} | |
const distributedFunction = fs.readFileSync('./train.py'); //=> not sure | |
const distributedTask = VelasSchere.GPUTask(distributedFunction, options); | |
const privateKey = "..."; | |
const signedTask = VelasSchere.sign(distributedTask, privateKey); | |
const taskHash = await VelasSchere.publish(signedTask); | |
const results = await VelasSchere.getResultLength(taskHash); | |
if (result.err === "task not found") return console.log(err); | |
console.log(results.length); | |
const result = await VelasSchere.getResult(taskHash, 0); | |
if (result.err === "task not found") return console.log(err); | |
if (result.err === "error during execution") | |
return console.log(VelasSchere.decrypt(result.body, privateKey)); | |
encryptedData = VelasSchere.encrypt(result.body, privateKey) | |
//storage opeation examples | |
result = await VelasSchere.putDB(privateKey, "key", result.body); //=> the data will be encrypted by privateKey | |
if (result.err) return console.log(result.err); | |
result = await VelasSchere.getDB(privateKey, "key"); //=> the data will be decrypted by privateKey | |
if (result.err) return console.log(result.err); | |
console.log(result.body); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//3 | |
//This function is encrypted by node public key, node decrypts it execute and then encrypt with requester public key | |
//also here we can use self encrypted (obfuscation) technique like https://www.npmjs.com/package/javascrypt to hide the logic from the remote computers | |
export default ({ claster, db, gpu, params }, cb)=> { | |
//db - get, put methods - local key value db | |
//claster - emit, on - broadcast and listen info between workers | |
const result = await db.get("get key by value"); | |
if (result.err) return cb(result.err); | |
const result = await db.put("put some value", "some data"); //=> could be a buffer | |
if (result.err) return cb(result.err); | |
const result = await db.get("train.py"); | |
const someGPUTask = result.body | |
gpu.execute(someGPUTask, { type: 'python' }, cb); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment