Furrent
peer.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cstdint>
4 #include <string>
5 #include <vector>
6 
7 #include "util/result.hpp"
8 
9 // Forward declare TorrentFile
10 namespace fur {
11 struct TorrentFile;
12 }
13 
16 namespace fur::peer {
17 
19 struct Peer {
20  uint32_t ip;
21  uint16_t port;
22 
24  explicit Peer();
25 
27  Peer(uint32_t ip, uint16_t port);
28 
30  Peer(const std::string& ip, uint16_t port);
31 
34  [[nodiscard]] std::string address() const;
35 };
36 
38 struct Announce {
41  int64_t interval;
43  std::vector<Peer> peers;
44 };
45 
46 enum class PeerError {
51 };
52 
54 
57 [[nodiscard]] PeerResult announce(const TorrentFile& torrent_f);
58 
59 } // namespace fur::peer
fur::peer::PeerError
PeerError
Definition: peer.hpp:46
fur::peer::Peer::address
std::string address() const
Definition: peer.cpp:17
fur::peer::Peer::port
uint16_t port
Definition: peer.hpp:21
fur::peer::Announce::peers
std::vector< Peer > peers
The list of peers that we can download the file from.
Definition: peer.hpp:43
fur::util::Result
Used to handle errors without using exceptions.
Definition: result.hpp:18
fur::peer::Peer::ip
uint32_t ip
Definition: peer.hpp:20
fur::peer::Announce::interval
int64_t interval
Definition: peer.hpp:41
fur::peer::Peer
Represents a single peer as given by the tracker.
Definition: peer.hpp:19
fur::TorrentFile
Represents a parsed .torrent file.
Definition: torrent.hpp:32
fur::peer
Definition: peer.cpp:15
fur::peer::Announce
The response sent from the tracker when announcing.
Definition: peer.hpp:38
fur::peer::PeerError::ParserError
@ ParserError
Generic error that comes from the BencodeParser.
fur::peer::announce
PeerResult announce(const TorrentFile &torrent_f)
Definition: peer.cpp:45
result.hpp
fur
Common types used in all the project.
Definition: bencode_parser.cpp:7
fur::peer::Peer::Peer
Peer()
Constructs an empty 'Peer'.
Definition: peer.cpp:22
fur::peer::PeerError::AnnounceError
@ AnnounceError
Can't announce to the tracker.