-
Notifications
You must be signed in to change notification settings - Fork 55
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
Conversation
There was a problem hiding this 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!
There was a problem hiding this 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?
Co-authored-by: J. Yi <93548144+jyyi1@users.noreply.github.com>
I've set up time next week! |
dns/resolver.go
Outdated
dialer := &shadowsocks.NewStreamDialer(endpoint, key, manualDns) | ||
```` | ||
*/ | ||
type Resolver func(host string) ([]string, error) |
There was a problem hiding this comment.
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)
}
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
Am I doing this right????