Squash some more debug messages, fix some other error handling

This commit is contained in:
Matt Joiner 2014-07-17 16:01:48 +10:00
parent b159968081
commit a258b9ab21
3 changed files with 10 additions and 11 deletions

View File

@ -353,7 +353,7 @@ func (me *Client) runConnection(sock net.Conn, torrent *torrent, discovery peerS
return
}
if string(b[:20]) != pp.Protocol {
err = fmt.Errorf("wrong protocol: %#v", string(b[:20]))
// err = fmt.Errorf("wrong protocol: %#v", string(b[:20]))
return
}
if 8 != copy(conn.PeerExtensions[:], b[20:]) {
@ -951,7 +951,7 @@ func (cl *Client) announceTorrentDHT(t *torrent) {
log.Printf("error adding peers from dht for torrent %q: %s", t, err)
break getPeers
}
log.Printf("got %d peers from dht for torrent %q", len(cps), t)
// log.Printf("got %d peers from dht for torrent %q", len(cps), t)
}
}
ps.Close()

View File

@ -3,7 +3,6 @@ package dht
import (
"bitbucket.org/anacrolix/go.torrent/tracker"
"bitbucket.org/anacrolix/go.torrent/util"
"bytes"
"crypto"
_ "crypto/sha1"
"encoding/binary"
@ -141,8 +140,7 @@ func (s *Server) Serve() error {
var d Msg
err = bencode.Unmarshal(b[:n], &d)
if err != nil {
// TODO: What are these messages?
if !bytes.HasPrefix(b[:], []byte("A\x00")) {
if se, ok := err.(*bencode.SyntaxError); !ok || se.Offset != 0 {
log.Printf("%s: received bad krpc message: %s: %q", s, err, b[:n])
}
continue
@ -284,6 +282,7 @@ func (s *Server) getNode(addr *net.UDPAddr) (n *Node) {
func (s *Server) writeToNode(b []byte, node *net.UDPAddr) (err error) {
n, err := s.Socket.WriteTo(b, node)
if err != nil {
err = fmt.Errorf("error writing %d bytes to %s: %s", len(b), node, err)
return
}
if n != len(b) {

View File

@ -127,18 +127,18 @@ func (d *Decoder) Decode(msg *Message) (err error) {
_, err = io.ReadFull(d.R, b)
if err == io.EOF {
err = io.ErrUnexpectedEOF
return
}
if err != nil {
return
}
r := bytes.NewReader(b)
// Check that all of r was utilized.
defer func() {
written, _ := io.Copy(ioutil.Discard, r)
if written != 0 && err == nil {
err = fmt.Errorf("short read on message type %d, left %d bytes", msg.Type, written)
} else if err == io.EOF {
err = io.ErrUnexpectedEOF
if err != nil {
return
}
if r.Len() != 0 {
err = fmt.Errorf("%d bytes unused in message type %d", r.Len(), msg.Type)
}
}()
msg.Keepalive = false