Working on portmaster restructure
This commit is contained in:
@@ -9,20 +9,17 @@ import (
|
||||
)
|
||||
|
||||
var (
|
||||
deadLinksTimeout = 5 * time.Minute
|
||||
thresholdDuration = 1 * time.Minute
|
||||
cleanerTickDuration = 1 * time.Minute
|
||||
deadLinksTimeout = 5 * time.Minute
|
||||
thresholdDuration = 1 * time.Minute
|
||||
)
|
||||
|
||||
func init() {
|
||||
go cleaner()
|
||||
}
|
||||
|
||||
func cleaner() {
|
||||
time.Sleep(15 * time.Second)
|
||||
for {
|
||||
markDeadLinks()
|
||||
purgeDeadFor(5 * time.Minute)
|
||||
time.Sleep(15 * time.Second)
|
||||
time.Sleep(cleanerTickDuration)
|
||||
cleanLinks()
|
||||
cleanConnections()
|
||||
cleanProcesses()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -234,7 +234,7 @@ func (conn *Connection) AddLink(link *Link) {
|
||||
conn.LinkCount++
|
||||
conn.LastLinkEstablished = time.Now().Unix()
|
||||
if conn.FirstLinkEstablished == 0 {
|
||||
conn.FirstLinkEstablished = conn.FirstLinkEstablished
|
||||
conn.FirstLinkEstablished = conn.LastLinkEstablished
|
||||
}
|
||||
conn.Save()
|
||||
}
|
||||
|
||||
@@ -38,8 +38,11 @@ func (s *StorageInterface) Get(key string) (record.Record, error) {
|
||||
switch len(splitted) {
|
||||
case 2:
|
||||
pid, err := strconv.Atoi(splitted[1])
|
||||
if err != nil {
|
||||
return process.GetProcessByPID(pid)
|
||||
if err == nil {
|
||||
proc, ok := process.GetProcessFromStorage(pid)
|
||||
if ok {
|
||||
return proc, nil
|
||||
}
|
||||
}
|
||||
case 3:
|
||||
conn, ok := connections[splitted[2]]
|
||||
@@ -69,7 +72,7 @@ func (s *StorageInterface) Query(q *query.Query, local, internal bool) (*iterato
|
||||
func (s *StorageInterface) processQuery(q *query.Query, it *iterator.Iterator) {
|
||||
// processes
|
||||
for _, proc := range process.All() {
|
||||
if strings.HasPrefix(proc.Meta().DatabaseKey, q.DatabaseKeyPrefix()) {
|
||||
if strings.HasPrefix(proc.DatabaseKey(), q.DatabaseKeyPrefix()) {
|
||||
it.Next <- proc
|
||||
}
|
||||
}
|
||||
@@ -79,14 +82,14 @@ func (s *StorageInterface) processQuery(q *query.Query, it *iterator.Iterator) {
|
||||
|
||||
// connections
|
||||
for _, conn := range connections {
|
||||
if strings.HasPrefix(conn.Meta().DatabaseKey, q.DatabaseKeyPrefix()) {
|
||||
if strings.HasPrefix(conn.DatabaseKey(), q.DatabaseKeyPrefix()) {
|
||||
it.Next <- conn
|
||||
}
|
||||
}
|
||||
|
||||
// links
|
||||
for _, link := range links {
|
||||
if strings.HasPrefix(opt.Meta().DatabaseKey, q.DatabaseKeyPrefix()) {
|
||||
if strings.HasPrefix(link.DatabaseKey(), q.DatabaseKeyPrefix()) {
|
||||
it.Next <- link
|
||||
}
|
||||
}
|
||||
@@ -105,7 +108,7 @@ func registerAsDatabase() error {
|
||||
return err
|
||||
}
|
||||
|
||||
controller, err := database.InjectDatabase("network", &ConfigStorageInterface{})
|
||||
controller, err := database.InjectDatabase("network", &StorageInterface{})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -177,6 +177,34 @@ func CreateLinkFromPacket(pkt packet.Packet) *Link {
|
||||
return link
|
||||
}
|
||||
|
||||
// GetActiveInspectors returns the list of active inspectors.
|
||||
func (link *Link) GetActiveInspectors() []bool {
|
||||
link.Lock()
|
||||
defer link.Unlock()
|
||||
return link.activeInspectors
|
||||
}
|
||||
|
||||
// SetActiveInspectors sets the list of active inspectors.
|
||||
func (link *Link) SetActiveInspectors(new []bool) {
|
||||
link.Lock()
|
||||
defer link.Unlock()
|
||||
link.activeInspectors = new
|
||||
}
|
||||
|
||||
// GetInspectorData returns the list of inspector data.
|
||||
func (link *Link) GetInspectorData() map[uint8]interface{} {
|
||||
link.Lock()
|
||||
defer link.Unlock()
|
||||
return link.inspectorData
|
||||
}
|
||||
|
||||
// SetInspectorData set the list of inspector data.
|
||||
func (link *Link) SetInspectorData(new map[uint8]interface{}) {
|
||||
link.Lock()
|
||||
defer link.Unlock()
|
||||
link.inspectorData = new
|
||||
}
|
||||
|
||||
// String returns a string representation of Link.
|
||||
func (link *Link) String() string {
|
||||
if link.connection == nil {
|
||||
|
||||
@@ -5,9 +5,10 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
modules.Register("network", prep, start, nil, "database")
|
||||
modules.Register("network", nil, start, nil, "database")
|
||||
}
|
||||
|
||||
func start() error {
|
||||
go cleaner()
|
||||
return registerAsDatabase()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user