Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions AdaptixServer/core/server/mgr_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"fmt"
"time"

"github.com/Adaptix-Framework/axc2"
adaptix "github.com/Adaptix-Framework/axc2"
)

type TaskHandler interface {
Expand Down Expand Up @@ -141,7 +141,7 @@ func (tm *TaskManager) Create(agentId string, cmdline string, client string, tas
return
}

if !agent.Active {
if !agent.IsActive() {
return
}

Expand Down
8 changes: 4 additions & 4 deletions AdaptixServer/core/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"os"
"time"

"github.com/Adaptix-Framework/axc2"
adaptix "github.com/Adaptix-Framework/axc2"
"github.com/goccy/go-yaml"
)

Expand Down Expand Up @@ -111,12 +111,12 @@ func (ts *Teamserver) RestoreData() {
RunningJobs: safe.NewMap(),
PivotParent: nil,
PivotChilds: safe.NewSlice(),
Tick: false,
Active: true,
}

if agentData.Mark == "Terminated" {
agent.Active = false
agent.SetActive(false)
} else {
agent.SetActive(true)
}

if agentData.Mark == "" {
Expand Down
15 changes: 7 additions & 8 deletions AdaptixServer/core/server/ts_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"
"time"

"github.com/Adaptix-Framework/axc2"
adaptix "github.com/Adaptix-Framework/axc2"
)

func (ts *Teamserver) TsAgentList() (string, error) {
Expand Down Expand Up @@ -89,9 +89,8 @@ func (ts *Teamserver) TsAgentCreate(agentCrc string, agentId string, beat []byte
RunningJobs: safe.NewMap(),
PivotParent: nil,
PivotChilds: safe.NewSlice(),
Tick: false,
Active: true,
}
agent.SetActive(true)
agent.SetData(agentData)

// --- PRE HOOK ---
Expand Down Expand Up @@ -137,7 +136,7 @@ func (ts *Teamserver) TsAgentCommand(agentName string, agentId string, clientNam
if err != nil {
return err
}
if !agent.Active {
if !agent.IsActive() {
return fmt.Errorf("agent '%v' not active", agentId)
}

Expand Down Expand Up @@ -615,7 +614,7 @@ func (ts *Teamserver) TsAgentTerminate(agentId string, terminateTaskId string) e
if !ok {
return errors.New("invalid agent type")
}
agent.Active = false
agent.SetActive(false)
agent.UpdateData(func(d *adaptix.AgentData) {
d.Mark = "Terminated"
})
Expand Down Expand Up @@ -854,7 +853,7 @@ func (ts *Teamserver) TsAgentSetTick(agentId string, listenerName string) error
})
_ = ts.DBMS.DbAgentTick(agent.GetData())
}
agent.Tick = true
agent.SetTicked(true)
} else if listenerChanged {
agent.UpdateData(func(d *adaptix.AgentData) {
d.Listener = listenerName
Expand All @@ -879,8 +878,8 @@ func (ts *Teamserver) TsAgentTickUpdate() {
}
agentData := agent.GetData()
if agentData.Async {
if agent.Tick {
agent.Tick = false
if agent.IsTicked() {
agent.SetTicked(false)
agentSlice = append(agentSlice, agentData.Id)
}
}
Expand Down
2 changes: 1 addition & 1 deletion AdaptixServer/core/server/ts_terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (ts *Teamserver) TsAgentTerminalCreateChannel(terminalData string, wsconn *
if err != nil {
return err
}
if !agent.Active {
if !agent.IsActive() {
return fmt.Errorf("agent '%v' not active", td.AgentId)
}

Expand Down
4 changes: 2 additions & 2 deletions AdaptixServer/core/server/ts_tunnels.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"sync"
"time"

"github.com/Adaptix-Framework/axc2"
adaptix "github.com/Adaptix-Framework/axc2"
"github.com/gorilla/websocket"
)

Expand Down Expand Up @@ -45,7 +45,7 @@ func (ts *Teamserver) TsTunnelClientStart(AgentId string, Listen bool, Type int,
if !ok {
return "", fmt.Errorf("invalid agent type for '%v'", AgentId)
}
if agent.Active == false {
if !agent.IsActive() {
return "", fmt.Errorf("agent '%v' not active", AgentId)
}

Expand Down
22 changes: 19 additions & 3 deletions AdaptixServer/core/server/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"sync"
"sync/atomic"

"github.com/Adaptix-Framework/axc2"
adaptix "github.com/Adaptix-Framework/axc2"
"github.com/gorilla/websocket"
)

Expand Down Expand Up @@ -68,8 +68,8 @@ type Agent struct {
mu sync.RWMutex
data adaptix.AgentData
Extender adaptix.ExtenderAgent
Tick bool
Active bool
tick atomic.Bool
active atomic.Bool

HostedTasks *safe.Queue // taskData TaskData
HostedTunnelTasks *safe.Queue // taskData TaskData
Expand All @@ -82,6 +82,22 @@ type Agent struct {
PivotChilds *safe.Slice
}

func (a *Agent) IsTicked() bool {
return a.tick.Load()
}

func (a *Agent) SetTicked(v bool) {
a.tick.Store(v)
}

func (a *Agent) IsActive() bool {
return a.active.Load()
}

func (a *Agent) SetActive(v bool) {
a.active.Store(v)
}

func (a *Agent) GetData() adaptix.AgentData {
a.mu.RLock()
defer a.mu.RUnlock()
Expand Down