Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 10 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@datasance/iofogcontroller",
"version": "3.5.3",
"version": "3.5.4",
"description": "ioFog Controller project for Datasance PoT @ datasance.com \\nCopyright (c) 2023 Datasance Teknoloji A.S.",
"main": "./src/main.js",
"author": "Emirhan Durmus",
Expand Down Expand Up @@ -55,7 +55,7 @@
"iofog-controller": "src/main.js"
},
"dependencies": {
"@datasance/ecn-viewer": "1.1.1",
"@datasance/ecn-viewer": "1.1.2",
"@kubernetes/client-node": "^0.22.3",
"@msgpack/msgpack": "^3.1.2",
"@opentelemetry/api": "^1.9.0",
Expand All @@ -64,7 +64,7 @@
"@opentelemetry/instrumentation-http": "^0.200.0",
"@opentelemetry/resources": "^1.8.0",
"@opentelemetry/sdk-node": "^0.200.0",
"axios": "1.11.0",
"axios": "1.12.2",
"bignumber.js": "^9.3.0",
"body-parser": "^1.20.3",
"child_process": "1.0.2",
Expand Down
4 changes: 4 additions & 0 deletions src/services/agent-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ const agentProvision = async function (provisionData, transaction) {
provisionKey: provisionData.key
}, transaction)

await ChangeTrackingService.update(fog.uuid, ChangeTrackingService.events.volumeMounts, transaction)
await ChangeTrackingService.update(fog.uuid, ChangeTrackingService.events.registries, transaction)
await ChangeTrackingService.update(fog.uuid, ChangeTrackingService.events.microserviceFull, transaction)

return {
uuid: fog.uuid,
privateKey: keyPair.privateKey
Expand Down
47 changes: 44 additions & 3 deletions src/websocket/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,9 +267,23 @@ class WebSocketServer {
// Wrap the entire connection handling in a transaction
TransactionDecorator.generateTransaction(async (transaction) => {
try {
const token = req.headers.authorization
// Check for token in Authorization header first (for agent and CLI connections)
let token = req.headers.authorization

// If no token in header, check query parameters (for React UI connections)
if (!token) {
logger.debug('Missing authentication token in header, checking query parameters')
const url = new URL(req.url, `http://${req.headers.host}`)
token = url.searchParams.get('token')

// If token is found in query params, format it as Bearer token
if (token) {
token = `Bearer ${token}`
}
}

if (!token) {
logger.error('WebSocket connection failed: Missing authentication token')
logger.error('WebSocket connection failed: Missing authentication token neither in header nor query parameters')
try {
ws.close(1008, 'Missing authentication token')
} catch (error) {
Expand Down Expand Up @@ -580,7 +594,7 @@ class WebSocketServer {
try {
const statusMsg = {
type: MESSAGE_TYPES.STDERR,
data: Buffer.from('Waiting for agent connection. Please ensure the microservice agent is running.\n'),
data: Buffer.from('Waiting for agent connection. Please ensure the microservice/agent is running.\n'),
microserviceUuid: microserviceUuid,
execId: 'pending', // Since we don't have execSessionId anymore
timestamp: Date.now()
Expand Down Expand Up @@ -878,6 +892,33 @@ class WebSocketServer {
return
}

if (msg.type === MESSAGE_TYPES.CONTROL) {
// Handle keep-alive messages from user
const controlData = msg.data.toString()
if (controlData === 'keepalive') {
// Send keep-alive response back to user
const keepAliveResponse = {
type: MESSAGE_TYPES.CONTROL,
data: Buffer.from('keepalive'),
microserviceUuid: session.microserviceUuid,
execId: execId,
timestamp: Date.now()
}
const encoded = this.encodeMessage(keepAliveResponse)
user.send(encoded, {
binary: true,
compress: false,
mask: false,
fin: true
})
logger.debug('[RELAY] Sent keep-alive response to user:' + JSON.stringify({
execId,
microserviceUuid: session.microserviceUuid
}))
return // Don't forward keep-alive to agent
}
}

await this.sendMessageToAgent(agent, msg, execId, session.microserviceUuid)
} catch (error) {
logger.error('[RELAY] Failed to process binary message:' + JSON.stringify({
Expand Down
Loading