Skip to content

Commit

Permalink
log registrations + add ip to backend errors (#2261)
Browse files Browse the repository at this point in the history
* log registrations + add ip to backend errors

* bump to 1.0.2

* attempt to diagnose #2256
  • Loading branch information
taoeffect authored Jul 27, 2024
1 parent 459c68c commit 5f69ba4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
26 changes: 16 additions & 10 deletions backend/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ const route = new Proxy({}, {

// RESTful API routes

// TODO: Update this regex once `chel` uses prefixed manifests
const manifestRegex = /^z9brRu3V[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{44}$/

// NOTE: We could get rid of this RESTful API and just rely on pubsub.js to do this
// —BUT HTTP2 might be better than websockets and so we keep this around.
// See related TODO in pubsub.js and the reddit discussion link.
Expand All @@ -52,8 +55,7 @@ route.POST('/event', {
},
validate: { payload: Joi.string().required() }
}, async function (request, h) {
// TODO: Update this regex once `chel` uses prefixed manifests
const manifestRegex = /^z9brRu3V[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]{44}$/
const ip = request.headers['x-real-ip'] || request.info.remoteAddress
try {
const deserializedHEAD = GIMessage.deserializeHEAD(request.payload)
try {
Expand Down Expand Up @@ -89,6 +91,7 @@ route.POST('/event', {
if (Boom.isBoom(r)) {
return r
}
console.info(`new user: ${name}=${deserializedHEAD.contractID} (${ip})`)
}
}
}
Expand All @@ -113,13 +116,15 @@ route.POST('/event', {
}
return deserializedHEAD.hash
} catch (err) {
err.ip = ip
logger.error(err, 'POST /event', err.message)
return err
}
})

route.GET('/eventsAfter/{contractID}/{since}/{limit?}', {}, async function (request, h) {
const { contractID, since, limit } = request.params
const ip = request.headers['x-real-ip'] || request.info.remoteAddress
try {
if (contractID.startsWith('_private') || since.startsWith('_private')) {
return Boom.notFound()
Expand All @@ -138,6 +143,7 @@ route.GET('/eventsAfter/{contractID}/{since}/{limit?}', {}, async function (requ
request.events.once('disconnect', stream.destroy.bind(stream))
return stream
} catch (err) {
err.ip = ip
logger.error(err, `GET /eventsAfter/${contractID}/${since}`, err.message)
return err
}
Expand Down Expand Up @@ -722,8 +728,8 @@ route.POST('/zkpp/register/{name}', {
}
}
} catch (e) {
const ip = req.headers['x-real-ip'] || req.info.remoteAddress
console.error(e, 'Error at POST /zkpp/{name}: ' + e.message, { ip })
e.ip = req.headers['x-real-ip'] || req.info.remoteAddress
console.error(e, 'Error at POST /zkpp/{name}: ' + e.message)
}

return Boom.internal('internal error')
Expand All @@ -740,8 +746,8 @@ route.GET('/zkpp/{name}/auth_hash', {

return challenge || Boom.notFound()
} catch (e) {
const ip = req.headers['x-real-ip'] || req.info.remoteAddress
console.error(e, 'Error at GET /zkpp/{name}/auth_hash: ' + e.message, { ip })
e.ip = req.headers['x-real-ip'] || req.info.remoteAddress
console.error(e, 'Error at GET /zkpp/{name}/auth_hash: ' + e.message)
}

return Boom.internal('internal error')
Expand All @@ -765,8 +771,8 @@ route.GET('/zkpp/{name}/contract_hash', {
return salt
}
} catch (e) {
const ip = req.headers['x-real-ip'] || req.info.remoteAddress
console.error(e, 'Error at GET /zkpp/{name}/contract_hash: ' + e.message, { ip })
e.ip = req.headers['x-real-ip'] || req.info.remoteAddress
console.error(e, 'Error at GET /zkpp/{name}/contract_hash: ' + e.message)
}

return Boom.internal('internal error')
Expand All @@ -791,8 +797,8 @@ route.POST('/zkpp/updatePasswordHash/{name}', {
return result
}
} catch (e) {
const ip = req.headers['x-real-ip'] || req.info.remoteAddress
console.error(e, 'Error at POST /zkpp/updatePasswordHash/{name}: ' + e.message, { ip })
e.ip = req.headers['x-real-ip'] || req.info.remoteAddress
console.error(e, 'Error at POST /zkpp/updatePasswordHash/{name}: ' + e.message)
}

return Boom.internal('internal error')
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "group-income",
"version": "1.0.1",
"version": "1.0.2",
"contractsVersion": "1.0.0",
"private": true,
"description": "Group Income is a decentralized and private (end-to-end encrypted) financial safety net for you and your friends.",
Expand Down
5 changes: 2 additions & 3 deletions test/cypress/integration/group-chat.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,7 @@ describe('Group Chat Basic Features (Create & Join & Leave & Close)', () => {

cy.giRedirectToGroupChat()

// TODO: uncomment this and fix this heisenbug: https://github.com/okTurtles/group-income/issues/2256
// cy.giCheckIfJoinedChatroom(CHATROOM_GENERAL_NAME, me)
// cy.giCheckIfJoinedChatroom(CHATROOM_GENERAL_NAME, me) // giAcceptGroupInvite already checks this
cy.getByDT('channelMembers').should('contain', '2 members')
cy.giLogout()
})
Expand All @@ -527,7 +526,7 @@ describe('Group Chat Basic Features (Create & Join & Leave & Close)', () => {

cy.giRedirectToGroupChat()

cy.giCheckIfJoinedChatroom(CHATROOM_GENERAL_NAME, me)
// cy.giCheckIfJoinedChatroom(CHATROOM_GENERAL_NAME, me) // giAcceptGroupInvite already checks this
cy.getByDT('channelMembers').should('contain', '3 members')
cy.giLogout()
})
Expand Down
2 changes: 2 additions & 0 deletions test/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,8 @@ Cypress.Commands.add('giCheckIfJoinedChatroom', (

cy.getByDT('conversationWrapper').within(($el) => {
if (inviter) {
// TODO: fix this heisenbug here: https://github.com/okTurtles/group-income/issues/2256
cy.get('.c-message:last-child .c-who > span:first-child').scrollIntoView()
cy.get('.c-message:last-child .c-who > span:first-child').should('contain', inviter)
}
const message = selfJoin ? `Joined ${channelName}` : `Added a member to ${channelName}: ${invitee}`
Expand Down

0 comments on commit 5f69ba4

Please sign in to comment.