ae691ada79
I've decided instead to release a minimum viable product for v0.7.0 and get some feedback from the community, and most importantly some motivation as well to be able to keep working on magnetico as it currently feels like a Sisyphean where the development seem to never going to end...
47 lines
954 B
Go
47 lines
954 B
Go
package dht
|
|
|
|
import "magnetico/magneticod/dht/mainline"
|
|
|
|
type TrawlingManager struct {
|
|
// private
|
|
output chan mainline.TrawlingResult
|
|
services []*mainline.TrawlingService
|
|
}
|
|
|
|
func NewTrawlingManager(mlAddrs []string) *TrawlingManager {
|
|
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,
|
|
mainline.TrawlingServiceEventHandlers{
|
|
OnResult: manager.onResult,
|
|
},
|
|
))
|
|
}
|
|
|
|
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()
|
|
}
|
|
}
|