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

start rejecting Metadata.ProtocolID == 0 #94

Closed
mvdan opened this issue Oct 12, 2021 · 2 comments
Closed

start rejecting Metadata.ProtocolID == 0 #94

mvdan opened this issue Oct 12, 2021 · 2 comments
Assignees

Comments

@mvdan
Copy link
Contributor

mvdan commented Oct 12, 2021

If the user forgets to set it, we should catch that as an error instead of silently assuming whatever id==0 happens to be. I imagine it will be an easy mistake to make, and could lead to very confusing errors down the line, e.g. metadata decode errors on the other side.

For instance, one can't make Go struct types exhaustive, so it can be easy to just type indexer.Metadata{Data: someData} and not set the protocol ID at all.

@mvdan mvdan self-assigned this Oct 12, 2021
@mvdan mvdan transferred this issue from ipni/go-indexer-core Oct 13, 2021
@mvdan
Copy link
Contributor Author

mvdan commented Oct 13, 2021

Moved the issue to storetheindex, as I see @gammazero moved the type here.

I'll send the first PR here shortly.

mvdan added a commit that referenced this issue Oct 13, 2021
Integers in Go default to the zero value, meaning that if the user
forgets to set the protocol ID, it could transparently default to a
confusing value. For instance:

	metadata := v0.Metadata{Data: someData}

This could lead to confusing decode errors later on, or to metadata
being mistaken for the wrong kind.

Instead, reject this zero value. The protocol ID is a multihash anyway,
and we want users to either select registered indexer metadata
multihashes, or a multihash in the reserved range for testing.

The check happens at both encode and decode, for extra safety.
This required adding an error return on the encode side.
While we're there, make Metadata implement encoding's Binary interfaces.

Updates #94.
@mvdan
Copy link
Contributor Author

mvdan commented Oct 13, 2021

PR up at #95. I'll keep this issue open until the changes are propagated. Presumably, only indexer-reference-provider needs to be updated.

mvdan added a commit that referenced this issue Oct 13, 2021
Integers in Go default to the zero value, meaning that if the user
forgets to set the protocol ID, it could transparently default to a
confusing value. For instance:

	metadata := v0.Metadata{Data: someData}

This could lead to confusing decode errors later on, or to metadata
being mistaken for the wrong kind.

Instead, reject this zero value. The protocol ID is a multihash anyway,
and we want users to either select registered indexer metadata
multihashes, or a multihash in the reserved range for testing.

The check happens at both encode and decode, for extra safety.
This required adding an error return on the encode side.
While we're there, make Metadata implement encoding's Binary interfaces.

Updates #94.
mvdan added a commit that referenced this issue Oct 13, 2021
Integers in Go default to the zero value, meaning that if the user
forgets to set the protocol ID, it could transparently default to a
confusing value. For instance:

	metadata := v0.Metadata{Data: someData}

This could lead to confusing decode errors later on, or to metadata
being mistaken for the wrong kind.

Instead, reject this zero value. The protocol ID is a multihash anyway,
and we want users to either select registered indexer metadata
multihashes, or a multihash in the reserved range for testing.

The check happens at both encode and decode, for extra safety.
This required adding an error return on the encode side.
While we're there, make Metadata implement encoding's Binary interfaces.

Updates #94.
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

No branches or pull requests

1 participant