[e-cvs] cvs commit: e/src/jsrc/net/captp/jcomm CapTPReplacer.java CapTPResolver.java ProxyConnection.java ProxyInputStream.java ProxyOutputStream.java
markm@eros.cs.jhu.edu
markm@eros.cs.jhu.edu
Fri, 24 Aug 2001 15:02:37 -0400
markm 01/08/24 15:02:37
Modified: src/jsrc/net/captp/jcomm ProxyConnection.java
Added: src/jsrc/net/captp/jcomm CapTPReplacer.java
CapTPResolver.java
Removed: src/jsrc/net/captp/jcomm ProxyInputStream.java
ProxyOutputStream.java
Log:
Now using Serializer/Unserializer in CapTP, rather than subclassing ObjectOutputStream/ObjectInputStream.
Revision Changes Path
1.24 +75 -66 e/src/jsrc/net/captp/jcomm/ProxyConnection.java
Index: ProxyConnection.java
===================================================================
RCS file: /cvs/e/src/jsrc/net/captp/jcomm/ProxyConnection.java,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -r1.23 -r1.24
--- ProxyConnection.java 2001/08/22 14:26:14 1.23
+++ ProxyConnection.java 2001/08/24 19:02:37 1.24
@@ -47,7 +47,10 @@
import org.erights.e.elib.sealing.SealedBox;
import org.erights.e.elib.sealing.Sealer;
import org.erights.e.elib.sealing.Unsealer;
+import org.erights.e.elib.serial.Serializer;
+import org.erights.e.elib.serial.Unserializer;
import org.erights.e.elib.tables.ConstList;
+import org.erights.e.elib.util.OneArgFunc;
import org.erights.e.meta.java.math.BigIntegerSugar;
/**
@@ -577,42 +580,43 @@
* @see net.vattp.data.MsgHandler
*/
public void processMessage(byte[] message, DataConnection dataConn) {
- Assertion.test(dataConn == myDataConnection,
- "message's DataConnection doesn't match");
+ try {
+ Assertion.test(dataConn == myDataConnection,
+ "message's DataConnection doesn't match");
- if (myOptProblem != null) {
- /* Just to be safe */
- return;
- }
+ if (myOptProblem != null) {
+ /* Just to be safe */
+ return;
+ }
- if (myShuttingDownFlag) {
- myShuttingDownFlag = false;
- if (null != myOptBufferedLookups) {
- submitLookups(myOptBufferedLookups);
- myOptBufferedLookups = null;
+ if (myShuttingDownFlag) {
+ myShuttingDownFlag = false;
+ if (null != myOptBufferedLookups) {
+ submitLookups(myOptBufferedLookups);
+ myOptBufferedLookups = null;
+ }
}
- }
- ByteArrayInputStream bis = new ByteArrayInputStream(message);
- ProxyInputStream pis;
+ ByteArrayInputStream bis = new ByteArrayInputStream(message);
- /* The message type (the first byte) should *always* be E_MSG */
- if ((byte)bis.read() != Msg.E_MSG) {
- Assertion.fail("ProxyConnection was handed a non-E_MSG message");
- }
+ /* The message type (the first byte) should *always* be E_MSG */
+ if ((byte)bis.read() != Msg.E_MSG) {
+ Assertion.fail
+ ("ProxyConnection was handed a non-E_MSG message");
+ }
- /* Read the command byte *before* starting to interpret the stream */
- ++myReceiveCount;
- byte cmd = (byte)bis.read();
+ //Read the command byte *before* starting to interpret the stream
+ ++myReceiveCount;
+ byte cmd = (byte)bis.read();
- try {
if (Trace.captp.debug && Trace.ON) {
Trace.captp.debugm(
"ProxyConnection " + this + " receive msg cmd=" + cmd);
}
- pis = new ProxyInputStream(bis, this);
- receiveMsg(cmd, pis);
+ OneArgFunc resolver = new CapTPResolver(this);
+ Unserializer uns = new Unserializer(bis, resolver);
+ receiveMsg(cmd, uns);
} catch (Throwable problem) {
/* They sent a badly formed message, trace it & ignore it */
@@ -622,14 +626,14 @@
}
}
- private void receiveMsg(byte cmd, ProxyInputStream pis)
+ private void receiveMsg(byte cmd, Unserializer uns)
throws IOException, ClassNotFoundException, OptionalDataException {
switch (cmd) {
case DELIVER_ONLY_OP: {
- int recipPos = pis.readInt();
- String verb = ((String)pis.readUTF()).intern();
+ int recipPos = uns.readInt();
+ String verb = ((String)uns.readUTF()).intern();
try {
- Object[] args = (Object[])pis.readObject();
+ Object[] args = (Object[])uns.readObject();
execDeliverOnlyOp(recipPos, verb, args);
} catch (Throwable problem) {
@@ -638,12 +642,12 @@
break;
}
case DELIVER_OP: {
- int answerPos = pis.readInt();
- Object rdr = pis.readObject();
- int recipPos = pis.readInt();
- String verb = ((String)pis.readUTF()).intern();
+ int answerPos = uns.readInt();
+ Object rdr = uns.readObject();
+ int recipPos = uns.readInt();
+ String verb = ((String)uns.readUTF()).intern();
try {
- Object[] args = (Object[])pis.readObject();
+ Object[] args = (Object[])uns.readObject();
execDeliverOp(answerPos, rdr,
recipPos, verb, args);
@@ -654,20 +658,20 @@
break;
}
case GC_EXPORT_OP: {
- int exportPos = pis.readInt();
- int wireCount = pis.readInt();
+ int exportPos = uns.readInt();
+ int wireCount = uns.readInt();
execGCExportOp(exportPos, wireCount);
break;
}
case GC_ANSWER_OP: {
- int answerPos = pis.readInt();
+ int answerPos = uns.readInt();
execGCAnswerOp(answerPos);
break;
}
case SHUTDOWN_OP: {
- int receivedCount = pis.readInt();
+ int receivedCount = uns.readInt();
execShutdownOp(receivedCount);
break;
@@ -805,20 +809,20 @@
/**
*
*/
- private ProxyOutputStream makeMsg(byte cmd) throws IOException {
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ private Serializer makeMsg(ByteArrayOutputStream bos, byte cmd)
+ throws IOException {
bos.write(Msg.E_MSG);
bos.write(cmd);
- return new ProxyOutputStream(bos, this);
+ OneArgFunc replacer = new CapTPReplacer(this);
+ return new Serializer(bos, replacer);
}
/**
* Send a message via our DataConnection.
*/
- private void sendMsg(ProxyOutputStream pos) throws IOException {
- pos.flush();
- ByteArrayOutputStream bos =
- (ByteArrayOutputStream)pos.getOutputStream();
+ private void sendMsg(ByteArrayOutputStream bos, Serializer ser)
+ throws IOException {
+ ser.flush();
byte[] msg = bos.toByteArray();
if (Trace.captp.debug && Trace.ON) {
Trace.captp.debugm(
@@ -845,11 +849,12 @@
throw ExceptionMgr.asSafe(myOptProblem);
}
try {
- ProxyOutputStream pos = makeMsg(DELIVER_ONLY_OP);
- pos.writeInt(recipPos);
- pos.writeUTF(verb);
- pos.writeObject(args);
- sendMsg(pos);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ Serializer ser = makeMsg(bos, DELIVER_ONLY_OP);
+ ser.writeInt(recipPos);
+ ser.writeUTF(verb);
+ ser.writeObject(args);
+ sendMsg(bos, ser);
} catch (Throwable problem) {
killConnection(problem, false);
throw ExceptionMgr.asSafe(problem);
@@ -875,13 +880,14 @@
throw ExceptionMgr.asSafe(myOptProblem);
}
try {
- ProxyOutputStream pos = makeMsg(DELIVER_OP);
- pos.writeInt(answerPos);
- pos.writeObject(rdr);
- pos.writeInt(recipPos);
- pos.writeUTF(verb);
- pos.writeObject(args);
- sendMsg(pos);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ Serializer ser = makeMsg(bos, DELIVER_OP);
+ ser.writeInt(answerPos);
+ ser.writeObject(rdr);
+ ser.writeInt(recipPos);
+ ser.writeUTF(verb);
+ ser.writeObject(args);
+ sendMsg(bos, ser);
} catch (Throwable problem) {
killConnection(problem, false);
throw ExceptionMgr.asSafe(problem);
@@ -900,10 +906,11 @@
throw ExceptionMgr.asSafe(myOptProblem);
}
try {
- ProxyOutputStream pos = makeMsg(GC_EXPORT_OP);
- pos.writeInt(exportPos);
- pos.writeInt(wireCount);
- sendMsg(pos);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ Serializer ser = makeMsg(bos, GC_EXPORT_OP);
+ ser.writeInt(exportPos);
+ ser.writeInt(wireCount);
+ sendMsg(bos, ser);
} catch (Throwable problem) {
killConnection(problem, false);
throw ExceptionMgr.asSafe(problem);
@@ -922,9 +929,10 @@
throw ExceptionMgr.asSafe(myOptProblem);
}
try {
- ProxyOutputStream pos = makeMsg(GC_ANSWER_OP);
- pos.writeInt(answerPos);
- sendMsg(pos);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ Serializer ser = makeMsg(bos, GC_ANSWER_OP);
+ ser.writeInt(answerPos);
+ sendMsg(bos, ser);
} catch (Throwable problem) {
killConnection(problem, false);
throw ExceptionMgr.asSafe(problem);
@@ -943,9 +951,10 @@
throw ExceptionMgr.asSafe(myOptProblem);
}
try {
- ProxyOutputStream pos = makeMsg(SHUTDOWN_OP);
- pos.writeInt(receivedCount);
- sendMsg(pos);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ Serializer ser = makeMsg(bos, SHUTDOWN_OP);
+ ser.writeInt(receivedCount);
+ sendMsg(bos, ser);
} catch (Throwable problem) {
killConnection(problem, false);
throw ExceptionMgr.asSafe(problem);
1.1 e/src/jsrc/net/captp/jcomm/CapTPReplacer.java
Index: CapTPReplacer.java
===================================================================
package net.captp.jcomm;
/*
The contents of this file are subject to the Improvements to the
Distributed E Language Implementation License Version 1.0 (the
"License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.erights.org/mmlicense.html
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
the License for the specific language governing rights and limitations
under the License.
The Original Code is the Improvements to the Distributed E Language
Implementation, released May 27, 1999.
The Initial Developer of the Original Code is Mark S. Miller.
Copyright (C) 1999 Mark S. Miller. All Rights Reserved.
Contributor(s): ______________________________________.
*/
import org.erights.e.elib.ref.Ref;
import org.erights.e.elib.serial.PassByConstruction;
import org.erights.e.elib.util.OneArgFunc;
/**
* Used to specialize the Serializer for encoding a reference over a CapTP
* connection.
* <p>
* When our run method returns an {@link ObjectRefDesc}, the corresponding
* decoded object is not simply this ObjectRefDesc. It is this ObjectRefDesc
* as dereferenced by {@link CapTPResolver}.
*
* @author <a href="mailto:markm@erights.org">Mark S. Miller</a>
*/
/*package*/ class CapTPReplacer implements OneArgFunc {
/**
* The connection over which we are communicating
*/
private ProxyConnection myConn;
/**
*
*/
/*package*/ CapTPReplacer(ProxyConnection conn) {
myConn = conn;
}
/**
* Replace any proxiable object (an implementer of PassByProxy, a Far
* reference, a Promise, or a Broken reference) with an appropriate
* over-the-wire representation, or if it's not a proxiable object, make
* sure we're actually permitted to pass it by construction.
*/
public Object run(Object ref) {
ref = Ref.resolution(ref);
//the following sequence of tests are cribbed from Ref.isPBC, except
//that we don't guard it with an isNear test, so as to include broken
//references.
if (null == ref) {
//null is trivially PassByCopy
return null;
}
Class clazz = ref.getClass();
if (PassByConstruction.class.isAssignableFrom(clazz)) {
return ref;
}
if (clazz.isArray()) {
//Because we try to pretend that arrays are PassByCopy lists,
//we just pass arrays by copy. This is XXX a potential security
//bug or at least a possible semantic confusion, since arrays are
//not actually immutable. After passing, the original and passed
//copy may diverge, whereas in an eventual send within a vat,
//they wouldn't diverge.
return ref;
}
if (PassByConstruction.HONORARY.has(clazz)) {
return ref;
}
//end PCB testing
if (Ref.isEventual(ref)) {
return myConn.makeEventualDesc(Ref.toRef(ref));
}
if (Ref.isNear(ref)) {
if (Ref.isPassByProxy(ref)) {
return myConn.makeImportingDesc(ref);
}
throw new RuntimeException("the " + clazz +
" is neither PassByConstruction nor PassByProxy");
}
throw new RuntimeException("bad state " + ref);
}
}
1.1 e/src/jsrc/net/captp/jcomm/CapTPResolver.java
Index: CapTPResolver.java
===================================================================
package net.captp.jcomm;
/*
The contents of this file are subject to the Improvements to the
Distributed E Language Implementation License Version 1.0 (the
"License"); you may not use this file except in compliance with the
License. You may obtain a copy of the License at
http://www.erights.org/mmlicense.html
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
the License for the specific language governing rights and limitations
under the License.
The Original Code is the Improvements to the Distributed E Language
Implementation, released May 27, 1999.
The Initial Developer of the Original Code is Mark S. Miller.
Copyright (C) 1999 Mark S. Miller. All Rights Reserved.
Contributor(s): ______________________________________.
*/
import org.erights.e.elib.ref.Ref;
import org.erights.e.elib.util.OneArgFunc;
/**
* Used to specialize the Unserializer for receiving state serialized over a
* CapTP connection.
*
* @author <a href="mailto:markm@erights.org">Mark S. Miller</a>
*/
/*package*/ class CapTPResolver implements OneArgFunc {
/**
* The connection over which we are communicating
*/
private ProxyConnection myConn;
/**
*
*/
/*package*/ CapTPResolver(ProxyConnection conn) {
myConn = conn;
}
/**
* Replace ObjectRefDescs in the input stream with the object reference
* they {@link ObjectRefDesc#dereference(ProxyConnection)} to.
*/
public Object run(Object ref) {
ref = Ref.resolution(ref);
if (ref instanceof ObjectRefDesc) {
return ((ObjectRefDesc)ref).dereference(myConn);
} else {
return ref;
}
}
}