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

define Resolver type #83

Closed
wants to merge 5 commits into from

Conversation

daniellacosse
Copy link
Contributor

Am I doing this right????

@daniellacosse daniellacosse requested review from fortuna and jyyi1 October 4, 2023 19:57
Copy link
Contributor

@jyyi1 jyyi1 left a comment

Choose a reason for hiding this comment

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

Thanks @daniellacosse , it would be helpful if you can illustrate more about the future use cases of this interface? And welcome to the Go world!

transport/resolver.go Outdated Show resolved Hide resolved
transport/resolver.go Outdated Show resolved Hide resolved
transport/resolver.go Outdated Show resolved Hide resolved
transport/resolver.go Outdated Show resolved Hide resolved
Copy link
Contributor

@fortuna fortuna left a comment

Choose a reason for hiding this comment

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

Thanks for starting this. I believe the best way to go about it is to discuss in person with some whiteboarding.
Can you set up some time with me and @jyyi1 for tomorrow to discuss and brainstorm?

transport/resolver.go Outdated Show resolved Hide resolved
transport/resolver.go Outdated Show resolved Hide resolved
transport/resolver.go Outdated Show resolved Hide resolved
Co-authored-by: J. Yi <93548144+jyyi1@users.noreply.github.com>
@daniellacosse
Copy link
Contributor Author

Thanks for starting this. I believe the best way to go about it is to discuss in person with some whiteboarding. Can you set up some time with me and @jyyi1 for tomorrow to discuss and brainstorm?

I've set up time next week!

@daniellacosse daniellacosse requested review from fortuna and jyyi1 October 5, 2023 14:05
dns/resolver.go Outdated Show resolved Hide resolved
dns/resolver.go Outdated Show resolved Hide resolved
dns/resolver.go Outdated Show resolved Hide resolved
dns/resolver.go Outdated
dialer := &shadowsocks.NewStreamDialer(endpoint, key, manualDns)
````
*/
type Resolver func(host string) ([]string, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

A function is unmodifiable. Think about the following scenario:

dohResolver := NewDoHResolver(...)
dialer := NewDialerWithResolver(dohResolver)
// ... initially
dohResolver.SetTimeout(xxx)
// ... after some time
dohResolver.SetTimeout(yyy)

Unless we decide that all our Resolver implementations are immutable, I would prefer to define it as an interface:

type Resolver interface {
  LookupIP func(string)([]string, 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.

Why would they need to be modifiable? I guess I don't see a reason it shouldn't be immutable

Copy link
Contributor

@jyyi1 jyyi1 Oct 6, 2023

Choose a reason for hiding this comment

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

For example Intra allows to you change the DoH server on the fly (without reconnecting).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

And switching out the one resolver function with another wouldn't work in that case?

Copy link
Contributor

@jyyi1 jyyi1 Oct 6, 2023

Choose a reason for hiding this comment

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

Sure it does. But it also means we will create a new interface in the app that wraps around this func.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we? Why can't it be a property on an existing struct?

Copy link
Contributor

@jyyi1 jyyi1 Oct 6, 2023

Choose a reason for hiding this comment

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

Well yes, defining a struct that wraps around the function, which is OK for a single app.

My concern is whether a "stateful" Resolver is common across all apps, and how it interacts with StreamDialer and PacketProxy.

For example, some implementation might maintain a connection to a remote server, then we need to have Close() function in the Resolver to prevent resource leak.

We can discuss them in the brainstorm meeting, it all depends on the use cases we would like to cover. We might need to consider more stuffs than the LocalResolver or shadowsocks.StreamDialer.

Another thing I can think of is the two Resolve methods, one with context.Context and one without (similar to Go Dialer's Dial and DialContext)? We can discuss whether we should support it too.

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.

3 participants