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 // Main
func minTunnelVersion(std adlin.Student) (int, error) { func minTunnelVersion(std adlin.Student, suffixip int) (int, error) {
tunnels, err := std.GetTunnelTokens() tunnels, err := std.GetTunnelTokens()
if err != nil { if err != nil {
return 0, err return 0, err
@ -141,7 +141,7 @@ func minTunnelVersion(std adlin.Student) (int, error) {
continue continue
} }
if tunnel.Dump != nil && tunnel.Version < minversion { if tunnel.Dump != nil && tunnel.Version < minversion && suffixip == tunnel.SuffixIP {
minversion = tunnel.Version minversion = tunnel.Version
} }
} }
@ -161,11 +161,17 @@ func studentsChecker() {
time.Sleep(250 * time.Millisecond) time.Sleep(250 * time.Millisecond)
// Check ping // Check ping
std := s 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) { go check_ping(stdIP, func(pkt *ping.Packet) {
tunnel_version, err := minTunnelVersion(std) tunnel_version, err := minTunnelVersion(std, tun.SuffixIP)
if verbose { 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) std.OnPong(true)
@ -261,4 +267,5 @@ func studentsChecker() {
return return
}) })
} }
}
} }

View File

@ -104,7 +104,11 @@ type TunnelToken struct {
} }
func (tt *TunnelToken) GetStudentIP() string { 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) return fmt.Sprintf("%s%x", StudentIP(tt.IdStudent).String(), tt.SuffixIP)
}
} }
func TokenFromText(token string) []byte { func TokenFromText(token string) []byte {

View File

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