From: Brian Demsky Date: Sat, 23 Jul 2016 17:34:20 +0000 (-0700) Subject: more code X-Git-Url: http://plrg.eecs.uci.edu/git/?p=iotcloud.git;a=commitdiff_plain;h=ec7439ada1c23627112237afcf4f8e3a64869495 more code --- diff --git a/src/java/iotcloud/CloudComm.java b/src/java/iotcloud/CloudComm.java index 4bc223b..4f64036 100644 --- a/src/java/iotcloud/CloudComm.java +++ b/src/java/iotcloud/CloudComm.java @@ -8,11 +8,13 @@ class CloudComm { String baseurl; Cipher encryptcipher; Cipher decryptcipher; + Mac mac; - CloudComm(String _baseurl, Cipher _encrypt, Cipher _decrypt) { + CloudComm(String _baseurl, Cipher _encrypt, Cipher _decrypt, Mac _mac) { this.baseurl=_baseurl; this.encryptcipher = _encrypt; this.decryptcipher = _decrypt; + this.mac = _mac; } private URL buildRequest(boolean isput, long sequencenumber, long maxentries) throws IOException { @@ -25,15 +27,17 @@ class CloudComm { public Slot[] putSlot(Slot slot, int max) throws IOException{ long sequencenumber=slot.getSequenceNumber(); + byte[] bytes=slot.encode(mac); + URL url=buildRequest(true, sequencenumber, max); URLConnection con=url.openConnection(); HttpURLConnection http = (HttpURLConnection) con; http.setRequestMethod("POST"); - http.setFixedLengthStreamingMode(slot.getBytes().length); + http.setFixedLengthStreamingMode(bytes.length); http.setDoOutput(true); http.connect(); OutputStream os=http.getOutputStream(); - os.write(slot.getBytes()); + os.write(bytes); System.out.println(http.getResponseMessage()); InputStream is=http.getInputStream(); @@ -41,7 +45,7 @@ class CloudComm { byte[] resptype=new byte[7]; dis.readFully(resptype); if (Arrays.equals(resptype, "getslot".getBytes())) - return processSlots(dis, sequencenumber); + return processSlots(dis); else if (Arrays.equals(resptype, "putslot".getBytes())) return null; else @@ -63,10 +67,10 @@ class CloudComm { if (!Arrays.equals(resptype, "getslot".getBytes())) throw new Error("Bad Response: "+new String(resptype)); else - return processSlots(dis, sequencenumber); + return processSlots(dis); } - Slot[] processSlots(DataInputStream dis, long sequencenumber) throws IOException { + Slot[] processSlots(DataInputStream dis) throws IOException { int numberofslots=dis.readInt(); int[] sizesofslots=new int[numberofslots]; Slot[] slots=new Slot[numberofslots]; @@ -77,7 +81,7 @@ class CloudComm { for(int i=0;i entries=new Vector(); + Vector entries=new Vector(); for(int i=0;i