jitsilg/internal/processor.go

95 lines
2.1 KiB
Go

/*
Copyright (C) 2021 j.r <j.r@jugendhacker.de>
jitsilg is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package jitsilg
import (
"net"
"regexp"
"sync"
)
type Domain struct {
Name string
IP net.IP
Available bool
UnwantedHoster bool
HosterName string
CountryCode string
UnwantedStun bool
Version string
AuthEnabled bool
AnalyticsEnabled bool
}
type Timeout struct {
WaitSeconds int
sync.Mutex
}
func ProcessDomains(domains []string, badStuns []*regexp.Regexp) []Domain {
apiQueue := make(chan Domain)
pageParsingQueue := make(chan Domain)
outputQueue := make(chan Domain)
go func() {
var wg sync.WaitGroup
for _, domain := range domains {
var domainObj Domain
domainObj.Name = domain
wg.Add(1)
go LookupDomain(domainObj, apiQueue, outputQueue, &wg)
}
wg.Wait()
close(apiQueue)
}()
go func() {
var wg sync.WaitGroup
var timeout Timeout
var apiDomains []Domain
for domain := range apiQueue {
apiDomains = append(apiDomains, domain)
if len(apiDomains) == 100 {
wg.Add(1)
go CheckGeoIP(apiDomains, pageParsingQueue, &wg, &timeout)
apiDomains = []Domain{}
}
}
wg.Add(1)
go CheckGeoIP(apiDomains, pageParsingQueue, &wg, &timeout)
wg.Wait()
close(pageParsingQueue)
}()
go func() {
var wg sync.WaitGroup
for domain := range pageParsingQueue {
wg.Add(1)
go CheckPage(domain, badStuns, outputQueue, &wg)
}
wg.Wait()
close(outputQueue)
}()
var output []Domain
for domain := range outputQueue {
output = append(output, domain)
}
return output
}