use of com.webpieces.http2parser.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class Level6LocalFlowControl method fireDataToClient.
public CompletableFuture<Void> fireDataToClient(Stream stream, StreamMsg payload) {
if (!(payload instanceof DataFrame))
return notifyListener.sendPieceToApp(stream, payload);
DataFrame f = (DataFrame) payload;
long frameLength = f.getTransmitFrameLength();
if (frameLength > connectionLocalWindowSize) {
throw new ConnectionException(CancelReasonCode.FLOW_CONTROL_ERROR, logId, f.getStreamId(), "connectionLocalWindowSize too small=" + connectionLocalWindowSize + " frame len=" + frameLength + " for frame=" + f);
} else if (frameLength > stream.getLocalWindowSize()) {
throw new StreamException(CancelReasonCode.FLOW_CONTROL_ERROR, logId, f.getStreamId(), "connectionLocalWindowSize too small=" + connectionLocalWindowSize + " frame len=" + frameLength + " for frame=" + f);
}
totalSent += frameLength;
connectionLocalWindowSize -= frameLength;
stream.incrementLocalWindow(-frameLength);
log.info("received framelen=" + frameLength + " newConnectionWindowSize=" + connectionLocalWindowSize + " streamSize=" + stream.getLocalWindowSize() + " totalSent=" + totalSent);
return notifyListener.sendPieceToApp(stream, payload).thenApply(c -> updateFlowControl(frameLength, stream));
}
use of com.webpieces.http2parser.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class Level6RemoteFlowControl method updateConnectionWindowSize.
public CompletableFuture<Void> updateConnectionWindowSize(WindowUpdateFrame msg) {
int increment = msg.getWindowSizeIncrement();
if (increment == 0) {
throw new ConnectionException(CancelReasonCode.WINDOW_SIZE_INVALID, logId, msg.getStreamId(), "Received windowUpdate size increment=0");
}
DataTry dataTry = null;
DataTry temp = dataQueue.peek();
synchronized (remoteLock) {
// we should delete this synchronized as we are virtually single threaded now!!!
remoteWindowSize += increment;
if (remoteWindowSize > Integer.MAX_VALUE)
throw new ConnectionException(CancelReasonCode.FLOW_CONTROL_ERROR, logId, 0, "(remote end bad)global remoteWindowSize too large=" + remoteWindowSize + " from windows increment=" + increment);
if (temp != null && remoteWindowSize > temp.getDataFrame().getTransmitFrameLength())
dataTry = dataQueue.poll();
log.info("updated window to=" + remoteWindowSize + " increment=" + msg.getWindowSizeIncrement() + " dataTry to submit=" + dataTry);
}
if (dataTry != null) {
dataTry.setWasQueuedBefore(true);
trySendPayload(dataTry);
}
return CompletableFuture.completedFuture(null);
}
use of com.webpieces.http2parser.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class Level6RemoteFlowControl method updateStreamWindowSize.
public CompletableFuture<Void> updateStreamWindowSize(Stream stream, WindowUpdateFrame msg) {
if (msg.getWindowSizeIncrement() == 0) {
throw new ConnectionException(CancelReasonCode.WINDOW_SIZE_INVALID, logId, msg.getStreamId(), "Received windowUpdate size increment=0");
}
DataTry dataTry = null;
DataTry temp = dataQueue.peek();
synchronized (remoteLock) {
long remoteWindowSize = stream.incrementRemoteWindow(msg.getWindowSizeIncrement());
if (temp != null && remoteWindowSize > temp.getDataFrame().getTransmitFrameLength())
dataTry = dataQueue.poll();
log.info("updated stream " + stream.getStreamId() + " window to=" + stream.getRemoteWindowSize() + " increment=" + msg.getWindowSizeIncrement() + " dataTry to submit=" + dataTry);
}
if (dataTry != null) {
dataTry.setWasQueuedBefore(true);
trySendPayload(dataTry);
}
//someday, remove synchronized above and then complete future when it is complete instead maybe
return CompletableFuture.completedFuture(null);
}
use of com.webpieces.http2parser.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class Level5ClientStateMachine method sendPushToApp.
public CompletableFuture<Void> sendPushToApp(Http2Push fullPromise) {
int newStreamId = fullPromise.getPromisedStreamId();
if (newStreamId % 2 == 1)
throw new ConnectionException(CancelReasonCode.INVALID_STREAM_ID, logId, newStreamId, "Server sent bad push promise=" + fullPromise + " as new stream id is incorrect and is an odd number");
ClientStream causalStream = (ClientStream) streamState.getStream(fullPromise, true);
ClientPushStream stream = createPushStream(newStreamId, causalStream.getResponseListener());
return firePushToClient(stream, fullPromise);
}
use of com.webpieces.http2parser.api.dto.error.ConnectionException in project webpieces by deanhiller.
the class Level2ParsingAndRemoteSettings method handleError.
private Void handleError(Object object, Throwable e) {
if (e == null)
return null;
else if (e instanceof ConnectionClosedException) {
log.error("Normal exception since we are closing and they do not know yet", e);
} else if (e instanceof StreamException) {
log.error("shutting the stream down due to error", e);
syncro.sendRstToServerAndApp((StreamException) e).exceptionally(t -> logExc("stream", t));
} else if (e instanceof ConnectionException) {
log.error("shutting the connection down due to error", e);
ConnectionFailure reset = new ConnectionFailure((ConnectionException) e);
//send GoAway
syncro.sendGoAwayToSvrAndResetAllToApp(reset).exceptionally(t -> logExc("connection", t));
} else {
log.error("shutting the connection down due to error(MAKE sure your clients try..catch, exceptions)", e);
ConnectionException exc = new ConnectionException(CancelReasonCode.BUG, logId, 0, e.getMessage(), e);
ConnectionFailure reset = new ConnectionFailure((ConnectionException) exc);
//send GoAwa
syncro.sendGoAwayToSvrAndResetAllToApp(reset).exceptionally(t -> logExc("connection", t));
}
return null;
}
Aggregations