Back to Site
Loading...
Searching...
No Matches
peer.h
Go to the documentation of this file.
1#pragma once
2
15#include "librats/util/rats_export.h"
16#include "librats/core/bytes.h"
19#include "librats/peer/peer_table.h" // PeerRoute
20
21#include <optional>
22#include <string_view>
23
24namespace librats {
25
26class Node;
27
28class RATS_API Peer {
29public:
30 const PeerId& id() const noexcept { return id_; }
31
42 bool send(std::string_view channel, ByteView payload) const;
43
45 void disconnect() const;
46
48 std::optional<PeerInfo> info() const;
49
50private:
51 friend class Node;
52 Peer(PeerId id, PeerRoute route, Node& node)
53 : id_(std::move(id)), route_(route), node_(&node) {}
54
55 PeerId id_;
56 PeerRoute route_;
57 Node* node_;
58};
59
60} // namespace librats
Lightweight byte container aliases and a non-owning byte view.
Non-owning view over a contiguous run of bytes.
Definition bytes.h:27
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:30
bool send(std::string_view channel, ByteView payload) const
Send bytes on a named application channel, to this peer over whichever connection currently serves it...
void disconnect() const
Request this peer be disconnected.
Definition node.h:73
STL namespace.
Self-certifying peer identity.
Addressing/metadata for a peer — the shareable, persistable identity.