mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-17 12:09:58 +00:00
Relocate WorkerICE (renamed worker.ICE) and WorkerRelay plus ConnPriority into client/internal/peer/worker. To break the peer<->worker cycle the workers no longer take *Conn or ConnConfig: callbacks are passed as plain functions (Conn's unexported methods as method values), and each worker receives only the fields it needs (key, ICE config, isController) plus a small services struct. Context is passed to OnNewOffer instead of stored. Move the worker connection-status helper the other way, out of the worker package into peer as worker_status.go (WorkerStatus / AtomicWorkerStatus), since only Conn uses it.
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package peer
|
|
|
|
import (
|
|
"sync/atomic"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
const (
|
|
WorkerStatusDisconnected WorkerStatus = iota
|
|
WorkerStatusConnected
|
|
)
|
|
|
|
type WorkerStatus int32
|
|
|
|
func (s WorkerStatus) String() string {
|
|
switch s {
|
|
case WorkerStatusDisconnected:
|
|
return "Disconnected"
|
|
case WorkerStatusConnected:
|
|
return "Connected"
|
|
default:
|
|
log.Errorf("unknown status: %d", s)
|
|
return "unknown"
|
|
}
|
|
}
|
|
|
|
// AtomicWorkerStatus is a thread-safe wrapper for worker status
|
|
type AtomicWorkerStatus struct {
|
|
status atomic.Int32
|
|
}
|
|
|
|
func NewAtomicStatus() *AtomicWorkerStatus {
|
|
acs := &AtomicWorkerStatus{}
|
|
acs.SetDisconnected()
|
|
return acs
|
|
}
|
|
|
|
// Get returns the current connection status
|
|
func (acs *AtomicWorkerStatus) Get() WorkerStatus {
|
|
return WorkerStatus(acs.status.Load())
|
|
}
|
|
|
|
func (acs *AtomicWorkerStatus) SetConnected() {
|
|
acs.status.Store(int32(WorkerStatusConnected))
|
|
}
|
|
|
|
func (acs *AtomicWorkerStatus) SetDisconnected() {
|
|
acs.status.Store(int32(WorkerStatusDisconnected))
|
|
}
|
|
|
|
// String returns the string representation of the current status
|
|
func (acs *AtomicWorkerStatus) String() string {
|
|
return acs.Get().String()
|
|
}
|