Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unified stream manager #444

Closed
wants to merge 169 commits into from
Closed
Show file tree
Hide file tree
Changes from 128 commits
Commits
Show all changes
169 commits
Select commit Hold shift + click to select a range
abba3db
empty to test
TingDaoK Oct 20, 2021
d00deed
phase 1
TingDaoK Oct 21, 2021
6c3d841
add comment
TingDaoK Oct 22, 2021
e617940
Merge branch 'main' into h2-support
TingDaoK Oct 22, 2021
0b37a88
test
TingDaoK Oct 25, 2021
82e9810
comments
TingDaoK Oct 25, 2021
addd531
WIP ping
TingDaoK Oct 25, 2021
289cb45
use future
TingDaoK Oct 25, 2021
123249b
fix the issue about object vs jlong
TingDaoK Oct 25, 2021
cb35552
mark the method unimplemented
TingDaoK Oct 25, 2021
16a5111
formatting
TingDaoK Oct 25, 2021
ece43cb
a little better check
TingDaoK Oct 26, 2021
7c10040
optimize code
TingDaoK Oct 26, 2021
0722323
goaway support
TingDaoK Oct 26, 2021
ac051f8
connection window update
TingDaoK Oct 26, 2021
22d49fb
WIP for settings
TingDaoK Oct 26, 2021
9d2adbd
update the name
TingDaoK Oct 26, 2021
e8369d1
settings
TingDaoK Oct 26, 2021
e91328b
comments addressed
TingDaoK Oct 27, 2021
6da168d
I don't like this format
TingDaoK Oct 27, 2021
30caba9
Merge branch 'h2-support' into h2-support-2
TingDaoK Oct 27, 2021
b1f64bd
add getter
TingDaoK Oct 27, 2021
d430a2a
exclude the marshall function from javadoc
TingDaoK Oct 27, 2021
0505971
clean up the jobject local ref
TingDaoK Oct 27, 2021
a46a555
Merge branch 'h2-support' into h2-support-2
TingDaoK Oct 27, 2021
ae4bbc7
update the doc about null is acceptable
TingDaoK Oct 27, 2021
b5d7470
Merge branch 'h2-support' into h2-support-2
TingDaoK Oct 27, 2021
3661a3b
Merge branch 'h2-support' into h2-support-2
TingDaoK Oct 28, 2021
4191525
todo: testing
TingDaoK Oct 28, 2021
f774190
tests added
TingDaoK Oct 28, 2021
6e2534c
check the value range
TingDaoK Oct 28, 2021
4798e80
allocate array to the heap
TingDaoK Oct 28, 2021
0b7efcc
you need allocator
TingDaoK Oct 28, 2021
33eb144
zero check
TingDaoK Oct 29, 2021
f157d8c
http2 stream support
TingDaoK Oct 29, 2021
c989e4a
Merge branch 'main' into h2-support
TingDaoK Oct 29, 2021
6e32484
Merge branch 'h2-support' into h2-support-2
TingDaoK Oct 29, 2021
74c48f3
add comment
TingDaoK Oct 29, 2021
8fd7696
thanks mike for fixing the exception
TingDaoK Oct 29, 2021
7f8b905
http2 request
TingDaoK Nov 2, 2021
4d88b71
http2 request
TingDaoK Nov 2, 2021
ecf504e
update the test
TingDaoK Nov 2, 2021
40f9377
auto format
TingDaoK Nov 2, 2021
895edc6
formatting
TingDaoK Nov 2, 2021
3727158
elasticurl wip
graebm May 18, 2020
dcbb787
use async callback instead
TingDaoK Nov 3, 2021
73d937e
address comments from Mike
TingDaoK Nov 3, 2021
d1a9e13
Remove s from the name of structure
TingDaoK Nov 3, 2021
2f643d7
Merge branch 'h2-support-2' into h2-message-header
TingDaoK Nov 3, 2021
d2b70c6
use the tag
TingDaoK Nov 3, 2021
feec4a9
address comments
TingDaoK Nov 3, 2021
5d9d9ed
the empty path and method should be read out
TingDaoK Nov 3, 2021
0f8506a
add comments around to make it more clear
TingDaoK Nov 4, 2021
dc0c3c2
Merge branch 'h2-message-header' into h2-elasticurl
TingDaoK Nov 4, 2021
1d515c6
Merge branch 'main' into h2-support
TingDaoK Nov 4, 2021
57f1a64
It's working! TIME TO FIND Out how to run java now
TingDaoK Nov 4, 2021
c795b78
I don't know...
TingDaoK Nov 4, 2021
13945b1
let's see
TingDaoK Nov 4, 2021
6548135
next test
TingDaoK Nov 4, 2021
7c65045
use a runner to run elasticurl
TingDaoK Nov 5, 2021
958f8a9
update the script
TingDaoK Nov 5, 2021
e2503c9
The builder folder is magic
TingDaoK Nov 5, 2021
2a6f61f
hmmm
TingDaoK Nov 5, 2021
c817504
normal test first
TingDaoK Nov 5, 2021
aacde74
runner to take care the "\"" stuff
TingDaoK Nov 5, 2021
ec83d5c
protocol version -> Http version
TingDaoK Nov 5, 2021
14528c6
more compile error
TingDaoK Nov 5, 2021
97ef42c
had fun
TingDaoK Nov 5, 2021
50a501a
why it's failling harder
TingDaoK Nov 8, 2021
c2fb4af
add some debug info
TingDaoK Nov 8, 2021
aca4378
why
TingDaoK Nov 8, 2021
ffe074c
use the string as shell command
TingDaoK Nov 8, 2021
f842a7f
if windows
TingDaoK Nov 8, 2021
4d6ab13
remove shell
TingDaoK Nov 8, 2021
f369483
last shot about subprocess
TingDaoK Nov 8, 2021
6262328
use sh for testing
TingDaoK Nov 12, 2021
c580eac
bring the accidental comment out back
TingDaoK Nov 12, 2021
26f79eb
maybe this?
TingDaoK Nov 12, 2021
8bc6ffe
normal test
TingDaoK Nov 12, 2021
8c5068b
try not use shell?
TingDaoK Nov 12, 2021
9f496a4
Revert "try not use shell?"
TingDaoK Nov 13, 2021
406059f
clean things up
TingDaoK Nov 15, 2021
6ed625a
add warn level log
TingDaoK Nov 15, 2021
ad1bf7f
do we really need compress?
TingDaoK Nov 15, 2021
3be8129
missing unknown
TingDaoK Nov 15, 2021
adb9ef6
Merge branch 'main' into h2-support
TingDaoK Nov 30, 2021
c4a4c91
settings
TingDaoK Nov 30, 2021
f706974
Merge branch 'h2-support' of github.com:awslabs/aws-crt-java into h2-…
TingDaoK Dec 1, 2021
b1ef988
Merge branch 'main' into h2-support
TingDaoK Dec 1, 2021
4596ec4
Merge branch 'h2-support' into h2-elasticurl
TingDaoK Dec 2, 2021
191162c
settings
TingDaoK Dec 2, 2021
f677a14
update name
TingDaoK Dec 2, 2021
f19f1c5
merge conflict
TingDaoK Dec 2, 2021
24be4c8
revert the formatting change
TingDaoK Dec 2, 2021
7e250f8
Not sure it's a merge error or something
TingDaoK Dec 2, 2021
f4bc91c
override http 1.1 function to be un implemented for h2
TingDaoK Dec 6, 2021
7f5fd3f
sm wip
TingDaoK Jan 6, 2022
50e7f72
bascially it
TingDaoK Jan 13, 2022
d0a6c92
Merge branch 'main' into stream-manager
TingDaoK Jan 31, 2022
e776a52
use stream manager branch
TingDaoK Jan 31, 2022
979a253
java part finalizing
TingDaoK Jan 31, 2022
3957adb
Merge branch 'main' into http2-all
TingDaoK Jan 31, 2022
9df51fd
use the tag
TingDaoK Jan 31, 2022
9c2dab6
Merge branch 'http2-all' into stream-manager
TingDaoK Jan 31, 2022
b406ab4
get the stream public
TingDaoK Jan 31, 2022
2daf6fe
binding WIP
TingDaoK Feb 1, 2022
8936925
binding WIP
TingDaoK Feb 3, 2022
8849aa3
add tests and finalize binding
TingDaoK Feb 4, 2022
b33ba8d
git rid of the logs
TingDaoK Feb 4, 2022
279f5ab
use the version we got instead
TingDaoK Feb 4, 2022
fa2792c
Merge branch 'main' into http2-all
TingDaoK Feb 9, 2022
15a6e35
update submodules
TingDaoK Feb 9, 2022
2fa36cc
use the version we got instead
TingDaoK Feb 4, 2022
a82e280
Merge branch 'http2-all' into stream-manager
TingDaoK Feb 9, 2022
6b606c8
comment addressed
TingDaoK Feb 18, 2022
c65ff37
unified stream manager
TingDaoK Feb 21, 2022
82fd0dd
update test and add shutdown complete future
TingDaoK Feb 21, 2022
0a73ffc
remove the check as the resource is created outside the function
TingDaoK Feb 21, 2022
6de6dc4
remove log
TingDaoK Feb 21, 2022
43fda92
try to add assertion
TingDaoK Feb 21, 2022
0165c16
throw the original exception
TingDaoK Feb 21, 2022
2b69707
Add timeout and comments
TingDaoK Feb 21, 2022
84e30a8
fix a previous bug
TingDaoK Feb 22, 2022
f1e9479
make sure the exception throw out at the right place
TingDaoK Feb 23, 2022
3804371
update the comments
TingDaoK Feb 23, 2022
e3f31ff
Merge branch 'main' into http2-all
TingDaoK Feb 23, 2022
8c7adcb
Merge branch 'http2-all' into stream-manager
TingDaoK Feb 23, 2022
20687ac
Merge branch 'stream-manager' into unified-stream-manager
TingDaoK Feb 23, 2022
7be0f71
Merge branch 'main' into stream-manager
TingDaoK May 18, 2022
01f3475
fix a bunch of merge conflict
TingDaoK May 18, 2022
57794d9
input stream refcount stuff
TingDaoK May 18, 2022
8380667
trivial update
TingDaoK May 18, 2022
d760f08
try localhost ci
TingDaoK May 19, 2022
7878f61
checkout with submodules
TingDaoK May 19, 2022
26ed971
what's the file?
TingDaoK May 19, 2022
35a2314
the submodule is not updated
TingDaoK May 19, 2022
516acca
update more
TingDaoK May 19, 2022
afedcd9
fix osx
TingDaoK May 19, 2022
bdce86c
try just use mvn?
TingDaoK May 19, 2022
66d07cd
try to use action
TingDaoK May 19, 2022
8f6a2ac
add localhost test
TingDaoK May 20, 2022
78aebd8
forgot to commit action
TingDaoK May 20, 2022
a07b6bc
remove log
TingDaoK May 20, 2022
1b6d426
add test wtih body
TingDaoK May 21, 2022
372410d
test only 5?
TingDaoK May 22, 2022
945ca20
test 500
TingDaoK May 22, 2022
eb7bd25
added upload and download stress test
TingDaoK May 23, 2022
d84b032
add error level log
TingDaoK May 23, 2022
0194696
run again
TingDaoK May 23, 2022
fca7b3e
checkout the body received?
TingDaoK May 23, 2022
4a25bed
back to 2.5G
TingDaoK May 23, 2022
d01c96a
why????
TingDaoK May 23, 2022
dfce85f
more printout
TingDaoK May 23, 2022
b9aa5bc
more?
TingDaoK May 23, 2022
8217515
use join instead
TingDaoK May 24, 2022
d86b303
get the rest of CI back
TingDaoK May 24, 2022
6517d51
get rid of sutff not needed
TingDaoK May 24, 2022
11fe5c0
Merge branch 'localhost' into unified-stream-manager
TingDaoK Jun 2, 2022
e7ad920
add todo and remove things don't support anymore
TingDaoK Jun 2, 2022
6e565e9
fix broken api
TingDaoK Jun 2, 2022
037214e
Merge branch 'main' into stream-manager
TingDaoK Jun 4, 2022
77eac51
update submodules
TingDaoK Jun 4, 2022
6b32929
Merge branch 'main' into stream-manager
TingDaoK Jun 17, 2022
2c7cdab
adapt new api
TingDaoK Jun 17, 2022
a1f6f90
comments addressed
TingDaoK Jun 20, 2022
28d7417
Localhost test (#490)
TingDaoK Jun 21, 2022
d716423
Merge branch 'main' into stream-manager
TingDaoK Jun 21, 2022
7c37c64
Merge branch 'stream-manager' into unified-stream-manager
TingDaoK Jun 21, 2022
d2902cc
adapt new api
TingDaoK Jun 21, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .builder/actions/aws_crt_java_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

import Builder
import sys
import os


Expand All @@ -9,12 +10,15 @@ def run(self, env):
# tests must run with leak detection turned on
env.shell.setenv('AWS_CRT_MEMORY_TRACING', '2')
actions = []

if os.system("mvn -B test -DredirectTestOutputToFile=true -DforkCount=0 \
-DrerunFailingTestsCount=5 -DskipAfterFailureCount=1 \
-Daws.crt.memory.tracing=2 -Daws.crt.debugnative=true"):
# Failed
actions.append("exit 1")
os.system("cat log.txt")
python = sys.executable
actions.append(
[python, 'crt/aws-c-http/integration-testing/http_client_test.py',
python, 'integration-testing/java_elasticurl_runner.py'])

return Builder.Script(actions, name='aws-crt-java-test')
44 changes: 44 additions & 0 deletions integration-testing/java_elasticurl_runner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import sys
import os
import subprocess
import shlex

TIMEOUT = 100
# Runner for elasticurl integration tests

mvn_args = " ".join(map(shlex.quote, sys.argv[1:]))

java_command = ['mvn', '-e', 'exec:java', '-Dexec.classpathScope=\"test\"',
'-Dexec.mainClass=\"software.amazon.awssdk.crt.test.Elasticurl\"', '-Dexec.args=\"{}\"'.format(mvn_args)]

if os.name == 'nt':
# Windows uses mvn.cmd instead
java_command[0] = 'mvn.cmd'
command_string = " ".join(java_command)


def run_command(args_str):
print(args_str)
# gather all stderr and stdout to a single string that we print only if things go wrong
process = subprocess.Popen(
args_str, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)
timedout = False
try:
output = process.communicate(timeout=TIMEOUT)[0]
except subprocess.TimeoutExpired:
timedout = True
process.kill()
output = process.communicate()[0]
finally:
if process.returncode != 0 or timedout:
for line in output.splitlines():
print(line.decode())
if timedout:
raise RuntimeError("Timeout happened after {secs} secs from: {cmd}".format(
secs=TIMEOUT, cmd=args_str))
else:
raise RuntimeError("Return code {code} from: {cmd}".format(
code=process.returncode, cmd=args_str))


run_command(command_string)
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,12 @@
<version>1.10.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.4</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,9 @@ public int getTotalByteLength() {
}

/**
* Marshals a list of headers into a usable headers block for an event-stream message.
* Used for sending headers across the JNI boundary more efficiently
* @exclude Marshals a list of headers into a usable headers block for an
* event-stream message. Used for sending headers across the JNI
* boundary more efficiently
* @param headers list of headers to write to the headers block
* @return a byte[] that matches the event-stream header-block format.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package software.amazon.awssdk.crt.http;

import software.amazon.awssdk.crt.AsyncCallback;
import software.amazon.awssdk.crt.CrtRuntimeException;

import java.util.concurrent.CompletableFuture;
import java.util.List;

/**
* This class wraps aws-c-http to provide the basic HTTP/2 request/response
* functionality via the AWS Common Runtime.
*
* Http2ClientConnection represents a single connection to a HTTP/2 service
* endpoint.
*
* This class is not thread safe and should not be called from different
* threads.
*/
public class Http2ClientConnection extends HttpClientConnection {

/*
* Error codes that may be present in HTTP/2 RST_STREAM and GOAWAY frames
* (RFC-7540 7).
*/
public enum Http2ErrorCode {
PROTOCOL_ERROR(1), INTERNAL_ERROR(2), FLOW_CONTROL_ERROR(3), SETTINGS_TIMEOUT(4), STREAM_CLOSED(5),
FRAME_SIZE_ERROR(6), REFUSED_STREAM(7), CANCEL(8), COMPRESSION_ERROR(9), CONNECT_ERROR(10),
ENHANCE_YOUR_CALM(11), INADEQUATE_SECURITY(12), HTTP_1_1_REQUIRED(13);

private int errorCode;

Http2ErrorCode(int value) {
errorCode = value;
}

public int getValue() {
return errorCode;
}
}

public Http2ClientConnection(long connectionBinding) {
super(connectionBinding);
}

/**
* Send a SETTINGS frame. SETTINGS will be applied locally when SETTINGS ACK is
* received from peer.
*
* @param settings The array of settings to change. Note: each setting has its
* boundary.
*
* @return When this future completes without exception, the peer has
* acknowledged the settings and the change has been applied.
*/
public CompletableFuture<Void> updateSettings(final List<Http2ConnectionSetting> settings) {
CompletableFuture<Void> future = new CompletableFuture<>();
if (isNull()) {
future.completeExceptionally(
new IllegalStateException("Http2ClientConnection has been closed, can't change settings on it."));
return future;
}
AsyncCallback updateSettingsCompleted = AsyncCallback.wrapFuture(future, null);
try {
http2ClientConnectionUpdateSettings(getNativeHandle(), updateSettingsCompleted,
Http2ConnectionSetting.marshallSettingsForJNI(settings));
} catch (CrtRuntimeException ex) {
future.completeExceptionally(ex);
}
return future;
}

/**
* Send a PING frame. Round-trip-time is calculated when PING ACK is received
* from peer.
*
* @param pingData 8 Bytes data with the PING frame or null for not include data
* in ping
*
* @return When this future completes without exception, the peer has
* acknowledged the PING and future will be completed with the round
* trip time in nano seconds for the connection.
*/
public CompletableFuture<Long> sendPing(final byte[] pingData) {
CompletableFuture<Long> completionFuture = new CompletableFuture<>();
if (isNull()) {
completionFuture.completeExceptionally(
new IllegalStateException("Http2ClientConnection has been closed, can't send ping on it."));
return completionFuture;
}
AsyncCallback pingCompleted = AsyncCallback.wrapFuture(completionFuture, 0L);
try {
http2ClientConnectionSendPing(getNativeHandle(), pingCompleted, pingData);
} catch (CrtRuntimeException ex) {
completionFuture.completeExceptionally(ex);
}
return completionFuture;
}

public CompletableFuture<Long> sendPing() {
return this.sendPing(null);
}

/**
* Send a custom GOAWAY frame.
*
* Note that the connection automatically attempts to send a GOAWAY during
* shutdown (unless a GOAWAY with a valid Last-Stream-ID has already been sent).
*
* This call can be used to gracefully warn the peer of an impending shutdown
* (http2_error=0, allow_more_streams=true), or to customize the final GOAWAY
* frame that is sent by this connection.
*
* The other end may not receive the goaway, if the connection already closed.
*
* @param Http2ErrorCode The HTTP/2 error code (RFC-7540 section 7) to send.
* `enum Http2ErrorCode` lists official codes.
* @param allowMoreStreams If true, new peer-initiated streams will continue to
* be acknowledged and the GOAWAY's Last-Stream-ID will
* be set to a max value. If false, new peer-initiated
* streams will be ignored and the GOAWAY's
* Last-Stream-ID will be set to the latest acknowledged
* stream.
* @param debugData Optional debug data to send. Size must not exceed
* 16KB. null is acceptable to not include debug data.
*/
public void sendGoAway(final Http2ErrorCode Http2ErrorCode, final boolean allowMoreStreams,
final byte[] debugData) {
http2ClientConnectionSendGoAway(getNativeHandle(), (long) Http2ErrorCode.getValue(), allowMoreStreams,
debugData);
}

public void sendGoAway(final Http2ErrorCode Http2ErrorCode, final boolean allowMoreStreams) {
this.sendGoAway(Http2ErrorCode, allowMoreStreams, null);
}

/**
* Increment the connection's flow-control window to keep data flowing.
*
* If the connection was created with `manualWindowManagement` set true, the
* flow-control window of the connection will shrink as body data is received
* for all the streams created on it. (headers, padding, and other metadata do
* not affect the window). The initial connection flow-control window is 65,535.
* Once the connection's flow-control window reaches to 0, all the streams on
* the connection stop receiving any further data.
*
* If `manualWindowManagement` is false, this call will have no effect. The
* connection maintains its flow-control windows such that no back-pressure is
* applied and data arrives as fast as possible.
*
* If you are not connected, this call will have no effect.
*
* Crashes when the connection is not http2 connection. The limit of the Maximum
* Size is 2**31 - 1. If the increment size cause the connection flow window
* exceeds the Maximum size, this call will result in the connection lost.
*
* @param increment_size The size to increment for the connection's flow control
* window
*/
public void updateConnectionWindow(long incrementSize) {
if (incrementSize > 4294967296L || incrementSize < 0) {
throw new IllegalArgumentException("increment size cannot exceed 4294967296");
}
http2ClientConnectionUpdateConnectionWindow(getNativeHandle(), incrementSize);
}

/**
* Schedules an HttpRequest on the Native EventLoop for this
* HttpClientConnection. The HTTP/1.1 request will be transformed to HTTP/2
* request under the hood.
*
* @param request The Request to make to the Server.
* @param streamHandler The Stream Handler to be called from the Native
* EventLoop
* @throws CrtRuntimeException if stream creation fails
* @return The Http2Stream that represents this Request/Response Pair. It can be
* closed at any time during the request/response, but must be closed by
* the user thread making this request when it's done.
*/
@Override
public Http2Stream makeRequest(HttpRequestBase request, HttpStreamResponseHandler streamHandler)
throws CrtRuntimeException {
if (isNull()) {
throw new IllegalStateException("Http2ClientConnection has been closed, can't make requests on it.");
}

Http2Stream stream = http2ClientConnectionMakeRequest(getNativeHandle(), request.marshalForJni(),
request.getBodyStream(), new HttpStreamResponseHandlerNativeAdapter(streamHandler));
return stream;
}

/**
* @TODO: bindings for getters of local/remote setting and goaway.
*/
/*******************************************************************************
* Native methods
******************************************************************************/

private static native Http2Stream http2ClientConnectionMakeRequest(long connectionBinding, byte[] marshalledRequest,
HttpRequestBodyStream bodyStream, HttpStreamResponseHandlerNativeAdapter responseHandler)
throws CrtRuntimeException;

private static native void http2ClientConnectionUpdateSettings(long connectionBinding,
AsyncCallback completedCallback, long[] marshalledSettings) throws CrtRuntimeException;

private static native void http2ClientConnectionSendPing(long connectionBinding, AsyncCallback completedCallback,
byte[] pingData) throws CrtRuntimeException;

private static native void http2ClientConnectionSendGoAway(long connectionBinding, long h2ErrorCode,
boolean allowMoreStreams, byte[] debugData) throws CrtRuntimeException;

private static native void http2ClientConnectionUpdateConnectionWindow(long connectionBinding, long incrementSize)
throws CrtRuntimeException;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

package software.amazon.awssdk.crt.http;

import java.util.List;

public class Http2ConnectionSetting {
/**
* Predefined settings identifiers (RFC-7540 6.5.2).
*/
public enum ID {
HEADER_TABLE_SIZE(1), ENABLE_PUSH(2), MAX_CONCURRENT_STREAMS(3), INITIAL_WINDOW_SIZE(4), MAX_FRAME_SIZE(5),
MAX_HEADER_LIST_SIZE(6);

private int settingID;

ID(int value) {
settingID = value;
}

public int getValue() {
return settingID;
}
}

private ID id;
private long value;

public long getValue() {
return value;
}

public ID getId() {
return id;
}

/**
* HTTP/2 connection settings.
*
* value is limited from 0 to UINT32_MAX (RFC-7540 6.5.1)
*/
public Http2ConnectionSetting(ID id, long value) {
if (value > 4294967296L || value < 0) {
throw new IllegalArgumentException();
}
this.id = id;
this.value = value;
}

/**
* @exclude Marshals a list of settings into an array for Jni to deal with.
*
* @param settings list of headers to write to the headers block
* @return a long[] that with the [id, value, id, value, *]
*/
public static long[] marshallSettingsForJNI(final List<Http2ConnectionSetting> settings) {
/* Each setting is two long */
int totalLength = settings.size();

long marshalledSettings[] = new long[totalLength * 2];

for (int i = 0; i < totalLength; i++) {
marshalledSettings[i * 2] = settings.get(i).id.getValue();
marshalledSettings[i * 2 + 1] = settings.get(i).value;
}

return marshalledSettings;
}
}
Loading