-
Notifications
You must be signed in to change notification settings - Fork 17
/
ConnectPacket.java
211 lines (191 loc) · 7.42 KB
/
ConnectPacket.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
* Copyright 2018-present HiveMQ GmbH
*
* Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.hivemq.extension.sdk.api.packets.connect;
import com.hivemq.extension.sdk.api.annotations.DoNotImplement;
import com.hivemq.extension.sdk.api.annotations.Immutable;
import com.hivemq.extension.sdk.api.annotations.NotNull;
import com.hivemq.extension.sdk.api.interceptor.connect.ConnectInboundInterceptor;
import com.hivemq.extension.sdk.api.packets.general.MqttVersion;
import com.hivemq.extension.sdk.api.packets.general.UserProperties;
import com.hivemq.extension.sdk.api.services.publish.Publish;
import java.nio.ByteBuffer;
import java.util.Optional;
/**
* Contains all information from a CONNECT packet.
*
* @author Christoph Schäbel
* @since 4.0.0, CE 2019.1
*/
@DoNotImplement
@Immutable
public interface ConnectPacket {
/**
* The {@link MqttVersion} the clients wants to use for the connection.
*
* @return The MQTT version.
* @since 4.0.0, CE 2019.1
*/
@NotNull MqttVersion getMqttVersion();
/**
* The client identifier the client wants to use.
* <p>
* An MQTT 5 client may send an empty string.
*
* @return The client identifier.
* @since 4.0.0, CE 2019.1
*/
@NotNull String getClientId();
/**
* Flag that indicates if the existing session for the client should be continued (<code>false</code>) or the
* existing session should be overwritten (<code>true</code>). Has no effect if no session for the client exists.
* <p>
* For an MQTT 3 client, this MQTT 5 property can be interpreted as followed:
* <ul>
* <li>cleanSession = true -> cleanStart = true
* <li>cleanSession = false -> cleanStart = false
* </ul>
*
* @return The clean start flag.
* @since 4.0.0, CE 2019.1
*/
boolean getCleanStart();
/**
* Contains the {@link WillPublishPacket} if it was sent in the CONNECT packet.
*
* @return An {@link Optional} that contains the {@link WillPublishPacket} if present.
* @since 4.0.0, CE 2019.1
*/
@NotNull Optional<WillPublishPacket> getWillPublish();
/**
* Duration in seconds how long session for the client is stored.
* <p>
* For an MQTT 3 client, this MQTT 5 property can be interpreted as followed:
* <ul>
* <li>cleanSession = true -> sessionExpiryInterval = 0
* <li>cleanSession = false -> sessionExpiryInterval = The configured {@code <session-expiry>} in the {@code
* <mqtt>} config in the config.xml. Default: 4294967295
* </ul>
*
* @return The session expiry interval.
* @since 4.0.0, CE 2019.1
*/
long getSessionExpiryInterval();
/**
* An interval in seconds in which the client has to send any MQTT control packet, so that HiveMQ doesn't end the
* connection.
*
* @return The keep alive.
* @since 4.0.0, CE 2019.1
*/
int getKeepAlive();
/**
* The limit of QoS 1 and QoS 2 {@link Publish}es that the client is willing to process concurrently.
* <p>
* For an MQTT 3 client this MQTT 5 property will always be 65,535.
*
* @return The receive maximum.
* @since 4.0.0, CE 2019.1
*/
int getReceiveMaximum();
/**
* The maximum packet size in bytes for an MQTT Control Packet, the client is willing to accept.
* <p>
* For an MQTT 3 client this MQTT 5 property will always be 268435460 bytes (protocol limit for the packet size).
*
* @return The maximum packet size.
* @since 4.0.0, CE 2019.1
*/
long getMaximumPacketSize();
/**
* The maximum amount of topic alias the client allows for this connection.
* <p>
* For an MQTT 3 client this MQTT 5 property will always be 0.
*
* @return The topic alias maximum.
* @since 4.0.0, CE 2019.1
*/
int getTopicAliasMaximum();
/**
* This flag indicates if the client wants to receive Response Information in the CONNACK packet (<code>true</code>)
* or not (<code>false</code>).
* <p>
* For an MQTT 3 client this MQTT 5 property will always be false.
*
* @return The request response information flag.
* @since 4.0.0, CE 2019.1
*/
boolean getRequestResponseInformation();
/**
* This flag indicates if the server may sent Reason String or User Properties in the case of failures. If
* <code>true</code> server may sent these in any MQTT packet, for <code>false</code> they may only be sent in a
* PUBLISH, CONNACK, or DISCONNECT packet.
* <p>
* For an MQTT 3 client this MQTT 5 property will always be false. This can be ignored for MQTT 3 clients.
*
* @return The request problem information flag.
* @since 4.0.0, CE 2019.1
*/
boolean getRequestProblemInformation();
/**
* If this property is present, the string contains the authentication method that should be used for the extended
* authentication.
* <p>
* For an MQTT 3 client this property can be set in the {@link ConnectInboundInterceptor}.
*
* @return An {@link Optional} that contains the authentication method if present.
* @since 4.0.0, CE 2019.1
*/
@NotNull Optional<String> getAuthenticationMethod();
/**
* If this property is present, the {@link ByteBuffer} contains the data used for the extended authentication. The
* contents of this data are defined by the authentication method.
* <p>
* For an MQTT 3 client this property can be set in the {@link ConnectInboundInterceptor}.
* <p>
* The ByteBuffer returned by this method is {@link ByteBuffer#asReadOnlyBuffer() read only} and will throw a
* {@link java.nio.ReadOnlyBufferException ReadOnlyBufferException} if handled incorrectly.
*
* @return An {@link Optional} that contains the authentication data if present.
* @since 4.0.0, CE 2019.1
*/
@NotNull Optional<@Immutable ByteBuffer> getAuthenticationData();
/**
* The user properties from the CONNECT packet.
* <p>
* For an MQTT 3 client this property can be set in the {@link ConnectInboundInterceptor}.
*
* @return The user properties.
* @since 4.0.0, CE 2019.1
*/
@NotNull UserProperties getUserProperties();
/**
* If this property is present, this is the username for the client.
*
* @return An {@link Optional} that contains the username if present.
* @since 4.0.0, CE 2019.1
*/
@NotNull Optional<String> getUserName();
/**
* If this property is present, this is the password for the client.
* <p>
* The ByteBuffer returned by this method is {@link ByteBuffer#asReadOnlyBuffer() read only} and will throw a
* {@link java.nio.ReadOnlyBufferException ReadOnlyBufferException} if handled incorrectly.
*
* @return An {@link Optional} that contains the password if present.
* @since 4.0.0, CE 2019.1
*/
@NotNull Optional<@Immutable ByteBuffer> getPassword();
}