Skip to content
This repository has been archived by the owner on Jan 3, 2022. It is now read-only.

fix: fdcostly should take only the prefix into account #5

Merged
4 commits merged into from
Mar 13, 2019

Conversation

Kubuxu
Copy link
Member

@Kubuxu Kubuxu commented Aug 4, 2017

also add tests for it

@Kubuxu Kubuxu requested review from whyrusleeping and a user August 4, 2017 14:55
filter.go Outdated
if len(mas) < 2 {
return false
}
a = mas[0].Encapsulate(mas[1])
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems pretty memory expensive...

Copy link
Member Author

Choose a reason for hiding this comment

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

better idea how to do it?

Copy link

Choose a reason for hiding this comment

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

A single a.Protocols() and then a check whether any of them is P_TCP, should simplify this a lot. Then mafmt.TCP.matches(a) can be dropped, which actually does quite a lot under the hood. Collecting only the protocols is less work than building up the whole thing and then matching. (We should amend multiaddr-fmt to the same, but that's for another time.)

That would also make this function more future-proof, TCP won't neccessarily always be at position 2 in the address, but it'll always be FD-costly.

@ghost
Copy link

ghost commented Mar 13, 2019

@Kubuxu is this patch still relevant?

also add tests for it

License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
@ghost ghost assigned Kubuxu Mar 13, 2019
@ghost ghost added the status/in-progress In progress label Mar 13, 2019
@Kubuxu
Copy link
Member Author

Kubuxu commented Mar 13, 2019

I've rebased it and it is relevant. Currently tcp/80/ws is not considered costly.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Nice, thanks! See comment

filter.go Outdated
if len(mas) < 2 {
return false
}
a = mas[0].Encapsulate(mas[1])
Copy link

Choose a reason for hiding this comment

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

A single a.Protocols() and then a check whether any of them is P_TCP, should simplify this a lot. Then mafmt.TCP.matches(a) can be dropped, which actually does quite a lot under the hood. Collecting only the protocols is less work than building up the whole thing and then matching. (We should amend multiaddr-fmt to the same, but that's for another time.)

That would also make this function more future-proof, TCP won't neccessarily always be at position 2 in the address, but it'll always be FD-costly.

@ghost ghost self-requested a review March 13, 2019 17:08
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Ooops, wrong click. Meant to "request changes" :)

License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
@Kubuxu
Copy link
Member Author

Kubuxu commented Mar 13, 2019

I've imported github.com/libp2p/go-ws-transport for tests. In case of gx it probably isn't the best to depend on it.

@ghost
Copy link

ghost commented Mar 13, 2019

I've imported github.com/libp2p/go-ws-transport for tests. In case of gx it probably isn't the best to depend on it.

Good point -- maybe use /http instead in those tests? It's present in go-multiaddr itself and ends up testing basically the same thing.

License: MIT
Signed-off-by: Jakub Sztandera <[email protected]>
@ghost
Copy link

ghost commented Mar 13, 2019

Leeet's go! Thanks 👍

@ghost ghost merged commit a4c5482 into master Mar 13, 2019
@ghost ghost removed the status/in-progress In progress label Mar 13, 2019
@ghost ghost deleted the fix/fdcostly/prefixx branch March 13, 2019 18:12
@Stebalien Stebalien mentioned this pull request May 26, 2020
77 tasks
This pull request was closed.
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.

2 participants