Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion .github/workflows/sdk-examples-smoke-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,15 @@ jobs:
import PackageDescription
let p = Package(
name: "smoke",
// Pilot's library requires macOS 12; the consuming
// executable must declare at least the same floor or
// SwiftPM refuses to resolve the dependency.
platforms: [.macOS(.v12)],
dependencies: [.package(path: "$GITHUB_WORKSPACE")],
targets: [.executableTarget(name: "smoke", dependencies: ["Pilot"])]
// The dependency package's identity is its directory name
// ("sdk-swift"), not its manifest name ("Pilot"), so the
// product must be referenced with an explicit package:.
targets: [.executableTarget(name: "smoke", dependencies: [.product(name: "Pilot", package: "sdk-swift")])]
)
PKG
mkdir -p Sources/smoke
Expand Down
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,14 @@ Requires iOS 14+ or macOS 12+, Swift 5.9+.
## Quick start

```swift
import Foundation
import Pilot

let dataDir = FileManager.default
.urls(for: .applicationSupportDirectory, in: .userDomainMask)[0]
.appendingPathComponent("pilot")

// Start the embedded daemon (no separate process needed).
let pilot = try Pilot.start(.init(
dataDir: dataDir,
socketPath: "p.sock",
Expand All @@ -57,15 +59,23 @@ let pilot = try Pilot.start(.init(

print("address=\(pilot.start.address) node_id=\(pilot.start.nodeID)")

try pilot.handshake(peerID: 12345, justification: "hello")
_ = try pilot.waitForTrust(peerID: 12345, timeoutMs: 30_000)
try pilot.send(to: "0:0000.0000.AAAA", port: 7777, data: Data("hi".utf8))

Task {
while let dg = try? pilot.receive() {
print("got \(dg.data.count) bytes from \(dg.srcAddr):\(dg.srcPort)")
}
}
// Confirm the node is up.
let health = try pilot.health()
print("status=\(health["status"] ?? "unknown")")

// To talk to a peer, handshake first, then send once trusted:
//
// try pilot.handshake(peerID: 12345, justification: "hello")
// _ = try pilot.waitForTrust(peerID: 12345, timeoutMs: 30_000)
// try pilot.send(to: "0:0000.0000.AAAA", port: 7777, data: Data("hi".utf8))
//
// And drain inbound datagrams on a background task:
//
// Task {
// while let dg = try? pilot.receive() {
// print("got \(dg.data.count) bytes from \(dg.srcAddr):\(dg.srcPort)")
// }
// }

// On shutdown
try pilot.stop()
Expand Down
Loading