mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-19 09:40:12 +00:00
feat(agentcompat): add shared runtime contracts
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
@@ -30,10 +30,10 @@ func NewServerClass() *ServerClass {
|
||||
|
||||
var servers []model.Server
|
||||
DB.Find(&servers)
|
||||
for _, s := range servers {
|
||||
innerS := s
|
||||
model.InitServer(&innerS)
|
||||
sc.list[innerS.ID] = &innerS
|
||||
for i := range servers {
|
||||
innerS := &servers[i]
|
||||
model.InitServer(innerS)
|
||||
sc.list[innerS.ID] = innerS
|
||||
sc.uuidToID[innerS.UUID] = innerS.ID
|
||||
}
|
||||
sc.sortList()
|
||||
|
||||
@@ -79,9 +79,9 @@ const defaultRevertDeliveryRecoveryWindow = defaultServerTransferTimeout
|
||||
// subscribers. All mutating operations go through methods so DB and in-memory
|
||||
// state stay in sync.
|
||||
type ServerTransferClass struct {
|
||||
mu sync.RWMutex
|
||||
pending map[uint64]*model.ServerTransfer
|
||||
revertDeliveries map[uint64]*model.ServerTransfer
|
||||
mu sync.RWMutex
|
||||
pending map[uint64]*model.ServerTransfer
|
||||
revertDeliveries map[uint64]*model.ServerTransfer
|
||||
// revertRecovery holds RevertHandshakeSecrets the dashboard has pushed
|
||||
// but the agent has not yet acknowledged, in the window between Cancel/
|
||||
// Fail/Timeout and either the agent's reconnect (which MarkRevertDelivered
|
||||
@@ -179,10 +179,14 @@ var ErrAgentTooOldForTransfer = fmt.Errorf("agent build older than %s does not s
|
||||
// never reported) so callers can defer the decision; PushIfOnline re-checks
|
||||
// at push time.
|
||||
func agentSupportsTransfer(s *model.Server) bool {
|
||||
if s == nil || s.Host == nil {
|
||||
if s == nil {
|
||||
return true
|
||||
}
|
||||
v := strings.TrimSpace(s.Host.Version)
|
||||
runtime := s.RuntimeSnapshot()
|
||||
if runtime.Host == nil {
|
||||
return true
|
||||
}
|
||||
v := strings.TrimSpace(runtime.Host.Version)
|
||||
if v == "" {
|
||||
return true
|
||||
}
|
||||
@@ -1103,7 +1107,7 @@ func (c *ServerTransferClass) revertTransition(transferID uint64, newStatus mode
|
||||
// back to a possibly-deleted FromUserID (regression pinned by
|
||||
// TestOnUserDeleteCancelsPendingTransfersAwayFromDeletedUser).
|
||||
var transitionedByThisCall bool
|
||||
err := DB.Transaction(func(tx *gorm.DB) error {
|
||||
err := DB.Transaction(func(tx *gorm.DB) error {
|
||||
if err := tx.First(&t, transferID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user