Back to Site
Loading...
Searching...
No Matches
circuit_service.h
Go to the documentation of this file.
1#pragma once
2
48
49#include "librats/core/types.h"
51#include "librats/peer/peer_table.h" // PeerRoute
52#include "librats/transport/link.h"
53#include "librats/transport/relay_link.h" // ForwardedCircuit
54
55#include <atomic>
56#include <cstdint>
57#include <memory>
58#include <optional>
59
60namespace librats {
61
63public:
64 virtual ~CircuitService() = default;
65
79 virtual std::optional<PeerRoute> adopt_circuit(const PeerId& carrier,
80 std::unique_ptr<Link> link,
81 ConnRole role, bool connected) = 0;
82
87 virtual void wake_circuit(PeerRoute route, uint32_t events) = 0;
88
91 virtual void close_circuit(PeerRoute route, CloseReason reason) = 0;
92
93 // — circuits whose relay forwards datagrams —
94 //
95 // `cid` is the dialer's (even) half of the connection id pair the relay chose.
96 // Each returns nullopt / false when the carrier is not a peer reached over UDP
97 // — the circuit is then ended — and otherwise reports failures that only the
98 // reactor can see by ending the circuit too.
99
101 virtual std::optional<PeerRoute> dial_relayed(const PeerId& carrier, uint64_t cid,
102 ForwardedCircuit circuit) = 0;
103
106 virtual std::optional<PeerRoute> expect_relayed(const PeerId& carrier, uint64_t cid,
107 ForwardedCircuit circuit) = 0;
108
114 virtual bool forward_datagrams(const PeerId& dialer, const PeerId& responder, uint64_t cid,
115 std::shared_ptr<std::atomic<uint64_t>> bytes, uint64_t rate,
116 uint64_t burst) = 0;
117 virtual void stop_forwarding(uint64_t cid) = 0;
118};
119
120} // namespace librats
virtual void stop_forwarding(uint64_t cid)=0
virtual std::optional< PeerRoute > adopt_circuit(const PeerId &carrier, std::unique_ptr< Link > link, ConnRole role, bool connected)=0
Adopt link as a connection carried by the peer carrier, on the reactor that owns the carrier's own co...
virtual std::optional< PeerRoute > expect_relayed(const PeerId &carrier, uint64_t cid, ForwardedCircuit circuit)=0
Accept the dial that will come through carrier, the relay, as an Inbound connection — under the same ...
virtual void wake_circuit(PeerRoute route, uint32_t events)=0
Deliver poll-equivalent events (PollIn / PollOut / PollErr, see core/io_poller.h) to a circuit connec...
virtual std::optional< PeerRoute > dial_relayed(const PeerId &carrier, uint64_t cid, ForwardedCircuit circuit)=0
Dial the far end through carrier, the relay. The connection is Outbound.
virtual ~CircuitService()=default
virtual bool forward_datagrams(const PeerId &dialer, const PeerId &responder, uint64_t cid, std::shared_ptr< std::atomic< uint64_t > > bytes, uint64_t rate, uint64_t burst)=0
As the relay: forward the packets of cid between dialer and responder, counting their bytes into byte...
virtual void close_circuit(PeerRoute route, CloseReason reason)=0
Tear a circuit connection down.
Definition node.h:75
Self-certifying peer identity.