Search in sources :

Example 1 with ConnectionException

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));
}
Also used : DataFrame(com.webpieces.http2parser.api.dto.DataFrame) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) StreamException(com.webpieces.http2parser.api.dto.error.StreamException)

Example 2 with ConnectionException

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);
}
Also used : DataTry(com.webpieces.http2engine.impl.DataTry) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 3 with ConnectionException

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);
}
Also used : DataTry(com.webpieces.http2engine.impl.DataTry) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 4 with ConnectionException

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);
}
Also used : ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException)

Example 5 with ConnectionException

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;
}
Also used : Http2Trailers(com.webpieces.hpack.api.dto.Http2Trailers) UnknownFrame(com.webpieces.http2parser.api.dto.UnknownFrame) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) Http2Config(com.webpieces.http2engine.api.client.Http2Config) CompletableFuture(java.util.concurrent.CompletableFuture) CancelReasonCode(com.webpieces.http2parser.api.dto.error.CancelReasonCode) Http2Msg(com.webpieces.http2parser.api.dto.lib.Http2Msg) HeaderSettings(com.webpieces.http2engine.impl.shared.data.HeaderSettings) SettingsFrame(com.webpieces.http2parser.api.dto.SettingsFrame) HpackParser(com.webpieces.hpack.api.HpackParser) UnmarshalState(com.webpieces.hpack.api.UnmarshalState) DataWrapper(org.webpieces.data.api.DataWrapper) StreamException(com.webpieces.http2parser.api.dto.error.StreamException) Logger(org.webpieces.util.logging.Logger) PriorityFrame(com.webpieces.http2parser.api.dto.PriorityFrame) ConnectionFailure(com.webpieces.http2engine.api.error.ConnectionFailure) PingFrame(com.webpieces.http2parser.api.dto.PingFrame) GoAwayFrame(com.webpieces.http2parser.api.dto.GoAwayFrame) List(java.util.List) ReceivedGoAway(com.webpieces.http2engine.api.error.ReceivedGoAway) RstStreamFrame(com.webpieces.http2parser.api.dto.RstStreamFrame) WindowUpdateFrame(com.webpieces.http2parser.api.dto.WindowUpdateFrame) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) LoggerFactory(org.webpieces.util.logging.LoggerFactory) DataFrame(com.webpieces.http2parser.api.dto.DataFrame) ConnectionFailure(com.webpieces.http2engine.api.error.ConnectionFailure) ConnectionClosedException(com.webpieces.http2engine.api.ConnectionClosedException) ConnectionException(com.webpieces.http2parser.api.dto.error.ConnectionException) StreamException(com.webpieces.http2parser.api.dto.error.StreamException)

Aggregations

ConnectionException (com.webpieces.http2parser.api.dto.error.ConnectionException)24 ByteBuffer (java.nio.ByteBuffer)8 FrameHeaderData (com.webpieces.http2parser.impl.FrameHeaderData)5 DataWrapper (org.webpieces.data.api.DataWrapper)5 DataFrame (com.webpieces.http2parser.api.dto.DataFrame)4 StreamException (com.webpieces.http2parser.api.dto.error.StreamException)4 HeadersFrame (com.webpieces.http2parser.api.dto.HeadersFrame)3 PriorityDetails (com.webpieces.http2parser.api.dto.lib.PriorityDetails)3 DataSplit (com.webpieces.http2parser.impl.DataSplit)3 DataTry (com.webpieces.http2engine.impl.DataTry)2 GoAwayFrame (com.webpieces.http2parser.api.dto.GoAwayFrame)2 PingFrame (com.webpieces.http2parser.api.dto.PingFrame)2 PriorityFrame (com.webpieces.http2parser.api.dto.PriorityFrame)2 PushPromiseFrame (com.webpieces.http2parser.api.dto.PushPromiseFrame)2 RstStreamFrame (com.webpieces.http2parser.api.dto.RstStreamFrame)2 SettingsFrame (com.webpieces.http2parser.api.dto.SettingsFrame)2 UnknownFrame (com.webpieces.http2parser.api.dto.UnknownFrame)2 WindowUpdateFrame (com.webpieces.http2parser.api.dto.WindowUpdateFrame)2 HasHeaderFragment (com.webpieces.http2parser.api.dto.lib.HasHeaderFragment)2 Http2Msg (com.webpieces.http2parser.api.dto.lib.Http2Msg)2