Skip to content

Commit

Permalink
add more readme and a simple demo
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnzhou committed May 15, 2024
1 parent 4a4f1a7 commit 018482e
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 5 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ debug_integration_test:
make setup_server
swift test -Xswiftc -DINTEGRATION_TEST -Xswiftc -DDEBUG --filter IntegrationTests
make teardown_server


.PHONY: demo
demo:
swift run Demo

.PHONY: clean
clean:
Expand Down
7 changes: 6 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let package = Package(
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: "LCLPing",
targets: ["LCLPing"]),
targets: ["LCLPing"])
],
dependencies: [
// Dependencies declare other packages that this package depends on.
Expand All @@ -36,6 +36,11 @@ let package = Package(
.product(name: "NIOSSL", package: "swift-nio-ssl"),
.product(name: "Collections", package: "swift-collections")
]),
.executableTarget(
name: "Demo",
dependencies: ["LCLPing"],
exclude: ["README.md"]
),
.testTarget(
name: "UtilitiesTests",
dependencies: ["LCLPing"]
Expand Down
66 changes: 63 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,75 @@
![Swift CI](https://github.com/Local-Connectivity-Lab/lcl-ping/actions/workflows/build.yaml/badge.svg?branch=main)
<p align:center>
<img src="images/logo.png" alt="Logo" width="557>
</p>


# LCLPing

![Swift CI](https://github.com/Local-Connectivity-Lab/lcl-ping/actions/workflows/build.yaml/badge.svg?branch=main)

LCLPing is a cross-platform Ping library written in Swift, and for Swift. It is designed to help streamline testing, measuring, and monitoring network reachability of a host for both the client side and server side applications and services.


## Requirements
- Swift 5.7+
- Swift 5.9+
- macOS 10.15+, iOS 14+, Linux

## Getting Started

## Installation

### Swift Package Manager (SPM)

Add the following to your `Package.swift` file:
```code
.package(url: "https://github.com/Local-Connectivity-Lab/lcl-ping.git", from: "0.2.0")
```

Then import the module to your project
```code
.target(
name: "YourAppName",
.dependencies: [
.product(name: "LCLPing", package: "lcl-ping")
]
)
```

### Basic Usage

```swift
// create ping configuration for each run
let pingConfig = LCLPing.PingConfiguration(type: pingType, endpoint: endpoint)

// create ping options
#if os(macOS) || os(iOS)
let options = LCLPing.Options(verbose: verbose, useNative: useURLSession)
#else
let options = LCLPing.Options(verbose: verbose)
#endif

// initialize ping object with the options
var ping = LCLPing(options: options)

try await ping.start(pingConfiguration: pingConfig)
switch ping.status {
case .error, .ready, .running:
// handle error here
case .stopped, .finished:
// retrieve ping summary
print(ping.summary)
}
```

You can also run the [demo](/Sources/Demo/README.md) using `make demo` or `swift run Demo` if you do not have make installed.

### Features
- Ping via ICMP and HTTP(S)
- Support IPv4
- flexible and configurable wait time, time-to-live, count, and duration


## Contributing
Any contribution and pull requests are welcome! However, before you plan to implement some features or try to fix an uncertain issue, it is recommended to open a discussion first. You can also join our [Discord channel](https://discord.com/invite/gn4DKF83bP), or visit our [website](https://seattlecommunitynetwork.org/).

## License
LCLPing is released under Apache License. See [LICENSE](/LICENSE) for more details.
9 changes: 9 additions & 0 deletions Sources/Demo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# LCLPing Demo

This example provides a simple look at how LCLPing can be used to issue ICMP requests and wait for corresponding responses

```bash
make demo
# OR
swift run Demo
```
39 changes: 39 additions & 0 deletions Sources/Demo/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// This source file is part of the LCL open source project
//
// Copyright (c) 2021-2023 Local Connectivity Lab and the project authors
// Licensed under Apache License v2.0
//
// See LICENSE for license information
// See CONTRIBUTORS for the list of project authors
//
// SPDX-License-Identifier: Apache-2.0
//

#if swift(>=5.9)
import Foundation
import LCLPing

// create ping configuration for each run
let pingConfig = LCLPing.PingConfiguration(type: .icmp, endpoint: .ipv4("google.com", 0))

// create ping options
#if os(macOS) || os(iOS)
let options = LCLPing.Options(verbose: false, useNative: false)
#else
let options = LCLPing.Options(verbose: false)
#endif

// initialize ping object with the options
var ping = LCLPing(options: options)

try await ping.start(pingConfiguration: pingConfig)
switch ping.status {
case .error, .ready, .running:
print("LCLPing is in invalid state. Abort")
case .stopped, .finished:
print(ping.summary)
}
#else
fatalError("Requires at least Swift 5.9")
#endif
Binary file added images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 018482e

Please sign in to comment.