Commit 8ca3ee85 authored by Matt Joiner's avatar Matt Joiner
Browse files

Remove or merge all the expvars into the "dht" map

parent 6cf13fc3
......@@ -7,15 +7,7 @@ import (
)
var (
readZeroPort = expvar.NewInt("dhtReadZeroPort")
readBlocked = expvar.NewInt("dhtReadBlocked")
readNotKRPCDict = expvar.NewInt("dhtReadNotKRPCDict")
readUnmarshalError = expvar.NewInt("dhtReadUnmarshalError")
readAnnouncePeer = expvar.NewInt("dhtReadAnnouncePeer")
announceErrors = expvar.NewInt("dhtAnnounceErrors")
writeErrors = expvar.NewInt("dhtWriteErrors")
writes = expvar.NewInt("dhtWrites")
expvars = expvar.NewMap("dht")
expvars = expvar.NewMap("dht")
)
func init() {
......
......@@ -197,7 +197,6 @@ func (s *Server) IPBlocklist() iplist.Ranger {
func (s *Server) processPacket(b []byte, addr Addr) {
if len(b) < 2 || b[0] != 'd' {
// KRPC messages are bencoded dicts.
readNotKRPCDict.Add(1)
return
}
var d krpc.Msg
......@@ -206,7 +205,6 @@ func (s *Server) processPacket(b []byte, addr Addr) {
// log.Printf("%s: received message packet with %d trailing bytes: %q", s, _err.NumUnusedBytes, b[len(b)-_err.NumUnusedBytes:])
expvars.Add("processed packets with trailing bytes", 1)
} else if err != nil {
readUnmarshalError.Add(1)
func() {
if se, ok := err.(*bencode.SyntaxError); ok {
// The message was truncated.
......@@ -270,14 +268,12 @@ func (s *Server) serve() error {
continue
}
if missinggo.AddrPort(addr) == 0 {
readZeroPort.Add(1)
continue
}
s.mu.Lock()
blocked := s.ipBlocked(missinggo.AddrIP(addr))
s.mu.Unlock()
if blocked {
readBlocked.Add(1)
continue
}
s.processPacket(b[:n], NewAddr(addr))
......@@ -402,7 +398,6 @@ func (s *Server) handleQuery(source Addr, m krpc.Msg) {
}
s.reply(source, m.T, r)
case "announce_peer":
readAnnouncePeer.Add(1)
if !s.validToken(args.Token, source) {
expvars.Add("received announce_peer with invalid token", 1)
return
......@@ -526,9 +521,9 @@ func (s *Server) writeToNode(b []byte, node Addr) (wrote bool, err error) {
}
// log.Printf("writing to %s: %q", node.UDPAddr(), b)
n, err := s.socket.WriteTo(b, node.Raw())
writes.Add(1)
expvars.Add("packet writes", 1)
if err != nil {
writeErrors.Add(1)
expvars.Add("packet write errors", 1)
err = fmt.Errorf("error writing %d bytes to %s: %s", len(b), node, err)
return
}
......@@ -708,7 +703,7 @@ func (s *Server) announcePeer(node Addr, infoHash int160, port int, token string
go callback(m, err)
}
if err := m.Error(); err != nil {
announceErrors.Add(1)
expvars.Add("announce_peer error responses received", 1)
return
}
s.mu.Lock()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment