From: joelbandi Date: Tue, 26 Jul 2016 12:56:21 +0000 (-0700) Subject: Added Js code (40%) X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iotcloud.git;a=commitdiff_plain;h=19547c373c92a2221d680840999e88d0884549b4 Added Js code (40%) --- diff --git a/.gitignore b/.gitignore index 68a8b77..b28f4ad 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,8 @@ build/ compiled/ *.o *~ +/src/js/iotjs/node_modules/ +node_modules/ +dist/ +bower_components +test/bower_components diff --git a/src/java/iotcloud/Slot.java b/src/java/iotcloud/Slot.java index 4db9133..ed577a6 100644 --- a/src/java/iotcloud/Slot.java +++ b/src/java/iotcloud/Slot.java @@ -19,7 +19,7 @@ class Slot implements Liveness { static final int HMAC_SIZE=32; /** Sequence number of the slot. */ - private long seqnum; + private long seqnum;// /** HMAC of previous slot. */ private byte[] prevhmac; /** HMAC of this slot. */ diff --git a/src/js/iotjs/.babelrc b/src/js/iotjs/.babelrc new file mode 100644 index 0000000..9d8d516 --- /dev/null +++ b/src/js/iotjs/.babelrc @@ -0,0 +1 @@ +{ "presets": ["es2015"] } diff --git a/src/js/iotjs/.bowerrc b/src/js/iotjs/.bowerrc new file mode 100644 index 0000000..baa91a3 --- /dev/null +++ b/src/js/iotjs/.bowerrc @@ -0,0 +1,3 @@ +{ + "directory": "bower_components" +} \ No newline at end of file diff --git a/src/js/iotjs/.editorconfig b/src/js/iotjs/.editorconfig new file mode 100644 index 0000000..e717f5e --- /dev/null +++ b/src/js/iotjs/.editorconfig @@ -0,0 +1,13 @@ +# http://editorconfig.org +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true + +[*.md] +trim_trailing_whitespace = false diff --git a/src/js/iotjs/.jshintrc b/src/js/iotjs/.jshintrc new file mode 100644 index 0000000..0959e67 --- /dev/null +++ b/src/js/iotjs/.jshintrc @@ -0,0 +1,20 @@ +{ + "node": true, + "esnext": true, + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "immed": true, + "indent": 2, + "latedef": true, + "newcap": true, + "noarg": true, + "quotmark": "single", + "regexp": true, + "undef": true, + "unused": true, + "trailing": true, + "smarttabs": true, + "white": true +} diff --git a/src/js/iotjs/README.md b/src/js/iotjs/README.md new file mode 100644 index 0000000..2e6e0a1 --- /dev/null +++ b/src/js/iotjs/README.md @@ -0,0 +1,21 @@ +iotjs +================================================== + +What does your library do? + +Getting Started +-------------------------------------- + +- Install dependencies: `npm install` +- Run `bower install` to install frontend dependencies +- Run `gulp` to build your library + +Usage +-------------------------------------- + +How can I use it? + +Future Development +-------------------------------------- + +What would you like to do but don't have the time for? diff --git a/src/js/iotjs/bower.json b/src/js/iotjs/bower.json new file mode 100644 index 0000000..cb33217 --- /dev/null +++ b/src/js/iotjs/bower.json @@ -0,0 +1,6 @@ +{ + "name": "iotjs", + "version": "0.0.0", + "dependencies": {} +} + diff --git a/src/js/iotjs/examples/index.html b/src/js/iotjs/examples/index.html new file mode 100644 index 0000000..8613e8e --- /dev/null +++ b/src/js/iotjs/examples/index.html @@ -0,0 +1,11 @@ + + + + + iotjs Example + + + + + + \ No newline at end of file diff --git a/src/js/iotjs/gulpfile.js b/src/js/iotjs/gulpfile.js new file mode 100644 index 0000000..ed79d92 --- /dev/null +++ b/src/js/iotjs/gulpfile.js @@ -0,0 +1,49 @@ +var gulp = require('gulp'); +var gulpif = require('gulp-if'); +var clean = require('gulp-clean'); +var order = require('gulp-order'); +var rename = require('gulp-rename'); +var concat = require('gulp-concat'); +var jshint = require('gulp-jshint'); +var uglify = require('gulp-uglify'); +var stylish = require('jshint-stylish'); +var livereload = require('gulp-livereload'); +var sourcemaps = require('gulp-sourcemaps'); +var flags = require('minimist')(process.argv.slice(2)); + +// Gulp command line arguments +var production = flags.production || false; +var debug = flags.debug || !production; +var watch = flags.watch; + +gulp.task('build', ['clean'], function() { + // Single entry point to browserify + gulp.src(['src/*.js', 'vendor/*.js']) + .pipe(order([ // The order of concatenation + 'src/main.js' + ], {base: '.'})) + .pipe(gulpif(debug, sourcemaps.init())) + .pipe(gulpif(production, uglify())) + .pipe(concat('iotjs.js')) + .pipe(gulpif(debug, sourcemaps.write())) + .pipe(gulp.dest('./build/')) + .pipe(gulpif(watch, livereload())); +}); + +gulp.task('lint', function() { + return gulp.src('src/*.js') + .pipe(jshint()) + .pipe(jshint.reporter(stylish)) +}); + +gulp.task('clean', function() { + return gulp.src(['./build'], {read: false}) + .pipe(clean({force: true})); +}); + +gulp.task('watch', function() { + livereload.listen(); + gulp.watch('src/*', ['lint', 'build']); +}); + +gulp.task('default', ['clean', 'lint', 'build']); diff --git a/src/js/iotjs/orig/entry.js b/src/js/iotjs/orig/entry.js new file mode 100644 index 0000000..8ad481a --- /dev/null +++ b/src/js/iotjs/orig/entry.js @@ -0,0 +1,54 @@ +class Entry{ + constructor(slot) { + if (slot && slot instanceof Slot) { + + this.TypeKeyValue = 1; + this.TypeLastmessage = 2; + this.TypeRejectedMessage = 3; + this.TypeTableStatus = 4; + this.liveStatus = true; + this.parentslot = slot; + + } + } + static decode(slot, bytebuffer) { + if (slot instanceof Slot && bytebuffer instanceof ByteBuffer) { + var type = bytebuffer.readByte(); + switch (type) { + case this.TypeKeyValue: + return KeyValue.decode(slot, bytebuffer); + case this.TypeLastmessage: + return LastMessage.decode(slot, bytebuffer); + case this.TypeRejectedMessage: + return RejectedMessage.decode(slot, bytebuffer); + case this.TypeTableStatus: + return TableStatus.decode(slot, bytebuffer); + default: + throw new Error("Unrecognized Entry Type: " + type); + } + } + } + isLive(){ + return this.liveStatus; + } + setDead() { + this.liveStatus = false; + parentslot.decrementLiveCount(); + } + + //must be overriden. + encode(bytebuffer){ + + } + getSize(){ + + } + getType(){ + + } + getCopy(slot){ + if(slot && slot instanceof Slot){ + + } + } +} \ No newline at end of file diff --git a/src/js/iotjs/orig/slot.js b/src/js/iotjs/orig/slot.js new file mode 100644 index 0000000..72352d9 --- /dev/null +++ b/src/js/iotjs/orig/slot.js @@ -0,0 +1,10 @@ +class Slot{ + constructor(seqnum,machineid,prevhmac,hmac){ + this.SLOT_SIZE=2048; + this.RESERVED_SPACE=64; + this.HMAC_SIZE=32; + (typeof seqnum === "number")? this.seqnum = seqnum : throw new Error("seqnum should be a number"); + (typeof machineid === "number")? this.machineid = seqnum : throw new Error("seqnum should be a number"); + + } +} \ No newline at end of file diff --git a/src/js/iotjs/package.json b/src/js/iotjs/package.json new file mode 100644 index 0000000..2b12bbe --- /dev/null +++ b/src/js/iotjs/package.json @@ -0,0 +1,32 @@ +{ + "name": "iotjs", + "version": "0.0.0", + "scripts": { + "test": "gulp && node ./test/test.js" + }, + "dependencies": { + "bytebuffer": "^5.0.1", + "crypto-js": "^3.1.6", + "gulp": "3.8.11", + "gulp-clean": "0.3.1", + "gulp-concat": "2.5.2", + "gulp-if": "1.2.5", + "gulp-jshint": "1.9.4", + "gulp-livereload": "3.8.0", + "gulp-load-plugins": "0.8.1", + "gulp-order": "1.1.1", + "gulp-rename": "1.2.0", + "gulp-sourcemaps": "1.5.1", + "gulp-uglify": "1.1.0", + "jshint-stylish": "1.0.1", + "minimist": "1.1.1", + "object-hash": "^1.1.3", + "request": "^2.74.0", + "underscore": "^1.8.3" + }, + "devDependencies": { + "babel-cli": "^6.11.4", + "babel-preset-es2015": "^6.9.0", + "browserify": "^13.1.0" + } +} diff --git a/src/js/iotjs/src/entry.js b/src/js/iotjs/src/entry.js new file mode 100644 index 0000000..e4a47a3 --- /dev/null +++ b/src/js/iotjs/src/entry.js @@ -0,0 +1,72 @@ +"use strict"; + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Entry = function () { + function Entry(slot) { + _classCallCheck(this, Entry); + + if (slot && slot instanceof Slot) { + + this.TypeKeyValue = 1; + this.TypeLastmessage = 2; + this.TypeRejectedMessage = 3; + this.TypeTableStatus = 4; + this.liveStatus = true; + this.parentslot = slot; + } + } + + _createClass(Entry, [{ + key: "isLive", + value: function isLive() { + return this.liveStatus; + } + }, { + key: "setDead", + value: function setDead() { + this.liveStatus = false; + parentslot.decrementLiveCount(); + } + + //must be overriden. + + }, { + key: "encode", + value: function encode(bytebuffer) {} + }, { + key: "getSize", + value: function getSize() {} + }, { + key: "getType", + value: function getType() {} + }, { + key: "getCopy", + value: function getCopy(slot) { + if (slot && slot instanceof Slot) {} + } + }], [{ + key: "decode", + value: function decode(slot, bytebuffer) { + if (slot instanceof Slot && bytebuffer instanceof ByteBuffer) { + var type = bytebuffer.readByte(); + switch (type) { + case this.TypeKeyValue: + return KeyValue.decode(slot, bytebuffer); + case this.TypeLastmessage: + return LastMessage.decode(slot, bytebuffer); + case this.TypeRejectedMessage: + return RejectedMessage.decode(slot, bytebuffer); + case this.TypeTableStatus: + return TableStatus.decode(slot, bytebuffer); + default: + throw new Error("Unrecognized Entry Type: " + type); + } + } + } + }]); + + return Entry; +}(); \ No newline at end of file diff --git a/src/js/iotjs/src/iotstring.js b/src/js/iotjs/src/iotstring.js new file mode 100644 index 0000000..05f35dc --- /dev/null +++ b/src/js/iotjs/src/iotstring.js @@ -0,0 +1,66 @@ +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var IoTString = function () { + function IoTString(arg) { + _classCallCheck(this, IoTString); + + if (arg === undefined) { + this.array = new Uint8Array(); + this.hashcode; + } else if (arg && typeof arg === "string") { + this.array = new Uint8Array(arg.length); + for (var i = 0; i < arg.length; ++i) { + this.array[i] = arg.charCodeAt(i); + } + this.hashcode = hash(this.array); + } else if (arg && arg instanceof Uint8Array) { + this.array = arg; + this.hashcode = hashcode(arg); + } + } + + _createClass(IoTString, [{ + key: "shallow", + value: function shallow(arg) { + if (arg && arg instanceof Uint8Array) { + var i = new IotString(arg); + return i; + } + } + }, { + key: "internalBytes", + value: function internalBytes() { + return this.array; + } + }, { + key: "hashCode", + value: function hashCode() { + return this.hashcode; + } + }, { + key: "toString", + value: function toString() { + return this.array.toString(); + } + }, { + key: "getBytes", + value: function getBytes() { + var obj; + return _.extend(obj, this.array); + } + }, { + key: "equals", + value: function equals(arr) { + return _.isEqual(arr, this.array); + } + }, { + key: "length", + value: function length() { + return this.array.length; + } + }]); + + return IoTString; +}(); \ No newline at end of file diff --git a/src/js/iotjs/src/liveness.js b/src/js/iotjs/src/liveness.js new file mode 100644 index 0000000..22cbd3f --- /dev/null +++ b/src/js/iotjs/src/liveness.js @@ -0,0 +1,5 @@ +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Liveness = function Liveness() { + _classCallCheck(this, Liveness); +}; \ No newline at end of file diff --git a/src/js/iotjs/src/main.js b/src/js/iotjs/src/main.js new file mode 100644 index 0000000..78e6a07 --- /dev/null +++ b/src/js/iotjs/src/main.js @@ -0,0 +1,67 @@ +/* jshint devel:true */ +"use strict"; +console.log('Welcome to iotjs-www','\n\n'); + +// set up the base line.. +// Using browserify to set up browser exports +var crypto = require('crypto-js'); +var hash = require('object-hash'); +var _ = require('underscore'); +var ByteBuffer = require("bytebuffer"); + + +(function() { + + var root = this; + + + // iot namespace main constructor + var iot = function(obj) { + if (obj instanceof iot) return obj; + if (!(this instanceof iot)) return new iot(obj); + this.iot = obj; + }; + + // export iot to the global exports + if (typeof exports !== 'undefined') { + if (typeof module !== 'undefined' && module.exports) { + exports = module.exports = iot; + } + exports.iot = iot; + } else { + root.iot = iot; + } + + iot.baselinetest = function(){ + // baseline test + console.log('its alive!!!'); + console.log(); + + //local hash test + console.log(hash('hello man')); + console.log(typeof hash('hello man')); + console.log(); + + //Pair test + var p = new Pair(1,2); + console.log(p.toString()); + console.log(); + + //iotstring test + var i = new IoTString('hello'); + console.log(i.length()); + console.log(); + } + + + + + + + + + + + + +}()) \ No newline at end of file diff --git a/src/js/iotjs/src/pair.js b/src/js/iotjs/src/pair.js new file mode 100644 index 0000000..e2467e3 --- /dev/null +++ b/src/js/iotjs/src/pair.js @@ -0,0 +1,32 @@ +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Pair = function () { + function Pair(a, b) { + _classCallCheck(this, Pair); + + this.a = a; + this.b = b; + } + + _createClass(Pair, [{ + key: 'getFirst', + value: function getFirst() { + return this.a; + } + }, { + key: 'getSecond', + value: function getSecond() { + return this.b; + } + }, { + key: 'toString', + value: function toString() { + var str = '<' + this.a + ',' + this.b + '>'; + return str; + } + }]); + + return Pair; +}(); \ No newline at end of file diff --git a/src/js/iotjs/src/slot.js b/src/js/iotjs/src/slot.js new file mode 100644 index 0000000..e69de29 diff --git a/src/js/iotjs/test/test.js b/src/js/iotjs/test/test.js new file mode 100644 index 0000000..7d78e72 --- /dev/null +++ b/src/js/iotjs/test/test.js @@ -0,0 +1,6 @@ +var iot = require('../build/iotjs.js'); + +iot.baselinetest(); + + +