-
-
Save barthap/64471efe13dd50dec2301b070f25b990 to your computer and use it in GitHub Desktop.
Tunnelbroker testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LOG Render: socketID: 0 changed: false initMessage exists: false | |
LOG isSocketActive: false | |
// trigger first credentials change here [step 2] | |
LOG SECONDARY DEVICE: setUseAnonymousSession 9/Dk+21eU27n7fpvFDVWqNrouje2XKGW2jtLPC7vx+A | |
LOG Render: socketID: 0 changed: true initMessage exists: true | |
LOG isSocketActive: false | |
LOG In hook, socketID: 0 | |
LOG Socket set, socketID: 1 | |
LOG Render: socketID: 1 changed: false initMessage exists: true | |
LOG isSocketActive: true | |
LOG session with Tunnelbroker created. Anonymous: true , socketID: 1 | |
LOG In hook, socketID: 1 | |
// triger second credentials change here [step 3] | |
LOG SECONDARY DEVICE: faking login | |
LOG Render: socketID: 1 changed: false initMessage exists: true | |
LOG isSocketActive: true | |
LOG Render: socketID: 1 changed: true initMessage exists: false | |
LOG isSocketActive: true | |
LOG In hook, socketID: 1 | |
LOG Init message change, resetting connection..., socketID= 1 | |
LOG Render: socketID: 1 changed: false initMessage exists: false | |
LOG isSocketActive: false | |
LOG In hook, socketID: 1 | |
LOG Render: socketID: 1 changed: true initMessage exists: true | |
LOG isSocketActive: false | |
LOG In hook, socketID: 1 | |
LOG Render: socketID: 1 changed: false initMessage exists: true | |
LOG isSocketActive: false | |
LOG Connection to Tunnelbroker closed, socketID: 1 | |
LOG In hook, socketID: 1 | |
LOG Socket set, socketID: 2 | |
LOG Render: socketID: 2 changed: false initMessage exists: true | |
LOG isSocketActive: true | |
LOG session with Tunnelbroker created. Anonymous: false , socketID: 2 | |
LOG In hook, socketID: 2 | |
// unset credentials here [step 4] | |
LOG SECONDARY DEVICE: faking logout | |
LOG Render: socketID: 2 changed: true initMessage exists: false | |
LOG isSocketActive: true | |
LOG In hook, socketID: 2 | |
LOG Init message change, resetting connection..., socketID= 2 | |
LOG Render: socketID: 2 changed: false initMessage exists: false | |
LOG isSocketActive: false | |
LOG In hook, socketID: 2 | |
LOG Render: socketID: 2 changed: false initMessage exists: false | |
LOG isSocketActive: false | |
LOG Render: socketID: 2 changed: false initMessage exists: false | |
LOG isSocketActive: false | |
LOG Connection to Tunnelbroker closed, socketID: 2 | |
LOG In hook, socketID: 2 | |
LOG Render: socketID: 2 changed: false initMessage exists: false | |
LOG isSocketActive: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/tunnelbroker/tunnelbroker-context.js b/lib/tunnelbroker/tunnelbroker-context.js | |
index 3d9d1880a..69d0b2d79 100644 | |
--- a/lib/tunnelbroker/tunnelbroker-context.js | |
+++ b/lib/tunnelbroker/tunnelbroker-context.js | |
@@ -57,6 +57,7 @@ function TunnelbrokerProvider(props: Props): React.Node { | |
const [connected, setConnected] = React.useState(false); | |
const listeners = React.useRef<Set<TunnelbrokerSocketListener>>(new Set()); | |
const socket = React.useRef<?WebSocket>(null); | |
+ const socketID = React.useRef<number>(0); | |
const promises = React.useRef<Promises>({}); | |
const heartbeatTimeoutID = React.useRef<?TimeoutID>(); | |
@@ -64,6 +65,14 @@ function TunnelbrokerProvider(props: Props): React.Node { | |
React.useRef<?ConnectionInitializationMessage>(initMessage); | |
const initMessageChanged = initMessage !== previousInitMessage.current; | |
previousInitMessage.current = initMessage; | |
+ console.log( | |
+ 'Render: socketID:', | |
+ socketID.current, | |
+ 'changed:', | |
+ initMessageChanged, | |
+ 'initMessage exists:', | |
+ initMessage != null, | |
+ ); | |
const stopHeartbeatTimeout = React.useCallback(() => { | |
if (heartbeatTimeoutID.current) { | |
@@ -84,6 +93,7 @@ function TunnelbrokerProvider(props: Props): React.Node { | |
const isSocketActive = | |
socket.current?.readyState === WebSocket.OPEN || | |
socket.current?.readyState === WebSocket.CONNECTING; | |
+ console.log('isSocketActive:', isSocketActive); | |
// The Tunnelbroker connection can have 4 states: | |
// - DISCONNECTED: isSocketActive = false, connected = false | |
@@ -94,8 +104,13 @@ function TunnelbrokerProvider(props: Props): React.Node { | |
// - DISCONNECTING: isSocketActive = false, connected = true | |
// This lasts between socket.close() and socket.onclose() | |
React.useEffect(() => { | |
+ console.log('In hook, socketID:', socketID.current); | |
// when initMessage changes, we need to close the socket and open a new one | |
if ((!initMessage || initMessageChanged) && isSocketActive) { | |
+ console.log( | |
+ 'Init message change, resetting connection..., socketID=', | |
+ socketID.current, | |
+ ); | |
socket.current?.close(); | |
return; | |
} | |
@@ -107,6 +122,7 @@ function TunnelbrokerProvider(props: Props): React.Node { | |
} | |
const tunnelbrokerSocket = new WebSocket(tunnnelbrokerURL); | |
+ const newSocketID = socketID.current + 1; | |
tunnelbrokerSocket.onopen = () => { | |
tunnelbrokerSocket.send(JSON.stringify(initMessage)); | |
@@ -115,7 +131,7 @@ function TunnelbrokerProvider(props: Props): React.Node { | |
tunnelbrokerSocket.onclose = () => { | |
// this triggers the effect hook again and reconnect | |
setConnected(false); | |
- console.log('Connection to Tunnelbroker closed'); | |
+ console.log('Connection to Tunnelbroker closed, socketID: ', newSocketID); | |
}; | |
tunnelbrokerSocket.onerror = e => { | |
console.log('Tunnelbroker socket error:', e.message); | |
@@ -217,6 +233,8 @@ function TunnelbrokerProvider(props: Props): React.Node { | |
}; | |
socket.current = tunnelbrokerSocket; | |
+ socketID.current = newSocketID; | |
+ console.log('Socket set, socketID: ', socketID.current); | |
}, [ | |
connected, | |
initMessage, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2024-01-26T09:21:16.687091Z INFO tunnelbroker::websockets: WebSocket listening on: 0.0.0.0:51001 | |
2024-01-26T09:21:16.721974Z INFO tunnelbroker::grpc: gRPC server listening on [::]:50051 | |
// first connection (socketID = 1) OPEN | |
2024-01-26T09:21:21.862898Z DEBUG tunnelbroker::websockets: Incoming connection from: 192.168.0.170:53901 | |
2024-01-26T09:21:21.995185Z DEBUG tunnelbroker::websockets::session: Starting unauthenticated session with device: 9/Dk+21eU27n7fpvFDVWqNrouje2XKGW2jtLPC7vx+A | |
2024-01-26T09:21:22.010081Z DEBUG tunnelbroker::database: Retrieving messages for device: 9/Dk+21eU27n7fpvFDVWqNrouje2XKGW2jtLPC7vx+A | |
2024-01-26T09:21:22.026386Z DEBUG tunnelbroker::database: Retrieved 0 messages for 9/Dk+21eU27n7fpvFDVWqNrouje2XKGW2jtLPC7vx+A | |
2024-01-26T09:21:22.026438Z DEBUG tunnelbroker::websockets::session: Flushed messages for device: 9/Dk+21eU27n7fpvFDVWqNrouje2XKGW2jtLPC7vx+A | |
2024-01-26T09:21:22.027784Z DEBUG tunnelbroker::websockets: Polling for messages from: 192.168.0.170:53901 | |
2024-01-26T09:21:25.029702Z DEBUG tunnelbroker::websockets: Polling for messages from: 192.168.0.170:53901 | |
2024-01-26T09:21:25.033941Z DEBUG tunnelbroker::websockets::session: Received heartbeat from: 9/Dk+21eU27n7fpvFDVWqNrouje2XKGW2jtLPC7vx+A | |
2024-01-26T09:21:25.034025Z DEBUG tunnelbroker::websockets: Polling for messages from: 192.168.0.170:53901 | |
// first connection (socketID = 1) CLOSE | |
2024-01-26T09:21:26.930806Z DEBUG tunnelbroker::websockets: Connection to 192.168.0.170:53901 closed. | |
2024-01-26T09:21:26.930843Z INFO tunnelbroker::websockets: Unregistering connection to: 192.168.0.170:53901 | |
// second connection (socketID = 2) OPEN | |
2024-01-26T09:21:26.998157Z DEBUG tunnelbroker::websockets: Incoming connection from: 192.168.0.170:53909 | |
2024-01-26T09:21:26.998695Z DEBUG tunnelbroker::websockets::session: Authenticating device: 9/Dk+21eU27n7fpvFDVWqNrouje2XKGW2jtLPC7vx+A | |
2024-01-26T09:21:27.029587Z DEBUG tunnelbroker::database: Retrieving messages for device: 9/Dk+21eU27n7fpvFDVWqNrouje2XKGW2jtLPC7vx+A | |
2024-01-26T09:21:27.040707Z DEBUG tunnelbroker::database: Retrieved 0 messages for 9/Dk+21eU27n7fpvFDVWqNrouje2XKGW2jtLPC7vx+A | |
2024-01-26T09:21:27.040757Z DEBUG tunnelbroker::websockets::session: Flushed messages for device: 9/Dk+21eU27n7fpvFDVWqNrouje2XKGW2jtLPC7vx+A | |
2024-01-26T09:21:27.041733Z DEBUG tunnelbroker::websockets: Polling for messages from: 192.168.0.170:53909 | |
2024-01-26T09:21:30.044081Z DEBUG tunnelbroker::websockets: Polling for messages from: 192.168.0.170:53909 | |
2024-01-26T09:21:30.048967Z DEBUG tunnelbroker::websockets::session: Received heartbeat from: 9/Dk+21eU27n7fpvFDVWqNrouje2XKGW2jtLPC7vx+A | |
2024-01-26T09:21:30.049057Z DEBUG tunnelbroker::websockets: Polling for messages from: 192.168.0.170:53909 | |
// second connection (socketID = 2) CLOSE | |
2024-01-26T09:21:31.924213Z DEBUG tunnelbroker::websockets: Connection to 192.168.0.170:53909 closed. | |
2024-01-26T09:21:31.924259Z INFO tunnelbroker::websockets: Unregistering connection to: 192.168.0.170:53909 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment