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

fix(peer) String() bounds check #222

Merged
merged 3 commits into from
Nov 16, 2014
Merged

fix(peer) String() bounds check #222

merged 3 commits into from
Nov 16, 2014

Conversation

btc
Copy link
Contributor

@btc btc commented Oct 28, 2014

fixes #217

if len(pid) < maxRunes {
maxRunes = len(pid)
}
return "[Peer " + pid[:maxRunes] + "]"
Copy link
Member

Choose a reason for hiding this comment

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

argh, so much of the code assumes peers have valid multihash ids. we should either enforce those assumptions at the peer-creation interfaces, or everywhere else in the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it generally safe to make certain assumptions about the length of multihashes?

Copy link
Member

Choose a reason for hiding this comment

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

@maybebtc no, multihashes describe their own length, which is variable. you can safely assume ipfs peer.IDs to be longer than 64bits though.

@jbenet
Copy link
Member

jbenet commented Oct 28, 2014

not sure i want to go this route. i think we should instead enforce peers are generated correctly. (WithID should check it's a valid multihash, and > a specific length.)

@btc
Copy link
Contributor Author

btc commented Oct 28, 2014

Perhaps it might be safest to ensure correctness at ID generation and enforce this by only exposing functions that generate IDs safely. Then any peer.ID type found in the codebase is known to be correct.

@jbenet
Copy link
Member

jbenet commented Oct 28, 2014

Perhaps it might be safest to ensure correctness at ID generation and enforce this by only exposing functions that generate IDs safely. Then any peer.ID type found in the codebase is known to be correct.

+1

@btc btc added ready and removed status/in-progress In progress labels Oct 28, 2014
@jbenet
Copy link
Member

jbenet commented Oct 31, 2014

@maybebtc status on this?

@btc
Copy link
Contributor Author

btc commented Oct 31, 2014

IDs are far-reaching. Was thinking that we'd wait until commands gets merged. Do we want to prioritize the ID cleanup over commands?

@jbenet
Copy link
Member

jbenet commented Nov 16, 2014

@maybebtc is this happening? otherwise I'll close it for now.

@btc
Copy link
Contributor Author

btc commented Nov 16, 2014

I think we should merge this in as is for now.

@jbenet
Copy link
Member

jbenet commented Nov 16, 2014

@maybebtc we should either validate it's a multihash or do nothing. the 12char check is not going to do much at all for us-- or is there some specific problem you want to work around?

@btc
Copy link
Contributor Author

btc commented Nov 16, 2014

The length check prevents tests from failing when you attempt to run them verbosely. go test ./... -v

NB: This check is performed on the String() method. It's not performed in the peer constructor. That'd be silly.

@jbenet
Copy link
Member

jbenet commented Nov 16, 2014

Ah somehow i misread it. ok, SGTM

Brian Tiger Chow added 3 commits November 16, 2014 03:43
TODO ensure correctness at ID generation and enforce this by only exposing functions that generate IDs safely. Then any peer.ID type found in the codebase is known to be correct.
@jbenet
Copy link
Member

jbenet commented Nov 16, 2014

I'll rebase and merge

btc pushed a commit that referenced this pull request Nov 16, 2014
@btc btc merged commit fba5db2 into master Nov 16, 2014
@btc btc removed the ready label Nov 16, 2014
@btc btc deleted the fix/peer-string-2014-10-28 branch November 16, 2014 14:59
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.

panic in bitswap TestSendToWantingPeer
2 participants