Skip to content
This repository was archived by the owner on Dec 21, 2021. It is now read-only.

Conversation

@timoxley
Copy link
Contributor

Cherry-picked a bunch of incidental changes/fixes made in the process of creating #204 and #205 so the changes in those PRs can be redone on top of this and reviewed + applied cleanly.

Many of these changes, mainly tests, TS conversions, improving error handling & other mild refactorings were made in the process of trying to track down the unhandled rejection issue I had last week.

@timoxley timoxley force-pushed the cherry-picked-improvements branch 4 times, most recently from 3ff1833 to af9e903 Compare March 11, 2021 21:03
Base automatically changed from 5.x to master March 12, 2021 17:53
@timoxley timoxley force-pushed the cherry-picked-improvements branch 2 times, most recently from aaf9a6c to 21b3e6c Compare March 19, 2021 15:59
timoxley added 23 commits March 19, 2021 12:48
Avoid suppressed errors in Subscription pipeline.
@timoxley timoxley force-pushed the cherry-picked-improvements branch from 21b3e6c to 9f0dbb1 Compare March 19, 2021 16:49
@timoxley timoxley requested a review from teogeb March 19, 2021 17:53
*/

static decryptStreamMessage(streamMessage, groupKey) {
static decryptStreamMessage(streamMessage: MessageLayer.StreamMessage, groupKey: GroupKey) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The static methods which take a non-null groupKey as a parameter could be instance methods of GroupKey class? That way this this EncryptionUtilBase would focus on abstract publicKey/privateKey handling.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another leftover from previous implementation.

They could definitely live elsewhere agreed, though not sure if they belong on GroupKey. This logic is implementation detail for the stream message encryption/decryption process, rather than anything specific to the GroupKey data. Adding this to GroupKey would make GroupKey aware of StreamMessage.

I'd prefer to have the GroupKey only knowing about GroupKey stuff, keep it as close to a self-contained data container as possible avoid slipping into "Fat Model" architecture. i.e. attach cross-model logic to features rather than datatypes.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, not good to couple components together too much.

One possibility would be to create a separate StreamMessageEncryptor which would know StreamMessage and GroupKey.

Or maybe that method could be in StreamMessage, if we create an encryptor interface. StreamMessage could know that, but not the actual implementing GroupKeyEncryptor.

constructor(options: StreamrClientOptions = {}, connection?: StreamrConnection) {
super()
this.id = counterId(`${this.constructor.name}:${uid}`)
this.id = counterId(`${this.constructor.name}:${uid}${options.id || ''}`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the use provides the id, it is maybe unique enough to distinguish the instances? This counterId(${this.constructor.name}:${uid}) could be just a fallback if no explicit id is provided.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, though the wrapper around the id here was added to ensure I get unique results across tests, but I can give the tests known "ids":
e.g.

const publisher = new Client({id: 'publisher'})
const subscriber = new Client({id: 'subscriber'})

Doesn't matter so much as this is 100% for debugging/logging purposes currently, but maybe id isn't the right option property, perhaps it should be name or something.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, name would describe it better 👍

There is the same situation in Subscription class (line 53)

groupKeyData: Uint8Array,
}

function GroupKeyObjectFromProps(data: GroupKeyProps | GroupKeyObject) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is either GroupKeyObject or GroupKeyProps a deprecated form or group key definition object? Or do we need both for other reasons?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't recall the details but the object is in different shapes depending on the source.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the are equal variants I could even name those types as GroupKeyDefinition1 and GroupKeyDefinition2. But doesn't make big difference, any naming is fine.

const cancelTask = sub.cancel()
sub = undefined
await cancelTask()
await cancelTask
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this same fix be applied to line 288, where we currently do await cancelTask()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, 100% correct, good spotting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in cb576fd

@timoxley timoxley merged commit 165f10c into master Mar 23, 2021
@timoxley timoxley deleted the cherry-picked-improvements branch March 23, 2021 14:01
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants