This commit is contained in:
evilsocket 2018-01-24 13:51:37 +01:00
commit 1cffa33264
7 changed files with 74 additions and 75 deletions

View file

@ -8,9 +8,10 @@ import (
)
type Environment struct {
sync.Mutex
Padding int `json:"-"`
Storage map[string]string `json:"storage"`
lock *sync.Mutex
sess *Session
}
@ -18,7 +19,6 @@ func NewEnvironment(s *Session) *Environment {
env := &Environment{
Padding: 0,
Storage: make(map[string]string),
lock: &sync.Mutex{},
sess: s,
}
@ -26,8 +26,8 @@ func NewEnvironment(s *Session) *Environment {
}
func (env *Environment) Has(name string) bool {
env.lock.Lock()
defer env.lock.Unlock()
env.Lock()
defer env.Unlock()
_, found := env.Storage[name]
@ -35,8 +35,8 @@ func (env *Environment) Has(name string) bool {
}
func (env *Environment) Set(name, value string) string {
env.lock.Lock()
defer env.lock.Unlock()
env.Lock()
defer env.Unlock()
old, _ := env.Storage[name]
env.Storage[name] = value
@ -58,8 +58,8 @@ func (env *Environment) Set(name, value string) string {
}
func (env *Environment) Get(name string) (bool, string) {
env.lock.Lock()
defer env.lock.Unlock()
env.Lock()
defer env.Unlock()
if value, found := env.Storage[name]; found == true {
return true, value
@ -81,8 +81,8 @@ func (env *Environment) GetInt(name string) (error, int) {
}
func (env *Environment) Sorted() []string {
env.lock.Lock()
defer env.lock.Unlock()
env.Lock()
defer env.Unlock()
var keys []string
for k := range env.Storage {

View file

@ -36,11 +36,12 @@ func (e Event) Label() string {
}
type EventPool struct {
sync.Mutex
NewEvents chan Event
debug bool
silent bool
events []Event
lock *sync.Mutex
}
func NewEventPool(debug bool, silent bool) *EventPool {
@ -49,13 +50,12 @@ func NewEventPool(debug bool, silent bool) *EventPool {
debug: debug,
silent: silent,
events: make([]Event, 0),
lock: &sync.Mutex{},
}
}
func (p *EventPool) Add(tag string, data interface{}) {
p.lock.Lock()
defer p.lock.Unlock()
p.Lock()
defer p.Unlock()
e := NewEvent(tag, data)
p.events = append([]Event{e}, p.events...)
@ -86,13 +86,13 @@ func (p *EventPool) Log(level int, format string, args ...interface{}) {
}
func (p *EventPool) Clear() {
p.lock.Lock()
defer p.lock.Unlock()
p.Lock()
defer p.Unlock()
p.events = make([]Event, 0)
}
func (p *EventPool) Events() []Event {
p.lock.Lock()
defer p.lock.Unlock()
p.Lock()
defer p.Unlock()
return p.events
}

View file

@ -7,12 +7,13 @@ import (
)
type Targets struct {
sync.Mutex
Session *Session `json:"-"`
Interface *net.Endpoint
Gateway *net.Endpoint
Targets map[string]*net.Endpoint
TTL map[string]uint
lock sync.Mutex
}
func NewTargets(s *Session, iface, gateway *net.Endpoint) *Targets {
@ -25,17 +26,9 @@ func NewTargets(s *Session, iface, gateway *net.Endpoint) *Targets {
}
}
func (tp *Targets) Lock() {
tp.lock.Lock()
}
func (tp *Targets) Unlock() {
tp.lock.Unlock()
}
func (tp *Targets) Remove(ip, mac string) {
tp.lock.Lock()
defer tp.lock.Unlock()
tp.Lock()
defer tp.Unlock()
if e, found := tp.Targets[mac]; found {
tp.TTL[mac]--
@ -53,8 +46,8 @@ func (tp *Targets) shouldIgnore(ip string) bool {
}
func (tp *Targets) Has(ip string) bool {
tp.lock.Lock()
defer tp.lock.Unlock()
tp.Lock()
defer tp.Unlock()
for _, e := range tp.Targets {
if e.IpAddress == ip {
@ -66,8 +59,8 @@ func (tp *Targets) Has(ip string) bool {
}
func (tp *Targets) AddIfNotExist(ip, mac string) *net.Endpoint {
tp.lock.Lock()
defer tp.lock.Unlock()
tp.Lock()
defer tp.Unlock()
if tp.shouldIgnore(ip) {
return nil