Convert MsgAddr errors to MessageError type.

This commit is contained in:
Dave Collins 2013-05-10 14:54:36 -05:00
parent 72348986c9
commit 1f72b40823

View file

@ -30,8 +30,9 @@ type MsgAddr struct {
// AddAddress adds a known active peer to the message. // AddAddress adds a known active peer to the message.
func (msg *MsgAddr) AddAddress(na *NetAddress) error { func (msg *MsgAddr) AddAddress(na *NetAddress) error {
if len(msg.AddrList)+1 > MaxAddrPerMsg { if len(msg.AddrList)+1 > MaxAddrPerMsg {
str := "MsgAddr.AddAddress: too many addresses for message [max %v]" str := fmt.Sprintf("too many addresses in message [max %v]",
return fmt.Errorf(str, MaxAddrPerMsg) MaxAddrPerMsg)
return messageError("MsgAddr.AddAddress", str)
} }
msg.AddrList = append(msg.AddrList, na) msg.AddrList = append(msg.AddrList, na)
@ -64,8 +65,9 @@ func (msg *MsgAddr) BtcDecode(r io.Reader, pver uint32) error {
// Limit to max addresses per message. // Limit to max addresses per message.
if count > MaxAddrPerMsg { if count > MaxAddrPerMsg {
str := "MsgAddr.BtcDecode: too many addresses in message [%v]" str := fmt.Sprintf("too many addresses for message "+
return fmt.Errorf(str, count) "[count %v, max %v]", count, MaxAddrPerMsg)
return messageError("MsgAddr.BtcDecode", str)
} }
for i := uint64(0); i < count; i++ { for i := uint64(0); i < count; i++ {
@ -86,14 +88,15 @@ func (msg *MsgAddr) BtcEncode(w io.Writer, pver uint32) error {
// per message. // per message.
count := len(msg.AddrList) count := len(msg.AddrList)
if pver < MultipleAddressVersion && count > 1 { if pver < MultipleAddressVersion && count > 1 {
str := "MsgAddr.BtcDecode: too many addresses in message " + str := fmt.Sprintf("too many addresses for message of "+
"for protocol version [version %v max 1]" "protocol version %v [count %v, max 1]", pver, count)
return fmt.Errorf(str, pver) return messageError("MsgAddr.BtcEncode", str)
} }
if count > MaxAddrPerMsg { if count > MaxAddrPerMsg {
str := "MsgAddr.BtcDecode: too many addresses in message [max %v]" str := fmt.Sprintf("too many addresses for message "+
return fmt.Errorf(str, count) "[count %v, max %v]", count, MaxAddrPerMsg)
return messageError("MsgAddr.BtcEncode", str)
} }
err := writeVarInt(w, pver, uint64(count)) err := writeVarInt(w, pver, uint64(count))