Thread: [Beepcore-java-commits] CVS: beepcore-java/src/org/beepcore/beep/core ChannelImpl.java,1.2,1.3
Status: Beta
Brought to you by:
huston
|
From: Huston F. <hu...@us...> - 2003-05-16 16:44:33
|
Update of /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/core
In directory sc8-pr-cvs1:/tmp/cvs-serv21584/src/org/beepcore/beep/core
Modified Files:
ChannelImpl.java
Log Message:
first pass at cleanup of frame validation
Index: ChannelImpl.java
===================================================================
RCS file: /cvsroot/beepcore-java/beepcore-java/src/org/beepcore/beep/core/ChannelImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** ChannelImpl.java 23 Apr 2003 15:23:04 -0000 1.2
--- ChannelImpl.java 16 May 2003 16:44:29 -0000 1.3
***************
*** 694,774 ****
log.trace("Channel::postFrame");
- boolean firstFrame = false;
- boolean createAndPostMessage = false;
- Message currentMessage = null;
- int msgno = frame.getMsgno();
-
if (state != STATE_ACTIVE && state != STATE_TUNING) {
throw new BEEPException("State is " + state);
}
! // Validate Frame
! synchronized (this) {
!
! // assume the frame has already been parsed by the session and
! // that the flags indicated are part of the frame object
!
! // is the message number correct?
! if (frame.getMessageType() == Message.MESSAGE_TYPE_MSG) {
! if (previousFrame != null) {
! if (frame.getMsgno() != previousFrame.getMsgno()) {
! throw new BEEPException("Incorrect message number: was "
! + frame.getMsgno()
! + "; expecting "
! + previousFrame.getMsgno());
! }
! } else {
! synchronized (recvMSGQueue) {
! ListIterator i =
! recvMSGQueue.listIterator(recvMSGQueue.size());
! while (i.hasPrevious()) {
! if (((Message) i.previous()).getMsgno()
! == frame.getMsgno())
! {
! throw new BEEPException("Received a frame " +
! "with a duplicate " +
! "msgno (" +
! frame.getMsgno() +
! ")");
! }
! }
! }
! }
! } else {
! MessageStatus mstatus;
!
! synchronized (sentMSGQueue) {
! if (sentMSGQueue.size() == 0) {
! throw new BEEPException("Received unsolicited reply");
! }
!
! mstatus = (MessageStatus) sentMSGQueue.get(0);
! }
!
! if (frame.getMsgno() != mstatus.getMsgno()) {
! throw new BEEPException("Incorrect message number: was "
! + frame.getMsgno()
! + "; expecting "
! + mstatus.getMsgno());
! }
! }
!
! // is the sequence number correct?
! if (frame.getSeqno() != recvSequence) {
! throw new BEEPException("Incorrect sequence number: was "
! + frame.getSeqno() + "; expecting "
! + recvSequence);
! }
!
! // is the message type the same as the previous frames?
! if ((previousFrame != null)
! && (previousFrame.getMessageType()
! != frame.getMessageType())) {
! throw new BEEPException("Incorrect message type: was "
! + frame.getMessageTypeString()
! + "; expecting "
! + previousFrame.getMessageTypeString());
! }
! }
recvSequence += frame.getSize();
--- 694,702 ----
log.trace("Channel::postFrame");
if (state != STATE_ACTIVE && state != STATE_TUNING) {
throw new BEEPException("State is " + state);
}
! validateFrame(frame);
recvSequence += frame.getSize();
***************
*** 782,819 ****
}
! if (frame.getMessageType() != Message.MESSAGE_TYPE_MSG) {
! MessageStatus mstatus;
!
! synchronized (sentMSGQueue) {
! if (sentMSGQueue.size() == 0) {
! throw new BEEPException("Received unsolicited reply");
! }
!
! mstatus = (MessageStatus) sentMSGQueue.get(0);
!
! if (mstatus.getMsgno() != frame.getMsgno()) {
! throw new BEEPException("Received reply out of order");
! }
! }
! }
!
! try {
! receiveFrame(frame);
! } catch (BEEPException e) {
! // @todo change this to do the right thing
! throw new BEEPException(e.getMessage());
! }
!
! // is this the last frame in the message?
! if (frame.isLast() == true) {
! log.trace("Got the last frame");
! }
!
! // save the previous frame to compare message types
! if (frame.isLast()) {
! previousFrame = null;
! } else {
! previousFrame = frame;
! }
}
--- 710,714 ----
}
! receiveFrame(frame);
}
***************
*** 1036,1039 ****
--- 931,1028 ----
}
+ private void validateFrame(Frame frame) throws BEEPException
+ {
+ synchronized (this) {
+
+ if (previousFrame == null) {
+ // is the message number correct?
+ if (frame.getMessageType() == Message.MESSAGE_TYPE_MSG) {
+ synchronized (recvMSGQueue) {
+ ListIterator i =
+ recvMSGQueue.listIterator(recvMSGQueue.size());
+ while (i.hasPrevious()) {
+ if (((Message) i.previous()).getMsgno()
+ == frame.getMsgno())
+ {
+ throw new BEEPException("Received a frame " +
+ "with a duplicate " +
+ "msgno (" +
+ frame.getMsgno() +
+ ")");
+ }
+ }
+ }
+ } else {
+ MessageStatus mstatus;
+
+ synchronized (sentMSGQueue) {
+ if (sentMSGQueue.size() == 0) {
+ throw new BEEPException("Received unsolicited reply");
+ }
+
+ mstatus = (MessageStatus) sentMSGQueue.get(0);
+ }
+
+ if (frame.getMsgno() != mstatus.getMsgno()) {
+ throw new BEEPException("Incorrect message number: was "
+ + frame.getMsgno()
+ + "; expecting "
+ + mstatus.getMsgno());
+ }
+ }
+ } else {
+ // is the message type the same as the previous frames?
+ if (previousFrame.getMessageType() != frame.getMessageType()) {
+ throw new BEEPException("Incorrect message type: was "
+ + frame.getMessageTypeString()
+ + "; expecting "
+ + previousFrame.getMessageTypeString());
+ }
+
+ // is the message number correct?
+ if (frame.getMessageType() == Message.MESSAGE_TYPE_MSG &&
+ frame.getMsgno() != previousFrame.getMsgno())
+ {
+ throw new BEEPException("Incorrect message number: was "
+ + frame.getMsgno()
+ + "; expecting "
+ + previousFrame.getMsgno());
+ }
+ }
+
+ // is the sequence number correct?
+ if (frame.getSeqno() != recvSequence) {
+ throw new BEEPException("Incorrect sequence number: was "
+ + frame.getSeqno() + "; expecting "
+ + recvSequence);
+ }
+
+ }
+
+ if (frame.getMessageType() != Message.MESSAGE_TYPE_MSG) {
+ MessageStatus mstatus;
+
+ synchronized (sentMSGQueue) {
+ if (sentMSGQueue.size() == 0) {
+ throw new BEEPException("Received unsolicited reply");
+ }
+
+ mstatus = (MessageStatus) sentMSGQueue.get(0);
+
+ if (mstatus.getMsgno() != frame.getMsgno()) {
+ throw new BEEPException("Received reply out of order");
+ }
+ }
+ }
+
+ // save the previous frame to compare message types
+ if (frame.isLast()) {
+ previousFrame = null;
+ } else {
+ previousFrame = frame;
+ }
+
+ }
+
synchronized void freeReceiveBufferBytes(int size)
{
|