You've already forked torrent-client
mirror of
https://github.com/veggiedefender/torrent-client.git
synced 2025-11-06 09:29:16 +02:00
Only use fmt.Errorf
This commit is contained in:
@@ -2,7 +2,7 @@ package handshake
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"errors"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -45,7 +45,7 @@ func Read(r *bufio.Reader) (*Handshake, error) {
|
|||||||
pstrlen := int(lengthBuf[0])
|
pstrlen := int(lengthBuf[0])
|
||||||
|
|
||||||
if pstrlen == 0 {
|
if pstrlen == 0 {
|
||||||
err := errors.New("pstrlen cannot be 0")
|
err := fmt.Errorf("pstrlen cannot be 0")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package message
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
@@ -52,7 +51,7 @@ func ParsePiece(index int, buf []byte, msg *Message) (int, error) {
|
|||||||
return 0, fmt.Errorf("Expected PIECE (ID %d), got ID %d", MsgPiece, msg.ID)
|
return 0, fmt.Errorf("Expected PIECE (ID %d), got ID %d", MsgPiece, msg.ID)
|
||||||
}
|
}
|
||||||
if len(msg.Payload) < 8 {
|
if len(msg.Payload) < 8 {
|
||||||
return 0, errors.New("Payload too short")
|
return 0, fmt.Errorf("Payload too short. %d < 8", len(msg.Payload))
|
||||||
}
|
}
|
||||||
parsedIndex := int(binary.BigEndian.Uint32(msg.Payload[0:4]))
|
parsedIndex := int(binary.BigEndian.Uint32(msg.Payload[0:4]))
|
||||||
if parsedIndex != index {
|
if parsedIndex != index {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package torrentfile
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"errors"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
@@ -21,7 +21,7 @@ func parsePeers(peersBin string) ([]p2p.Peer, error) {
|
|||||||
const peerSize = 6 // 4 for IP, 2 for port
|
const peerSize = 6 // 4 for IP, 2 for port
|
||||||
numPeers := len(peersBin) / peerSize
|
numPeers := len(peersBin) / peerSize
|
||||||
if len(peersBin)%peerSize != 0 {
|
if len(peersBin)%peerSize != 0 {
|
||||||
err := errors.New("Received malformed peers")
|
err := fmt.Errorf("Received malformed peers")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
peers := make([]p2p.Peer, numPeers)
|
peers := make([]p2p.Peer, numPeers)
|
||||||
|
|||||||
Reference in New Issue
Block a user