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

perf: simplify go-libp2p and https implementation #201

Merged
merged 2 commits into from
Jun 22, 2023
Merged

perf: simplify go-libp2p and https implementation #201

merged 2 commits into from
Jun 22, 2023

Conversation

marten-seemann
Copy link
Contributor

Lots of nits. The biggest change here is that I refactored sendBytes and drainStream into pure functions, and copy-pasted them into the https implementation. Using an io.MultiReader allows us to simplify the reading of the http.Request.Body.

@mxinden Feel free to merge (this is targeting #184). Does this PR trigger a CI run? Would be good in order to see if this actually works.

Copy link
Member

@mxinden mxinden left a comment

Choose a reason for hiding this comment

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

Great. Thank you @marten-seemann!

Comment on lines +59 to 70
func (r *nullReader) Read(b []byte) (int, error) {
remaining := r.N - r.read
l := uint64(len(b))
if uint64(len(b)) > remaining {
l = remaining
}
return b
r.read += l
if r.read == r.N {
return int(l), io.EOF
}
return int(l), nil
}
Copy link
Member

@mxinden mxinden Jun 22, 2023

Choose a reason for hiding this comment

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

I am assuming that it is safe in Golang to return "uninitialized" bytes, i.e. the original bytes in b to a remote machine. E.g. there is no risk of b containing deallocated secret key material.

Just for others, returning non-zero bytes is just fine according to the perf specification:

The bytes themselves should be a predetermined arbitrary set of bytes. Zero is fine, but so is random bytes (as long as it's not a different set of random bytes, because then you may be limited by how fast you can generate random bytes).

https://github.com/libp2p/specs/blob/master/perf/perf.md

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.

2 participants