[#1] treesvc: Properly check for secure transport

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
pull/484/head
Evgenii Stratonikov 2023-06-26 15:00:44 +03:00 committed by Evgenii Stratonikov
parent cab51c8cbe
commit 4f413fe86e
5 changed files with 6 additions and 8 deletions

View File

@ -47,7 +47,7 @@ func (a Address) URIAddr() string {
panic(fmt.Errorf("could not get host addr: %w", err))
}
if !a.isTLSEnabled() {
if !a.IsTLSEnabled() {
return host
}

View File

@ -57,7 +57,7 @@ func (x AddressGroup) Len() int {
// Less returns true if i-th address in AddressGroup supports TLS
// and j-th one doesn't.
func (x AddressGroup) Less(i, j int) bool {
return x[i].isTLSEnabled() && !x[j].isTLSEnabled()
return x[i].IsTLSEnabled() && !x[j].IsTLSEnabled()
}
// Swap swaps i-th and j-th addresses in AddressGroup.

View File

@ -11,8 +11,8 @@ const (
// tls var is used for (un)wrapping other multiaddrs around TLS multiaddr.
var tls, _ = multiaddr.NewMultiaddr("/" + tlsProtocolName)
// isTLSEnabled searches for wrapped TLS protocol in multiaddr.
func (a Address) isTLSEnabled() bool {
// IsTLSEnabled searches for wrapped TLS protocol in multiaddr.
func (a Address) IsTLSEnabled() bool {
for _, protoc := range a.ma.Protocols() {
if protoc.Code == multiaddr.P_TLS {
return true

View File

@ -24,6 +24,6 @@ func TestAddress_TLSEnabled(t *testing.T) {
err := addr.FromString(test.input)
require.NoError(t, err)
require.Equal(t, test.wantTLS, addr.isTLSEnabled(), test.input)
require.Equal(t, test.wantTLS, addr.IsTLSEnabled(), test.input)
}
}

View File

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"strings"
"sync"
"time"
@ -100,8 +99,7 @@ func dialTreeService(ctx context.Context, netmapAddr string) (*grpc.ClientConn,
),
}
// FIXME(@fyrchik): ugly hack #1322
if !strings.HasPrefix(netAddr.URIAddr(), "grpcs:") {
if netAddr.IsTLSEnabled() {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}