more js
authorjoelbandi <joelvivekbandi@gmail.com>
Sat, 30 Jul 2016 12:42:13 +0000 (05:42 -0700)
committerjoelbandi <joelvivekbandi@gmail.com>
Sat, 30 Jul 2016 12:42:13 +0000 (05:42 -0700)
src/java/iotcloud/Entry.java
src/java/iotcloud/Slot.java
src/js/iotjs/orig/slot.js
src/js/iotjs/package.json
src/js/iotjs/src/main.js

index 70f90ee60e7f57d072a76f15e569466df9d34cf1..5e0f3f832aa529899fb0878d46fee6f68bfa369d 100644 (file)
@@ -29,7 +29,7 @@ abstract class Entry implements Liveness {
         * byte tells the type of entry.
         */
 
-       static Entry decode(Slot slot, ByteBuffer bb) {
+       slottatic Entry decode(Slot slot, ByteBuffer bb) {
                byte type=bb.get();
                switch(type) {
                case TypeKeyValue:
index d23e5c1b86dd76cb0c215b84d1b954ba4ac8fa15..c114a8762c0eba7f83fdfe03178fc89000ffca5a 100644 (file)
@@ -19,18 +19,18 @@ class Slot implements Liveness {
        /** Sequence number of the slot. */
        private long seqnum;//
        /** HMAC of previous slot. */
-       private byte[] prevhmac;
+       private byte[] prevhmac;//
        /** HMAC of this slot. */
-       private byte[] hmac;
+       private byte[] hmac;//
        /** Machine that sent this slot. */
-       private long machineid;
+       private long machineid;//
        /** Vector of entries in this slot. */
        private Vector<Entry> entries;
        /** Pieces of information that are live. */
-       private int livecount;
+       private int livecount;//
        /** Flag that indicates whether this slot is still live for
         * recording the machine that sent it. */
-       private boolean seqnumlive;
+       private boolean seqnumlive;//
        /** Number of bytes of free space. */
        private int freespace;
        /** Reference to Table */
@@ -52,8 +52,13 @@ class Slot implements Liveness {
                this(_table, _seqnum, _machineid, _prevhmac, null);
        }
 
+<<<<<<< HEAD
+       Slot(long _seqnum, long _machineid) {
+               this(_seqnum, _machineid, new byte[ HMAC_SIZE], null);
+=======
        Slot(Table _table, long _seqnum, long _machineid) {
                this(_table, _seqnum, _machineid, new byte[HMAC_SIZE], null);
+>>>>>>> f80cc30f294899f47cef3507334f8ca357862e5e
        }
 
        byte[] getHMAC() {
index 72352d9f073f497c396d2028581adae035984da1..35ca26611b99545cc827c7f7c04d108c2a482087 100644 (file)
@@ -1,10 +1,52 @@
-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");
-
+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("machine should be a number");
+        this.livecount = 1;
+        this.seqnumlive = true;
+        (prevhmac && prevhmac instanceof Uint8Array) ? this.prevhmac = prevhmac: this.prevhmac = new Uint8Array(this.HMAC_SIZE));
+           (hmac && hmac instanceof Uint8Array) ? this.hmac = hmac: this.hmac = null;
+       this.entries = [];
+       this.freespace = this.SLOT_SIZE - getBaseSize(); //???????
+       }
+       getHMAC() {
+       return this.hmac;
+       }
+       getPrevHmac() {
+       return this.prevhmac;
+       }
+       addEntry(entry) {
+           if (entry && entry instanceof Entry) {
+               var obj;
+               this.entries.push(_.extend(obj, entry));
+               this.livecount++;
+               freespace -= entry.getSize();
+           }
+       }
+       addShallowEntry(entry){
+               if(entry && entry instanceof Entry){
+                       this.entries.push(entry);
+                       this.livecount++;
+               freespace -= entry.getSize();
+               }
+       }
+       hasSpace(entry){
+               var newfreespace = this.freespace - entry.getSize();
+               return newfreespace > this.RESERVED_SPACE;
+       }
+       canFit(entry){
+               var newfreespace = this.freespace - entry.getSize();
+               return newfreespace >= 0; 
+       }
+       getEntries(){
+               return this.entries;
+       }
+       static decode(array){
+               var cond1 = (array && array instanceof Uint8Array);
+               if(cond1){
+               }
        }
 }
\ No newline at end of file
index 2b12bbebd4bf7f52e0b8900b6e301346a1741c8f..277b0baf22b0773c7599173ee1d25323eecee403 100644 (file)
@@ -20,6 +20,7 @@
     "gulp-uglify": "1.1.0",
     "jshint-stylish": "1.0.1",
     "minimist": "1.1.1",
+    "node-forge": "^0.6.41",
     "object-hash": "^1.1.3",
     "request": "^2.74.0",
     "underscore": "^1.8.3"
index 78e6a07ec2f3af2f204fa3b6811b85ea8ea54a44..b4485fdf8f8e8f44e0aab52d1e4cd934550cfcf2 100644 (file)
@@ -1,27 +1,21 @@
 /* jshint devel:true */
 "use strict";
-console.log('Welcome to iotjs-www','\n\n');
-
+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");
-
-
+var ByteBuffer = require('bytebuffer');
+var hash = require('object-hash');
+var forge = require('node-forge');
 (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) {
@@ -32,36 +26,41 @@ var ByteBuffer = require("bytebuffer");
         root.iot = iot;
     }
 
-    iot.baselinetest = function(){
-       // baseline test
+
+    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);
+        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();
-    }
-
-    
-
-
-
-
-
-
-
 
 
+        //local crypto test
+        var data = [{id: 1}, {id: 2}];
+        // Encrypt 
+        var ciphertext = crypto.AES.encrypt(JSON.stringify(data), 'secret key 123');
+        // Decrypt 
+        var bytes = crypto.AES.decrypt(ciphertext.toString(), 'secret key 123');
+        var decryptedData = JSON.parse(bytes.toString(crypto.enc.Utf8));
+        // console.log(decryptedData);
 
+        var e = crypto.HmacMD5("Mess", "Secret Passphrase");
+        console.log(typeof e.toString());
+    }
 }())
\ No newline at end of file