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

Proposals for improving netx API and implementation #420

Closed
wants to merge 13 commits into from

Conversation

bassosimone
Copy link
Contributor

@bassosimone bassosimone commented Mar 24, 2020

This pull request contains a bunch of patches aimed at improving the netx API and implementation. It is meant as a companion of #359, where we specify how such changes should look like. It has been originally triggered by work on #125 and on #404, where I learned a lot about ways in which we can evolve netx. At the moment of opening this PR, the plan is to keep this as a Draft PR for documentation purposes, and cherry-pick specific patches if/when needed.

@bassosimone bassosimone changed the title add(internal/tapkit): toolkit to tap network events add(internal/tapkit): toolkit to tap into network events Mar 24, 2020
@bassosimone bassosimone changed the title add(internal/tapkit): toolkit to tap into network events Proposals for improve netx API and implementation Mar 24, 2020
After a few days spent mulling over #125
and #359, I reached the conclusion that we
most likely want to heavily refactor netx.

This is even more true in light of the introduction of DialTLSContext instead of
Go 1.14, which allows us to more cleanly separate the place where we allow tapping
into events from the place in which we collect such events.

This diff distills some code I've been working on for the past few days into a
single file where we make all kind of tapping/wrapping possible and easy.
@bassosimone bassosimone changed the title Proposals for improve netx API and implementation Proposals for improving netx API and implementation Mar 25, 2020
return nil, err
}
return &connWrapper{Conn: conn, Counter: c}, err
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The specific problem of this implementation is that the byte counter is also a dialer, therefore we cannot separate the byte counting and the dialing. However, we sometimes want to account for session and sometimes for both session and experiment. Therefore, this implementation here is not actually meeting our objectives.

// 3. otherwise, it returns the OONI failure string
//
// See the netx/DESIGN.md for more info.
func Failure(err error) string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Failure and Operation are quite useful and there should probably be an issue about them.

type Event struct {
Op string
Time time.Time
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is probably more convenient to be able to wrap every Dialer independently of, say, a Resolver, because this gives us more flexibility. Also, a best practice of Go is to keep interfaces small, so...

Handshake(ctx context.Context, conn net.Conn, config *tls.Config) (
net.Conn, tls.ConnectionState, error)
RoundTrip(req *http.Request) (*http.Response, error)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As said earlier it would be more flexible to have several smaller interfaces.

func ContextOperations(ctx context.Context) Operations {
operations, _ := ctx.Value(operationsKey{}).(Operations)
return operations
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This design allows us to change basically everything with every request using a context. This is nice but at the same time it becomes very confusing to understand what is happening when you are reading the code. It seems that we should not pursue this strategy and rather see to use the context as sparingly as possible.

@bassosimone
Copy link
Contributor Author

There is too much magic when we're using the context to possibly hijack every operation. It seems better to use the context much less frequently as we do in #421

@bassosimone bassosimone deleted the issue/359 branch March 27, 2020 13:29
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.

1 participant