From dbb26f92021e0a1048967baae5328a45ff896c09 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 28 Sep 2023 08:57:02 +0900 Subject: [PATCH 1/4] logging connection informations --- handlers.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/handlers.go b/handlers.go index e73efc1..737edb3 100644 --- a/handlers.go +++ b/handlers.go @@ -56,6 +56,8 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) { ticker := time.NewTicker(pingPeriod) stop := make(chan struct{}) + s.Log.Infof("connected from %s", conn.RemoteAddr().String()) + // NIP-42 challenge challenge := make([]byte, 8) rand.Read(challenge) @@ -85,6 +87,7 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) { removeListener(ws) } s.clientsMu.Unlock() + s.Log.Infof("diconnected from %s", conn.RemoteAddr().String()) }() conn.SetReadLimit(maxMessageSize) @@ -387,6 +390,7 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) { s.Log.Errorf("error writing ping: %v; closing websocket", err) return } + s.Log.Infof("pinging for %s", conn.RemoteAddr().String()) case <-stop: return } From 18c8a56135d36743b33c210c59d46d798070b94e Mon Sep 17 00:00:00 2001 From: mattn Date: Thu, 28 Sep 2023 09:56:57 +0900 Subject: [PATCH 2/4] Update handlers.go --- handlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers.go b/handlers.go index 737edb3..f205ef8 100644 --- a/handlers.go +++ b/handlers.go @@ -87,7 +87,7 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) { removeListener(ws) } s.clientsMu.Unlock() - s.Log.Infof("diconnected from %s", conn.RemoteAddr().String()) + s.Log.Infof("disconnected from %s", conn.RemoteAddr().String()) }() conn.SetReadLimit(maxMessageSize) From 1740e67512ce5ff509c198c229b0825a131b5eb9 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 28 Sep 2023 10:39:22 +0900 Subject: [PATCH 3/4] read stop channel --- handlers.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/handlers.go b/handlers.go index 737edb3..1ea8f45 100644 --- a/handlers.go +++ b/handlers.go @@ -87,7 +87,7 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) { removeListener(ws) } s.clientsMu.Unlock() - s.Log.Infof("diconnected from %s", conn.RemoteAddr().String()) + s.Log.Infof("disconnected from %s", conn.RemoteAddr().String()) }() conn.SetReadLimit(maxMessageSize) @@ -379,6 +379,8 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) { defer func() { ticker.Stop() conn.Close() + for := range stop { + } }() for { From 90a9680b7d8d0f930165e7abbab612b3dfa4bfbe Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Thu, 28 Sep 2023 10:42:15 +0900 Subject: [PATCH 4/4] fix --- handlers.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/handlers.go b/handlers.go index 1ea8f45..74f6064 100644 --- a/handlers.go +++ b/handlers.go @@ -379,7 +379,7 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) { defer func() { ticker.Stop() conn.Close() - for := range stop { + for range stop { } }()