log messages for sockets
This commit is contained in:
@@ -18,7 +18,7 @@ type ConfigTOML struct {
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
log.Println("Program started")
|
||||
cfg, err := configs.GetConfigTOML()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
@@ -31,6 +31,6 @@ func main() {
|
||||
|
||||
fs := http.FileServer(http.Dir(cfg.Config.Cache_d))
|
||||
http.Handle("/", fs)
|
||||
|
||||
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%d", cfg.Config.HttpPort), nil))
|
||||
log.Printf("Listening and serving on port %d\n", cfg.Config.HttpPort)
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ func CheckDownloaded(filename string) bool {
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.Println("Program started")
|
||||
pid := os.Getpid()
|
||||
if err := os.WriteFile(filepath.Join(consts.DefaultLinux_d, "udp.pid"), []byte(fmt.Sprint(pid)), 0664); err != nil {
|
||||
fmt.Println("error saving subprocess pid", err)
|
||||
@@ -37,6 +38,7 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
log.Println("Started connection listener")
|
||||
defer conn.Close()
|
||||
buf := make([]byte, 1500)
|
||||
|
||||
@@ -46,12 +48,15 @@ func main() {
|
||||
log.Println("error creating udp socket", err)
|
||||
}
|
||||
msg := string(buf[:n])
|
||||
log.Printf("Received message : %s\n", msg)
|
||||
if !strings.HasPrefix(msg, "Q:") {
|
||||
log.Println("error: invalid message, this message don't follow the protocol")
|
||||
continue
|
||||
}
|
||||
filename := strings.TrimPrefix(msg, "Q:")
|
||||
if CheckDownloaded(filename) {
|
||||
reply := fmt.Sprintf("H:%s:%d", filename, cfg.Config.HttpPort)
|
||||
log.Printf("Package founded in cache dir, answering with: '%s'\n", reply)
|
||||
conn.WriteToUDP([]byte(reply), remote)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user