mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-07-27 19:29:57 +00:00
chore: Remove h2mux code
Some more legacy h2mux code to be cleaned up and moved out of the way. The h2mux.Header used in the serialization for http2 proxied headers is moved to connection module. Additionally, the booleanfuse structure is also moved to supervisor as it is also needed. Both of these structures could be evaluated later for removal/updates, however, the intent of the proposed changes here is to remove the dependencies on the h2mux code and removal. Approved-by: Chung-Ting Huang <chungting@cloudflare.com> Approved-by: Luis Neto <lneto@cloudflare.com> Approved-by: Gonçalo Garcia <ggarcia@cloudflare.com> MR: https://gitlab.cfdata.org/cloudflare/tun/cloudflared/-/merge_requests/1576
This commit is contained in:
50
supervisor/fuse.go
Normal file
50
supervisor/fuse.go
Normal file
@@ -0,0 +1,50 @@
|
||||
package supervisor
|
||||
|
||||
import "sync"
|
||||
|
||||
// booleanFuse is a data structure that can be set once to a particular value using Fuse(value).
|
||||
// Subsequent calls to Fuse() will have no effect.
|
||||
type booleanFuse struct {
|
||||
value int32
|
||||
mu sync.Mutex
|
||||
cond *sync.Cond
|
||||
}
|
||||
|
||||
func newBooleanFuse() *booleanFuse {
|
||||
f := &booleanFuse{}
|
||||
f.cond = sync.NewCond(&f.mu)
|
||||
return f
|
||||
}
|
||||
|
||||
// Value gets the value
|
||||
func (f *booleanFuse) Value() bool {
|
||||
// 0: unset
|
||||
// 1: set true
|
||||
// 2: set false
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
return f.value == 1
|
||||
}
|
||||
|
||||
func (f *booleanFuse) Fuse(result bool) {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
newValue := int32(2)
|
||||
if result {
|
||||
newValue = 1
|
||||
}
|
||||
if f.value == 0 {
|
||||
f.value = newValue
|
||||
f.cond.Broadcast()
|
||||
}
|
||||
}
|
||||
|
||||
// Await blocks until Fuse has been called at least once.
|
||||
func (f *booleanFuse) Await() bool {
|
||||
f.mu.Lock()
|
||||
defer f.mu.Unlock()
|
||||
for f.value == 0 {
|
||||
f.cond.Wait()
|
||||
}
|
||||
return f.value == 1
|
||||
}
|
@@ -19,7 +19,6 @@ import (
|
||||
"github.com/cloudflare/cloudflared/edgediscovery"
|
||||
"github.com/cloudflare/cloudflared/edgediscovery/allregions"
|
||||
"github.com/cloudflare/cloudflared/features"
|
||||
"github.com/cloudflare/cloudflared/h2mux"
|
||||
"github.com/cloudflare/cloudflared/ingress"
|
||||
"github.com/cloudflare/cloudflared/management"
|
||||
"github.com/cloudflare/cloudflared/orchestration"
|
||||
@@ -199,7 +198,7 @@ func (e *EdgeTunnelServer) Serve(ctx context.Context, connIndex uint8, protocolF
|
||||
haConnections.Inc()
|
||||
defer haConnections.Dec()
|
||||
|
||||
connectedFuse := h2mux.NewBooleanFuse()
|
||||
connectedFuse := newBooleanFuse()
|
||||
go func() {
|
||||
if connectedFuse.Await() {
|
||||
connectedSignal.Notify()
|
||||
@@ -375,7 +374,7 @@ func (e *EdgeTunnelServer) serveTunnel(
|
||||
connLog *ConnAwareLogger,
|
||||
addr *allregions.EdgeAddr,
|
||||
connIndex uint8,
|
||||
fuse *h2mux.BooleanFuse,
|
||||
fuse *booleanFuse,
|
||||
backoff *protocolFallback,
|
||||
protocol connection.Protocol,
|
||||
) (err error, recoverable bool) {
|
||||
@@ -441,7 +440,7 @@ func (e *EdgeTunnelServer) serveConnection(
|
||||
connLog *ConnAwareLogger,
|
||||
addr *allregions.EdgeAddr,
|
||||
connIndex uint8,
|
||||
fuse *h2mux.BooleanFuse,
|
||||
fuse *booleanFuse,
|
||||
backoff *protocolFallback,
|
||||
protocol connection.Protocol,
|
||||
) (err error, recoverable bool) {
|
||||
@@ -645,7 +644,7 @@ func listenReconnect(ctx context.Context, reconnectCh <-chan ReconnectSignal, gr
|
||||
}
|
||||
|
||||
type connectedFuse struct {
|
||||
fuse *h2mux.BooleanFuse
|
||||
fuse *booleanFuse
|
||||
backoff *protocolFallback
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user