[#35] network: Use AppendComponent() for TLS encapsulation
All checks were successful
DCO / DCO (pull_request) Successful in 30s
Code generation / Generate proto (pull_request) Successful in 37s
Tests and linters / Tests (pull_request) Successful in 1m0s
Tests and linters / Lint (pull_request) Successful in 1m51s

As advocated explicitly in https://github.com/multiformats/go-multiaddr/blob/master/v015-MIGRATION.md

Answering a question about safety:
AppendComponent() appends to `a.ma`` in place.
`a.ma` is created by FromString() function,
so there is only a single goroutine appending to it.
Thus, assuming `FromString()` itself is called from a single goroutine,
no data race is introduced.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2025-03-17 15:24:15 +03:00
parent fc8f9637fe
commit 971e740ea3
Signed by: fyrchik
SSH key fingerprint: SHA256:m/TTwCzjnRkXgnzEx9X92ccxy1CcVeinOgDb3NPWWmg
2 changed files with 2 additions and 2 deletions

View file

@ -66,7 +66,7 @@ func (a *Address) FromString(s string) error {
if err == nil {
a.ma, err = multiaddr.NewMultiaddr(s)
if err == nil && hasTLS {
a.ma = a.ma.Encapsulate(tls)
a.ma = a.ma.AppendComponent(tls)
}
}
}

View file

@ -9,7 +9,7 @@ const (
)
// tls var is used for (un)wrapping other multiaddrs around TLS multiaddr.
var tls, _ = multiaddr.NewMultiaddr("/" + tlsProtocolName)
var tls, _ = multiaddr.NewComponent(tlsProtocolName, "")
// IsTLSEnabled searches for wrapped TLS protocol in multiaddr.
func (a Address) IsTLSEnabled() bool {