Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update msquic #126

Merged
merged 43 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c9f742a
change preimage size to data count
MacOMNI Aug 19, 2024
78c8816
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 20, 2024
b0804b5
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 21, 2024
98897c7
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 22, 2024
f0423dc
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 22, 2024
6315754
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 23, 2024
87acd80
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 26, 2024
c59a82f
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 27, 2024
6d4fd70
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 27, 2024
76984e2
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 28, 2024
d2ebd09
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 29, 2024
15b60fb
update
MacOMNI Aug 29, 2024
7d54e13
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 29, 2024
7e0c3cd
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 30, 2024
1e85be6
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 30, 2024
2b654c4
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Aug 31, 2024
e05af5c
update ignore
MacOMNI Aug 31, 2024
992d120
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 2, 2024
1fffaff
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 2, 2024
31bb085
Merge branches 'master' and 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 3, 2024
9304473
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 4, 2024
cf144ed
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 5, 2024
c5e78a5
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 5, 2024
65486ff
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 6, 2024
b3af474
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 9, 2024
df0a630
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 11, 2024
a59766e
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 13, 2024
5b66d0d
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 17, 2024
4033c58
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 19, 2024
32518e8
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 20, 2024
60862b8
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 23, 2024
3469c60
update msquic
MacOMNI Sep 24, 2024
dec7e6d
update readme
MacOMNI Sep 24, 2024
af53dee
update quic more test
MacOMNI Sep 24, 2024
d73f276
update submodule
MacOMNI Sep 24, 2024
5ba1ab3
update quic
MacOMNI Sep 24, 2024
a727ef3
update submodule
MacOMNI Sep 24, 2024
a80768f
Merge branch 'master' of github.com:AcalaNetwork/boka
MacOMNI Sep 24, 2024
5358461
Merge branch 'master' into dev_mackun
MacOMNI Sep 24, 2024
180926c
update msquic
MacOMNI Sep 24, 2024
08588ab
update alpn
MacOMNI Sep 24, 2024
62a5ed3
update alpn
MacOMNI Sep 24, 2024
cfbda13
update alpn
MacOMNI Sep 24, 2024
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
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ jobs:
uses: actions/checkout@v4
with:
submodules: recursive
- name: MsQuic Install Dependencies
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-add-repository -y ppa:lttng/stable-2.13
sudo apt-get update
sudo apt-get install -y lttng-tools lttng-modules-dkms babeltrace2 liblttng-ust-dev python3-babeltrace
sudo apt-get install -y cmake
sudo apt-get install -y build-essential
- name: Get msquic submodule commit hash
id: msquic-commit-hash
run: |
echo "commit-hash=$(git submodule status Networking/Sources/msquic/ | cut -c2-41)" >> $GITHUB_OUTPUT
- name: Get blst submodule commit hash
id: blst-commit-hash
run: |
Expand All @@ -56,6 +68,13 @@ jobs:
~/.cargo/git/db/
Utils/Sources/bandersnatch/target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- name: Cache msquic static lib
uses: actions/cache@v4
with:
path: .lib/libmsquic.a
key: ${{ runner.os }}-libs-msquic-${{ steps.msquic-commit-hash.outputs.commit-hash }}
restore-keys: |
${{ runner.os }}-libs-msquic
- name: Cache blst static lib
uses: actions/cache@v4
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,5 @@ tasks.json

*.d
*.swiftdeps
Package.resolved
contents.xcworkspacedata
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "Database/Sources/rocksdb"]
path = Database/Sources/rocksdb
url = https://github.com/facebook/rocksdb.git
[submodule "Networking/Sources/msquic"]
path = Networking/Sources/msquic
url = https://github.com/microsoft/msquic.git
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ default: build
githooks: .git/hooks/pre-commit

.PHONY: deps
deps: .lib/libblst.a .lib/libbandersnatch_vrfs.a .lib/librocksdb.a .lib/libec.a
deps: .lib/libblst.a .lib/libbandersnatch_vrfs.a .lib/librocksdb.a .lib/libec.a .lib/libmsquic.a

.lib/libblst.a:
./scripts/blst.sh
Expand All @@ -22,6 +22,9 @@ deps: .lib/libblst.a .lib/libbandersnatch_vrfs.a .lib/librocksdb.a .lib/libec.a
.lib/librocksdb.a:
./scripts/rocksdb.sh

.lib/libmsquic.a:
./scripts/msquic.sh

