Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
removing variable shadowing
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilfred Tannr Allard committed Mar 29, 2018
1 parent b236d26 commit 9de3760
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion batnode.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class BatNode {

this.kadenceNode.iterativeFindValue(shardId, (err, value, responder) => {
let kadNodeTarget = value.value;
this.kadenceNode.getOtherBatNodeContact(kadNodeTarget, (err, batNode) => {
this.kadenceNode.getOtherBatNodeContact(kadNodeTarget, (error, batNode) => {
this.auditShardData(batNode, shards, shaIdx, shardDupIdx, shardAuditData)
})
})
Expand Down
10 changes: 5 additions & 5 deletions seednode/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ publicIp.v4().then(ip => {
console.log("received data: ", receivedData)

if (receivedData.messageType === "RETRIEVE_FILE") {
batNode.readFile(`./hosted/${receivedData.fileName}`, (error, data) => {
batNode.readFile(`./hosted/${receivedData.fileName}`, (err, data) => {
serverConnection.write(data)
})
} else if (receivedData.messageType === "STORE_FILE"){
let fileName = receivedData.fileName
batNode.kadenceNode.iterativeStore(fileName, [batNode.kadenceNode.identity.toString(), batNode.kadenceNode.contact], (err, stored) => {
console.log('nodes who stored this value: ', stored)
let fileContent = new Buffer(receivedData.fileContent)
batNode.writeFile(`./hosted/${fileName}`, fileContent, (err) => {
if (err) {
throw err;
batNode.writeFile(`./hosted/${fileName}`, fileContent, (writeErr) => {
if (writeErr) {
throw writeErr;
}
serverConnection.write(JSON.stringify({messageType: "SUCCESS"}))
})
})
} else if (receivedData.messageType === "AUDIT_FILE") {
fs.readFile(`./hosted/${receivedData.fileName}`, (error, data) => {
fs.readFile(`./hosted/${receivedData.fileName}`, (err, data) => {
const shardSha1 = fileUtils.sha1HashData(data);
serverConnection.write(shardSha1);
});
Expand Down
12 changes: 6 additions & 6 deletions start.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const fs = require('fs');
const fileUtils = require('./utils/file').fileSystem;

publicIp.v4().then(ip => {
kademliaNode = new kad.KademliaNode({
const kademliaNode = new kad.KademliaNode({
transport: new kad.HTTPTransport(),
storage: levelup(encoding(leveldown('./dbbb'))),
contact: {hostname: ip, port: kadNodePort}
Expand All @@ -34,23 +34,23 @@ publicIp.v4().then(ip => {
console.log("received data: ", receivedData)

if (receivedData.messageType === "RETRIEVE_FILE") {
batNode.readFile(`./hosted/${receivedData.fileName}`, (error, data) => {
batNode.readFile(`./hosted/${receivedData.fileName}`, (err, data) => {
serverConnection.write(data)
})
} else if (receivedData.messageType === "STORE_FILE"){
let fileName = receivedData.fileName
batNode.kadenceNode.iterativeStore(fileName, [batNode.kadenceNode.identity.toString(), batNode.kadenceNode.contact], (err, stored) => {
console.log('nodes who stored this value: ', stored)
let fileContent = new Buffer(receivedData.fileContent)
batNode.writeFile(`./hosted/${fileName}`, fileContent, (err) => {
if (err) {
throw err;
batNode.writeFile(`./hosted/${fileName}`, fileContent, (writeErr) => {
if (writeErr) {
throw writeErr;
}
serverConnection.write(JSON.stringify({messageType: "SUCCESS"}))
})
})
} else if (receivedData.messageType === "AUDIT_FILE") {
fs.readFile(`./hosted/${receivedData.fileName}`, (error, data) => {
fs.readFile(`./hosted/${receivedData.fileName}`, (err, data) => {
const shardSha1 = fileUtils.sha1HashData(data);
serverConnection.write(shardSha1);
});
Expand Down
8 changes: 4 additions & 4 deletions utils/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ exports.fileSystem = (function(){

const fileData = fileSystem.createReadStream(filepath)
const zip = zlib.createGzip()
const encrypt = crypto.createCipher(algorithm, privateKey)
const encryptStream = crypto.createCipher(algorithm, privateKey)
const encryptedFileStore = fileSystem.createWriteStream(tmpPath)

// read the file, zip it, encrypt it, and write it
fileData.pipe(zip).pipe(encrypt).pipe(encryptedFileStore).on('close', () => {
fileData.pipe(zip).pipe(encryptStream).pipe(encryptedFileStore).on('close', () => {
if(callback) {
callback(tmpPath)
}
Expand All @@ -47,11 +47,11 @@ exports.fileSystem = (function(){
const privateKey = dotenv.config().parsed.PRIVATE_KEY;

const encryptedFileData = fileSystem.createReadStream(filepath)
const decrypt = crypto.createDecipher(algorithm, privateKey)
const decryptStream = crypto.createDecipher(algorithm, privateKey)
const unzip = zlib.createGunzip()
const writeStream = fileSystem.createWriteStream(tempPath)
//
encryptedFileData.pipe(decrypt).pipe(unzip).pipe(writeStream)
encryptedFileData.pipe(decryptStream).pipe(unzip).pipe(writeStream)
}
const sha1Hash = (file) => {
const fileData = fileSystem.readFileSync(file)
Expand Down

0 comments on commit 9de3760

Please sign in to comment.