Skip to content

Commit

Permalink
Merge pull request #42 from sicpa-dlab/bugfix/fix-websocket-transport…
Browse files Browse the repository at this point in the history
…s-priority

Bugfix/Fix transports priority for WS mediator connection
  • Loading branch information
Artemkaaas authored Aug 22, 2022
2 parents 43481ba + ee1d570 commit 677eaa0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@sicpa-dlab/aries-framework-core",
"main": "build/index",
"types": "build/index",
"version": "0.1.51",
"version": "0.1.52",
"files": [
"build"
],
Expand Down
21 changes: 13 additions & 8 deletions packages/core/src/agent/MessageSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,13 @@ export class MessageSender {
public async sendDIDCommV2Message(
message: DIDCommV2Message,
sendingMessageType: SendingMessageType = SendingMessageType.Encrypted,
transport?: Transports
transports?: Transports[]
) {
// recipient is not specified -> send to defaultTransport
if (!message.to?.length && transport) {
if (!message.to?.length && transports?.length) {
const service = new DidCommV2Service({
id: transport,
serviceEndpoint: transport,
id: transports[0],
serviceEndpoint: transports[0],
})

if (sendingMessageType === SendingMessageType.Plain) {
Expand All @@ -307,10 +307,10 @@ export class MessageSender {
}

// recipient is not specified and transport is not passed explicitly
if (!message.to?.length && !transport) return
if (!message.to?.length && !transports?.length) return

// else find service and send message there
const service = await this.findRecipientService(message, transport)
const service = await this.findRecipientService(message, transports)

if (sendingMessageType === SendingMessageType.Plain) {
// send message plaintext
Expand Down Expand Up @@ -366,7 +366,10 @@ export class MessageSender {
await this.sendMessage(outboundPackage, service.protocolScheme)
}

private async findRecipientService(message: DIDCommV2Message, transport?: Transports): Promise<DidDocumentService> {
private async findRecipientService(
message: DIDCommV2Message,
transports?: Transports[]
): Promise<DidDocumentService> {
if (!message.to?.length) {
throw new AriesFrameworkError(`Unable to send message encrypted. Message doesn't contain recipient DID.`)
}
Expand All @@ -384,7 +387,9 @@ export class MessageSender {

let services = didDocument?.service || []

const supportedTransports = transport ? [transport, ...this.agentConfig.transports] : this.agentConfig.transports
const supportedTransports = transports?.length
? [...transports, ...this.agentConfig.transports]
: this.agentConfig.transports

// Sort services according to supported transports
const priority = supportedTransports.map((transport) => transport.toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export class OutOfBandService {
public async sendMessage(message: DIDCommV2Message, transport?: Transports) {
this.agentConfig.logger.info(`Sending VTP message with type '${message.type}' to DID ${message?.to}`)
const sendingMessageType = message.to ? SendingMessageType.Encrypted : SendingMessageType.Signed
await this.messageSender.sendDIDCommV2Message(message, sendingMessageType, transport)
const transports = transport ? [transport] : undefined
await this.messageSender.sendDIDCommV2Message(message, sendingMessageType, transports)
}
}
2 changes: 1 addition & 1 deletion packages/core/src/modules/routing/RecipientModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class RecipientModule {
}

try {
await this.messageSender.sendDIDCommV2Message(message, undefined, Transports.WS)
await this.messageSender.sendDIDCommV2Message(message, undefined, [Transports.WSS, Transports.WS])
} catch (error) {
this.logger.warn('Unable to open websocket connection to mediator', { error })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ export class ValueTransferService {
public async sendMessage(message: DIDCommV2Message, transport?: Transports) {
this.config.logger.info(`Sending VTP message with type '${message.type}' to DID ${message?.to}`)
const sendingMessageType = message.to ? SendingMessageType.Encrypted : SendingMessageType.Signed
await this.messageSender.sendDIDCommV2Message(message, sendingMessageType, transport)
const transports = transport ? [transport] : undefined
await this.messageSender.sendDIDCommV2Message(message, sendingMessageType, transports)
}

public async getBalance(): Promise<number> {
Expand Down

0 comments on commit 677eaa0

Please sign in to comment.