mirror of
https://github.com/bettercap/bettercap
synced 2025-07-29 19:20:00 -07:00
misc: small fix or general refactoring i did not bother commenting
This commit is contained in:
parent
9c6eb70eb3
commit
8d6402323f
1 changed files with 15 additions and 14 deletions
|
@ -21,10 +21,10 @@ type Module interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SessionModule struct {
|
type SessionModule struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Session *Session `json:"-"`
|
Session *Session `json:"-"`
|
||||||
Started bool `json:"started"`
|
Started bool `json:"started"`
|
||||||
StatusLock *sync.Mutex `json:"-"`
|
StatusLock *sync.RWMutex `json:"-"`
|
||||||
|
|
||||||
handlers []ModuleHandler
|
handlers []ModuleHandler
|
||||||
params map[string]*ModuleParam
|
params map[string]*ModuleParam
|
||||||
|
@ -35,7 +35,7 @@ func NewSessionModule(name string, s *Session) SessionModule {
|
||||||
Name: name,
|
Name: name,
|
||||||
Session: s,
|
Session: s,
|
||||||
Started: false,
|
Started: false,
|
||||||
StatusLock: &sync.Mutex{},
|
StatusLock: &sync.RWMutex{},
|
||||||
|
|
||||||
handlers: make([]ModuleHandler, 0),
|
handlers: make([]ModuleHandler, 0),
|
||||||
params: make(map[string]*ModuleParam),
|
params: make(map[string]*ModuleParam),
|
||||||
|
@ -117,22 +117,23 @@ func (m *SessionModule) AddParam(p *ModuleParam) *ModuleParam {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SessionModule) Running() bool {
|
func (m *SessionModule) Running() bool {
|
||||||
m.StatusLock.Lock()
|
m.StatusLock.RLock()
|
||||||
defer m.StatusLock.Unlock()
|
defer m.StatusLock.RUnlock()
|
||||||
return m.Started
|
return m.Started
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *SessionModule) SetRunning(running bool, cb func()) error {
|
func (m *SessionModule) SetRunning(running bool, cb func()) error {
|
||||||
m.StatusLock.Lock()
|
if running == m.Running() {
|
||||||
defer m.StatusLock.Unlock()
|
if m.Started {
|
||||||
|
return ErrAlreadyStarted
|
||||||
if running && m.Started == true {
|
} else {
|
||||||
return ErrAlreadyStarted
|
return ErrAlreadyStopped
|
||||||
} else if running == false && m.Started == false {
|
}
|
||||||
return ErrAlreadyStopped
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.StatusLock.Lock()
|
||||||
m.Started = running
|
m.Started = running
|
||||||
|
m.StatusLock.Unlock()
|
||||||
|
|
||||||
if *m.Session.Options.Debug == true {
|
if *m.Session.Options.Debug == true {
|
||||||
if running {
|
if running {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue