[#35] network: Use AppendComponent() for TLS encapsulation
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:
parent
fc8f9637fe
commit
971e740ea3
2 changed files with 2 additions and 2 deletions
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Reference in a new issue