Support hostnames #6

Merged
fyrchik merged 1 commit from dstepanov-yadro/multinet:feat/host_names into master 2024-09-04 19:51:22 +00:00

Now IP adresses are resolved by hostname. The implementation is very similar to the implementation of the standard library: https://github.com/golang/go/blob/master/src/net/dial.go#L490 First, possible IP addresses are determined, then a connection is created to the first available IP address. If IPv4 and IPv6 addresses are available, then the connection to the addresses of the version of the first address is carried out first. After FallbackDelay, connections to addresses of another version begin to be created.

Also fixed some issues:

  • hardcoded network values

  • use dialContext (with override check) method in all requests

  • set Dialer from Config to dialer field

  • tests requires sudo moved to integration tag

Closes #4

Now IP adresses are resolved by hostname. The implementation is very similar to the implementation of the standard library: https://github.com/golang/go/blob/master/src/net/dial.go#L490 First, possible IP addresses are determined, then a connection is created to the first available IP address. If IPv4 and IPv6 addresses are available, then the connection to the addresses of the version of the first address is carried out first. After `FallbackDelay`, connections to addresses of another version begin to be created. Also fixed some issues: - hardcoded network values - use `dialContext` (with override check) method in all requests - set `Dialer` from `Config` to `dialer` field - tests requires `sudo` moved to `integration` tag Closes #4
dstepanov-yadro force-pushed feat/host_names from b9ccf8bcfb to 068d8e9a4c 2023-10-23 13:35:12 +00:00 Compare
dstepanov-yadro force-pushed feat/host_names from 068d8e9a4c to fff0ee7c85 2023-10-23 13:39:46 +00:00 Compare
dstepanov-yadro force-pushed feat/host_names from d3217f2aac to 1db030957d 2023-10-24 12:49:37 +00:00 Compare
dstepanov-yadro requested review from storage-core-committers 2023-10-24 13:21:17 +00:00
dstepanov-yadro requested review from storage-core-developers 2023-10-24 13:21:19 +00:00
dstepanov-yadro changed title from WIP: Support hostnames to Support hostnames 2023-10-24 13:21:30 +00:00
fyrchik reviewed 2023-10-25 12:53:29 +00:00
dialer.go Outdated
@ -68,0 +85,4 @@
FallbackDelay time.Duration
// InterfaceSource is custom `Interface`` source.
// If not specified, default implementation is used (`net.Interfaces()``).
InterfaceSource func() ([]Interface, error)
Owner

Do we have usecase for this besides using in tests?

Do we have usecase for this besides using in tests?
Author
Member

For example tracing, logging, metrics.

For example tracing, logging, metrics.
Owner

It is called once during construction, so I doubt it is useful, but ok

It is called once during construction, so I doubt it is useful, but ok
fyrchik marked this conversation as resolved
dialer.go Outdated
@ -173,2 +228,4 @@
}
var primaries, fallbacks []netip.AddrPort
if d.fallbackDelay >= 0 && network == "tcp" {
Owner

Only tcp or tcp4/tcp6 too?

Only `tcp` or `tcp4`/`tcp6` too?
Author
Member
In stdlib only `tcp` defined: https://github.com/golang/go/blob/master/src/net/dial.go#L502
Owner

I was looking at this function https://github.com/golang/go/blob/master/src/net/dial.go#L229, which is called inside resolveAddrList

I was looking at this function https://github.com/golang/go/blob/master/src/net/dial.go#L229, which is called inside `resolveAddrList`
dialer.go Outdated
@ -175,0 +237,4 @@
return d.dialParallel(ctx, network, primaries, fallbacks)
}
func (d *dialer) dialSerial(ctx context.Context, network string, addrs []netip.AddrPort) (net.Conn, error) {
Owner

If this is taken from stdlib, could we supply references in comments?

If this is taken from stdlib, could we supply references in comments?
Author
Member

Done

Done
fyrchik marked this conversation as resolved
dialer.go Outdated
@ -190,3 +382,2 @@
func (d *dialer) dialContext(nd *net.Dialer, ctx context.Context, network, address string) (net.Conn, error) {
if h := d.testHookDialContext; h != nil {
return h(nd, ctx, "tcp", address)
if h := d.customDialContext; h != nil {
Owner

What was wrong with testHook? It is in spirit of the related stdlib pieces b5f87b5407/src/net/dial.go (L423)

What was wrong with `testHook`? It is in spirit of the related stdlib pieces https://github.com/golang/go/blob/b5f87b5407916c4049a3158cc944cebfd7a883a9/src/net/dial.go#L423
Author
Member

Nothing wrong. But I guess it could be used not only for tests. For example tracing, logging, metrics.

Nothing wrong. But I guess it could be used not only for tests. For example tracing, logging, metrics.
fyrchik marked this conversation as resolved
dstepanov-yadro force-pushed feat/host_names from 1db030957d to 5298ec4295 2023-10-26 08:14:08 +00:00 Compare
aarifullin reviewed 2023-10-26 08:48:23 +00:00
@ -175,0 +302,4 @@
select {
case <-fallbackTimer.C:
fallbackCtx, fallbackCancel := context.WithCancel(ctx)
defer fallbackCancel()
Member

I don't know whether it was your idea or this is copy-pasted but seems really good

I don't know whether it was your idea or this is copy-pasted but seems really good
aarifullin approved these changes 2023-10-26 08:48:46 +00:00
aarifullin left a comment
Member

Nice!

Nice!
fyrchik approved these changes 2023-10-30 08:46:56 +00:00
fyrchik merged commit 5298ec4295 into master 2023-10-30 08:47:05 +00:00
Sign in to join this conversation.
No description provided.