dht: Export some useful variables
This commit is contained in:
parent
4a8ba4faaf
commit
c41aa941f3
|
@ -585,6 +585,7 @@ func (s *Server) processPacket(b []byte, addr dHTAddr) {
|
|||
var d Msg
|
||||
err := bencode.Unmarshal(b, &d)
|
||||
if err != nil {
|
||||
readUnmarshalError.Add(1)
|
||||
func() {
|
||||
if se, ok := err.(*bencode.SyntaxError); ok {
|
||||
// The message was truncated.
|
||||
|
@ -607,6 +608,7 @@ func (s *Server) processPacket(b []byte, addr dHTAddr) {
|
|||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if d["y"] == "q" {
|
||||
readQuery.Add(1)
|
||||
s.handleQuery(addr, d)
|
||||
return
|
||||
}
|
||||
|
@ -629,6 +631,7 @@ func (s *Server) serve() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
read.Add(1)
|
||||
if n == len(b) {
|
||||
logonce.Stderr.Printf("received dht packet exceeds buffer size")
|
||||
continue
|
||||
|
@ -637,6 +640,7 @@ func (s *Server) serve() error {
|
|||
blocked := s.ipBlocked(util.AddrIP(addr))
|
||||
s.mu.Unlock()
|
||||
if blocked {
|
||||
readBlocked.Add(1)
|
||||
continue
|
||||
}
|
||||
s.processPacket(b[:n], newDHTAddr(addr))
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
package dht
|
||||
|
||||
import (
|
||||
"expvar"
|
||||
)
|
||||
|
||||
var (
|
||||
read = expvar.NewInt("dhtRead")
|
||||
readBlocked = expvar.NewInt("dhtReadBlocked")
|
||||
readUnmarshalError = expvar.NewInt("dhtReadUnmarshalError")
|
||||
readQuery = expvar.NewInt("dhtReadQuery")
|
||||
)
|
Loading…
Reference in New Issue