.PHONY: test
test: githooks deps
./scripts/runTests.sh test
Expand Down
62 changes: 62 additions & 0 deletions Networking/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// swift-tools-version: 6.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Networking",
platforms: [
.macOS(.v14),
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "Networking",
targets: ["Networking"]
),
],
dependencies: [
.package(path: "../Utils"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.0"),
.package(url: "https://github.com/apple/swift-testing.git", branch: "0.10.0"),
.package(url: "https://github.com/apple/swift-nio.git", from: "2.65.0"),
.package(url: "https://github.com/apple/swift-atomics.git", from: "1.2.0"),

],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "Networking",

dependencies: [
"msquic",
"Utils",
.product(name: "NIO", package: "swift-nio"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
.product(name: "Logging", package: "swift-log"),
.product(name: "Atomics", package: "swift-atomics"),

],
resources: [
.process("assets"),
],
linkerSettings: [
.unsafeFlags(["-L../.lib"]),
]
),
.systemLibrary(
name: "msquic",
path: "Sources"
),
.testTarget(
name: "NetworkingTests",
dependencies: [
"Networking",
.product(name: "Testing", package: "swift-testing"),
]
),
],
swiftLanguageVersions: [.version("6")]
)
15 changes: 15 additions & 0 deletions Networking/Sources/Networking/Networking.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import msquic

public class Networking {
public class Config {
public let listenAddress: String
public let port: Int

public init(listenAddress: String, port: Int) {
self.listenAddress = listenAddress
self.port = port
}
}

init() {}
}
21 changes: 21 additions & 0 deletions Networking/Sources/Networking/assets/server.cert
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
-----BEGIN CERTIFICATE-----
MIIDazCCAlOgAwIBAgIUYaN9BKGKso1vf23K1JQINstBQ5IwDQYJKoZIhvcNAQEL
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yNDA5MDMwMTQ3MjFaFw0yNDEw
MDMwMTQ3MjFaMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEw
HwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwggEiMA0GCSqGSIb3DQEB
AQUAA4IBDwAwggEKAoIBAQC8OtKwzLpWXCHOaFu6pPgNiKoXtIo45h4aF83HLULc
GJsCx2AuSdhNQjbG+G9kTsUp+kTEaXpyDdMm/KGNDzg9Iunj1swzXpp3Q9MmELTu
gkkkHKuFnhKNspqdZGWMMqtvqktVu0dLaxebSkwqH+i3eR9L1PHJcb4Tj6rdw14o
Aw4ZnqcMiv+iGq/usg/FmIWgkBUWko3pHEBdudKj1fKzlzkUlvDZQ3hN74GNGMdy
BxUHUQr17mr4/nb0CH2JcSHfV0z1eW6I+fKTY0E/zlY1yCUXzpgwlGvgc0h2kDhr
9i9IYDDUZtmtLSsC75LkkmvKben111r4AD08r1/6HiyjAgMBAAGjUzBRMB0GA1Ud
DgQWBBT/Zhl2dPN0OtpQ/KbT8tr3zxenuzAfBgNVHSMEGDAWgBT/Zhl2dPN0OtpQ
/KbT8tr3zxenuzAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQAM
8Q0Ods8Y2rNwXd9Dcu2jx09PCQG+Urn0upaNiAG9eowsZiJZYZLE31kBZXLQBqnu
frGgcYWXFlMXpKU3qYXeVeq8Vug1gnp3k3T8fsPCZxrMyOgXz7/EV1rjh3k+xIsC
zg5pJDk9pHmWfElpbfE0GuJZR8hdK4h9xabNq/h/g9jagwfFw2kvtP65bGXzEULF
B/4QQmFb8hZqYcOn9Q6QkW7FKHj2NWbippBqFGwcr6/61CTmuZXHvKijg8q8syCI
rF5PC773w9DWgZ0lY2YgvSdG5YUiVpfWzoOq8mfmnQ4QEVulBSm1NIf/7nDvXlm/
qe+ux+F3fBiIOBvnH8N3
-----END CERTIFICATE-----
28 changes: 28 additions & 0 deletions Networking/Sources/Networking/assets/server.key
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQC8OtKwzLpWXCHO
aFu6pPgNiKoXtIo45h4aF83HLULcGJsCx2AuSdhNQjbG+G9kTsUp+kTEaXpyDdMm
/KGNDzg9Iunj1swzXpp3Q9MmELTugkkkHKuFnhKNspqdZGWMMqtvqktVu0dLaxeb
SkwqH+i3eR9L1PHJcb4Tj6rdw14oAw4ZnqcMiv+iGq/usg/FmIWgkBUWko3pHEBd
udKj1fKzlzkUlvDZQ3hN74GNGMdyBxUHUQr17mr4/nb0CH2JcSHfV0z1eW6I+fKT
Y0E/zlY1yCUXzpgwlGvgc0h2kDhr9i9IYDDUZtmtLSsC75LkkmvKben111r4AD08
r1/6HiyjAgMBAAECggEAMjLl2azfzQRJJ8kBHae9V66o3iWR71a/lGngwUu61wPg
4z7U0cNz4jbUcP/0hSXUwzsxd8hBlYVGWNFrLDl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8e361jiX+nEpx95ffNPG3p2cbq0ZkFtQrFFI46a6B9J53sI9S9w6
9vu7dtndG49uP6SdCXu44w==
-----END PRIVATE KEY-----
12 changes: 12 additions & 0 deletions Networking/Sources/Networking/msquic/Alpn.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Foundation

