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

Conversation

@timoxley
Copy link
Contributor

@timoxley timoxley commented Aug 12, 2020

Removed encryption logic in preparation for re-adding the encryption/decryption logic in a more "pipeline"-like architecture.

Did some substantial refactoring of the client to try isolate related pieces of logic & state: Connection, Publishing, Subscribing + Resends. Flattened some logic and moved event handlers into methods so it's possible to actually remove them, but otherwise the code is largely unchanged, things are just moved around a bit.

Followed by:

@timoxley timoxley requested a review from hpihkala August 12, 2020 17:48
@timoxley timoxley force-pushed the remove-encryption-code branch from cfc2b5c to 197232e Compare September 8, 2020 19:14
@timoxley timoxley requested review from harbu and mirpo September 17, 2020 13:33
Copy link
Contributor

@mirpo mirpo left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@harbu harbu left a comment

Choose a reason for hiding this comment

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

LGTM; Skimmed through since it was a pretty big PR.

A few very minor comments. Prolly were in the code before these changes so feel free to ignore.

One thing that I took note of with the current code base: lots of state handling, registering / unregistering, bookkeeping, connection management etc. Wonder how much of this is really necessary and how much a result of accidental complexity.

src/Publisher.js Outdated
client.on('connected', this.onConnected)
}

async onConnected() {
Copy link
Contributor

Choose a reason for hiding this comment

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

No await keyword in method. Is async needed?

src/Publisher.js Outdated
// Check pending publish requests
const publishQueueCopy = this.publishQueue.slice(0)
this.publishQueue = []
publishQueueCopy.forEach((publishFn) => publishFn())
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it would be better to remove an item from the queue only after is has been successfully published?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's probably better, though this is the old-code as-is.

I have a 'queue' in the new version but it isn't clamped at a max value like this, just works on promises. Should probably get a proper queue again in order to limit the max outstanding.

stream.getSubscription(sub.id).handleResending(response)
}

async onUnicastMessage(msg) {
Copy link
Contributor

Choose a reason for hiding this comment

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

async not necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

right, doesn't help for event handlers

this._checkAutoDisconnect()
}

async onClientConnected() {
Copy link
Contributor

Choose a reason for hiding this comment

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

async needed?

})
})
} catch (err) {
this.client.emit('error', err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since _resendAndSubscribe has a catch above, seems like anything that would fall here would be a "genuine" error worth throwing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep correct, good spotting

@timoxley timoxley changed the title Remove Encryption, Refactor Client 1. Remove Encryption, Refactor Client Sep 21, 2020
* Promisify subscribe/unsubscribe.

* Fail _request call if unsubscribe/subscribe request fails to send.

* Fix missing import in resend test.

* Fix browser tests.

* Clean up unused function in test.

* 4. Refactor Publish (#164)

* Refactor & co-locate publish code.

* Avoid using expensive ethers.Wallet.createRandom() calls in test. e.g. 1000x calls with ethers: 14s, randomBytes: 3.5ms.

* Ensure messageCreationUtil is cleaned up after test.

* Fix non-functional MessageCreationUtil test.

* Swap out receptacle for more flexible mem/p-memoize/quick-lru.

* Convert LoginEndpoints test to async/await.

* Remove calls to ensureConnected/ensureDisconnected in test.

* 5. Message Sequencing – Guarantee sequence follows publish order & Prevent backdated messages silently breaking future publishes (#166)

* Improve authFetch logging.

* Update message sequencer to strictly enforce message order.

* Queue publishes per-stream otherwise can skip forward then back even when messages published in correct sequence.

* Add partial solution to broken backdated messages, at least doesn't break regular sequential publishes.

* Tidy up, add some comments.

* Move publish queue fn into utils.
@timoxley timoxley mentioned this pull request Nov 24, 2020
2. Refactor Connection & Retry Handling
@timoxley
Copy link
Contributor Author

This all lives in the 5.x branch and PR #192 now.

@timoxley timoxley closed this Jan 19, 2021
@timoxley timoxley deleted the remove-encryption-code branch January 19, 2021 18:34
@timoxley timoxley mentioned this pull request Jan 20, 2021
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.

4 participants