Skip to content

Commit

Permalink
Merge pull request #89 from mattn/logging
Browse files Browse the repository at this point in the history
logging connection informations
  • Loading branch information
fiatjaf committed Sep 28, 2023
2 parents dc3f542 + 90a9680 commit 01fde86
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -85,6 +87,7 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
removeListener(ws)
}
s.clientsMu.Unlock()
s.Log.Infof("disconnected from %s", conn.RemoteAddr().String())
}()

conn.SetReadLimit(maxMessageSize)
Expand Down Expand Up @@ -376,6 +379,8 @@ func (s *Server) HandleWebsocket(w http.ResponseWriter, r *http.Request) {
defer func() {
ticker.Stop()
conn.Close()
for range stop {
}
}()

for {
Expand All @@ -387,6 +392,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
}
Expand Down

0 comments on commit 01fde86

Please sign in to comment.