struct Alpn {
public let alpnString: String
private static let headerPrefixLength = 4
init(_ protocolName: String = "jamnp-s", version: String = "0", genesisHeader: String) throws {
guard genesisHeader.count >= Alpn.headerPrefixLength else {
throw QuicError.invalidAlpn
}
alpnString = "\(protocolName)/\(version)/\(genesisHeader.prefix(Alpn.headerPrefixLength))"
}
}
113 changes: 113 additions & 0 deletions Networking/Sources/Networking/msquic/QuicError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import Foundation

public enum QuicError: Error, Equatable, Sendable, Codable {
case invalidStatus(status: QuicStatusCode)
case invalidAlpn
case getApiFailed
case getRegistrationFailed
case getConnectionFailed
case getStreamFailed
case getClientFailed
case messageNotFound
case sendFailed
case unknown // For handling unknown error types

enum CodingKeys: String, CodingKey {
case type
case status
}

enum ErrorType: String, Codable {
case invalidStatus
case invalidAlpn
case getApiFailed
case getRegistrationFailed
case getConnectionFailed
case getStreamFailed
case getClientFailed
case messageNotFound
case sendFailed
case unknown // For handling unknown error types
}

// Encode the QuicError to a Codable format
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
switch self {
case let .invalidStatus(status):
try container.encode(ErrorType.invalidStatus, forKey: .type)
try container.encode(status, forKey: .status)
default:
let type = ErrorType(from: self)
try container.encode(type, forKey: .type)
}
}

// Decode the QuicError from a Codable format
public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
let type = try container.decode(ErrorType.self, forKey: .type)

switch type {
case .invalidStatus:
let status = try container.decode(QuicStatusCode.self, forKey: .status)
self = .invalidStatus(status: status)
default:
self = type.toQuicError()
}
}
}

extension QuicError.ErrorType {
// Initialize ErrorType from QuicError
init(from error: QuicError) {
switch error {
case .invalidStatus:
self = .invalidStatus
case .invalidAlpn:
self = .invalidAlpn
case .getApiFailed:
self = .getApiFailed
case .getRegistrationFailed:
self = .getRegistrationFailed
case .getConnectionFailed:
self = .getConnectionFailed
case .getStreamFailed:
self = .getStreamFailed
case .getClientFailed:
self = .getClientFailed
case .messageNotFound:
self = .messageNotFound
case .sendFailed:
self = .sendFailed
case .unknown:
self = .unknown
}
}

// Convert ErrorType back to QuicError
func toQuicError() -> QuicError {
switch self {
case .invalidStatus:
.invalidStatus(status: .unknown) // Provide a default status
case .invalidAlpn:
.invalidAlpn
case .getApiFailed:
.getApiFailed
case .getRegistrationFailed:
.getRegistrationFailed
case .getConnectionFailed:
.getConnectionFailed
case .getStreamFailed:
.getStreamFailed
case .getClientFailed:
.getClientFailed
case .messageNotFound:
.messageNotFound
case .sendFailed:
.sendFailed
case .unknown:
.unknown
}
}
}
14 changes: 14 additions & 0 deletions Networking/Sources/Networking/msquic/QuicMessage.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Foundation

enum QuicMessageType: String, Codable {
case unknown
case received
case close
case connected
case shutdownComplete
}

public struct QuicMessage: Sendable, Equatable, Codable {
let type: QuicMessageType
let data: Data?
}
Loading