-
Notifications
You must be signed in to change notification settings - Fork 200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add support for WebSocket transports #256
feat: Add support for WebSocket transports #256
Conversation
Codecov Report
@@ Coverage Diff @@
## main #256 +/- ##
==========================================
+ Coverage 89.47% 89.62% +0.15%
==========================================
Files 195 196 +1
Lines 3581 3645 +64
Branches 393 403 +10
==========================================
+ Hits 3204 3267 +63
- Misses 377 378 +1
Continue to review full report at Codecov.
|
@@ -0,0 +1,140 @@ | |||
import express from 'express' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like we could get away with a bit less duplication in the http/ws mediator files
@@ -159,8 +162,8 @@ export class Agent { | |||
return this.agentConfig.mediatorUrl | |||
} | |||
|
|||
public async receiveMessage(inboundPackedMessage: unknown) { | |||
return await this.messageReceiver.receiveMessage(inboundPackedMessage) | |||
public async receiveMessage(inboundPackedMessage: unknown, transport?: Transport) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather create a single InboundMessage
or InboundSession
that contains both the packed message, the transport and any other context that may arise in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about creating the InboundMessageContext
here and then enhanced it with other attributes inside MessageReciever
?
I would rather not introduce yet another type because we already have perhaps too much (XxxMessage, XxxMessageContext, XxxPackage, ...) Then we could do the same for the outbound messages as OutboundMessageContext
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah we already have InboundMessageContext
of course. Yes that sounds perfect!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like a much larger change than I anticipated. I suggest doing it in separate PR.
We would need to add wireMessage
into InboundMessageContext
and make message
optional but then validate everywhere that it's present. Or we can figure out a different solution.
src/agent/TransportService.ts
Outdated
|
||
private findEndpoint(connection: ConnectionRecord) { | ||
if (connection.theirDidDoc) { | ||
const endpoint = connection.theirDidDoc.service[0].serviceEndpoint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didCommServices returns only the didcomm services (diddoc may include other service types) and also automatically orders the transports by priority.
We should probably also update this method to pass in supported outbound transport /schemes so we don't return the first transport scheme that may be my_custom_scheme://
while the second service is http://
which we do support
const endpoint = connection.theirDidDoc.service[0].serviceEndpoint | |
const endpoint = connection.theirDidDoc.didCommServices[0].serviceEndpoint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this could potentially throw an error if there are no service endpoints. Dunno if we want to check that here
this.transportTable[connectionId] = transport | ||
} | ||
|
||
public resolveTransport(connection: ConnectionRecord): Transport { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice if we can make this more dynamic. this implementation requires to support the transport in core. Ideally adding an outbound/inbound transport class is enough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I think we would need to move this logic to outbound transporters and just provide some utility functions to get the endpoint from DidDoc instead of having it in the core. That would also solve your other suggestions like "update this method to pass in supported outbound transport /schemes".
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
Signed-off-by: Jakub Koci <jakub.koci@gmail.com>
@TimoGlastra Updated the PR according to your suggestions. I think we can update and refactor the transport resolve mechanism when we add multi-transport. It will be more obvious how to structure the code then. |
I added another two mediators to test WebSocket transports. So now, we run tests for both HTTP and websocket. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
This introduces some technical debt with how transports are managed that we can hopefully fix in the near future, but I think it is good to get this merged now.
The release pipeline is failing. I'll take a look at it today |
This is how it works now:
config
.inboundConnection
if it has any.ws
endpoint because we want to make a connection via WebSocket.indbound
connection. Therefore it’s the samews
endpoint as it is contained in the mediator invitation.To integrate ws and http servers together and support multiple transports we would need to enable following:
inbound
connection invitation or DidDoc.Other notes:
config.endpoint
to valuews://localhost:${PORT}
mediator-ws.ts
(or integrate ws and HTTP together as I mentioned)Related to #250