dht: Export some useful variables

This commit is contained in:
Matt Joiner 2015-06-29 19:36:08 +10:00
parent 4a8ba4faaf
commit c41aa941f3
2 changed files with 16 additions and 0 deletions

View File

@ -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))

12
dht/expvar.go Normal file
View File

@ -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")
)