Skip to content
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

createServer implementation #2

Merged
merged 19 commits into from
Oct 29, 2020

Conversation

getlarge
Copy link
Member

@getlarge getlarge commented Oct 13, 2020

Just to make a demonstration, i opened the PR.

The implementation can be manually tested for TCP connection, with node ./example.js.
It seems to work fine, the proxy header is parsed then removed from the stream.

Now the issue that remains is how to pass the protocol (aka connDetails in Aedes) to the client, i made a wrong assumption here. So maybe we could extend the arguments passed to aedes.handle to include the connection details and pass them to the client by sending them via preConnect event or by directly assigning to the client object ?

Anyway i don't see how to do it properly without modifying aedes.handle function.

@robertsLando Any suggestions ?
Btw i was not able to push to the moscajs repo directly, is it normal ?

@robertsLando
Copy link
Member

robertsLando commented Oct 13, 2020

So maybe we could extend the arguments passed to aedes.handle to include the connection details and pass them to the client by sending them via preConnect event or by directly assigning to the client object ?

I would definetly modify aedes.handle function in order to accept a connDetails parameter that could be added then in Client constructor.

I was also thinking about another idea, I would like to move the mqtt parser to the server factory, so the client will always receive plain mqtt, in that case I would create another function for example handleMqtt that will accept a plain mqtt stream instead (along with connection details)

Thoughts?

Btw i was not able to push to the moscajs repo directly, is it normal ?

Now I check your permissions

@robertsLando
Copy link
Member

@getlarge Check now you should be able to push in the repo :)

Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

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

Please remove package-lock.json

@getlarge
Copy link
Member Author

Could you explain further your suggestion for handleMqtt, is it something that would replace client._parser.parse(buf) in aedes ?
Or would it be a readable stream in objectMode 'containing' the original buffer parsed as mqtt packet ?
Where do you imagine that this process would happen ?

@robertsLando
Copy link
Member

is it something that would replace client._parser.parse(buf) in aedes

Yes, that will allow us to remove the client nextBatch function. We could also think about a 1.0.0 version that completely remove that without back compatibility. I don't like how nextBatch actually works I have already tried some other implementation but Matteo said that would be a perf killer: moscajs/aedes#519

@getlarge
Copy link
Member Author

Wow the stream implementation looks very good on that PR! Haven't you tested its performance ? Do you know the reason(s) why it would be a "perf killer" ?
Maybe we can finish that "simple" createServer factory, update aedes and the protocol decoder and later we can discuss on that new implementation of mqtt parser ?

@robertsLando
Copy link
Member

Wow the stream implementation looks very good on that PR!

Based on @mcollina comment seems not :( I dunno why, I made some tests and performances seems almost the same, maybe a little bit better but not worse. Anyway we could speak about that next. In the meanwhile we can go on with this. Are you ready to merge here?

Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

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

lgtm

@robertsLando
Copy link
Member

@getlarge We could add connDetails to req and add this.connDetails = req ? req.connDetails : null here ?

Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

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

Remember to remove package-lock.json

@getlarge
Copy link
Member Author

It's still not ready for merge i have issues with websocket connection and the protocolDecoder (_socket is undefined), i'm currently extending the example and writing some tests.
Or maybe we can merge after my next push and i will update the protocol decoder module after ?

I'm ok with the connDetails assigned to req.

package-lock.json is removed and .gitignore updated.

lib/server-factory.js Outdated Show resolved Hide resolved
lib/server-factory.js Outdated Show resolved Hide resolved
test.js Show resolved Hide resolved
example.js Show resolved Hide resolved
index.js Show resolved Hide resolved
lib/server-factory.js Outdated Show resolved Hide resolved
lib/server-factory.js Outdated Show resolved Hide resolved
@robertsLando
Copy link
Member

It's still not ready for merge i have issues with websocket connection and the protocolDecoder (_socket is undefined), i'm currently extending the example and writing some tests.

I opened a issue on ws module here about this. I fixed with: here

@getlarge
Copy link
Member Author

It's still not ready for merge i have issues with websocket connection and the protocolDecoder (_socket is undefined), i'm currently extending the example and writing some tests.

I opened a issue on ws module here about this. I fixed with: here

Yes i already noticed, the issue was due to conn reassignement. It's fixed now.

@getlarge
Copy link
Member Author

getlarge commented Oct 14, 2020

The latest commit use branches from github instead of packages (for aedes and protocol-decoder) with required changes to validate the behaviour of this new module

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
index.js Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Show resolved Hide resolved
index.js Outdated
}

const extractConnectionDetails = (options, aedesHandler, conn, req = {}) => {
const onReadable = (err) => {

Choose a reason for hiding this comment

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

This does not have err

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, should i check the stream error event ?

Choose a reason for hiding this comment

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

yes exactly!

Copy link
Member Author

Choose a reason for hiding this comment

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

i simply added this handler for error event:

  const onError = (error) => {
    conn.removeListener('error', onError)
    aedes.emit('error', error)
  }

  conn.on('error', onError)

Do you anything else to add in it ?

Copy link
Member

Choose a reason for hiding this comment

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

@mcollina ping

index.js Outdated Show resolved Hide resolved
index.js Show resolved Hide resolved
index.js Outdated Show resolved Hide resolved
index.js Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
index.js Show resolved Hide resolved
Copy link

@mcollina mcollina 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
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

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

LGTM once we release protocol decoder and aedes so we can chenge them in deps

@getlarge
Copy link
Member Author

I think it doesn't matter in which order we publish the repo.

  • protocol-decoder has aedes and server-factory as devDependencies
  • server-factory has protocol-decoder as dependency and aedes as devDependency

So we'll have to create a new PR for one of the 2 repos in any case.
I'm currently updating the test suites for protocol-decoder and after this, everything should be ready.

Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

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

So we'll have to create a new PR for one of the 2 repos in any case.

ok so feeel free to merge when you want. Good job @getlarge :)

@robertsLando
Copy link
Member

@getlarge Aedes 0.44.0 is on npm

@getlarge
Copy link
Member Author

@robertsLando Just ping when protocol-decoder is published and i will update package.json on this one.

@robertsLando
Copy link
Member

@getlarge Ping :)

@getlarge
Copy link
Member Author

@robertsLando ready to merge!

@robertsLando
Copy link
Member

@getlarge you should have the permission for this so I let you do it :) please use squash and merge and try to use angular commit style:

https://github.com/angular/angular/blob/master/CONTRIBUTING.md

Also @mcollina please add @getlarge to npm org too so he can help me with releases.

P.S: for releases the script is really handy, just run "npm run release" and follow the ci instructions

@getlarge
Copy link
Member Author

I still don't have write access to the repositories, instead of merge button, i have this : "Only those with write access to this repository can merge pull requests."
No problem for the release, i also use release-it, additionally to the package, should i create a tag and a release too ?

@robertsLando
Copy link
Member

robertsLando commented Oct 28, 2020 via email

@robertsLando robertsLando merged commit bee7b04 into moscajs:main Oct 29, 2020
@robertsLando
Copy link
Member

@getlarge Now you should have write access to this repo too, I dunno why but the permissions of the team was read on this repo.

@robertsLando
Copy link
Member

@mcollina When you have time please add @getlarge to moscajs npm org (I don't have admin permissions there)

@robertsLando
Copy link
Member

@getlarge I have just release a new version on npm, hope matteo will add you there when he can :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants