Swiftpack.co - Package - OperatorFoundation/Flower
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.

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: 0


Dual stack - 2020-09-14T17:21:41

Added IPv4/IPv6 dual stack address assignment support

Updated Datable - 2020-06-26T17:21:17

Updated Datable versions

Updated versions - 2020-06-26T17:18:17

Updated versions

Fixed Write Bug - 2020-05-19T20:57:11

Added Prints - 2020-05-13T21:37:03

DataUtils Bug Fix - 2020-05-12T18:09:17

MacOS 10.15 - 2020-04-07T00:41:52

swift-tools-version:5.1 - 2020-04-07T00:02:34

Require MacOS 10.14 or Later - 2020-04-06T23:55:28

Swift 5 compatiblity - 2019-03-27T18:54:29

Now compiles with Swift 5

More IP tunneling - 2019-01-31T18:47:54

Added additional IP tunneling messages

IP Tunneling - 2019-01-29T21:12:39

Added tunneling of raw IP packets

Connection extension - 2018-11-02T18:36:54

Moved message stream functions to an extension on Connection

Allowed endpoint initialization with direct values - 2018-11-01T22:36:48

Allowed endpoint initialization with direct values

Removed unnecessary src addresses - 2018-11-01T22:32:22

Removed unnecessary src addresses

Initial test release - 2018-11-01T21:43:08

Just for testing