Swiftpack.co -  OperatorFoundation/Flower as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
A simple protocol for packet encapsulation
.package(url: "https://github.com/OperatorFoundation/Flower.git", from: "0.1.17")

The Operator Foundation

Operator makes useable tools to help people around the world with censorship, security, and privacy.


Flower is a simple protocol for packet encapsulation. The Flower library can be integrated into Swift applications running on iOS or macOS. The intended use case is for macOS and iOS Network Extensions. A Network Extension is the Apple-approved way to create custom VPN protocols.


Obtain a Connection

The Flower library does not provide connections. A Connection must be obtained elsewhere, either a NWConnection from the Network framework or any transport Connection type from the Shapeshifter library.

Example using an NWConnection
import Network

let conn = NWConnection(host: NWEndpoint.Host("localhost"), port: NWEndpoint.Port(integerLiteral: 5555), using: .tcp)
conn.start(queue: .global())
Example using Shapeshifter transport Connection
import Shapeshifter-Swift-Transports

// Only use Rot13 transport for examples, never for real deployments.
let factory = Rot13ConnectionFactory((host: NWEndpoint.Host("localhost"), port: NWEndpoint.Port(integerLiteral: 5555))
let conn = factory.connect(using: .tcp)

Create Message objects

Create Message objects for encapsulated packets.

Example using IPv4 packet
import Flower

let data = Data(repeating: 0x00, count: 80)
let message = Message.IPDataV4(data)
Example using IPv6 packet
import Flower

let data = Data(repeating: 0x00, count: 80)
let message = Message.IPDataV6(data)

Send Message objects over Connection

Flower extends the Connection protocol to include the sendMessage function. You can call sendMessage on any Connection.

  maybeError in
  // Handle errors while attempting to send message

Read Message objects from Connection

Flower extends the Connection protocol to include the readMessages function. You can call readMessages on any Connection.

  message in
  switch message
    case .IPDataV4(let data):
      print("Received an IPv4 packet")
    case .IPDataV6(let data):
      print("Receieved an IPv6 packet")

The readMessages function only needs to be called once. It will call the provided callback multiple times, once for each packet received.


Stars: 3
Last commit: Yesterday

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Submit a free job ad (while I'm testing this). The analytics numbers for this website are here.

Release Notes

updated dependencies

updated all dependencies to most recent versions

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics