checker: for each tun IP

This commit is contained in:
nemunaire 2021-03-04 01:32:09 +01:00
parent 0af7437693
commit 9cd237daff
3 changed files with 112 additions and 101 deletions

View File

@ -129,7 +129,7 @@ func check_https(domain, ip string) (err error) {
// Main
func minTunnelVersion(std adlin.Student) (int, error) {
func minTunnelVersion(std adlin.Student, suffixip int) (int, error) {
tunnels, err := std.GetTunnelTokens()
if err != nil {
return 0, err
@ -141,7 +141,7 @@ func minTunnelVersion(std adlin.Student) (int, error) {
continue
}
if tunnel.Dump != nil && tunnel.Version < minversion {
if tunnel.Dump != nil && tunnel.Version < minversion && suffixip == tunnel.SuffixIP {
minversion = tunnel.Version
}
}
@ -161,11 +161,17 @@ func studentsChecker() {
time.Sleep(250 * time.Millisecond)
// Check ping
std := s
stdIP := adlin.StudentIP(std.Id).String() + "1"
tuns, err := std.GetActivesTunnels()
if err != nil {
continue
}
for _, tun := range tuns {
stdIP := tun.GetStudentIP()
go check_ping(stdIP, func(pkt *ping.Packet) {
tunnel_version, err := minTunnelVersion(std)
tunnel_version, err := minTunnelVersion(std, tun.SuffixIP)
if verbose {
log.Printf("%s PONG; version=%d (%v)\n", std.Login, tunnel_version, err)
log.Printf("%s PONG (on %x); version=%d (%v)\n", std.Login, tun.SuffixIP, tunnel_version, err)
}
std.OnPong(true)
@ -262,3 +268,4 @@ func studentsChecker() {
})
}
}
}

View File

@ -104,8 +104,12 @@ type TunnelToken struct {
}
func (tt *TunnelToken) GetStudentIP() string {
if tt.SuffixIP == 0 {
return fmt.Sprintf("%s%x", StudentIP(tt.IdStudent).String(), 1)
} else {
return fmt.Sprintf("%s%x", StudentIP(tt.IdStudent).String(), tt.SuffixIP)
}
}
func TokenFromText(token string) []byte {
sha := sha512.Sum512([]byte(token))

View File

@ -60,7 +60,7 @@ func GetStudentTunnelIPs(student adlin.Student) (ips []string) {
ips = append(ips, adlin.StudentIP(student.Id).String()+"1")
} else {
for _, t := range ts {
ips = append(ips, t.GetTunnelIP())
ips = append(ips, t.GetStudentIP())
}
}
return