"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "pkg/netutil/netutil.go" between
etcd-3.5.5.tar.gz and etcd-3.5.6.tar.gz

About: etcd is a distributed reliable key-value store for the most critical data of a distributed system (written in "Go").

netutil.go  (etcd-3.5.5):netutil.go  (etcd-3.5.6)
skipping to change at line 151 skipping to change at line 151
} }
return "", ctx.Err() return "", ctx.Err()
} }
// urlsEqual checks equality of url.URLS between two arrays. // urlsEqual checks equality of url.URLS between two arrays.
// This check pass even if an URL is in hostname and opposite is in IP address. // This check pass even if an URL is in hostname and opposite is in IP address.
func urlsEqual(ctx context.Context, lg *zap.Logger, a []url.URL, b []url.URL) (b ool, error) { func urlsEqual(ctx context.Context, lg *zap.Logger, a []url.URL, b []url.URL) (b ool, error) {
if len(a) != len(b) { if len(a) != len(b) {
return false, fmt.Errorf("len(%q) != len(%q)", urlsToStrings(a), urlsToStrings(b)) return false, fmt.Errorf("len(%q) != len(%q)", urlsToStrings(a), urlsToStrings(b))
} }
sort.Sort(types.URLs(a))
sort.Sort(types.URLs(b))
var needResolve bool
for i := range a {
if !reflect.DeepEqual(a[i], b[i]) {
needResolve = true
break
}
}
if !needResolve {
return true, nil
}
// If URLs are not equal, try to resolve it and compare again.
urls, err := resolveTCPAddrs(ctx, lg, [][]url.URL{a, b}) urls, err := resolveTCPAddrs(ctx, lg, [][]url.URL{a, b})
if err != nil { if err != nil {
return false, err return false, err
} }
preva, prevb := a, b
a, b = urls[0], urls[1] a, b = urls[0], urls[1]
sort.Sort(types.URLs(a)) sort.Sort(types.URLs(a))
sort.Sort(types.URLs(b)) sort.Sort(types.URLs(b))
for i := range a { for i := range a {
if !reflect.DeepEqual(a[i], b[i]) { if !reflect.DeepEqual(a[i], b[i]) {
return false, fmt.Errorf("%q(resolved from %q) != %q(reso return false, fmt.Errorf("resolved urls: %q != %q", a[i].
lved from %q)", String(), b[i].String())
a[i].String(), preva[i].String(),
b[i].String(), prevb[i].String(),
)
} }
} }
return true, nil return true, nil
} }
// URLStringsEqual returns "true" if given URLs are valid // URLStringsEqual returns "true" if given URLs are valid
// and resolved to same IP addresses. Otherwise, return "false" // and resolved to same IP addresses. Otherwise, return "false"
// and error, if any. // and error, if any.
func URLStringsEqual(ctx context.Context, lg *zap.Logger, a []string, b []string ) (bool, error) { func URLStringsEqual(ctx context.Context, lg *zap.Logger, a []string, b []string ) (bool, error) {
if len(a) != len(b) { if len(a) != len(b) {
return false, fmt.Errorf("len(%q) != len(%q)", a, b) return false, fmt.Errorf("len(%q) != len(%q)", a, b)
} }
urlsA := make([]url.URL, 0) urlsA, err := stringsToURLs(a)
for _, str := range a { if err != nil {
u, err := url.Parse(str) return false, err
if err != nil {
return false, fmt.Errorf("failed to parse %q", str)
}
urlsA = append(urlsA, *u)
} }
urlsB := make([]url.URL, 0) urlsB, err := stringsToURLs(b)
for _, str := range b { if err != nil {
u, err := url.Parse(str) return false, err
if err != nil {
return false, fmt.Errorf("failed to parse %q", str)
}
urlsB = append(urlsB, *u)
} }
return urlsEqual(ctx, lg, urlsA, urlsB) return urlsEqual(ctx, lg, urlsA, urlsB)
} }
func urlsToStrings(us []url.URL) []string { func urlsToStrings(us []url.URL) []string {
rs := make([]string, len(us)) rs := make([]string, len(us))
for i := range us { for i := range us {
rs[i] = us[i].String() rs[i] = us[i].String()
} }
return rs return rs
} }
func stringsToURLs(us []string) ([]url.URL, error) {
urls := make([]url.URL, 0, len(us))
for _, str := range us {
u, err := url.Parse(str)
if err != nil {
return nil, fmt.Errorf("failed to parse string to URL: %q
", str)
}
urls = append(urls, *u)
}
return urls, nil
}
func IsNetworkTimeoutError(err error) bool { func IsNetworkTimeoutError(err error) bool {
nerr, ok := err.(net.Error) nerr, ok := err.(net.Error)
return ok && nerr.Timeout() return ok && nerr.Timeout()
} }
 End of changes. 6 change blocks. 
20 lines changed or deleted 36 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)