Skip to content

Commit

Permalink
More logs on alias server (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
HDegroote authored Jul 25, 2024
1 parent bf4e049 commit 9f4cb57
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/alias-rpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,18 @@ class AliasRpcServer extends ReadyResource {
await this.swarm.destroy()
}

_onconnection (socket, info) {
_onconnection (socket, peerInfo) {
const uid = crypto.randomUUID()
const remotePublicKey = socket.remotePublicKey

this.emit('connection-open', { uid, peerInfo })

socket.on('error', (error) => {
this.emit('socket-error', { error, uid, remotePublicKey })
this.emit('connection-error', { error, uid, peerInfo })
})

socket.on('close', () => {
this.emit('connection-close', { uid, peerInfo })
})

const rpc = new RPC(socket, { protocol: PROTOCOL_NAME })
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"dependencies": {
"b4a": "^1.6.6",
"debounceify": "^1.1.0",
"dht-prom-client": "^0.0.1-alpha.6",
"dht-prom-client": "^0.0.1-alpha.7",
"fastify": "^4.28.0",
"graceful-goodbye": "^1.3.0",
"hypercore-id-encoding": "^1.3.0",
Expand Down
22 changes: 22 additions & 0 deletions run.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,28 @@ function setupLogging (bridge, logger) {
logger.info(`Alias error: ${error} (${uid})`)
}
)

bridge.aliasRpcServer.on(
'connection-open',
({ uid, peerInfo }) => {
const remotePublicKey = idEnc.normalize(peerInfo.publicKey)
logger.info(`Alias server opened connection to ${idEnc.normalize(remotePublicKey)} (uid ${uid})`)
}
)
bridge.aliasRpcServer.on(
'connection-close',
({ uid, peerInfo }) => {
const remotePublicKey = idEnc.normalize(peerInfo.publicKey)
logger.info(`Alias server closed connection to ${idEnc.normalize(remotePublicKey)} (uid ${uid})`)
}
)
bridge.aliasRpcServer.on(
'connection-error',
({ uid, error, peerInfo }) => {
const remotePublicKey = idEnc.normalize(peerInfo.publicKey)
logger.info(`Alias server socket error: ${error.stack} on connection to ${idEnc.normalize(remotePublicKey)} (uid ${uid})`)
}
)
}

main()

0 comments on commit 9f4cb57

Please sign in to comment.