Back to Site
Loading...
Searching...
No Matches
peer.h
Go to the documentation of this file.
1#pragma once
2
13#include "util/rats_export.h"
14#include "core/bytes.h"
15#include "peer/peer_id.h"
16#include "peer/peer_info.h"
17#include "peer/peer_table.h" // PeerRoute
18
19#include <optional>
20#include <string_view>
21
22namespace librats {
23
24class Node;
25
26class RATS_API Peer {
27public:
28 const PeerId& id() const noexcept { return id_; }
29
31 void send(std::string_view channel, ByteView payload) const;
32
34 void disconnect() const;
35
37 std::optional<PeerInfo> info() const;
38
39private:
40 friend class Node;
41 Peer(PeerId id, PeerRoute route, Node& node)
42 : id_(std::move(id)), route_(route), node_(&node) {}
43
44 PeerId id_;
45 PeerRoute route_;
46 Node* node_;
47};
48
49} // 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:28
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:66
STL namespace.
Self-certifying peer identity.
Addressing/metadata for a peer — the shareable, persistable identity.