[relay] Rename ConnRacer to FallbackOpener and align file names with types

Rename the ConnRacer type to FallbackOpener and its constructor to
NewFallbackOpener. Rename fallback.go to fallback_opener.go and
foreign_relays.go to foreign_relays_store.go so file names mirror their
primary struct.
This commit is contained in:
Zoltan Papp
2026-07-01 16:53:42 +02:00
parent 50a29c07ce
commit 6774a43eae
3 changed files with 12 additions and 12 deletions
@@ -20,7 +20,7 @@ type raceAttempt struct {
} }
type connRace struct { type connRace struct {
racer *ConnRacer opener *FallbackOpener
peerKey string peerKey string
remoteRelayServer RelayServer remoteRelayServer RelayServer
preferForeign bool preferForeign bool
@@ -37,19 +37,19 @@ type connRace struct {
lastErr error lastErr error
} }
type ConnRacer struct { type FallbackOpener struct {
home *Client home *Client
foreignStore *ForeignRelaysStore foreignStore *ForeignRelaysStore
} }
func NewConnRacer(home *Client, foreignStore *ForeignRelaysStore) *ConnRacer { func NewFallbackOpener(home *Client, foreignStore *ForeignRelaysStore) *FallbackOpener {
return &ConnRacer{ return &FallbackOpener{
home: home, home: home,
foreignStore: foreignStore, foreignStore: foreignStore,
} }
} }
func (r *ConnRacer) Run(ctx context.Context, peerKey string, remoteRelayServer RelayServer, preferForeign bool) (net.Conn, error) { func (r *FallbackOpener) Run(ctx context.Context, peerKey string, remoteRelayServer RelayServer, preferForeign bool) (net.Conn, error) {
raceCtx, cancel := context.WithTimeout(ctx, raceTotalTimeout) raceCtx, cancel := context.WithTimeout(ctx, raceTotalTimeout)
defer cancel() defer cancel()
@@ -57,7 +57,7 @@ func (r *ConnRacer) Run(ctx context.Context, peerKey string, remoteRelayServer R
otherCtx, cancelOther := context.WithCancel(raceCtx) otherCtx, cancelOther := context.WithCancel(raceCtx)
race := &connRace{ race := &connRace{
racer: r, opener: r,
peerKey: peerKey, peerKey: peerKey,
remoteRelayServer: remoteRelayServer, remoteRelayServer: remoteRelayServer,
preferForeign: preferForeign, preferForeign: preferForeign,
@@ -95,7 +95,7 @@ func (c *connRace) startOther() {
c.otherStarted = true c.otherStarted = true
c.fallbackTimer.Stop() c.fallbackTimer.Stop()
go func() { go func() {
c.results <- c.racer.open(c.otherCtx, c.peerKey, c.remoteRelayServer, !c.preferForeign) c.results <- c.opener.open(c.otherCtx, c.peerKey, c.remoteRelayServer, !c.preferForeign)
}() }()
} }
@@ -130,10 +130,10 @@ func (c *connRace) onTimeout() (net.Conn, error) {
func (c *connRace) stop() { func (c *connRace) stop() {
c.cancelPreferred() c.cancelPreferred()
c.cancelOther() c.cancelOther()
go c.racer.drainLoser(c.results, c.settled, c.otherStarted) go c.opener.drainLoser(c.results, c.settled, c.otherStarted)
} }
func (r *ConnRacer) open(ctx context.Context, peerKey string, remoteRelayServer RelayServer, foreign bool) raceAttempt { func (r *FallbackOpener) open(ctx context.Context, peerKey string, remoteRelayServer RelayServer, foreign bool) raceAttempt {
if foreign { if foreign {
conn, err := r.foreignStore.OpenConn(ctx, peerKey, remoteRelayServer) conn, err := r.foreignStore.OpenConn(ctx, peerKey, remoteRelayServer)
return raceAttempt{conn: conn, err: err} return raceAttempt{conn: conn, err: err}
@@ -142,7 +142,7 @@ func (r *ConnRacer) open(ctx context.Context, peerKey string, remoteRelayServer
return raceAttempt{conn: conn, err: err} return raceAttempt{conn: conn, err: err}
} }
func (r *ConnRacer) drainLoser(results chan raceAttempt, settled int, otherStarted bool) { func (r *FallbackOpener) drainLoser(results chan raceAttempt, settled int, otherStarted bool) {
started := 1 started := 1
if otherStarted { if otherStarted {
started = 2 started = 2
+2 -2
View File
@@ -159,8 +159,8 @@ func (m *Manager) OpenConn(ctx context.Context, remoteRelayServer RelayServer, p
return m.relayClient.OpenConn(ctx, peerKey) return m.relayClient.OpenConn(ctx, peerKey)
} }
racer := NewConnRacer(m.relayClient, m.foreign) opener := NewFallbackOpener(m.relayClient, m.foreign)
return racer.Run(ctx, peerKey, remoteRelayServer, preferForeign) return opener.Run(ctx, peerKey, remoteRelayServer, preferForeign)
} }
// Ready returns true if the home Relay client is connected to the relay server. // Ready returns true if the home Relay client is connected to the relay server.