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

Refactor registry and encoding #50

Merged
merged 8 commits into from May 1, 2020
Merged

Conversation

hannahhoward
Copy link
Collaborator

Goals

We're about to add a bunch more voucher types, and it seems like an important time to clean up some aspects of our protocol. This addresses various issues:

  • removing the need for seperate FromBytes/ToBytes methods on vouchers on top of existing CBOR encoding/decoding methods
  • making registry of vouchers thread safe
  • making our protocol a single valid CBOR data-structure via cbg.Deferred

Implementation

  • Build an encoder/decoder library to seperate logic around encoding and support:
    • cbor-gen types
    • ipld prime types
    • old school go-ipld-cbor types
  • Build a seperate registry that handles
    • maintaining the map from TypeIdentifier -> Type, Validator (actually the registry stories a generic Processor, as several additional registries are incoming for an upcoming data transfer add)
    • keeping it thread safe
  • Move encoding and decoding inside the message data structure
    • The message is responsible for encoding vouchers and selectors
    • The message receives a decoder to get back to the voucher, but it's called inside the message data itself
    • This allows us to insure we're working with CBOR encodable objects, and then to switch to cbg.Deferred inside the message
    • This is important so the whole message is a valid IPLD encoded CBOR data structure

Create a new library for general type encoding
add a simple threadsafe registry to handle registering types like vouchers
incorporate registry into data transfer module
Move encode/decode inside the message -- so that we can insure cbor encodable values, and then use
cbg.Deferred later
convert messages to use cbg.Deferred so that the whole message is a proper CBOR value and also move
selector encoding inside the message
remove utils.go which is not used
move Identifier & Registerable to root types package
Copy link
Contributor

@shannonwells shannonwells left a comment

Choose a reason for hiding this comment

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

I approve this PR

)

func TestRoundTrip(t *testing.T) {
testCases := map[string]struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@shannonwells now that you've turned me on to them... I am all about those table tests.

@hannahhoward hannahhoward merged commit 9a1d95f into master May 1, 2020
@rvagg rvagg deleted the feat/refactor-registry branch January 5, 2023 01:08
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.

None yet

2 participants