[relay] Use instanceURL instead of Exposed address. (#4905)

Replaces string-based exposed address handling with URL-based InstanceURL() (type url.URL) across relay/server and relay/healthcheck; adds SchemeREL/SchemeRELS constants; updates getInstanceURL to return *url.URL with scheme and TLS validation; adjusts WS dialing and health-check logic to use URL fields.
This commit is contained in:
Zoltan Papp
2025-12-03 18:42:53 +01:00
committed by GitHub
parent 27dd97c9c4
commit d2e48d4f5e
7 changed files with 47 additions and 45 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"net"
"net/url"
"sync"
"time"
@@ -22,7 +23,7 @@ type Config struct {
TLSSupport bool
AuthValidator Validator
instanceURL string
instanceURL url.URL
}
func (c *Config) validate() error {
@@ -37,7 +38,7 @@ func (c *Config) validate() error {
if err != nil {
return fmt.Errorf("invalid url: %v", err)
}
c.instanceURL = instanceURL
c.instanceURL = *instanceURL
if c.AuthValidator == nil {
return fmt.Errorf("auth validator is required")
@@ -53,7 +54,7 @@ type Relay struct {
store *store.Store
notifier *store.PeerNotifier
instanceURL string
instanceURL url.URL
exposedAddress string
preparedMsg *preparedMsg
@@ -97,7 +98,7 @@ func NewRelay(config Config) (*Relay, error) {
notifier: store.NewPeerNotifier(),
}
r.preparedMsg, err = newPreparedMsg(r.instanceURL)
r.preparedMsg, err = newPreparedMsg(r.instanceURL.String())
if err != nil {
metricsCancel()
return nil, fmt.Errorf("prepare message: %v", err)
@@ -177,11 +178,6 @@ func (r *Relay) Shutdown(ctx context.Context) {
}
// InstanceURL returns the instance URL of the relay server
func (r *Relay) InstanceURL() string {
func (r *Relay) InstanceURL() url.URL {
return r.instanceURL
}
// ExposedAddress returns the exposed address (domain:port) where clients connect
func (r *Relay) ExposedAddress() string {
return r.exposedAddress
}