---
title: llarp/apple/context.hpp

---

# llarp/apple/context.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::apple](Namespaces/namespacellarp_1_1apple.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::apple::AppleRouter](Classes/structllarp_1_1apple_1_1AppleRouter.md)** <br>router with apple quarks applied.  |
| struct | **[llarp::apple::Context](Classes/structllarp_1_1apple_1_1Context.md)**  |
| class | **[llarp::apple::AppleOSTraffic_IO](Classes/classllarp_1_1apple_1_1AppleOSTraffic__IO.md)** <br>applies os traffic io quarks for apple platform  |
| class | **[llarp::apple::ApplePlatformLayer](Classes/classllarp_1_1apple_1_1ApplePlatformLayer.md)** <br>applies quarks for apple for the platform layer.  |




## Source code

```cpp
#pragma once

#include <llarp.hpp>
#include "vpn_platform.hpp"
#include "route_manager.hpp"

namespace llarp::apple
{
  struct Context;

  std::unique_ptr<const layers::Layers>
  make_apple_layers(Context& ctx, Config conf);

  struct AppleRouter : public llarp::Router
  {
    AppleRouter(
        const std::shared_ptr<EventLoop>& loop, std::shared_ptr<VPNPlatform> plat, Context& ctx)
        : Router{loop, std::move(plat)}, _apple_ctx{ctx}

    {}

    ~AppleRouter() override = default;

    Context& _apple_ctx;

    std::unique_ptr<const layers::Layers>
    create_layers() override
    {
      return make_apple_layers(_apple_ctx, *m_Config);
    }
  };

  struct Context : public llarp::Context
  {
    std::shared_ptr<vpn::Platform>
    makeVPNPlatform() override
    {
      return std::make_shared<VPNPlatform>(*this, write_packet, route_callbacks, callback_context);
    }

    std::shared_ptr<AbstractRouter>
    makeRouter(const std::shared_ptr<EventLoop>& loop) override
    {
      auto ptr = std::make_shared<AppleRouter>(loop, makeVPNPlatform(), *this);
      return std::static_pointer_cast<AbstractRouter>(ptr);
    }

    // Callbacks that must be set for packet handling *before* calling Setup/Configure/Run; the main
    // point of these is to get passed through to VPNInterface, which will be called during setup,
    // after construction.
    packet_write_callback write_packet;
    on_readable_callback on_readable;
    llarp_route_callbacks route_callbacks{};
    void* callback_context = nullptr;
  };

  class AppleOSTraffic_IO : public layers::platform::OSTraffic_IO_Base
  {
   public:
    using layers::platform::OSTraffic_IO_Base::OSTraffic_IO_Base;

    std::vector<layers::platform::OSTraffic>
    read_platform_traffic() override
    {
      auto vec = layers::platform::OSTraffic_IO_Base::read_platform_traffic();
      // we collected all reads from the past read cycle. queue reads again.
      if (auto ptr = std::dynamic_pointer_cast<llarp::apple::AppleVPNInterface>(_netif))
        ptr->on_readable();

      return vec;
    }
  };

  class ApplePlatformLayer : public layers::platform::PlatformLayer
  {
   protected:
    std::unique_ptr<layers::platform::OSTraffic_IO_Base>
    make_io() const override
    {
      return std::unique_ptr<layers::platform::OSTraffic_IO_Base>{
          new AppleOSTraffic_IO{_router.loop()}};
    }

   public:
    using layers::platform::PlatformLayer::PlatformLayer;
  };

  std::unique_ptr<const layers::Layers>
  make_apple_layers(AbstractRouter& router, Config conf)
  {
    auto ptr = layers::make_layers(router, conf);
    ptr->platform.reset(new ApplePlatformLayer{router, *ptr->flow, conf.network});

    return ptr->freeze();
  }

}  // namespace llarp::apple
```


-------------------------------

Updated on 2023-04-27 at 04:17:17 +0000
