Convert MsgGetData errors to MessageError type.

This commit is contained in:
Dave Collins 2013-05-10 13:04:20 -05:00
parent 0c65e7da89
commit 7c3129bf89

View file

@ -26,8 +26,9 @@ type MsgGetData struct {
// AddInvVect adds an inventory vector to the message. // AddInvVect adds an inventory vector to the message.
func (msg *MsgGetData) AddInvVect(iv *InvVect) error { func (msg *MsgGetData) AddInvVect(iv *InvVect) error {
if len(msg.InvList)+1 > MaxInvPerMsg { if len(msg.InvList)+1 > MaxInvPerMsg {
str := "MsgAddr.AddAddress: too many invvect in message [max %v]" str := fmt.Sprintf("too many invvect in message [max %v]",
return fmt.Errorf(str, MaxInvPerMsg) MaxInvPerMsg)
return messageError("MsgAddr.AddInvVect", str)
} }
msg.InvList = append(msg.InvList, iv) msg.InvList = append(msg.InvList, iv)
@ -44,8 +45,8 @@ func (msg *MsgGetData) BtcDecode(r io.Reader, pver uint32) error {
// Limit to max inventory vectors per message. // Limit to max inventory vectors per message.
if count > MaxInvPerMsg { if count > MaxInvPerMsg {
str := "MsgGetData.BtcDecode: too many invvect in message [%v]" str := fmt.Sprintf("too many invvect in message [%v]", count)
return fmt.Errorf(str, count) return messageError("MsgGetData.BtcDecode", str)
} }
for i := uint64(0); i < count; i++ { for i := uint64(0); i < count; i++ {
@ -66,8 +67,8 @@ func (msg *MsgGetData) BtcEncode(w io.Writer, pver uint32) error {
// Limit to max inventory vectors per message. // Limit to max inventory vectors per message.
count := len(msg.InvList) count := len(msg.InvList)
if count > MaxInvPerMsg { if count > MaxInvPerMsg {
str := "MsgGetData.BtcDecode: too many invvect in message [%v]" str := fmt.Sprintf("too many invvect in message [%v]", count)
return fmt.Errorf(str, count) return messageError("MsgGetData.BtcEncode", str)
} }
err := writeVarInt(w, pver, uint64(count)) err := writeVarInt(w, pver, uint64(count))