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