magnetico/cmd/magneticod/dht/managers.go

48 lines
989 B
Go
Raw Normal View History

2017-08-08 13:58:51 +02:00
package dht
2018-04-16 17:40:54 +02:00
import "github.com/boramalper/magnetico/cmd/magneticod/dht/mainline"
2017-08-08 13:58:51 +02:00
type TrawlingManager struct {
// private
output chan mainline.TrawlingResult
2017-08-08 13:58:51 +02:00
services []*mainline.TrawlingService
}
func NewTrawlingManager(mlAddrs []string) *TrawlingManager {
2017-08-08 13:58:51 +02:00
manager := new(TrawlingManager)
manager.output = make(chan mainline.TrawlingResult)
if mlAddrs == nil {
mlAddrs = []string{"0.0.0.0:0"}
}
for _, addr := range mlAddrs {
manager.services = append(manager.services, mainline.NewTrawlingService(
addr,
2000,
mainline.TrawlingServiceEventHandlers{
OnResult: manager.onResult,
},
))
2017-08-08 13:58:51 +02:00
}
for _, service := range manager.services {
service.Start()
}
return manager
}
func (m *TrawlingManager) onResult(res mainline.TrawlingResult) {
m.output <- res
}
func (m *TrawlingManager) Output() <-chan mainline.TrawlingResult {
return m.output
}
func (m *TrawlingManager) Terminate() {
for _, service := range m.services {
service.Terminate()
}
}