Back to Site
Loading...
Searching...
No Matches
peer.h
Go to the documentation of this file.
1#pragma once
2
13#include "core/bytes.h"
14#include "peer/peer_id.h"
15#include "peer/peer_info.h"
16#include "peer/peer_table.h" // PeerRoute
17
18#include <optional>
19#include <string_view>
20
21namespace librats {
22
23class Node;
24
25class Peer {
26public:
27 const PeerId& id() const noexcept { return id_; }
28
30 void send(std::string_view channel, ByteView payload) const;
31
33 void disconnect() const;
34
36 std::optional<PeerInfo> info() const;
37
38private:
39 friend class Node;
40 Peer(PeerId id, PeerRoute route, Node& node)
41 : id_(std::move(id)), route_(route), node_(&node) {}
42
43 PeerId id_;
44 PeerRoute route_;
45 Node* node_;
46};
47
48} // namespace librats
std::optional< PeerInfo > info() const
Look up the peer's metadata in the directory (nullopt if gone).
const PeerId & id() const noexcept
Definition peer.h:27
void send(std::string_view channel, ByteView payload) const
Send bytes on a named application channel.
void disconnect() const
Request this peer be disconnected.
Definition node.h:65
STL namespace.
Self-certifying peer identity.
Addressing/metadata for a peer — the shareable, persistable identity.