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

thread Context into protocol and dataunit APIs #16

Merged
merged 28 commits into from
Dec 5, 2023
Merged

thread Context into protocol and dataunit APIs #16

merged 28 commits into from
Dec 5, 2023

Conversation

ydnar
Copy link
Member

@ydnar ydnar commented Dec 4, 2023

  • protocol/dataunit: add Context support for cancelation and timeouts
  • protocol: add Context support to Client
  • protocol, protocol/dataunit: thread Context into Server, add Responder types
  • protocol/dataunit: remove separate Reader and Writer types
  • protocol/dataunit: clarify that the Context passed to Serve governs reads and writes on the underlying connection
  • protocol: improve docs

@ydnar ydnar requested a review from cee-dub December 4, 2023 18:17
@ydnar ydnar self-assigned this Dec 4, 2023
var cfg config.Config
cfg.Join(opts...)
return connect(conn, cfg)
}
Copy link
Member

Choose a reason for hiding this comment

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

When would someone use Connect vs. Dial?

Copy link
Member Author

Choose a reason for hiding this comment

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

Dial will likely go away, or exist only as a helper, which would remove the direct dependency on crypto/tls in this package.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe Dial is better as an example?

// Read the initial <greeting> from the server.
data, err := conn.ReadDataUnit()
data, err := dataunit.Receive(ctx, conn)
if err != nil {
return c, nil, err
}
body, err := c.coder.umarshalXML(data)
return c, body, err
Copy link
Member

Choose a reason for hiding this comment

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

The protocol client seems like the perfect place to enforce the ordering of messages, asserting here that this is a greeting or returning an error instead.

// RespondEPP writes an EPP response to the client. It blocks until the message is written,
// Context is cancelled, or the underlying connection is closed.
//
// RespondEPP can be called from an arbriary goroutine, but must only be called once.
Copy link
Member

Choose a reason for hiding this comment

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

Similar question about the "once" aspect.

//
// [RFC 5730]: https://datatracker.ietf.org/doc/rfc5730/
type Server interface {
// ServeEPP provides an client EPP request and a mechanism to respond to the request.
// It blocks until a response is received or the underlying connection is closed.
// The returned [Writer] should only be used once. The returned Writer will always
// It blocks until a response is received, Context is canceled, or the underlying connection is closed.
Copy link
Member

Choose a reason for hiding this comment

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

Is this blocking not until a response is sent/returned to the client? I didn't think the server would wait for the client to read (beyond a timeout) from the server and respond to it.

// If no schemas are provided, a set of reasonable defaults will be used.
func Serve(conn dataunit.Conn, greeting epp.Body, schemas ...schema.Schema) (Server, error) {
func Serve(ctx context.Context, conn io.ReadWriter, greeting epp.Body, schemas ...schema.Schema) (Server, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Appreciate the documentation, but perhaps this should be renamed greetingCtx to be clearer about the scope.

Copy link
Member

@cee-dub cee-dub Dec 5, 2023

Choose a reason for hiding this comment

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

Sorry for the greetingCtx comment duplication. This is the top level location that passes down to protocol.Connect.

Copy link
Member

@cee-dub cee-dub left a comment

Choose a reason for hiding this comment

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

Still some minor outstanding comments, but this seems cleaner than yesterday's version.

// If no schemas are provided, a set of reasonable defaults will be used.
func Connect(conn dataunit.Conn, schemas ...schema.Schema) (Client, epp.Body, error) {
func Connect(ctx context.Context, conn io.ReadWriter, schemas ...schema.Schema) (Client, epp.Body, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func Connect(ctx context.Context, conn io.ReadWriter, schemas ...schema.Schema) (Client, epp.Body, error) {
func Connect(greetingCtx context.Context, conn io.ReadWriter, schemas ...schema.Schema) (Client, epp.Body, error) {

I wonder if there's a better name than Connect for this function since it is really only about receiving the greeting, which initializes the EPP protocol over whatever connection is already established in conn.

Copy link
Member Author

Choose a reason for hiding this comment

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

It initializes the Client, which maintains the schemas, but to your point…does it need to carry that state?

// If no schemas are provided, a set of reasonable defaults will be used.
func Serve(conn dataunit.Conn, greeting epp.Body, schemas ...schema.Schema) (Server, error) {
func Serve(ctx context.Context, conn io.ReadWriter, greeting epp.Body, schemas ...schema.Schema) (Server, error) {
Copy link
Member

@cee-dub cee-dub Dec 5, 2023

Choose a reason for hiding this comment

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

Sorry for the greetingCtx comment duplication. This is the top level location that passes down to protocol.Connect.

@ydnar ydnar merged commit 4fa1ed8 into main Dec 5, 2023
@ydnar ydnar deleted the ydnar/context branch December 5, 2023 22:50
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