Remove 'get' prefix
This commit is contained in:
parent
eacc474cda
commit
4472fe9795
@ -28,7 +28,7 @@ import java.net.URI;
|
|||||||
*/
|
*/
|
||||||
public abstract class WebSocketClientHandshaker {
|
public abstract class WebSocketClientHandshaker {
|
||||||
|
|
||||||
private final URI webSocketUrl;
|
private final URI uri;
|
||||||
|
|
||||||
private final WebSocketVersion version;
|
private final WebSocketVersion version;
|
||||||
|
|
||||||
@ -45,7 +45,7 @@ public abstract class WebSocketClientHandshaker {
|
|||||||
/**
|
/**
|
||||||
* Base constructor
|
* Base constructor
|
||||||
*
|
*
|
||||||
* @param webSocketUrl
|
* @param uri
|
||||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||||
* sent to this URL.
|
* sent to this URL.
|
||||||
* @param version
|
* @param version
|
||||||
@ -57,9 +57,9 @@ public abstract class WebSocketClientHandshaker {
|
|||||||
* @param maxFramePayloadLength
|
* @param maxFramePayloadLength
|
||||||
* Maximum length of a frame's payload
|
* Maximum length of a frame's payload
|
||||||
*/
|
*/
|
||||||
protected WebSocketClientHandshaker(URI webSocketUrl, WebSocketVersion version, String subprotocol,
|
protected WebSocketClientHandshaker(URI uri, WebSocketVersion version, String subprotocol,
|
||||||
HttpHeaders customHeaders, int maxFramePayloadLength) {
|
HttpHeaders customHeaders, int maxFramePayloadLength) {
|
||||||
this.webSocketUrl = webSocketUrl;
|
this.uri = uri;
|
||||||
this.version = version;
|
this.version = version;
|
||||||
expectedSubprotocol = subprotocol;
|
expectedSubprotocol = subprotocol;
|
||||||
this.customHeaders = customHeaders;
|
this.customHeaders = customHeaders;
|
||||||
@ -69,21 +69,21 @@ public abstract class WebSocketClientHandshaker {
|
|||||||
/**
|
/**
|
||||||
* Returns the URI to the web socket. e.g. "ws://myhost.com/path"
|
* Returns the URI to the web socket. e.g. "ws://myhost.com/path"
|
||||||
*/
|
*/
|
||||||
public URI getWebSocketUrl() {
|
public URI uri() {
|
||||||
return webSocketUrl;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Version of the web socket specification that is being used
|
* Version of the web socket specification that is being used
|
||||||
*/
|
*/
|
||||||
public WebSocketVersion getVersion() {
|
public WebSocketVersion version() {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the max length for any frame's payload
|
* Returns the max length for any frame's payload
|
||||||
*/
|
*/
|
||||||
public int getMaxFramePayloadLength() {
|
public int maxFramePayloadLength() {
|
||||||
return maxFramePayloadLength;
|
return maxFramePayloadLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +101,7 @@ public abstract class WebSocketClientHandshaker {
|
|||||||
/**
|
/**
|
||||||
* Returns the CSV of requested subprotocol(s) sent to the server as specified in the constructor
|
* Returns the CSV of requested subprotocol(s) sent to the server as specified in the constructor
|
||||||
*/
|
*/
|
||||||
public String getExpectedSubprotocol() {
|
public String expectedSubprotocol() {
|
||||||
return expectedSubprotocol;
|
return expectedSubprotocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ public abstract class WebSocketClientHandshaker {
|
|||||||
* Returns the subprotocol response sent by the server. Only available after end of handshake.
|
* Returns the subprotocol response sent by the server. Only available after end of handshake.
|
||||||
* Null if no subprotocol was requested or confirmed by the server.
|
* Null if no subprotocol was requested or confirmed by the server.
|
||||||
*/
|
*/
|
||||||
public String getActualSubprotocol() {
|
public String actualSubprotocol() {
|
||||||
return actualSubprotocol;
|
return actualSubprotocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
|
|||||||
expectedChallengeResponseBytes = WebSocketUtil.md5(challenge);
|
expectedChallengeResponseBytes = WebSocketUtil.md5(challenge);
|
||||||
|
|
||||||
// Get path
|
// Get path
|
||||||
URI wsURL = getWebSocketUrl();
|
URI wsURL = uri();
|
||||||
String path = wsURL.getPath();
|
String path = wsURL.getPath();
|
||||||
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
|
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
|
||||||
path = wsURL.getPath() + '?' + wsURL.getQuery();
|
path = wsURL.getPath() + '?' + wsURL.getQuery();
|
||||||
@ -159,7 +159,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
|
|||||||
.add(Names.SEC_WEBSOCKET_KEY1, key1)
|
.add(Names.SEC_WEBSOCKET_KEY1, key1)
|
||||||
.add(Names.SEC_WEBSOCKET_KEY2, key2);
|
.add(Names.SEC_WEBSOCKET_KEY2, key2);
|
||||||
|
|
||||||
String expectedSubprotocol = getExpectedSubprotocol();
|
String expectedSubprotocol = expectedSubprotocol();
|
||||||
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
|
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
|
||||||
headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
|
headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
|
||||||
}
|
}
|
||||||
@ -250,7 +250,7 @@ public class WebSocketClientHandshaker00 extends WebSocketClientHandshaker {
|
|||||||
ChannelPipeline p = channel.pipeline();
|
ChannelPipeline p = channel.pipeline();
|
||||||
p.remove(HttpRequestEncoder.class);
|
p.remove(HttpRequestEncoder.class);
|
||||||
p.get(HttpResponseDecoder.class).replace(
|
p.get(HttpResponseDecoder.class).replace(
|
||||||
"ws-decoder", new WebSocket00FrameDecoder(getMaxFramePayloadLength()));
|
"ws-decoder", new WebSocket00FrameDecoder(maxFramePayloadLength()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String insertRandomCharacters(String key) {
|
private static String insertRandomCharacters(String key) {
|
||||||
|
@ -100,7 +100,7 @@ public class WebSocketClientHandshaker07 extends WebSocketClientHandshaker {
|
|||||||
@Override
|
@Override
|
||||||
public ChannelFuture handshake(Channel channel, final ChannelPromise promise) {
|
public ChannelFuture handshake(Channel channel, final ChannelPromise promise) {
|
||||||
// Get path
|
// Get path
|
||||||
URI wsURL = getWebSocketUrl();
|
URI wsURL = uri();
|
||||||
String path = wsURL.getPath();
|
String path = wsURL.getPath();
|
||||||
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
|
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
|
||||||
path = wsURL.getPath() + '?' + wsURL.getQuery();
|
path = wsURL.getPath() + '?' + wsURL.getQuery();
|
||||||
@ -141,7 +141,7 @@ public class WebSocketClientHandshaker07 extends WebSocketClientHandshaker {
|
|||||||
}
|
}
|
||||||
headers.add(Names.SEC_WEBSOCKET_ORIGIN, originValue);
|
headers.add(Names.SEC_WEBSOCKET_ORIGIN, originValue);
|
||||||
|
|
||||||
String expectedSubprotocol = getExpectedSubprotocol();
|
String expectedSubprotocol = expectedSubprotocol();
|
||||||
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
|
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
|
||||||
headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
|
headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
|
||||||
}
|
}
|
||||||
@ -224,6 +224,6 @@ public class WebSocketClientHandshaker07 extends WebSocketClientHandshaker {
|
|||||||
ChannelPipeline p = channel.pipeline();
|
ChannelPipeline p = channel.pipeline();
|
||||||
p.get(HttpResponseDecoder.class).replace(
|
p.get(HttpResponseDecoder.class).replace(
|
||||||
"ws-decoder",
|
"ws-decoder",
|
||||||
new WebSocket07FrameDecoder(false, allowExtensions, getMaxFramePayloadLength()));
|
new WebSocket07FrameDecoder(false, allowExtensions, maxFramePayloadLength()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
|||||||
@Override
|
@Override
|
||||||
public ChannelFuture handshake(Channel channel, final ChannelPromise promise) {
|
public ChannelFuture handshake(Channel channel, final ChannelPromise promise) {
|
||||||
// Get path
|
// Get path
|
||||||
URI wsURL = getWebSocketUrl();
|
URI wsURL = uri();
|
||||||
String path = wsURL.getPath();
|
String path = wsURL.getPath();
|
||||||
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
|
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
|
||||||
path = wsURL.getPath() + '?' + wsURL.getQuery();
|
path = wsURL.getPath() + '?' + wsURL.getQuery();
|
||||||
@ -141,7 +141,7 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
|||||||
}
|
}
|
||||||
headers.add(Names.SEC_WEBSOCKET_ORIGIN, originValue);
|
headers.add(Names.SEC_WEBSOCKET_ORIGIN, originValue);
|
||||||
|
|
||||||
String expectedSubprotocol = getExpectedSubprotocol();
|
String expectedSubprotocol = expectedSubprotocol();
|
||||||
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
|
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
|
||||||
headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
|
headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
|
||||||
}
|
}
|
||||||
@ -225,6 +225,6 @@ public class WebSocketClientHandshaker08 extends WebSocketClientHandshaker {
|
|||||||
p.remove(HttpRequestEncoder.class);
|
p.remove(HttpRequestEncoder.class);
|
||||||
p.get(HttpResponseDecoder.class).replace(
|
p.get(HttpResponseDecoder.class).replace(
|
||||||
"ws-decoder",
|
"ws-decoder",
|
||||||
new WebSocket08FrameDecoder(false, allowExtensions, getMaxFramePayloadLength()));
|
new WebSocket08FrameDecoder(false, allowExtensions, maxFramePayloadLength()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,7 +100,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
|||||||
@Override
|
@Override
|
||||||
public ChannelFuture handshake(Channel channel, final ChannelPromise promise) {
|
public ChannelFuture handshake(Channel channel, final ChannelPromise promise) {
|
||||||
// Get path
|
// Get path
|
||||||
URI wsURL = getWebSocketUrl();
|
URI wsURL = uri();
|
||||||
String path = wsURL.getPath();
|
String path = wsURL.getPath();
|
||||||
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
|
if (wsURL.getQuery() != null && !wsURL.getQuery().isEmpty()) {
|
||||||
path = wsURL.getPath() + '?' + wsURL.getQuery();
|
path = wsURL.getPath() + '?' + wsURL.getQuery();
|
||||||
@ -141,7 +141,7 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
|||||||
}
|
}
|
||||||
headers.add(Names.SEC_WEBSOCKET_ORIGIN, originValue);
|
headers.add(Names.SEC_WEBSOCKET_ORIGIN, originValue);
|
||||||
|
|
||||||
String expectedSubprotocol = getExpectedSubprotocol();
|
String expectedSubprotocol = expectedSubprotocol();
|
||||||
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
|
if (expectedSubprotocol != null && !expectedSubprotocol.isEmpty()) {
|
||||||
headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
|
headers.add(Names.SEC_WEBSOCKET_PROTOCOL, expectedSubprotocol);
|
||||||
}
|
}
|
||||||
@ -224,6 +224,6 @@ public class WebSocketClientHandshaker13 extends WebSocketClientHandshaker {
|
|||||||
p.remove(HttpRequestEncoder.class);
|
p.remove(HttpRequestEncoder.class);
|
||||||
p.get(HttpResponseDecoder.class).replace(
|
p.get(HttpResponseDecoder.class).replace(
|
||||||
"ws-decoder",
|
"ws-decoder",
|
||||||
new WebSocket13FrameDecoder(false, allowExtensions, getMaxFramePayloadLength()));
|
new WebSocket13FrameDecoder(false, allowExtensions, maxFramePayloadLength()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public abstract class WebSocketServerHandshaker {
|
|||||||
|
|
||||||
private static final String[] EMPTY_ARRAY = new String[0];
|
private static final String[] EMPTY_ARRAY = new String[0];
|
||||||
|
|
||||||
private final String webSocketUrl;
|
private final String uri;
|
||||||
|
|
||||||
private final String[] subprotocols;
|
private final String[] subprotocols;
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ public abstract class WebSocketServerHandshaker {
|
|||||||
*
|
*
|
||||||
* @param version
|
* @param version
|
||||||
* the protocol version
|
* the protocol version
|
||||||
* @param webSocketUrl
|
* @param uri
|
||||||
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
* URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
|
||||||
* sent to this URL.
|
* sent to this URL.
|
||||||
* @param subprotocols
|
* @param subprotocols
|
||||||
@ -56,10 +56,10 @@ public abstract class WebSocketServerHandshaker {
|
|||||||
* Maximum length of a frame's payload
|
* Maximum length of a frame's payload
|
||||||
*/
|
*/
|
||||||
protected WebSocketServerHandshaker(
|
protected WebSocketServerHandshaker(
|
||||||
WebSocketVersion version, String webSocketUrl, String subprotocols,
|
WebSocketVersion version, String uri, String subprotocols,
|
||||||
int maxFramePayloadLength) {
|
int maxFramePayloadLength) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
this.webSocketUrl = webSocketUrl;
|
this.uri = uri;
|
||||||
if (subprotocols != null) {
|
if (subprotocols != null) {
|
||||||
String[] subprotocolArray = StringUtil.split(subprotocols, ',');
|
String[] subprotocolArray = StringUtil.split(subprotocols, ',');
|
||||||
for (int i = 0; i < subprotocolArray.length; i++) {
|
for (int i = 0; i < subprotocolArray.length; i++) {
|
||||||
@ -75,14 +75,14 @@ public abstract class WebSocketServerHandshaker {
|
|||||||
/**
|
/**
|
||||||
* Returns the URL of the web socket
|
* Returns the URL of the web socket
|
||||||
*/
|
*/
|
||||||
public String getWebSocketUrl() {
|
public String uri() {
|
||||||
return webSocketUrl;
|
return uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the CSV of supported sub protocols
|
* Returns the CSV of supported sub protocols
|
||||||
*/
|
*/
|
||||||
public Set<String> getSubprotocols() {
|
public Set<String> subprotocols() {
|
||||||
Set<String> ret = new LinkedHashSet<String>();
|
Set<String> ret = new LinkedHashSet<String>();
|
||||||
Collections.addAll(ret, subprotocols);
|
Collections.addAll(ret, subprotocols);
|
||||||
return ret;
|
return ret;
|
||||||
@ -91,7 +91,7 @@ public abstract class WebSocketServerHandshaker {
|
|||||||
/**
|
/**
|
||||||
* Returns the version of the specification being supported
|
* Returns the version of the specification being supported
|
||||||
*/
|
*/
|
||||||
public WebSocketVersion getVersion() {
|
public WebSocketVersion version() {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ public abstract class WebSocketServerHandshaker {
|
|||||||
*
|
*
|
||||||
* @return The maximum length for a frame's payload
|
* @return The maximum length for a frame's payload
|
||||||
*/
|
*/
|
||||||
public int getMaxFramePayloadLength() {
|
public int maxFramePayloadLength() {
|
||||||
return maxFramePayloadLength;
|
return maxFramePayloadLength;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,7 +191,7 @@ public abstract class WebSocketServerHandshaker {
|
|||||||
* This is only available AFTER <tt>handshake()</tt> has been called.
|
* This is only available AFTER <tt>handshake()</tt> has been called.
|
||||||
* </p>
|
* </p>
|
||||||
*/
|
*/
|
||||||
public String getSelectedSubprotocol() {
|
public String selectedSubprotocol() {
|
||||||
return selectedSubprotocol;
|
return selectedSubprotocol;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
|||||||
if (isHixie76) {
|
if (isHixie76) {
|
||||||
// New handshake method with a challenge:
|
// New handshake method with a challenge:
|
||||||
res.headers().add(SEC_WEBSOCKET_ORIGIN, req.headers().get(ORIGIN));
|
res.headers().add(SEC_WEBSOCKET_ORIGIN, req.headers().get(ORIGIN));
|
||||||
res.headers().add(SEC_WEBSOCKET_LOCATION, getWebSocketUrl());
|
res.headers().add(SEC_WEBSOCKET_LOCATION, uri());
|
||||||
String subprotocols = req.headers().get(SEC_WEBSOCKET_PROTOCOL);
|
String subprotocols = req.headers().get(SEC_WEBSOCKET_PROTOCOL);
|
||||||
if (subprotocols != null) {
|
if (subprotocols != null) {
|
||||||
String selectedSubprotocol = selectSubprotocol(subprotocols);
|
String selectedSubprotocol = selectSubprotocol(subprotocols);
|
||||||
@ -172,7 +172,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
|||||||
} else {
|
} else {
|
||||||
// Old Hixie 75 handshake method with no challenge:
|
// Old Hixie 75 handshake method with no challenge:
|
||||||
res.headers().add(WEBSOCKET_ORIGIN, req.headers().get(ORIGIN));
|
res.headers().add(WEBSOCKET_ORIGIN, req.headers().get(ORIGIN));
|
||||||
res.headers().add(WEBSOCKET_LOCATION, getWebSocketUrl());
|
res.headers().add(WEBSOCKET_LOCATION, uri());
|
||||||
String protocol = req.headers().get(WEBSOCKET_PROTOCOL);
|
String protocol = req.headers().get(WEBSOCKET_PROTOCOL);
|
||||||
if (protocol != null) {
|
if (protocol != null) {
|
||||||
res.headers().add(WEBSOCKET_PROTOCOL, selectSubprotocol(protocol));
|
res.headers().add(WEBSOCKET_PROTOCOL, selectSubprotocol(protocol));
|
||||||
@ -189,7 +189,7 @@ public class WebSocketServerHandshaker00 extends WebSocketServerHandshaker {
|
|||||||
p.remove(HttpObjectAggregator.class);
|
p.remove(HttpObjectAggregator.class);
|
||||||
}
|
}
|
||||||
p.get(HttpRequestDecoder.class).replace("wsdecoder",
|
p.get(HttpRequestDecoder.class).replace("wsdecoder",
|
||||||
new WebSocket00FrameDecoder(getMaxFramePayloadLength()));
|
new WebSocket00FrameDecoder(maxFramePayloadLength()));
|
||||||
|
|
||||||
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket00FrameEncoder());
|
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket00FrameEncoder());
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ public class WebSocketServerHandshaker07 extends WebSocketServerHandshaker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.get(HttpRequestDecoder.class).replace("wsdecoder",
|
p.get(HttpRequestDecoder.class).replace("wsdecoder",
|
||||||
new WebSocket07FrameDecoder(true, allowExtensions, getMaxFramePayloadLength()));
|
new WebSocket07FrameDecoder(true, allowExtensions, maxFramePayloadLength()));
|
||||||
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket07FrameEncoder(false));
|
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket07FrameEncoder(false));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -156,7 +156,7 @@ public class WebSocketServerHandshaker08 extends WebSocketServerHandshaker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.get(HttpRequestDecoder.class).replace("wsdecoder",
|
p.get(HttpRequestDecoder.class).replace("wsdecoder",
|
||||||
new WebSocket08FrameDecoder(true, allowExtensions, getMaxFramePayloadLength()));
|
new WebSocket08FrameDecoder(true, allowExtensions, maxFramePayloadLength()));
|
||||||
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket08FrameEncoder(false));
|
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket08FrameEncoder(false));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -156,7 +156,7 @@ public class WebSocketServerHandshaker13 extends WebSocketServerHandshaker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
p.get(HttpRequestDecoder.class).replace("wsdecoder",
|
p.get(HttpRequestDecoder.class).replace("wsdecoder",
|
||||||
new WebSocket13FrameDecoder(true, allowExtensions, getMaxFramePayloadLength()));
|
new WebSocket13FrameDecoder(true, allowExtensions, maxFramePayloadLength()));
|
||||||
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket13FrameEncoder(false));
|
p.replace(HttpResponseEncoder.class, "wsencoder", new WebSocket13FrameEncoder(false));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -96,7 +96,7 @@ public abstract class SpdyOrHttpChooser extends ChannelHandlerAdapter implements
|
|||||||
throw new IllegalStateException("SslHandler is needed for SPDY");
|
throw new IllegalStateException("SslHandler is needed for SPDY");
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectedProtocol protocol = getProtocol(handler.getEngine());
|
SelectedProtocol protocol = getProtocol(handler.engine());
|
||||||
switch (protocol) {
|
switch (protocol) {
|
||||||
case None:
|
case None:
|
||||||
// Not done with choosing the protocol, so just return here for now,
|
// Not done with choosing the protocol, so just return here for now,
|
||||||
|
@ -153,10 +153,8 @@ public class WebSocketServerProtocolHandlerTest {
|
|||||||
content = "processed: " + msg.text();
|
content = "processed: " + msg.text();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getContent() {
|
String getContent() {
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ public final class SocksAuthRequest extends SocksRequest {
|
|||||||
*
|
*
|
||||||
* @return username that needs to be authenticated
|
* @return username that needs to be authenticated
|
||||||
*/
|
*/
|
||||||
public String getUsername() {
|
public String username() {
|
||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ public final class SocksAuthRequest extends SocksRequest {
|
|||||||
*
|
*
|
||||||
* @return password that needs to be validated
|
* @return password that needs to be validated
|
||||||
*/
|
*/
|
||||||
public String getPassword() {
|
public String password() {
|
||||||
return password;
|
return password;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public final class SocksAuthResponse extends SocksResponse {
|
|||||||
*
|
*
|
||||||
* @return The {@link AuthStatus} of this {@link SocksAuthResponse}
|
* @return The {@link AuthStatus} of this {@link SocksAuthResponse}
|
||||||
*/
|
*/
|
||||||
public AuthStatus getAuthStatus() {
|
public AuthStatus authStatus() {
|
||||||
return authStatus;
|
return authStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +77,7 @@ public final class SocksCmdRequest extends SocksRequest {
|
|||||||
*
|
*
|
||||||
* @return The {@link CmdType} of this {@link SocksCmdRequest}
|
* @return The {@link CmdType} of this {@link SocksCmdRequest}
|
||||||
*/
|
*/
|
||||||
public CmdType getCmdType() {
|
public CmdType cmdType() {
|
||||||
return cmdType;
|
return cmdType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,7 +86,7 @@ public final class SocksCmdRequest extends SocksRequest {
|
|||||||
*
|
*
|
||||||
* @return The {@link AddressType} of this {@link SocksCmdRequest}
|
* @return The {@link AddressType} of this {@link SocksCmdRequest}
|
||||||
*/
|
*/
|
||||||
public AddressType getAddressType() {
|
public AddressType addressType() {
|
||||||
return addressType;
|
return addressType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ public final class SocksCmdRequest extends SocksRequest {
|
|||||||
*
|
*
|
||||||
* @return host that is used as a parameter in {@link CmdType}
|
* @return host that is used as a parameter in {@link CmdType}
|
||||||
*/
|
*/
|
||||||
public String getHost() {
|
public String host() {
|
||||||
return IDN.toUnicode(host);
|
return IDN.toUnicode(host);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,13 +104,13 @@ public final class SocksCmdRequest extends SocksRequest {
|
|||||||
*
|
*
|
||||||
* @return port that is used as a parameter in {@link CmdType}
|
* @return port that is used as a parameter in {@link CmdType}
|
||||||
*/
|
*/
|
||||||
public int getPort() {
|
public int port() {
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||||
byteBuf.writeByte(getProtocolVersion().getByteValue());
|
byteBuf.writeByte(protocolVersion().getByteValue());
|
||||||
byteBuf.writeByte(cmdType.getByteValue());
|
byteBuf.writeByte(cmdType.getByteValue());
|
||||||
byteBuf.writeByte(0x00);
|
byteBuf.writeByte(0x00);
|
||||||
byteBuf.writeByte(addressType.getByteValue());
|
byteBuf.writeByte(addressType.getByteValue());
|
||||||
|
@ -51,7 +51,7 @@ public final class SocksCmdResponse extends SocksResponse {
|
|||||||
*
|
*
|
||||||
* @return The {@link CmdStatus} of this {@link SocksCmdResponse}
|
* @return The {@link CmdStatus} of this {@link SocksCmdResponse}
|
||||||
*/
|
*/
|
||||||
public CmdStatus getCmdStatus() {
|
public CmdStatus cmdStatus() {
|
||||||
return cmdStatus;
|
return cmdStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,13 +60,13 @@ public final class SocksCmdResponse extends SocksResponse {
|
|||||||
*
|
*
|
||||||
* @return The {@link AddressType} of this {@link SocksCmdResponse}
|
* @return The {@link AddressType} of this {@link SocksCmdResponse}
|
||||||
*/
|
*/
|
||||||
public AddressType getAddressType() {
|
public AddressType addressType() {
|
||||||
return addressType;
|
return addressType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||||
byteBuf.writeByte(getProtocolVersion().getByteValue());
|
byteBuf.writeByte(protocolVersion().getByteValue());
|
||||||
byteBuf.writeByte(cmdStatus.getByteValue());
|
byteBuf.writeByte(cmdStatus.getByteValue());
|
||||||
byteBuf.writeByte(0x00);
|
byteBuf.writeByte(0x00);
|
||||||
byteBuf.writeByte(addressType.getByteValue());
|
byteBuf.writeByte(addressType.getByteValue());
|
||||||
|
@ -42,13 +42,13 @@ public final class SocksInitRequest extends SocksRequest {
|
|||||||
*
|
*
|
||||||
* @return The List<{@link AuthScheme}> of this {@link SocksInitRequest}
|
* @return The List<{@link AuthScheme}> of this {@link SocksInitRequest}
|
||||||
*/
|
*/
|
||||||
public List<AuthScheme> getAuthSchemes() {
|
public List<AuthScheme> authSchemes() {
|
||||||
return Collections.unmodifiableList(authSchemes);
|
return Collections.unmodifiableList(authSchemes);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||||
byteBuf.writeByte(getProtocolVersion().getByteValue());
|
byteBuf.writeByte(protocolVersion().getByteValue());
|
||||||
byteBuf.writeByte(authSchemes.size());
|
byteBuf.writeByte(authSchemes.size());
|
||||||
for (AuthScheme authScheme : authSchemes) {
|
for (AuthScheme authScheme : authSchemes) {
|
||||||
byteBuf.writeByte(authScheme.getByteValue());
|
byteBuf.writeByte(authScheme.getByteValue());
|
||||||
|
@ -39,13 +39,13 @@ public final class SocksInitResponse extends SocksResponse {
|
|||||||
*
|
*
|
||||||
* @return The {@link AuthScheme} of this {@link SocksInitResponse}
|
* @return The {@link AuthScheme} of this {@link SocksInitResponse}
|
||||||
*/
|
*/
|
||||||
public AuthScheme getAuthScheme() {
|
public AuthScheme authScheme() {
|
||||||
return authScheme;
|
return authScheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
public void encodeAsByteBuf(ByteBuf byteBuf) {
|
||||||
byteBuf.writeByte(getProtocolVersion().getByteValue());
|
byteBuf.writeByte(protocolVersion().getByteValue());
|
||||||
byteBuf.writeByte(authScheme.getByteValue());
|
byteBuf.writeByte(authScheme.getByteValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,14 +26,14 @@ import io.netty.buffer.ByteBuf;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public abstract class SocksMessage {
|
public abstract class SocksMessage {
|
||||||
private final MessageType messageType;
|
private final MessageType type;
|
||||||
private final ProtocolVersion protocolVersion = ProtocolVersion.SOCKS5;
|
private final ProtocolVersion protocolVersion = ProtocolVersion.SOCKS5;
|
||||||
|
|
||||||
protected SocksMessage(MessageType messageType) {
|
protected SocksMessage(MessageType type) {
|
||||||
if (messageType == null) {
|
if (type == null) {
|
||||||
throw new NullPointerException("messageType");
|
throw new NullPointerException("type");
|
||||||
}
|
}
|
||||||
this.messageType = messageType;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,8 +41,8 @@ public abstract class SocksMessage {
|
|||||||
*
|
*
|
||||||
* @return The {@link MessageType} of this {@link SocksMessage}
|
* @return The {@link MessageType} of this {@link SocksMessage}
|
||||||
*/
|
*/
|
||||||
public MessageType getMessageType() {
|
public MessageType type() {
|
||||||
return messageType;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum MessageType {
|
public enum MessageType {
|
||||||
@ -239,7 +239,7 @@ public abstract class SocksMessage {
|
|||||||
*
|
*
|
||||||
* @return The {@link ProtocolVersion} of this {@link SocksMessage}
|
* @return The {@link ProtocolVersion} of this {@link SocksMessage}
|
||||||
*/
|
*/
|
||||||
public ProtocolVersion getProtocolVersion() {
|
public ProtocolVersion protocolVersion() {
|
||||||
return protocolVersion;
|
return protocolVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,14 +25,14 @@ package io.netty.handler.codec.socks;
|
|||||||
* @see UnknownSocksRequest
|
* @see UnknownSocksRequest
|
||||||
*/
|
*/
|
||||||
public abstract class SocksRequest extends SocksMessage {
|
public abstract class SocksRequest extends SocksMessage {
|
||||||
private final SocksRequestType socksRequestType;
|
private final SocksRequestType requestType;
|
||||||
|
|
||||||
protected SocksRequest(SocksRequestType socksRequestType) {
|
protected SocksRequest(SocksRequestType requestType) {
|
||||||
super(MessageType.REQUEST);
|
super(MessageType.REQUEST);
|
||||||
if (socksRequestType == null) {
|
if (requestType == null) {
|
||||||
throw new NullPointerException("socksRequestType");
|
throw new NullPointerException("requestType");
|
||||||
}
|
}
|
||||||
this.socksRequestType = socksRequestType;
|
this.requestType = requestType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,8 +40,8 @@ public abstract class SocksRequest extends SocksMessage {
|
|||||||
*
|
*
|
||||||
* @return socks request type
|
* @return socks request type
|
||||||
*/
|
*/
|
||||||
public SocksRequestType getSocksRequestType() {
|
public SocksRequestType requestType() {
|
||||||
return socksRequestType;
|
return requestType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,14 +25,14 @@ package io.netty.handler.codec.socks;
|
|||||||
* @see UnknownSocksResponse
|
* @see UnknownSocksResponse
|
||||||
*/
|
*/
|
||||||
public abstract class SocksResponse extends SocksMessage {
|
public abstract class SocksResponse extends SocksMessage {
|
||||||
private final SocksResponseType socksResponseType;
|
private final SocksResponseType responseType;
|
||||||
|
|
||||||
protected SocksResponse(SocksResponseType socksResponseType) {
|
protected SocksResponse(SocksResponseType responseType) {
|
||||||
super(MessageType.RESPONSE);
|
super(MessageType.RESPONSE);
|
||||||
if (socksResponseType == null) {
|
if (responseType == null) {
|
||||||
throw new NullPointerException("socksResponseType");
|
throw new NullPointerException("responseType");
|
||||||
}
|
}
|
||||||
this.socksResponseType = socksResponseType;
|
this.responseType = responseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -40,8 +40,8 @@ public abstract class SocksResponse extends SocksMessage {
|
|||||||
*
|
*
|
||||||
* @return socks response type
|
* @return socks response type
|
||||||
*/
|
*/
|
||||||
public SocksResponseType getSocksResponseType() {
|
public SocksResponseType responseType() {
|
||||||
return socksResponseType;
|
return responseType;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,13 +17,11 @@ package io.netty.handler.codec.socks;
|
|||||||
|
|
||||||
import io.netty.channel.embedded.EmbeddedByteChannel;
|
import io.netty.channel.embedded.EmbeddedByteChannel;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
public class SocksAuthRequestDecoderTest {
|
public class SocksAuthRequestDecoderTest {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(SocksAuthRequestDecoderTest.class);
|
|
||||||
@Test
|
@Test
|
||||||
public void testAuthRequestDecoder() {
|
public void testAuthRequestDecoder() {
|
||||||
String username = "test";
|
String username = "test";
|
||||||
@ -33,8 +31,8 @@ public class SocksAuthRequestDecoderTest {
|
|||||||
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
|
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
|
||||||
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
||||||
msg = (SocksAuthRequest) embedder.readInbound();
|
msg = (SocksAuthRequest) embedder.readInbound();
|
||||||
assertEquals(msg.getUsername(), username);
|
assertEquals(msg.username(), username);
|
||||||
assertEquals(msg.getUsername(), password);
|
assertEquals(msg.username(), password);
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class SocksAuthResponseDecoderTest {
|
|||||||
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
|
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
|
||||||
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
||||||
msg = (SocksAuthResponse) embedder.readInbound();
|
msg = (SocksAuthResponse) embedder.readInbound();
|
||||||
assertSame(msg.getAuthStatus(), authStatus);
|
assertSame(msg.authStatus(), authStatus);
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,14 +32,14 @@ public class SocksCmdRequestDecoderTest {
|
|||||||
SocksCmdRequestDecoder decoder = new SocksCmdRequestDecoder();
|
SocksCmdRequestDecoder decoder = new SocksCmdRequestDecoder();
|
||||||
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
|
EmbeddedByteChannel embedder = new EmbeddedByteChannel(decoder);
|
||||||
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
SocksCommonTestUtils.writeMessageIntoEmbedder(embedder, msg);
|
||||||
if (msg.getAddressType() == SocksMessage.AddressType.UNKNOWN) {
|
if (msg.addressType() == SocksMessage.AddressType.UNKNOWN) {
|
||||||
assertTrue(embedder.readInbound() instanceof UnknownSocksRequest);
|
assertTrue(embedder.readInbound() instanceof UnknownSocksRequest);
|
||||||
} else {
|
} else {
|
||||||
msg = (SocksCmdRequest) embedder.readInbound();
|
msg = (SocksCmdRequest) embedder.readInbound();
|
||||||
assertSame(msg.getCmdType(), cmdType);
|
assertSame(msg.cmdType(), cmdType);
|
||||||
assertSame(msg.getAddressType(), addressType);
|
assertSame(msg.addressType(), addressType);
|
||||||
assertEquals(msg.getHost(), host);
|
assertEquals(msg.host(), host);
|
||||||
assertEquals(msg.getPort(), port);
|
assertEquals(msg.port(), port);
|
||||||
}
|
}
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class SocksCmdResponseDecoderTest {
|
|||||||
assertTrue(embedder.readInbound() instanceof UnknownSocksResponse);
|
assertTrue(embedder.readInbound() instanceof UnknownSocksResponse);
|
||||||
} else {
|
} else {
|
||||||
msg = (SocksResponse) embedder.readInbound();
|
msg = (SocksResponse) embedder.readInbound();
|
||||||
assertEquals(((SocksCmdResponse) msg).getCmdStatus(), cmdStatus);
|
assertEquals(((SocksCmdResponse) msg).cmdStatus(), cmdStatus);
|
||||||
}
|
}
|
||||||
assertNull(embedder.readInbound());
|
assertNull(embedder.readInbound());
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ public class WebSocketSslServerInitializer extends ChannelInitializer<SocketChan
|
|||||||
public void initChannel(SocketChannel ch) throws Exception {
|
public void initChannel(SocketChannel ch) throws Exception {
|
||||||
ChannelPipeline pipeline = ch.pipeline();
|
ChannelPipeline pipeline = ch.pipeline();
|
||||||
|
|
||||||
SSLEngine engine = WebSocketSslServerSslContext.getInstance().getServerContext().createSSLEngine();
|
SSLEngine engine = WebSocketSslServerSslContext.getInstance().serverContext().createSSLEngine();
|
||||||
engine.setUseClientMode(false);
|
engine.setUseClientMode(false);
|
||||||
pipeline.addLast("ssl", new SslHandler(engine));
|
pipeline.addLast("ssl", new SslHandler(engine));
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public final class WebSocketSslServerSslContext {
|
|||||||
/**
|
/**
|
||||||
* Returns the server context with server side key store
|
* Returns the server context with server side key store
|
||||||
*/
|
*/
|
||||||
public SSLContext getServerContext() {
|
public SSLContext serverContext() {
|
||||||
return _serverContext;
|
return _serverContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ public class SecureChatServerHandler extends ChannelInboundMessageHandlerAdapter
|
|||||||
" secure chat service!\n");
|
" secure chat service!\n");
|
||||||
ctx.write(
|
ctx.write(
|
||||||
"Your session is protected by " +
|
"Your session is protected by " +
|
||||||
ctx.pipeline().get(SslHandler.class).getEngine().getSession().getCipherSuite() +
|
ctx.pipeline().get(SslHandler.class).engine().getSession().getCipherSuite() +
|
||||||
" cipher suite.\n");
|
" cipher suite.\n");
|
||||||
|
|
||||||
channels.add(ctx.channel());
|
channels.add(ctx.channel());
|
||||||
|
@ -49,7 +49,7 @@ public final class SocksServerConnectHandler extends ChannelInboundMessageHandle
|
|||||||
CallbackNotifier cb = new CallbackNotifier() {
|
CallbackNotifier cb = new CallbackNotifier() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(final ChannelHandlerContext outboundCtx) {
|
public void onSuccess(final ChannelHandlerContext outboundCtx) {
|
||||||
ctx.channel().write(new SocksCmdResponse(SocksMessage.CmdStatus.SUCCESS, request.getAddressType()))
|
ctx.channel().write(new SocksCmdResponse(SocksMessage.CmdStatus.SUCCESS, request.addressType()))
|
||||||
.addListener(new ChannelFutureListener() {
|
.addListener(new ChannelFutureListener() {
|
||||||
@Override
|
@Override
|
||||||
public void operationComplete(ChannelFuture channelFuture) throws Exception {
|
public void operationComplete(ChannelFuture channelFuture) throws Exception {
|
||||||
@ -62,7 +62,7 @@ public final class SocksServerConnectHandler extends ChannelInboundMessageHandle
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(ChannelHandlerContext outboundCtx, Throwable cause) {
|
public void onFailure(ChannelHandlerContext outboundCtx, Throwable cause) {
|
||||||
ctx.channel().write(new SocksCmdResponse(SocksMessage.CmdStatus.FAILURE, request.getAddressType()));
|
ctx.channel().write(new SocksCmdResponse(SocksMessage.CmdStatus.FAILURE, request.addressType()));
|
||||||
SocksServerUtils.closeOnFlush(ctx.channel());
|
SocksServerUtils.closeOnFlush(ctx.channel());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -73,7 +73,7 @@ public final class SocksServerConnectHandler extends ChannelInboundMessageHandle
|
|||||||
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
|
.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 10000)
|
||||||
.option(ChannelOption.SO_KEEPALIVE, true)
|
.option(ChannelOption.SO_KEEPALIVE, true)
|
||||||
.handler(new DirectClientInitializer(cb))
|
.handler(new DirectClientInitializer(cb))
|
||||||
.remoteAddress(request.getHost(), request.getPort());
|
.remoteAddress(request.host(), request.port());
|
||||||
b.connect();
|
b.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,12 +18,12 @@ package io.netty.example.socksproxy;
|
|||||||
import io.netty.channel.ChannelHandler;
|
import io.netty.channel.ChannelHandler;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
import io.netty.channel.ChannelInboundMessageHandlerAdapter;
|
||||||
|
import io.netty.handler.codec.socks.SocksAuthResponse;
|
||||||
|
import io.netty.handler.codec.socks.SocksCmdRequest;
|
||||||
import io.netty.handler.codec.socks.SocksCmdRequestDecoder;
|
import io.netty.handler.codec.socks.SocksCmdRequestDecoder;
|
||||||
import io.netty.handler.codec.socks.SocksInitResponse;
|
import io.netty.handler.codec.socks.SocksInitResponse;
|
||||||
import io.netty.handler.codec.socks.SocksMessage;
|
import io.netty.handler.codec.socks.SocksMessage;
|
||||||
import io.netty.handler.codec.socks.SocksRequest;
|
import io.netty.handler.codec.socks.SocksRequest;
|
||||||
import io.netty.handler.codec.socks.SocksAuthResponse;
|
|
||||||
import io.netty.handler.codec.socks.SocksCmdRequest;
|
|
||||||
|
|
||||||
|
|
||||||
@ChannelHandler.Sharable
|
@ChannelHandler.Sharable
|
||||||
@ -40,7 +40,7 @@ public final class SocksServerHandler extends ChannelInboundMessageHandlerAdapte
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(ChannelHandlerContext ctx, SocksRequest socksRequest) throws Exception {
|
public void messageReceived(ChannelHandlerContext ctx, SocksRequest socksRequest) throws Exception {
|
||||||
switch (socksRequest.getSocksRequestType()) {
|
switch (socksRequest.requestType()) {
|
||||||
case INIT: {
|
case INIT: {
|
||||||
// auth support example
|
// auth support example
|
||||||
// ctx.pipeline().addFirst("socksAuthRequestDecoder",new SocksAuthRequestDecoder());
|
// ctx.pipeline().addFirst("socksAuthRequestDecoder",new SocksAuthRequestDecoder());
|
||||||
@ -55,7 +55,7 @@ public final class SocksServerHandler extends ChannelInboundMessageHandlerAdapte
|
|||||||
break;
|
break;
|
||||||
case CMD:
|
case CMD:
|
||||||
SocksCmdRequest req = (SocksCmdRequest) socksRequest;
|
SocksCmdRequest req = (SocksCmdRequest) socksRequest;
|
||||||
if (req.getCmdType() == SocksMessage.CmdType.CONNECT) {
|
if (req.cmdType() == SocksMessage.CmdType.CONNECT) {
|
||||||
ctx.pipeline().addLast(SocksServerConnectHandler.getName(), new SocksServerConnectHandler());
|
ctx.pipeline().addLast(SocksServerConnectHandler.getName(), new SocksServerConnectHandler());
|
||||||
ctx.pipeline().remove(this);
|
ctx.pipeline().remove(this);
|
||||||
ctx.nextInboundMessageBuffer().add(socksRequest);
|
ctx.nextInboundMessageBuffer().add(socksRequest);
|
||||||
|
@ -268,7 +268,7 @@ public class SslHandler
|
|||||||
/**
|
/**
|
||||||
* Returns the {@link SSLEngine} which is used by this handler.
|
* Returns the {@link SSLEngine} which is used by this handler.
|
||||||
*/
|
*/
|
||||||
public SSLEngine getEngine() {
|
public SSLEngine engine() {
|
||||||
return engine;
|
return engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,8 +263,8 @@ public abstract class AbstractTrafficShapingHandler extends ChannelHandlerAdapte
|
|||||||
|
|
||||||
// compute the number of ms to wait before reopening the channel
|
// compute the number of ms to wait before reopening the channel
|
||||||
long wait = getTimeToWait(readLimit,
|
long wait = getTimeToWait(readLimit,
|
||||||
trafficCounter.getCurrentReadBytes(),
|
trafficCounter.currentReadBytes(),
|
||||||
trafficCounter.getLastTime(), curtime);
|
trafficCounter.lastTime(), curtime);
|
||||||
if (wait >= MINIMAL_WAIT) { // At least 10ms seems a minimal
|
if (wait >= MINIMAL_WAIT) { // At least 10ms seems a minimal
|
||||||
// time in order to
|
// time in order to
|
||||||
// try to limit the traffic
|
// try to limit the traffic
|
||||||
@ -324,8 +324,8 @@ public abstract class AbstractTrafficShapingHandler extends ChannelHandlerAdapte
|
|||||||
// compute the number of ms to wait before continue with the
|
// compute the number of ms to wait before continue with the
|
||||||
// channel
|
// channel
|
||||||
long wait = getTimeToWait(writeLimit,
|
long wait = getTimeToWait(writeLimit,
|
||||||
trafficCounter.getCurrentWrittenBytes(),
|
trafficCounter.currentWrittenBytes(),
|
||||||
trafficCounter.getLastTime(), curtime);
|
trafficCounter.lastTime(), curtime);
|
||||||
if (wait >= MINIMAL_WAIT) {
|
if (wait >= MINIMAL_WAIT) {
|
||||||
ctx.executor().schedule(new Runnable() {
|
ctx.executor().schedule(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@ -344,7 +344,7 @@ public abstract class AbstractTrafficShapingHandler extends ChannelHandlerAdapte
|
|||||||
* @return the current TrafficCounter (if
|
* @return the current TrafficCounter (if
|
||||||
* channel is still connected)
|
* channel is still connected)
|
||||||
*/
|
*/
|
||||||
public TrafficCounter getTrafficCounter() {
|
public TrafficCounter trafficCounter() {
|
||||||
return trafficCounter;
|
return trafficCounter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,7 +282,7 @@ public class TrafficCounter {
|
|||||||
* @return the current checkInterval between two computations of traffic counter
|
* @return the current checkInterval between two computations of traffic counter
|
||||||
* in millisecond
|
* in millisecond
|
||||||
*/
|
*/
|
||||||
public long getCheckInterval() {
|
public long checkInterval() {
|
||||||
return checkInterval.get();
|
return checkInterval.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,7 +290,7 @@ public class TrafficCounter {
|
|||||||
*
|
*
|
||||||
* @return the Read Throughput in bytes/s computes in the last check interval
|
* @return the Read Throughput in bytes/s computes in the last check interval
|
||||||
*/
|
*/
|
||||||
public long getLastReadThroughput() {
|
public long lastReadThroughput() {
|
||||||
return lastReadThroughput;
|
return lastReadThroughput;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +298,7 @@ public class TrafficCounter {
|
|||||||
*
|
*
|
||||||
* @return the Write Throughput in bytes/s computes in the last check interval
|
* @return the Write Throughput in bytes/s computes in the last check interval
|
||||||
*/
|
*/
|
||||||
public long getLastWriteThroughput() {
|
public long lastWriteThroughput() {
|
||||||
return lastWriteThroughput;
|
return lastWriteThroughput;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -306,7 +306,7 @@ public class TrafficCounter {
|
|||||||
*
|
*
|
||||||
* @return the number of bytes read during the last check Interval
|
* @return the number of bytes read during the last check Interval
|
||||||
*/
|
*/
|
||||||
public long getLastReadBytes() {
|
public long lastReadBytes() {
|
||||||
return lastReadBytes;
|
return lastReadBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +314,7 @@ public class TrafficCounter {
|
|||||||
*
|
*
|
||||||
* @return the number of bytes written during the last check Interval
|
* @return the number of bytes written during the last check Interval
|
||||||
*/
|
*/
|
||||||
public long getLastWrittenBytes() {
|
public long lastWrittenBytes() {
|
||||||
return lastWrittenBytes;
|
return lastWrittenBytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,7 +322,7 @@ public class TrafficCounter {
|
|||||||
*
|
*
|
||||||
* @return the current number of bytes read since the last checkInterval
|
* @return the current number of bytes read since the last checkInterval
|
||||||
*/
|
*/
|
||||||
public long getCurrentReadBytes() {
|
public long currentReadBytes() {
|
||||||
return currentReadBytes.get();
|
return currentReadBytes.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,28 +330,28 @@ public class TrafficCounter {
|
|||||||
*
|
*
|
||||||
* @return the current number of bytes written since the last check Interval
|
* @return the current number of bytes written since the last check Interval
|
||||||
*/
|
*/
|
||||||
public long getCurrentWrittenBytes() {
|
public long currentWrittenBytes() {
|
||||||
return currentWrittenBytes.get();
|
return currentWrittenBytes.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the Time in millisecond of the last check as of System.currentTimeMillis()
|
* @return the Time in millisecond of the last check as of System.currentTimeMillis()
|
||||||
*/
|
*/
|
||||||
public long getLastTime() {
|
public long lastTime() {
|
||||||
return lastTime.get();
|
return lastTime.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the cumulativeWrittenBytes
|
* @return the cumulativeWrittenBytes
|
||||||
*/
|
*/
|
||||||
public long getCumulativeWrittenBytes() {
|
public long cumulativeWrittenBytes() {
|
||||||
return cumulativeWrittenBytes.get();
|
return cumulativeWrittenBytes.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the cumulativeReadBytes
|
* @return the cumulativeReadBytes
|
||||||
*/
|
*/
|
||||||
public long getCumulativeReadBytes() {
|
public long cumulativeReadBytes() {
|
||||||
return cumulativeReadBytes.get();
|
return cumulativeReadBytes.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,7 +359,7 @@ public class TrafficCounter {
|
|||||||
* @return the lastCumulativeTime in millisecond as of System.currentTimeMillis()
|
* @return the lastCumulativeTime in millisecond as of System.currentTimeMillis()
|
||||||
* when the cumulative counters were reset to 0.
|
* when the cumulative counters were reset to 0.
|
||||||
*/
|
*/
|
||||||
public long getLastCumulativeTime() {
|
public long lastCumulativeTime() {
|
||||||
return lastCumulativeTime;
|
return lastCumulativeTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ public class TrafficCounter {
|
|||||||
/**
|
/**
|
||||||
* @return the name
|
* @return the name
|
||||||
*/
|
*/
|
||||||
public String getName() {
|
public String name() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +103,7 @@ public class RxtxChannel extends AbstractOioByteChannel {
|
|||||||
@Override
|
@Override
|
||||||
protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
|
protected void doConnect(SocketAddress remoteAddress, SocketAddress localAddress) throws Exception {
|
||||||
RxtxDeviceAddress remote = (RxtxDeviceAddress) remoteAddress;
|
RxtxDeviceAddress remote = (RxtxDeviceAddress) remoteAddress;
|
||||||
final CommPortIdentifier cpi = CommPortIdentifier.getPortIdentifier(remote.getDeviceAddress());
|
final CommPortIdentifier cpi = CommPortIdentifier.getPortIdentifier(remote.value());
|
||||||
final CommPort commPort = cpi.open(getClass().getName(), 1000);
|
final CommPort commPort = cpi.open(getClass().getName(), 1000);
|
||||||
|
|
||||||
deviceAddress = remote;
|
deviceAddress = remote;
|
||||||
|
@ -25,21 +25,21 @@ public class RxtxDeviceAddress extends SocketAddress {
|
|||||||
|
|
||||||
private static final long serialVersionUID = -2907820090993709523L;
|
private static final long serialVersionUID = -2907820090993709523L;
|
||||||
|
|
||||||
private final String deviceAddress;
|
private final String value;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a RxtxDeviceAddress representing the address of the serial port.
|
* Creates a RxtxDeviceAddress representing the address of the serial port.
|
||||||
*
|
*
|
||||||
* @param deviceAddress the address of the device (e.g. COM1, /dev/ttyUSB0, ...)
|
* @param value the address of the device (e.g. COM1, /dev/ttyUSB0, ...)
|
||||||
*/
|
*/
|
||||||
public RxtxDeviceAddress(String deviceAddress) {
|
public RxtxDeviceAddress(String value) {
|
||||||
this.deviceAddress = deviceAddress;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return The serial port address of the device (e.g. COM1, /dev/ttyUSB0, ...)
|
* @return The serial port address of the device (e.g. COM1, /dev/ttyUSB0, ...)
|
||||||
*/
|
*/
|
||||||
public String getDeviceAddress() {
|
public String value() {
|
||||||
return deviceAddress;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ public interface ChannelGroupFuture extends Iterable<ChannelFuture> {
|
|||||||
/**
|
/**
|
||||||
* Returns the {@link ChannelGroup} which is associated with this future.
|
* Returns the {@link ChannelGroup} which is associated with this future.
|
||||||
*/
|
*/
|
||||||
ChannelGroup getGroup();
|
ChannelGroup group();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the {@link ChannelFuture} of the individual I/O operation which
|
* Returns the {@link ChannelFuture} of the individual I/O operation which
|
||||||
|
@ -115,7 +115,7 @@ public class DefaultChannelGroupFuture implements ChannelGroupFuture {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChannelGroup getGroup() {
|
public ChannelGroup group() {
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user