flowsdk 0.5.3

Safety-first, realistic, behavior-predictable messaging SDK for MQTT and more.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
name: CI

on:
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]

env:
  CARGO_TERM_COLOR: always

jobs:
  test:
    name: Test Suite
    runs-on: ubuntu-latest
    strategy:
      matrix:
        rust:
          - stable
          #- beta
          - nightly
        include:
          - rust: nightly
            allow_failure: true

    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@master
      with:
        toolchain: ${{ matrix.rust }}
        components: rustfmt, clippy

    - name: Install protoc
      uses: arduino/setup-protoc@v3
      with:
        version: '25.x'
        repo-token: ${{ secrets.GITHUB_TOKEN }}

    - name: Install OpenSSL (required for quic-openssl feature in --all-features builds)
      run: sudo apt-get update -qq && sudo apt-get install -y libssl-dev

    - name: Cache dependencies
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/registry
          ~/.cargo/git
          target
          mqtt_grpc_duality/target
        key: ${{ runner.os }}-cargo-${{ matrix.rust }}-${{ hashFiles('**/Cargo.lock') }}

    - name: Check formatting
      if: matrix.rust == 'stable'
      run: cargo fmt --all -- --check

    - name: Run clippy
      if: matrix.rust == 'stable'
      run: cargo clippy --workspace --all-targets --all-features -- -D warnings

    - name: Build workspace
      run: cargo build --workspace --verbose

    - name: Run tests - Main library
      run: cargo test --verbose

    - name: Run tests - Proxy workspace
      run: cd mqtt_grpc_duality && cargo test --verbose

    - name: Run tests - Workspace (all)
      run: cargo test --workspace --verbose

    - name: Run tests all features
      run:  cargo test --workspace --all-features 

    - name: Build and Run C FFI Examples
      run: |
        make -C examples/c_ffi_example clean
        # Build all variations
        make -C examples/c_ffi_example mqtt_c_example
        make -C examples/c_ffi_example quic_c_example
        make -C examples/c_ffi_example tls_c_example
        
        # Run brief verifications against demo broker
        LD_LIBRARY_PATH="$PWD/target/debug:$LD_LIBRARY_PATH" timeout 5s ./examples/c_ffi_example/out/mqtt_c_example || true
        LD_LIBRARY_PATH="$PWD/target/debug:$LD_LIBRARY_PATH" timeout 5s ./examples/c_ffi_example/out/quic_c_example broker.emqx.io 14567 || true
        LD_LIBRARY_PATH="$PWD/target/debug:$LD_LIBRARY_PATH" timeout 5s ./examples/c_ffi_example/out/tls_c_example broker.emqx.io 8883 || true

  fuzz:
    name: Fuzz Tests
    runs-on: ubuntu-latest
    if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/dev/'))
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Install Rust nightly
      uses: dtolnay/rust-toolchain@nightly

    - name: Install cargo-fuzz
      run: cargo install cargo-fuzz

    - name: Cache fuzz dependencies
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/registry
          ~/.cargo/git
          fuzz/target
        key: ${{ runner.os }}-fuzz-${{ hashFiles('fuzz/Cargo.lock') }}

    - name: Build fuzz targets
      run: cd fuzz && cargo build

    - name: Run fuzz tests (limited time)
      run: |
        cd fuzz
        timeout 30s cargo fuzz run fuzz_parser_funs || true
        timeout 30s cargo fuzz run fuzz_mqtt_packet_symmetric || true

  quic-build-modes:
    name: QUIC build modes
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Install Rust toolchain
      uses: dtolnay/rust-toolchain@stable

    - name: Install OpenSSL (required for quic-openssl backend)
      run: sudo apt-get update -qq && sudo apt-get install -y libssl-dev

    - name: Install protoc
      uses: arduino/setup-protoc@v3
      with:
        version: '25.x'
        repo-token: ${{ secrets.GITHUB_TOKEN }}

    - name: Cache dependencies
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-quic-build-${{ hashFiles('**/Cargo.lock') }}

    # Mode 1: default build — quinn not in the dep tree at all
    - name: Build (default, no QUIC)
      run: cargo build

    # Mode 2: mainstream quinn 0.11 (crates.io) + ring crypto
    - name: Build flowsdk_ffi --features quic (mainstream quinn)
      run: cargo build -p flowsdk_ffi --features quic --no-default-features

    # Mode 3: git fork + OpenSSL crypto, optimised for binary size
    - name: Build flowsdk_ffi --features quic-openssl --profile release-small (OpenSSL fork)
      run: cargo build -p flowsdk_ffi --features quic-openssl --no-default-features --profile release-small

  security:
    name: Security Audit
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable

    - name: Install cargo-audit
      run: cargo install cargo-audit

    - name: Run security audit
      run: cargo audit

  python-bindings:
    name: Python Bindings
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Install Rust
      uses: dtolnay/rust-toolchain@stable

    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: '3.10'

    - name: Build and Test Bindings
      run: ./scripts/build_python_bindings.sh --test

  kotlin-bindings:
    name: Kotlin Bindings
    runs-on: ubuntu-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Install Rust
      uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8

    - name: Set up JDK 17
      uses: actions/setup-java@v4
      with:
        distribution: 'temurin'
        java-version: '17'

    - name: Cache Gradle dependencies
      uses: actions/cache@v4
      with:
        path: |
          ~/.gradle/caches
          ~/.gradle/wrapper
        key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
        restore-keys: |
          ${{ runner.os }}-gradle-

    - name: Cache Cargo dependencies
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-cargo-kotlin-${{ hashFiles('**/Cargo.lock') }}
        restore-keys: |
          ${{ runner.os }}-cargo-kotlin-

    - name: Build and Verify Kotlin Bindings
      run: ./scripts/build_kotlin_bindings.sh

    - name: Verify Examples Build
      run: |
        cd kotlin
        ./gradlew :examples:simple_client:build
        ./gradlew :examples:quic_client:build

  swift-bindings:
    name: Swift Bindings
    runs-on: macos-latest
    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Install Rust
      uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8
      with:
        components: llvm-tools-preview

    - name: Install cargo-llvm-cov
      run: cargo install cargo-llvm-cov

    - name: Cache Cargo dependencies
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-cargo-swift-${{ hashFiles('**/Cargo.toml','**/Cargo.lock') }}
        restore-keys: |
          ${{ runner.os }}-cargo-swift-

    - name: Build Rust, Generate Swift Bindings, and Verify swift build
      run: ./scripts/build_swift_bindings.sh --coverage --test

    - name: Export coverage to lcov
      run: |
        PROFDATA_VAR=$(cargo +stable llvm-cov show-env | grep LLVM_PROFDATA) || true
        PROFDATA_TOOL=$(echo "$PROFDATA_VAR" | cut -d= -f2- | tr -d '"' | tr -d "'" | xargs)
        if [ -z "$PROFDATA_TOOL" ] || [ ! -x "$PROFDATA_TOOL" ]; then
          export PATH="$(rustc --print=target-libdir)/../bin:$PATH"
          PROFDATA_TOOL=$(which llvm-profdata)
        fi
        if ls target/llvm-cov-target/*.profraw 2>/dev/null; then
          "$PROFDATA_TOOL" merge -sparse target/llvm-cov-target/*.profraw \
            -o target/llvm-cov-target/swift-cov.profdata
          llvm-cov export -format=lcov \
            --instr-profile target/llvm-cov-target/swift-cov.profdata \
            -object target/debug/libflowsdk_ffi.dylib \
            > lcov-swift.info
        else
          echo "No profraw files found; skipping lcov export."
        fi

    - name: Upload coverage artifacts
      uses: actions/upload-artifact@v4
      if: always()
      with:
        name: swift-coverage-data
        path: |
          lcov-swift.info
          target/llvm-cov-target/swift-cov.profdata
          target/llvm-cov-target/*.profraw
        retention-days: 7

    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v4
      with:
        files: lcov-swift.info
        fail_ci_if_error: false
        token: ${{ secrets.CODECOV_TOKEN }}
        verbose: true

  coverage:
    name: Code Coverage
    runs-on: ubuntu-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Install Rust
      uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8
      with:
        components: llvm-tools-preview

    - name: Install protoc
      uses: arduino/setup-protoc@v3
      with:
        version: '25.x'
        repo-token: ${{ secrets.GITHUB_TOKEN }}

    - name: Install cargo-llvm-cov
      run: cargo install cargo-llvm-cov

    - name: Install OpenSSL (required for quic-openssl feature)
      run: sudo apt-get update -qq && sudo apt-get install -y libssl-dev

    - name: Generate coverage report
      run: |
        ./scripts/generate_coverage.sh
        ./scripts/generate_coverage_integration.sh

    - name: Upload coverage artifacts
      uses: actions/upload-artifact@v4
      if: always()
      with:
        name: coverage-data
        path: |
          lcov.info
          lcov2.info
          lcov3.info
          target/llvm-cov-target/cargo-llvm-cov.profdata
          target/llvm-cov-target/cargo-llvm-cov2.profdata
          target/integration-llvm-cov2.profdata
          target/llvm-cov-target/*.profraw
        retention-days: 7

    - name: Upload coverage to Codecov
      uses: codecov/codecov-action@v4
      with:
        files: lcov.info,lcov2.info,lcov3.info
        fail_ci_if_error: false
        token: ${{ secrets.CODECOV_TOKEN }}
        verbose: true

  benchmarks:
    name: Performance Benchmarks
    runs-on: ubuntu-latest
    if: github.event_name == 'push' && github.ref == 'refs/heads/main'
    
    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Install Rust
      uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8

    - name: Install protoc
      uses: arduino/setup-protoc@v3
      with:
        version: '25.x'
        repo-token: ${{ secrets.GITHUB_TOKEN }}

    - name: Cache benchmark dependencies
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-bench-${{ hashFiles('**/Cargo.lock') }}

    - name: Run benchmarks
      run: cargo bench --workspace

  build-binaries:
    name: Build Release Binaries
    runs-on: ${{ matrix.os }}    
    strategy:
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
          - target: x86_64-apple-darwin
            os: macos-latest
          - target: aarch64-apple-darwin
            os: macos-latest
          - target: x86_64-pc-windows-msvc
            os: windows-latest

    steps:
    - name: Checkout code
      uses: actions/checkout@v4

    - name: Install Rust
      uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8
      with:
        targets: ${{ matrix.target }}

    - name: Install protoc
      uses: arduino/setup-protoc@v3
      with:
        version: '25.x'
        repo-token: ${{ secrets.GITHUB_TOKEN }}

    - name: Cache dependencies
      uses: actions/cache@v4
      with:
        path: |
          ~/.cargo/registry
          ~/.cargo/git
          target
        key: ${{ runner.os }}-release-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}

    - name: Build release binaries
      run: |
        cargo build --release --target ${{ matrix.target }} --workspace

    - name: Create artifact directory
      run: mkdir -p artifacts

    - name: Copy binaries (Unix)
      if: runner.os != 'Windows'
      run: |
        cp target/${{ matrix.target }}/release/r-proxy artifacts/r-proxy-${{ matrix.target }}
        cp target/${{ matrix.target }}/release/s-proxy artifacts/s-proxy-${{ matrix.target }}

    - name: Copy binaries (Windows)
      if: runner.os == 'Windows'
      run: |
        cp target/${{ matrix.target }}/release/r-proxy.exe artifacts/r-proxy-${{ matrix.target }}.exe
        cp target/${{ matrix.target }}/release/s-proxy.exe artifacts/s-proxy-${{ matrix.target }}.exe

    - name: Upload artifacts
      uses: actions/upload-artifact@v4
      with:
        name: binaries-${{ matrix.target }}
        path: artifacts/