1
0
mirror of https://github.com/veggiedefender/torrent-client.git synced 2025-11-06 09:29:16 +02:00
Files
torrent-client/p2p/p2p.go
2019-12-22 22:25:57 -05:00

35 lines
657 B
Go

package p2p
import (
"net"
"strconv"
)
// Peer encodes connection information for a peer
type Peer struct {
IP net.IP
Port uint16
}
// Downloader holds data required to download a torrent from a list of peers
type Downloader struct {
Peers []Peer
InfoHash [20]byte
PieceLength int
Length int
}
// Download downloads a torrent
func (d *Downloader) Download() error {
return nil
}
func connect(p *Peer, peerID [20]byte, infoHash [20]byte) (net.Conn, error) {
hostPort := net.JoinHostPort(p.IP.String(), strconv.Itoa(int(p.Port)))
conn, err := net.Dial("tcp", hostPort)
if err != nil {
return nil, err
}
return conn, nil
}