Skip to content

Commit

Permalink
Network Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
vijayee committed Jun 13, 2018
1 parent 2a44400 commit 47ecf09
Show file tree
Hide file tree
Showing 10 changed files with 316 additions and 18 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@
/.nano-cache
/node1
/node2
/~
/~
js-offs-linux-x64/
js-offs-win32-x64/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "js-offs",
"version": "0.0.1",
"description": "",
"description": "Owner Free File System",
"main": "src/index.js",
"appname": "offs",
"scripts": {
Expand Down
119 changes: 114 additions & 5 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const extend = require('util')._extend
const fs = require('fs')
const path = require('path')
const kb = 1000
const mb = 1000000
const gb = 1000000000
Expand All @@ -24,8 +26,7 @@ let defaults = {
bucketSize: 4,
httpPort: 23402,
startPort: 8200,
numPortTries: 2,// how long to wait on a rpc response
packetSize: 512, // message size in bytes
numPortTries: 2,
nodeCount: 10, // how many nodes to find in or query in total
concurrency: 3, // how many nodes to query simultaneously
kbucketSize: 20, // size of each k bucket
Expand Down Expand Up @@ -67,11 +68,60 @@ let _maxFillRate = new WeakMap()
let _redundancy = new WeakMap()
let _batchConcurrency = new WeakMap()
let _bootstrap = new WeakMap()
let _path = new WeakMap()
class Config {
constructor () {
this.loadDefaults()
}

save (pth) {
if (!pth) {
pth = _path.get(this)
}
_path.set(this, pth)
fs.writeFile(path.join(pth, 'config'), JSON.stringify(this.toJSON()), (err) => {
if (err) {
console.error(err)
//TODO Dunno what to do with this error
}
})
}
load (pth) {
try {
let config = JSON.parse(fs.readFileSync(path.join(pth, 'config')))
_path.set(this, pth)
_blockPath.set(this, config.blockPath)
_miniPath.set(this, config.miniPath)
_nanoPath.set(this, config.nanoPath)
_blockCacheSize.set(this, config.blockCacheSize)
_miniBlockCacheSize.set(this, config.miniBlockCacheSize)
_nanoBlockCacheSize.set(this, config.nanoBlockCacheSize)
_nano.set(this, config.nano)
_block.set(this, config.block)
_mini.set(this, config.mini)
_tupleSize.set(this, config.tupleSize)
_blockSize.set(this, config.blockSize)
_miniBlockSize.set(this, config.miniBlockSize)
_nanoBlockSize.set(this, config.nanoBlockSize)
_descriptorPad.set(this, config.descriptorPad)
_scale.set(this, config.scale)
_filterSize.set(this, config.filterSize)
_fingerprintSize.set(this, config.fingerprintSize)
_hitBoxSize.set(this, config.hitBoxSize)
_bucketSize.set(this, config.bucketSize)
_httpPort.set(this, config.httpPort)
_startPort.set(this, config.startPort)
_numPortTries.set(this, config.numPortTries)
_nodeCount.set(this, config.nodeCount)
_concurrency.set(this, config.concurrency)
_kbucketSize.set(this, config.kbucketSize)
_storeCount.set(this, config.storeCount)
_maxFillRate.set(this, config.maxFillRate)
_redundancy.set(this, config.redundancy)
_batchConcurrency.set(this, config.batchConcurrency)
_bootstrap.set(this, config.bootstrap.slice(0))
} catch (ex) {
return ex
}
}
loadDefaults () {
_blockPath.set(this, defaults.blockPath)
_miniPath.set(this, defaults.miniPath)
Expand All @@ -95,7 +145,7 @@ class Config {
_httpPort.set(this, defaults.httpPort)
_startPort.set(this, defaults.startPort)
_numPortTries.set(this, defaults.numPortTries)
_nodeCount.set(this, defaults.packetSize)
_nodeCount.set(this, defaults.nodeCount)
_concurrency.set(this, defaults.concurrency)
_kbucketSize.set(this, defaults.kbucketSize)
_storeCount.set(this, defaults.storeCount)
Expand Down Expand Up @@ -197,14 +247,38 @@ class Config {
return _httpPort.get(this)
}

set httpPort (value) {
if (!Number.isInteger(value)){
throw new TypeError("Invalid HTTP Port")
}
_startPort.set(this, value)
this.save()
}

get startPort () {
return _startPort.get(this)
}

set startPort (value) {
if (!Number.isInteger(value)){
throw new TypeError("Invalid Port Number")
}
_startPort.set(this, value)
this.save()
}

get numPortTries () {
return _numPortTries.get(this)
}

set numPortTries (value) {
if (!Number.isInteger(value)){
throw new TypeError("Invalid Number of Port Tries")
}
_startPort.set(this, value)
this.save()
}

get nodeCount () {
return _nodeCount.get(this)
}
Expand Down Expand Up @@ -247,6 +321,41 @@ class Config {
throw new TypeError("Invalid Boostsrap Peer Array")
}
_bootstrap.set(this, value)
this.save()
}
toJSON () {
return {
blockPath: this.blockPath,
miniPath: this.miniPath,
nanoPath: this.nanoPath,
blockCacheSize: this.blockCacheSize,
miniBlockCacheSize: this.miniBlockCacheSize,
nanoBlockCacheSize: this.nanoBlockCacheSize,
nano: this.nano,
block: this.block,
mini: this.mini,
tupleSize: this.tupleSize,
blockSize: this.blockSize,
miniBlockSize: this.miniBlockSize,
nanoBlockSize: this.nanoBlockSize,
descriptorPad: this.descriptorPad,
scale: this.scale,
filterSize: this.filterSize,
fingerprintSize: this.fingerprintSize,
hitBoxSize: this.hitBoxSize,
bucketSize: this.bucketSize,
httpPort: this.httpPort,
startPort: this.startPort,
numPortTries: this.numPortTries,
nodeCount: this.nodeCount,
concurrency: this.concurrency,
kbucketSize: this.kbucketSize,
storeCount: this.storeCount,
maxFillRate: this.maxFillRate,
redundancy: this.redundancy,
batchConcurrency: this.batchConcurrency,
bootstrap: this.bootstrap
}
}
}
module.exports = new Config()
9 changes: 7 additions & 2 deletions src/electron/views/configuration/configuration.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
Bootstrap
</router-link>
</li>
<li>
<router-link to="/network" :class="$router.currentRoute.path.startsWith('/network') ? 'active' : ''" >
Network
</router-link>
</li>
</ul>
</nav>
<router-view/>
Expand Down Expand Up @@ -41,8 +46,8 @@ ul.navigation li {
padding:0 5px 0 5px;
height: 100%;
}
ul.navigation li:hover {
background: #56574f;
ul.navigation li:hover a {
border-bottom: solid 2px #fc9e56;
}
ul.navigation li a {
display: block;
Expand Down
84 changes: 80 additions & 4 deletions src/electron/views/configuration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11146,7 +11146,7 @@ if (module.hot) {(function () { var hotAPI = require("vue-hot-reload-api")
}
})()}
},{"babel-runtime/core-js/number/is-integer":1,"vue":23,"vue-hot-reload-api":21}],26:[function(require,module,exports){
var __vueify_style_dispose__ = require("vueify/lib/insert-css").insert(".notifbar {\n display: grid;\n height: 15px;\n padding: 5px;\n justify-items: right;\n align-items: right;\n }\n .navbar {\n position: relative;\n display: grid;\n border-top: 2px solid #ebe3de;\n height: 40px;\n justify-items: center;\n align-items: center;\n }\nul.navigation {\n height: 100%;\n list-style-type: none;\n margin: 0;\n padding: 0;\n position: relative;\n}\nul.navigation li {\n display: inline-block;\n margin: 0 5px 0 5px;\n padding:0 5px 0 5px;\n height: 100%;\n}\nul.navigation li:hover {\n background: #56574f;\n}\nul.navigation li a {\n display: block;\n padding-top: 7px;\n height: 34px;\n}\nul.navigation li a:hover {\n //border-bottom: 2px solid #ebe3de\n}\nul.navigation li a.active {\n border-bottom: solid 2px #00d1b2;\n}")
var __vueify_style_dispose__ = require("vueify/lib/insert-css").insert(".notifbar {\n display: grid;\n height: 15px;\n padding: 5px;\n justify-items: right;\n align-items: right;\n }\n .navbar {\n position: relative;\n display: grid;\n border-top: 2px solid #ebe3de;\n height: 40px;\n justify-items: center;\n align-items: center;\n }\nul.navigation {\n height: 100%;\n list-style-type: none;\n margin: 0;\n padding: 0;\n position: relative;\n}\nul.navigation li {\n display: inline-block;\n margin: 0 5px 0 5px;\n padding:0 5px 0 5px;\n height: 100%;\n}\nul.navigation li:hover a {\n border-bottom: solid 2px #fc9e56;\n}\nul.navigation li a {\n display: block;\n padding-top: 7px;\n height: 34px;\n}\nul.navigation li a:hover {\n //border-bottom: 2px solid #ebe3de\n}\nul.navigation li a.active {\n border-bottom: solid 2px #00d1b2;\n}")
;(function(){
"use strict";

Expand All @@ -11158,7 +11158,7 @@ exports.default = {};
if (module.exports.__esModule) module.exports = module.exports.default
var __vue__options__ = (typeof module.exports === "function"? module.exports.options: module.exports)
if (__vue__options__.functional) {console.error("[vueify] functional components are not supported and should be defined in plain js files using render functions.")}
__vue__options__.render = function render () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[_c('nav',{staticClass:"navbar"},[_c('ul',{staticClass:"navigation"},[_c('li',[_c('router-link',{class:_vm.$router.currentRoute.path.startsWith('/bootstrap') ? 'active' : '',attrs:{"to":"/bootstrap"}},[_vm._v("\n Bootstrap\n ")])],1)])]),_vm._v(" "),_c('router-view')],1)}
__vue__options__.render = function render () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[_c('nav',{staticClass:"navbar"},[_c('ul',{staticClass:"navigation"},[_c('li',[_c('router-link',{class:_vm.$router.currentRoute.path.startsWith('/bootstrap') ? 'active' : '',attrs:{"to":"/bootstrap"}},[_vm._v("\n Bootstrap\n ")])],1),_vm._v(" "),_c('li',[_c('router-link',{class:_vm.$router.currentRoute.path.startsWith('/network') ? 'active' : '',attrs:{"to":"/network"}},[_vm._v("\n Network\n ")])],1)])]),_vm._v(" "),_c('router-view')],1)}
__vue__options__.staticRenderFns = []
if (module.hot) {(function () { var hotAPI = require("vue-hot-reload-api")
hotAPI.install(require("vue"), true)
Expand All @@ -11185,9 +11185,80 @@ new Vue({
return createElement(App)
}
})
},{"./configuration.vue":26,"./router":28,"vue":23,"vue-router":22}],28:[function(require,module,exports){
},{"./configuration.vue":26,"./router":29,"vue":23,"vue-router":22}],28:[function(require,module,exports){
;(function(){
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {
mounted: function mounted() {
var _this = this;

this.configurator = new Configurator(ipcRenderer, function (err) {
_this.error = err;
});
this.configurator.get('startPort').then(function (port) {
_this.startPort = port;
});
this.configurator.get('numPortTries').then(function (retry) {
_this.portRetries = retry;
});
this.configurator.get('httpPort').then(function (port) {
_this.httpPort = port;
});
},
data: function data() {
return {
startPort: 0,
httpPort: 0,
numPortTries: 0,
error: null,
configurator: null,
success: null
};
},

methods: {
save: async function save() {
this.success = null;
var ok = await this.configurator.set('startPort', this.startPort);
if (!ok) {
return;
}
ok = await this.configurator.set('numPortTries', this.httpPort);
if (!ok) {
return;
}
ok = await this.configurator.set('httpPort', this.numPortTries);
if (!ok) {
return;
}
this.success = 'Saved';
}
}
};
})()
if (module.exports.__esModule) module.exports = module.exports.default
var __vue__options__ = (typeof module.exports === "function"? module.exports.options: module.exports)
if (__vue__options__.functional) {console.error("[vueify] functional components are not supported and should be defined in plain js files using render functions.")}
__vue__options__.render = function render () {var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;return _c('div',[_c('div',{staticClass:"columns"},[_c('div',{staticClass:"column"}),_vm._v(" "),_c('div',{staticClass:"column"},[_c('form',{on:{"submit":function($event){$event.preventDefault();_vm.save($event)}}},[_c('div',{staticClass:"field"},[_c('label',{staticClass:"label"},[_vm._v("Node Port")]),_vm._v(" "),_c('div',{staticClass:"control has-icons-left has-icons-right"},[_c('input',{directives:[{name:"model",rawName:"v-model",value:(_vm.startPort),expression:"startPort"}],staticClass:"input is-success",attrs:{"type":"text","name":"startPort"},domProps:{"value":(_vm.startPort)},on:{"input":function($event){if($event.target.composing){ return; }_vm.startPort=$event.target.value}}}),_vm._v(" "),_c('span',{staticClass:"icon is-small is-left"},[_vm._v("\n #\n ")])])]),_vm._v(" "),_c('div',{staticClass:"field"},[_c('label',{staticClass:"label"},[_vm._v("Port Retries")]),_vm._v(" "),_c('div',{staticClass:"control has-icons-left has-icons-right"},[_c('input',{directives:[{name:"model",rawName:"v-model",value:(_vm.numPortTries),expression:"numPortTries"}],staticClass:"input is-success",attrs:{"type":"text","name":"numPortTries"},domProps:{"value":(_vm.numPortTries)},on:{"input":function($event){if($event.target.composing){ return; }_vm.numPortTries=$event.target.value}}}),_vm._v(" "),_c('span',{staticClass:"icon is-small is-left"},[_vm._v("\n #\n ")])])]),_vm._v(" "),_c('div',{staticClass:"field"},[_c('label',{staticClass:"label"},[_vm._v("HTTP Port")]),_vm._v(" "),_c('div',{staticClass:"control has-icons-left has-icons-right"},[_c('input',{directives:[{name:"model",rawName:"v-model",value:(_vm.httpPort),expression:"httpPort"}],staticClass:"input is-success",attrs:{"type":"text","name":"httpPort"},domProps:{"value":(_vm.httpPort)},on:{"input":function($event){if($event.target.composing){ return; }_vm.httpPort=$event.target.value}}}),_vm._v(" "),_c('span',{staticClass:"icon is-small is-left"},[_vm._v("\n #\n ")])])]),_vm._v(" "),_c('div',{staticClass:"control"},[(_vm.success)?_c('span',{staticClass:"message is-sucess"},[_vm._v(_vm._s(_vm.success))]):_vm._e(),_vm._v(" "),(_vm.error)?_c('span',{staticClass:"message is-danger"},[_vm._v(_vm._s(_vm.error))]):_vm._e(),_vm._v(" "),_c('input',{staticClass:"button is-primary",staticStyle:{"float":"right"},attrs:{"type":"submit","value":"Save"}})])])]),_vm._v(" "),_c('div',{staticClass:"column"})])])}
__vue__options__.staticRenderFns = []
if (module.hot) {(function () { var hotAPI = require("vue-hot-reload-api")
hotAPI.install(require("vue"), true)
if (!hotAPI.compatible) return
module.hot.accept()
if (!module.hot.data) {
hotAPI.createRecord("data-v-23566114", __vue__options__)
} else {
hotAPI.reload("data-v-23566114", __vue__options__)
}
})()}
},{"vue":23,"vue-hot-reload-api":21}],29:[function(require,module,exports){
var VueRouter = require('vue-router')
var Bootstrap = require('./bootstrap.vue')
var Network = require('./network.vue')
module.exports = new VueRouter({
routes: [
{
Expand All @@ -11199,7 +11270,12 @@ module.exports = new VueRouter({
path: '/bootstrap',
name: 'Boostrap',
component: Bootstrap
},
{
path: '/network',
name: 'Network',
component: Network
}
]
})
},{"./bootstrap.vue":25,"vue-router":22}]},{},[27]);
},{"./bootstrap.vue":25,"./network.vue":28,"vue-router":22}]},{},[27]);
Loading

0 comments on commit 47ecf09

Please sign in to comment.