Add ReadExtendedHandshake callback

This commit is contained in:
Matt Joiner 2020-07-15 16:16:09 +10:00
parent 9d0ea15044
commit dd906f8fa7
2 changed files with 6 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
// These are called synchronously, and do not pass ownership. The Client and other locks may still
// be held. nil functions are not called.
type Callbacks struct {
CompletedHandshake func(_ *PeerConn, infoHash InfoHash)
ReadMessage func(*PeerConn, *pp.Message)
CompletedHandshake func(_ *PeerConn, infoHash InfoHash)
ReadMessage func(*PeerConn, *pp.Message)
ReadExtendedHandshake func(*PeerConn, *pp.ExtendedHandshakeMessage)
}

View File

@ -1195,6 +1195,9 @@ func (c *PeerConn) onReadExtendedMsg(id pp.ExtensionNumber, payload []byte) (err
c.logger.Printf("error parsing extended handshake message %q: %s", payload, err)
return errors.Wrap(err, "unmarshalling extended handshake payload")
}
if cb := cl.config.Callbacks.ReadExtendedHandshake; cb != nil {
cb(c, &d)
}
//c.logger.WithDefaultLevel(log.Debug).Printf("received extended handshake message:\n%s", spew.Sdump(d))
if d.Reqq != 0 {
c.PeerMaxRequests = d.Reqq