-
Notifications
You must be signed in to change notification settings - Fork 6
fix: fdcostly should take only the prefix into account #5
Conversation
filter.go
Outdated
if len(mas) < 2 { | ||
return false | ||
} | ||
a = mas[0].Encapsulate(mas[1]) |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
@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]>
f54ed6e
to
83e4765
Compare
I've rebased it and it is relevant. Currently |
There was a problem hiding this 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]) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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]>
I've imported |
Good point -- maybe use |
License: MIT Signed-off-by: Jakub Sztandera <[email protected]>
Leeet's go! Thanks 👍 |
also add tests for it