#include "ipcz/node_link.h"
#include <algorithm>
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <optional>
#include <utility>
#include "ipcz/box.h"
#include "ipcz/fragment_ref.h"
#include "ipcz/ipcz.h"
#include "ipcz/link_side.h"
#include "ipcz/link_type.h"
#include "ipcz/message.h"
#include "ipcz/node.h"
#include "ipcz/node_connector.h"
#include "ipcz/node_link_memory.h"
#include "ipcz/node_messages.h"
#include "ipcz/parcel.h"
#include "ipcz/remote_router_link.h"
#include "ipcz/router.h"
#include "ipcz/router_link.h"
#include "ipcz/router_link_state.h"
#include "ipcz/sublink_id.h"
#include "third_party/abseil-cpp/absl/base/macros.h"
#include "util/log.h"
#include "util/ref_counted.h"
#include "util/safe_math.h"
namespace ipcz {
namespace {
template <typename T>
FragmentRef<T> MaybeAdoptFragmentRef(NodeLinkMemory& memory,
const FragmentDescriptor& descriptor) { … }
}
Ref<NodeLink> NodeLink::CreateActive(Ref<Node> node,
LinkSide link_side,
const NodeName& local_node_name,
const NodeName& remote_node_name,
Node::Type remote_node_type,
uint32_t remote_protocol_version,
const Features& remote_features,
Ref<DriverTransport> transport,
Ref<NodeLinkMemory> memory) { … }
Ref<NodeLink> NodeLink::CreateInactive(Ref<Node> node,
LinkSide link_side,
const NodeName& local_node_name,
const NodeName& remote_node_name,
Node::Type remote_node_type,
uint32_t remote_protocol_version,
const Features& remote_features,
Ref<DriverTransport> transport,
Ref<NodeLinkMemory> memory) { … }
NodeLink::NodeLink(Ref<Node> node,
LinkSide link_side,
const NodeName& local_node_name,
const NodeName& remote_node_name,
Node::Type remote_node_type,
uint32_t remote_protocol_version,
const Features& remote_features,
Ref<DriverTransport> transport,
Ref<NodeLinkMemory> memory,
ActivationState initial_activation_state)
: … { … }
NodeLink::~NodeLink() { … }
void NodeLink::Activate() { … }
Ref<RemoteRouterLink> NodeLink::AddRemoteRouterLink(
SublinkId sublink,
FragmentRef<RouterLinkState> link_state,
LinkType type,
LinkSide side,
Ref<Router> router) { … }
void NodeLink::RemoveRemoteRouterLink(SublinkId sublink) { … }
std::optional<NodeLink::Sublink> NodeLink::GetSublink(SublinkId sublink) { … }
Ref<Router> NodeLink::GetRouter(SublinkId sublink) { … }
void NodeLink::AddBlockBuffer(BufferId id,
uint32_t block_size,
DriverMemory memory) { … }
void NodeLink::RequestIntroduction(const NodeName& name) { … }
void NodeLink::AcceptIntroduction(const NodeName& name,
LinkSide side,
Node::Type remote_node_type,
uint32_t remote_protocol_version,
const Features& remote_features,
Ref<DriverTransport> transport,
DriverMemory memory) { … }
void NodeLink::RejectIntroduction(const NodeName& name) { … }
void NodeLink::ReferNonBroker(Ref<DriverTransport> transport,
uint32_t num_initial_portals,
ReferralCallback callback) { … }
void NodeLink::AcceptBypassLink(
const NodeName& current_peer_node,
SublinkId current_peer_sublink,
SequenceNumber inbound_sequence_length_from_bypassed_link,
SublinkId new_sublink,
FragmentRef<RouterLinkState> link_state) { … }
void NodeLink::RequestMemory(size_t size, RequestMemoryCallback callback) { … }
void NodeLink::RelayMessage(const NodeName& to_node, Message& message) { … }
bool NodeLink::DispatchRelayedMessage(msg::AcceptRelayedMessage& accept) { … }
void NodeLink::Deactivate() { … }
void NodeLink::Transmit(Message& message) { … }
SequenceNumber NodeLink::GenerateOutgoingSequenceNumber() { … }
bool NodeLink::OnReferNonBroker(msg::ReferNonBroker& refer) { … }
bool NodeLink::OnNonBrokerReferralAccepted(
msg::NonBrokerReferralAccepted& accepted) { … }
bool NodeLink::OnNonBrokerReferralRejected(
msg::NonBrokerReferralRejected& rejected) { … }
bool NodeLink::OnRequestIntroduction(msg::RequestIntroduction& request) { … }
bool NodeLink::OnAcceptIntroduction(msg::AcceptIntroduction& accept) { … }
bool NodeLink::OnRejectIntroduction(msg::RejectIntroduction& reject) { … }
bool NodeLink::OnRequestIndirectIntroduction(
msg::RequestIndirectIntroduction& request) { … }
bool NodeLink::OnAddBlockBuffer(msg::AddBlockBuffer& add) { … }
bool NodeLink::OnAcceptParcel(msg::AcceptParcel& accept) { … }
bool NodeLink::OnAcceptParcelDriverObjects(
msg::AcceptParcelDriverObjects& accept) { … }
bool NodeLink::OnRouteClosed(msg::RouteClosed& route_closed) { … }
bool NodeLink::OnRouteDisconnected(msg::RouteDisconnected& route_closed) { … }
bool NodeLink::OnBypassPeer(msg::BypassPeer& bypass) { … }
bool NodeLink::OnAcceptBypassLink(msg::AcceptBypassLink& accept) { … }
bool NodeLink::OnStopProxying(msg::StopProxying& stop) { … }
bool NodeLink::OnProxyWillStop(msg::ProxyWillStop& will_stop) { … }
bool NodeLink::OnBypassPeerWithLink(msg::BypassPeerWithLink& bypass) { … }
bool NodeLink::OnStopProxyingToLocalPeer(msg::StopProxyingToLocalPeer& stop) { … }
bool NodeLink::OnFlushRouter(msg::FlushRouter& flush) { … }
bool NodeLink::OnRequestMemory(msg::RequestMemory& request) { … }
bool NodeLink::OnProvideMemory(msg::ProvideMemory& provide) { … }
bool NodeLink::OnRelayMessage(msg::RelayMessage& relay) { … }
bool NodeLink::OnAcceptRelayedMessage(msg::AcceptRelayedMessage& accept) { … }
void NodeLink::OnTransportError() { … }
void NodeLink::HandleTransportError() { … }
void NodeLink::WaitForParcelFragmentToResolve(
SublinkId for_sublink,
std::unique_ptr<Parcel> parcel,
const FragmentDescriptor& descriptor,
bool is_split_parcel) { … }
bool NodeLink::AcceptParcelWithoutDriverObjects(
SublinkId for_sublink,
std::unique_ptr<Parcel> parcel) { … }
bool NodeLink::AcceptParcelDriverObjects(SublinkId for_sublink,
std::unique_ptr<Parcel> parcel) { … }
bool NodeLink::AcceptSplitParcel(
SublinkId for_sublink,
std::unique_ptr<Parcel> parcel_without_driver_objects,
std::unique_ptr<Parcel> parcel_with_driver_objects) { … }
bool NodeLink::AcceptCompleteParcel(SublinkId for_sublink,
std::unique_ptr<Parcel> parcel) { … }
NodeLink::Sublink::Sublink(Ref<RemoteRouterLink> router_link,
Ref<Router> receiver)
: … { … }
NodeLink::Sublink::Sublink(Sublink&&) = default;
NodeLink::Sublink::Sublink(const Sublink&) = default;
NodeLink::Sublink& NodeLink::Sublink::operator=(Sublink&&) = default;
NodeLink::Sublink& NodeLink::Sublink::operator=(const Sublink&) = default;
NodeLink::Sublink::~Sublink() = default;
}