Skip to content

Commit

Permalink
调整日志输出逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
biezhihua committed Sep 24, 2024
1 parent eb2f714 commit f5cffec
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,6 @@ class GXSocket : SocketListener {

companion object {
const val TAG = "GaiaX.Socket"
private const val SOCKET_KEY = "GaiaXSocket"
private const val SOCKET_KEY = "GaiaX.Socket"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ public void setConnectionLostTimeout(int connectionLostTimeout) {
synchronized (syncConnectionLost) {
this.connectionLostTimeout = connectionLostTimeout;
if (this.connectionLostTimeout <= 0) {
Log.e("GaiaXSocket", "Connection lost timer stopped");
Log.e("GaiaX.Socket", "Connection lost timer stopped");
cancelConnectionLostTimer();
return;
}
if (this.websocketRunning) {
Log.e("GaiaXSocket", "Connection lost timer restarted");
Log.e("GaiaX.Socket", "Connection lost timer restarted");
//Reset all the pings
try {
ArrayList<WebSocket> connections = new ArrayList<WebSocket>(getConnections());
Expand All @@ -129,7 +129,7 @@ public void setConnectionLostTimeout(int connectionLostTimeout) {
}
}
} catch (Exception e) {
Log.e("GaiaXSocket", "Exception during connection lost restart", e);
Log.e("GaiaX.Socket", "Exception during connection lost restart", e);
}
restartConnectionLostTimer();
}
Expand All @@ -145,7 +145,7 @@ protected void stopConnectionLostTimer() {
synchronized (syncConnectionLost) {
if (connectionLostTimer != null || connectionLostTimerTask != null) {
this.websocketRunning = false;
Log.e("GaiaXSocket", "Connection lost timer stopped");
Log.e("GaiaX.Socket", "Connection lost timer stopped");
cancelConnectionLostTimer();
}
}
Expand All @@ -159,10 +159,10 @@ protected void stopConnectionLostTimer() {
protected void startConnectionLostTimer() {
synchronized (syncConnectionLost) {
if (this.connectionLostTimeout <= 0) {
Log.e("GaiaXSocket", "Connection lost timer deactivated");
Log.e("GaiaX.Socket", "Connection lost timer deactivated");
return;
}
Log.e("GaiaXSocket", "Connection lost timer started");
Log.e("GaiaX.Socket", "Connection lost timer started");
this.websocketRunning = true;
restartConnectionLostTimer();
}
Expand Down Expand Up @@ -214,13 +214,13 @@ private void executeConnectionLostDetection(WebSocket webSocket, long current) {
}
WebSocketImpl webSocketImpl = (WebSocketImpl) webSocket;
if (webSocketImpl.getLastPong() < current) {
Log.e("GaiaXSocket", "Closing connection due to no pong received: {}");
Log.e("GaiaX.Socket", "Closing connection due to no pong received: {}");
webSocketImpl.closeConnection(CloseFrame.ABNORMAL_CLOSE, "The connection was closed because the other endpoint did not respond with a pong in time. For more information check: https://github.com/TooTallNate/Java-WebSocket/wiki/Lost-connection-detection");
} else {
if (webSocketImpl.isOpen()) {
webSocketImpl.sendPing();
} else {
Log.e("GaiaXSocket", "Trying to ping a non open connection: {}");
Log.e("GaiaX.Socket", "Trying to ping a non open connection: {}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public SSLSocketChannel(SocketChannel inputSocketChannel, SSLEngine inputEngine,
try {
socketChannel.close();
} catch (IOException e) {
Log.e("GaiaXSocket", "Exception during the closing of the channel", e);
Log.e("GaiaX.Socket", "Exception during the closing of the channel", e);
}
}
}
Expand Down Expand Up @@ -163,7 +163,7 @@ public synchronized int read(ByteBuffer dst) throws IOException {
try {
result = engine.unwrap(peerNetData, peerAppData);
} catch (SSLException e) {
Log.e("GaiaXSocket", "SSLExcpetion during unwrap", e);
Log.e("GaiaX.Socket", "SSLExcpetion during unwrap", e);
throw e;
}
switch (result.getStatus()) {
Expand Down Expand Up @@ -469,7 +469,7 @@ private void handleEndOfStream() throws IOException {
try {
engine.closeInbound();
} catch (Exception e) {
Log.e("GaiaXSocket", "This engine was forced to close inbound, without having received the proper SSL/TLS close notification message from the peer, due to end of stream.");
Log.e("GaiaX.Socket", "This engine was forced to close inbound, without having received the proper SSL/TLS close notification message from the peer, due to end of stream.");
}
closeConnection();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ private boolean decodeHandshake(ByteBuffer socketBufferNew) {
socketBuffer.reset();
Handshakedata tmphandshake = d.translateHandshake(socketBuffer);
if (!(tmphandshake instanceof ClientHandshake)) {
Log.e("GaiaXSocket", "Closing due to wrong handshake");
Log.e("GaiaX.Socket", "Closing due to wrong handshake");
closeConnectionDueToWrongHandshake(new InvalidDataException(CloseFrame.PROTOCOL_ERROR, "wrong http function"));
return false;
}
Expand All @@ -280,11 +280,11 @@ private boolean decodeHandshake(ByteBuffer socketBufferNew) {
try {
response = wsl.onWebsocketHandshakeReceivedAsServer(this, d, handshake);
} catch (InvalidDataException e) {
Log.e("GaiaXSocket", "Closing due to wrong handshake. Possible handshake rejection", e);
Log.e("GaiaX.Socket", "Closing due to wrong handshake. Possible handshake rejection", e);
closeConnectionDueToWrongHandshake(e);
return false;
} catch (RuntimeException e) {
Log.e("GaiaXSocket", "Closing due to internal server error", e);
Log.e("GaiaX.Socket", "Closing due to internal server error", e);
wsl.onWebsocketError(this, e);
closeConnectionDueToInternalServerError(e);
return false;
Expand All @@ -299,15 +299,15 @@ private boolean decodeHandshake(ByteBuffer socketBufferNew) {
}
}
if (draft == null) {
Log.e("GaiaXSocket", "Closing due to protocol error: no draft matches");
Log.e("GaiaX.Socket", "Closing due to protocol error: no draft matches");
closeConnectionDueToWrongHandshake(new InvalidDataException(CloseFrame.PROTOCOL_ERROR, "no draft matches"));
}
return false;
} else {
// special case for multiple step handshakes
Handshakedata tmphandshake = draft.translateHandshake(socketBuffer);
if (!(tmphandshake instanceof ClientHandshake)) {
Log.e("GaiaXSocket", "Closing due to protocol error: wrong http function");
Log.e("GaiaX.Socket", "Closing due to protocol error: wrong http function");
flushAndClose(CloseFrame.PROTOCOL_ERROR, "wrong http function", false);
return false;
}
Expand All @@ -318,7 +318,7 @@ private boolean decodeHandshake(ByteBuffer socketBufferNew) {
open(handshake);
return true;
} else {
Log.e("GaiaXSocket", "Closing due to protocol error: the handshake did finally not match");
Log.e("GaiaX.Socket", "Closing due to protocol error: the handshake did finally not match");
close(CloseFrame.PROTOCOL_ERROR, "the handshake did finally not match");
}
return false;
Expand All @@ -327,7 +327,7 @@ private boolean decodeHandshake(ByteBuffer socketBufferNew) {
draft.setParseMode(role);
Handshakedata tmphandshake = draft.translateHandshake(socketBuffer);
if (!(tmphandshake instanceof ServerHandshake)) {
Log.e("GaiaXSocket", "Closing due to protocol error: wrong http function");
Log.e("GaiaX.Socket", "Closing due to protocol error: wrong http function");
flushAndClose(CloseFrame.PROTOCOL_ERROR, "wrong http function", false);
return false;
}
Expand All @@ -337,24 +337,24 @@ private boolean decodeHandshake(ByteBuffer socketBufferNew) {
try {
wsl.onWebsocketHandshakeReceivedAsClient(this, handshakerequest, handshake);
} catch (InvalidDataException e) {
Log.e("GaiaXSocket", "Closing due to invalid data exception. Possible handshake rejection", e);
Log.e("GaiaX.Socket", "Closing due to invalid data exception. Possible handshake rejection", e);
flushAndClose(e.getCloseCode(), e.getMessage(), false);
return false;
} catch (RuntimeException e) {
Log.e("GaiaXSocket", "Closing since client was never connected", e);
Log.e("GaiaX.Socket", "Closing since client was never connected", e);
wsl.onWebsocketError(this, e);
flushAndClose(CloseFrame.NEVER_CONNECTED, e.getMessage(), false);
return false;
}
open(handshake);
return true;
} else {
Log.e("GaiaXSocket", "Closing due to protocol error: draft {} refuses handshake");
Log.e("GaiaX.Socket", "Closing due to protocol error: draft {} refuses handshake");
close(CloseFrame.PROTOCOL_ERROR, "draft " + draft + " refuses handshake");
}
}
} catch (InvalidHandshakeException e) {
Log.e("GaiaXSocket", "Closing due to invalid handshake", e);
Log.e("GaiaX.Socket", "Closing due to invalid handshake", e);
close(e);
}
} catch (IncompleteHandshakeException e) {
Expand Down Expand Up @@ -387,12 +387,12 @@ private void decodeFrames(ByteBuffer socketBuffer) {
}
} catch (LimitExceededException e) {
if (e.getLimit() == Integer.MAX_VALUE) {
Log.e("GaiaXSocket", "Closing due to invalid size of frame", e);
Log.e("GaiaX.Socket", "Closing due to invalid size of frame", e);
wsl.onWebsocketError(this, e);
}
close(e);
} catch (InvalidDataException e) {
Log.e("GaiaXSocket", "Closing due to invalid data in frame", e);
Log.e("GaiaX.Socket", "Closing due to invalid data in frame", e);
wsl.onWebsocketError(this, e);
close(e);
}
Expand Down Expand Up @@ -463,7 +463,7 @@ public synchronized void close(int code, String message, boolean remote) {
sendFrame(closeFrame);
}
} catch (InvalidDataException e) {
Log.e("GaiaXSocket", "generated frame is invalid", e);
Log.e("GaiaX.Socket", "generated frame is invalid", e);
wsl.onWebsocketError(this, e);
flushAndClose(CloseFrame.ABNORMAL_CLOSE, "generated frame is invalid", false);
}
Expand Down Expand Up @@ -518,9 +518,9 @@ public synchronized void closeConnection(int code, String message, boolean remot
channel.close();
} catch (IOException e) {
if (e.getMessage().equals("Broken pipe")) {
Log.e("GaiaXSocket", "Caught IOException: Broken pipe during closeConnection()", e);
Log.e("GaiaX.Socket", "Caught IOException: Broken pipe during closeConnection()", e);
} else {
Log.e("GaiaXSocket", "Exception during channel.close()", e);
Log.e("GaiaX.Socket", "Exception during channel.close()", e);
wsl.onWebsocketError(this, e);
}
}
Expand Down Expand Up @@ -566,7 +566,7 @@ public synchronized void flushAndClose(int code, String message, boolean remote)
try {
wsl.onWebsocketClosing(this, code, message, remote);
} catch (RuntimeException e) {
Log.e("GaiaXSocket", "Exception in onWebsocketClosing", e);
Log.e("GaiaX.Socket", "Exception in onWebsocketClosing", e);
wsl.onWebsocketError(this, e);
}
if (draft != null)
Expand Down Expand Up @@ -685,7 +685,7 @@ public void startHandshake(ClientHandshakeBuilder handshakedata) throws InvalidH
// Stop if the client code throws an exception
throw new InvalidHandshakeException("Handshake data rejected by client.");
} catch (RuntimeException e) {
Log.e("GaiaXSocket", "Exception in startHandshake", e);
Log.e("GaiaX.Socket", "Exception in startHandshake", e);
wsl.onWebsocketError(this, e);
throw new InvalidHandshakeException("rejected because of " + e);
}
Expand Down Expand Up @@ -713,7 +713,7 @@ private void write(List<ByteBuffer> bufs) {
}

private void open(Handshakedata d) {
Log.e("GaiaXSocket", "open using draft: {}");
Log.e("GaiaX.Socket", "open using draft: {}");
readyState = ReadyState.OPEN;
try {
wsl.onWebsocketOpen(this, d);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public Draft_6455(List<IExtension> inputExtensions, List<IProtocol> inputProtoco
public HandshakeState acceptHandshakeAsServer(ClientHandshake handshakedata) throws InvalidHandshakeException {
int v = readVersion(handshakedata);
if (v != 13) {
Log.e("GaiaXSocket", "acceptHandshakeAsServer - Wrong websocket version.");
Log.e("GaiaX.Socket", "acceptHandshakeAsServer - Wrong websocket version.");
return HandshakeState.NOT_MATCHED;
}
HandshakeState extensionState = HandshakeState.NOT_MATCHED;
Expand All @@ -249,15 +249,15 @@ public HandshakeState acceptHandshakeAsServer(ClientHandshake handshakedata) thr
if (knownExtension.acceptProvidedExtensionAsServer(requestedExtension)) {
extension = knownExtension;
extensionState = HandshakeState.MATCHED;
Log.e("GaiaXSocket", "acceptHandshakeAsServer - Matching extension found: {}");
Log.e("GaiaX.Socket", "acceptHandshakeAsServer - Matching extension found: {}");
break;
}
}
HandshakeState protocolState = containsRequestedProtocol(handshakedata.getFieldValue(SEC_WEB_SOCKET_PROTOCOL));
if (protocolState == HandshakeState.MATCHED && extensionState == HandshakeState.MATCHED) {
return HandshakeState.MATCHED;
}
Log.e("GaiaXSocket", "acceptHandshakeAsServer - No matching extension or protocol found.");
Log.e("GaiaX.Socket", "acceptHandshakeAsServer - No matching extension or protocol found.");
return HandshakeState.NOT_MATCHED;
}

Expand All @@ -271,7 +271,7 @@ private HandshakeState containsRequestedProtocol(String requestedProtocol) {
for (IProtocol knownProtocol : knownProtocols) {
if (knownProtocol.acceptProvidedProtocol(requestedProtocol)) {
protocol = knownProtocol;
Log.e("GaiaXSocket", "acceptHandshake - Matching protocol found: {}");
Log.e("GaiaX.Socket", "acceptHandshake - Matching protocol found: {}");
return HandshakeState.MATCHED;
}
}
Expand All @@ -281,11 +281,11 @@ private HandshakeState containsRequestedProtocol(String requestedProtocol) {
@Override
public HandshakeState acceptHandshakeAsClient(ClientHandshake request, ServerHandshake response) throws InvalidHandshakeException {
if (!basicAccept(response)) {
Log.e("GaiaXSocket", "acceptHandshakeAsClient - Missing/wrong upgrade or connection in handshake.");
Log.e("GaiaX.Socket", "acceptHandshakeAsClient - Missing/wrong upgrade or connection in handshake.");
return HandshakeState.NOT_MATCHED;
}
if (!request.hasFieldValue(SEC_WEB_SOCKET_KEY) || !response.hasFieldValue(SEC_WEB_SOCKET_ACCEPT)) {
Log.e("GaiaXSocket", "acceptHandshakeAsClient - Missing Sec-WebSocket-Key or Sec-WebSocket-Accept");
Log.e("GaiaX.Socket", "acceptHandshakeAsClient - Missing Sec-WebSocket-Key or Sec-WebSocket-Accept");
return HandshakeState.NOT_MATCHED;
}

Expand All @@ -294,7 +294,7 @@ public HandshakeState acceptHandshakeAsClient(ClientHandshake request, ServerHan
seckeyChallenge = generateFinalKey(seckeyChallenge);

if (!seckeyChallenge.equals(seckeyAnswer)) {
Log.e("GaiaXSocket", "acceptHandshakeAsClient - Wrong key for Sec-WebSocket-Key.");
Log.e("GaiaX.Socket", "acceptHandshakeAsClient - Wrong key for Sec-WebSocket-Key.");
return HandshakeState.NOT_MATCHED;
}
HandshakeState extensionState = HandshakeState.NOT_MATCHED;
Expand All @@ -303,15 +303,15 @@ public HandshakeState acceptHandshakeAsClient(ClientHandshake request, ServerHan
if (knownExtension.acceptProvidedExtensionAsClient(requestedExtension)) {
extension = knownExtension;
extensionState = HandshakeState.MATCHED;
Log.e("GaiaXSocket", "acceptHandshakeAsClient - Matching extension found: {}");
Log.e("GaiaX.Socket", "acceptHandshakeAsClient - Matching extension found: {}");
break;
}
}
HandshakeState protocolState = containsRequestedProtocol(response.getFieldValue(SEC_WEB_SOCKET_PROTOCOL));
if (protocolState == HandshakeState.MATCHED && extensionState == HandshakeState.MATCHED) {
return HandshakeState.MATCHED;
}
Log.e("GaiaXSocket", "acceptHandshakeAsClient - No matching extension or protocol found.");
Log.e("GaiaX.Socket", "acceptHandshakeAsClient - No matching extension or protocol found.");
return HandshakeState.NOT_MATCHED;
}

Expand Down Expand Up @@ -547,7 +547,7 @@ private TranslatedPayloadMetaData translateSingleFramePayloadLength(ByteBuffer b
int payloadlength = oldPayloadlength,
realpacketsize = oldRealpacketsize;
if (optcode == Opcode.PING || optcode == Opcode.PONG || optcode == Opcode.CLOSING) {
Log.e("GaiaXSocket", "Invalid frame: more than 125 octets");
Log.e("GaiaX.Socket", "Invalid frame: more than 125 octets");
throw new InvalidFrameException("more than 125 octets");
}
if (payloadlength == 126) {
Expand Down

0 comments on commit f5cffec

Please sign in to comment.