Skip to content

Commit 9ada4ba

Browse files
committed
cpp: run clang-format
1 parent 9dfdaa6 commit 9ada4ba

File tree

28 files changed

+897
-808
lines changed

28 files changed

+897
-808
lines changed

accless/libs/attestation/attestation.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
using namespace attest;
1818

1919
#define SNP_GUEST_REQ_IOC_TYPE 'S'
20-
#define SNP_GET_REPORT _IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x0, struct snp_guest_request_ioctl)
20+
#define SNP_GET_REPORT \
21+
_IOWR(SNP_GUEST_REQ_IOC_TYPE, 0x0, struct snp_guest_request_ioctl)
2122

2223
namespace accless::attestation {
2324
void Logger::Log(const char *log_tag, AttestationLogger::LogLevel level,
@@ -120,15 +121,16 @@ getSnpReportFromDev(std::optional<std::array<uint8_t, 64>> userData,
120121
// Prepare the ioctl wrapper.
121122
snp_guest_request_ioctl guestReq;
122123
std::memset(&guestReq, 0, sizeof(guestReq));
123-
guestReq.msg_version = 1; // Must be non-zero.
124+
guestReq.msg_version = 1; // Must be non-zero.
124125
guestReq.req_data = reinterpret_cast<uint64_t>(&reqPayload);
125126
guestReq.resp_data = reinterpret_cast<uint64_t>(&respPayload);
126127

127128
// Issue the ioctl.
128129
if (ioctl(fd, SNP_GET_REPORT, &guestReq) < 0) {
129130
int err = errno;
130131
close(fd);
131-
std::cerr << "accless(att): ioctl SNP_GET_REPORT failed: " << strerror(err) << std::endl;
132+
std::cerr << "accless(att): ioctl SNP_GET_REPORT failed: "
133+
<< strerror(err) << std::endl;
132134
throw std::runtime_error("ioctl SNP_GET_REPORT failed");
133135
}
134136
close(fd);
@@ -141,7 +143,8 @@ getSnpReportFromDev(std::optional<std::array<uint8_t, 64>> userData,
141143
}
142144

143145
// Convert the response to a vector.
144-
std::vector<uint8_t> report(respPayload.data, respPayload.data + SNP_REPORT_RESP_SIZE);
146+
std::vector<uint8_t> report(respPayload.data,
147+
respPayload.data + SNP_REPORT_RESP_SIZE);
145148
return report;
146149
}
147150

accless/libs/jwt/cpp-bindings/jwt.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@
44
#include <string>
55

66
namespace accless::jwt {
7-
bool verify(const std::string& jwt)
8-
{
9-
return verify_jwt(jwt.c_str());
10-
}
7+
bool verify(const std::string &jwt) { return verify_jwt(jwt.c_str()); }
118

12-
bool checkProperty(const std::string& jwt, const std::string& property, const std::string& expVal)
13-
{
9+
bool checkProperty(const std::string &jwt, const std::string &property,
10+
const std::string &expVal) {
1411
return check_property(jwt.c_str(), property.c_str(), expVal.c_str());
1512
}
1613

17-
std::string getProperty(const std::string& jwt, const std::string& property)
18-
{
19-
char* result = get_property(jwt.c_str(), property.c_str());
14+
std::string getProperty(const std::string &jwt, const std::string &property) {
15+
char *result = get_property(jwt.c_str(), property.c_str());
2016
if (!result) {
2117
return "";
2218
}
@@ -27,4 +23,4 @@ std::string getProperty(const std::string& jwt, const std::string& property)
2723

2824
return propertyOut;
2925
}
30-
}
26+
} // namespace accless::jwt

accless/libs/jwt/cpp-bindings/jwt.h

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
#include <string>
44

55
extern "C" {
6-
bool verify_jwt(const char* jwt);
7-
bool check_property(const char* jwt, const char* property, const char* exp_value);
8-
char* get_property(const char* jwt, const char* property);
9-
void free_string(char* ptr);
6+
bool verify_jwt(const char *jwt);
7+
bool check_property(const char *jwt, const char *property,
8+
const char *exp_value);
9+
char *get_property(const char *jwt, const char *property);
10+
void free_string(char *ptr);
1011
}
1112

1213
namespace accless::jwt {
13-
bool verify(const std::string& jwt);
14-
bool checkProperty(const std::string& jwt, const std::string& property, const std::string& expVal);
15-
std::string getProperty(const std::string& jwt, const std::string& property);
16-
}
14+
bool verify(const std::string &jwt);
15+
bool checkProperty(const std::string &jwt, const std::string &property,
16+
const std::string &expVal);
17+
std::string getProperty(const std::string &jwt, const std::string &property);
18+
} // namespace accless::jwt

accless/libs/jwt/test.cpp

Lines changed: 119 additions & 8 deletions
Large diffs are not rendered by default.

accless/src/accless.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "accless.h"
22
// Both tless::aes256gcm and tles::sha256 are declared in this header
33
#include "dag.h"
4+
#include "jwt.h"
45
#include "tless_abe.h"
56
#include "tless_aes.h"
6-
#include "jwt.h"
77
#include "utils.h"
88

99
#ifdef __faasm

invrs/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ enum Command {
4242
eval_command: EvalCommand,
4343
},
4444
/// Run code formatting: clang-format, cargo fmt, and cargo clippy
45-
FormatCode { check: bool },
45+
FormatCode {
46+
/// Dry-run and report errors if not formatted well
47+
#[arg(long)]
48+
check: bool
49+
},
4650
/// Run microbenchmark
4751
Ubench {
4852
#[command(subcommand)]

ubench/cold-start/src/main.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#include <iostream>
55
#include <string>
66

7-
int main()
8-
{
7+
int main() {
98
if (accless::checkChain("word-count", "splitter", 1)) {
109
std::cout << "accless: access approved :-)" << std::endl;
1110
} else {

ubench/cold-start/src/server.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ int main() {
2525

2626
// Allow reuse of the address.
2727
int opt = 1;
28-
if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) {
28+
if (setsockopt(server_fd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) <
29+
0) {
2930
perror("setsockopt");
3031
close(server_fd);
3132
exit(EXIT_FAILURE);
@@ -89,7 +90,8 @@ int main() {
8990
std::string responseStr = response.str();
9091
write(client_fd, responseStr.c_str(), responseStr.size());
9192
} else {
92-
std::string badResponse = "HTTP/1.1 400 Bad Request\r\n\r\nOnly GET supported.";
93+
std::string badResponse =
94+
"HTTP/1.1 400 Bad Request\r\n\r\nOnly GET supported.";
9395
write(client_fd, badResponse.c_str(), badResponse.size());
9496
}
9597
close(client_fd);

workflows/finra/audit/function.cpp

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
#ifdef __faasm
2-
extern "C"
3-
{
2+
extern "C" {
43
#include "faasm/host_interface.h"
54
}
65

76
#include <faasm/faasm.h>
87
#else
8+
#include "s3/S3Wrapper.hpp"
99
#include <cstdlib>
1010
#include <fstream>
1111
#include <iostream>
12-
#include "s3/S3Wrapper.hpp"
1312
#endif
1413

1514
#include "accless.h"
@@ -20,8 +19,8 @@ extern "C"
2019
#include <string_view>
2120
#include <vector>
2221

23-
std::vector<std::string> splitByDelimiter(std::string stringCopy, const std::string& delimiter)
24-
{
22+
std::vector<std::string> splitByDelimiter(std::string stringCopy,
23+
const std::string &delimiter) {
2524
std::vector<std::string> splitString;
2625

2726
size_t pos = 0;
@@ -37,8 +36,7 @@ std::vector<std::string> splitByDelimiter(std::string stringCopy, const std::str
3736

3837
/* Run Audit Rule - FINRA workflow
3938
*/
40-
int main(int argc, char** argv)
41-
{
39+
int main(int argc, char **argv) {
4240
// TODO: the bucket name is currently hardcoded
4341
std::string bucketName = "tless";
4442

@@ -50,7 +48,7 @@ int main(int argc, char** argv)
5048
// Get the object key as an input
5149
int inputSize = faasmGetInputSize();
5250
char inputChar[inputSize];
53-
faasmGetInput((uint8_t*)inputChar, inputSize);
51+
faasmGetInput((uint8_t *)inputChar, inputSize);
5452

5553
std::string tmpStr(inputChar, inputChar + inputSize);
5654
auto parts = splitByDelimiter(tmpStr, ":");
@@ -78,83 +76,80 @@ int main(int argc, char** argv)
7876
std::string us = "audit-" + std::to_string(id);
7977

8078
if (!accless::checkChain("finra", "audit", id)) {
81-
std::cerr << "finra(" << us << "): error checking TLess chain" << std::endl;
79+
std::cerr << "finra(" << us << "): error checking TLess chain"
80+
<< std::endl;
8281
return 1;
8382
}
8483

8584
std::cout << "finra(" << us << "): fetching public trades data from "
86-
<< tradesKey
87-
<< std::endl;
85+
<< tradesKey << std::endl;
8886

8987
std::vector<uint8_t> tradeData;
9088
#ifdef __faasm
91-
uint8_t* keyBytes;
89+
uint8_t *keyBytes;
9290
int keyBytesLen;
9391

94-
int ret =
95-
__faasm_s3_get_key_bytes(bucketName.c_str(), tradesKey.c_str(), &keyBytes, &keyBytesLen);
92+
int ret = __faasm_s3_get_key_bytes(bucketName.c_str(), tradesKey.c_str(),
93+
&keyBytes, &keyBytesLen);
9694
if (ret != 0) {
97-
std::cerr << "finra(" << us << "): error: error getting bytes from key: "
98-
<< tradesKey << "(bucket: " << bucketName << ")"
99-
<< std::endl;
95+
std::cerr << "finra(" << us
96+
<< "): error: error getting bytes from key: " << tradesKey
97+
<< "(bucket: " << bucketName << ")" << std::endl;
10098
return 1;
10199
}
102100
// WARNING: can we avoid the copy
103-
tradeData.assign((char*) keyBytes, (char*) keyBytes + keyBytesLen);
101+
tradeData.assign((char *)keyBytes, (char *)keyBytes + keyBytesLen);
104102
#else
105103
tradeData = s3cli.getKeyBytes(bucketName, tradesKey);
106104
#endif
107105

108106
std::cout << "finra(" << us << "): fetching portfolio data from "
109-
<< portfolioKey
110-
<< std::endl;
107+
<< portfolioKey << std::endl;
111108

112109
std::vector<uint8_t> portfolioData;
113110
#ifdef __faasm
114111
keyBytes = nullptr;
115112
keyBytesLen = 0;
116113

117-
ret =
118-
__faasm_s3_get_key_bytes(bucketName.c_str(), portfolioKey.c_str(), &keyBytes, &keyBytesLen);
114+
ret = __faasm_s3_get_key_bytes(bucketName.c_str(), portfolioKey.c_str(),
115+
&keyBytes, &keyBytesLen);
119116
if (ret != 0) {
120-
std::cerr << "finra(" << us << "): error: error getting bytes from key: "
121-
<< portfolioKey << "(bucket: " << bucketName << ")"
122-
<< std::endl;
117+
std::cerr << "finra(" << us
118+
<< "): error: error getting bytes from key: " << portfolioKey
119+
<< "(bucket: " << bucketName << ")" << std::endl;
123120
return 1;
124121
}
125122
// WARNING: can we avoid the copy
126-
portfolioData.assign((char*) keyBytes, (char*) keyBytes + keyBytesLen);
123+
portfolioData.assign((char *)keyBytes, (char *)keyBytes + keyBytesLen);
127124
#else
128125
portfolioData = s3cli.getKeyBytes(bucketName, portfolioKey);
129126
#endif
130127

131128
std::cout << "finra(" << us << "): de-serializing data" << std::endl;
132-
std::vector<TradeData> trades = tless::finra::deserializeTradeVector(tradeData);
129+
std::vector<TradeData> trades =
130+
tless::finra::deserializeTradeVector(tradeData);
133131
Portfolio portfolio = tless::finra::deserializePortfolio(portfolioData);
134132

135-
std::cout << "finra(" << us << "): running audit rule on " << trades.size() << " trades ..." << std::endl;
133+
std::cout << "finra(" << us << "): running audit rule on " << trades.size()
134+
<< " trades ..." << std::endl;
136135
std::string auditResults;
137-
for (const auto& trade : trades) {
138-
bool insideTradeDetected =
139-
tless::finra::rules::potentialInsiderTrade(portfolio, trades, trade.date);
136+
for (const auto &trade : trades) {
137+
bool insideTradeDetected = tless::finra::rules::potentialInsiderTrade(
138+
portfolio, trades, trade.date);
140139
auditResults += std::to_string(insideTradeDetected) + ",";
141140
}
142141
auditResults.pop_back();
143142
std::cout << "finra(" << us << "): done running audit rule!" << std::endl;
144143

145144
// Upload structured data to S3
146145
std::string key = "finra/outputs/audit/" + us;
147-
std::cout << "finra(" << us << "): uploading audit results to "
148-
<< key
146+
std::cout << "finra(" << us << "): uploading audit results to " << key
149147
<< std::endl;
150148
#ifdef __faasm
151149
// Overwrite the results
152-
ret =
153-
__faasm_s3_add_key_bytes(bucketName.c_str(),
154-
key.c_str(),
155-
(uint8_t*) auditResults.c_str(),
156-
auditResults.size(),
157-
true);
150+
ret = __faasm_s3_add_key_bytes(bucketName.c_str(), key.c_str(),
151+
(uint8_t *)auditResults.c_str(),
152+
auditResults.size(), true);
158153
if (ret != 0) {
159154
std::cerr << "finra(" << us << "): error uploading trade data"
160155
<< std::endl;

workflows/finra/driver/function.cpp

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,61 +8,62 @@
88

99
/* Driver Function - FINRA workflow
1010
*/
11-
int main(int argc, char** argv)
12-
{
11+
int main(int argc, char **argv) {
1312
#ifdef __faasm
1413
if (argc != 3) {
15-
std::cout << "finra(driver): usage: <s3_public_data_path> <num_audit_funcs>"
16-
<< std::endl;
14+
std::cout
15+
<< "finra(driver): usage: <s3_public_data_path> <num_audit_funcs>"
16+
<< std::endl;
1717
return 1;
1818
}
1919
std::string s3DataFile = argv[1];
2020
int numAuditFuncs = std::stoi(argv[2]);
2121

22-
std::cout << "finra(driver): invoking one fetch-public function" << std::endl;
23-
int fetchPublicId = faasmChainNamed("fetch-public", (uint8_t*) s3DataFile.c_str(), s3DataFile.size());
22+
std::cout << "finra(driver): invoking one fetch-public function"
23+
<< std::endl;
24+
int fetchPublicId = faasmChainNamed(
25+
"fetch-public", (uint8_t *)s3DataFile.c_str(), s3DataFile.size());
2426

25-
std::cout << "finra(driver): invoking one fetch-private function" << std::endl;
27+
std::cout << "finra(driver): invoking one fetch-private function"
28+
<< std::endl;
2629
int fetchPrivateId = faasmChainNamed("fetch-private", nullptr, 0);
2730

2831
// Wait for both functions to finish
2932
int result = faasmAwaitCall(fetchPublicId);
3033
if (result != 0) {
3134
std::cerr << "finra(driver): error: "
32-
<< "fetch-public execution failed with rc: "
33-
<< result
35+
<< "fetch-public execution failed with rc: " << result
3436
<< std::endl;
3537
return 1;
3638
}
3739
result = faasmAwaitCall(fetchPrivateId);
3840
if (result != 0) {
3941
std::cerr << "finra(driver): error: "
40-
<< "fetch-private execution failed with rc: "
41-
<< result
42+
<< "fetch-private execution failed with rc: " << result
4243
<< std::endl;
4344
return 1;
4445
}
4546

46-
std::cout << "finra(driver): invoking " << numAuditFuncs << " audit function" << std::endl;
47+
std::cout << "finra(driver): invoking " << numAuditFuncs
48+
<< " audit function" << std::endl;
4749
std::vector<int> auditFuncIds;
4850
int auditId;
4951
for (int i = 0; i < numAuditFuncs; i++) {
5052
std::string auditInput = std::to_string(i);
5153
auditInput += ":finra/outputs/fetch-public/trades";
5254
auditInput += ":finra/outputs/fetch-private/portfolio";
53-
int auditId = faasmChainNamed("audit", (uint8_t*) auditInput.c_str(), auditInput.size());
55+
int auditId = faasmChainNamed("audit", (uint8_t *)auditInput.c_str(),
56+
auditInput.size());
5457
auditFuncIds.push_back(auditId);
5558
}
5659

5760
// Wait for all audit functions
5861
for (const auto auditId : auditFuncIds) {
5962
result = faasmAwaitCall(auditId);
6063
if (result != 0) {
61-
std::cerr << "finra(driver): error: "
62-
<< " audit execution (id: " << auditId << ")"
63-
<< std::endl
64-
<< "finra(driver): error: failed with rc: "
65-
<< result
64+
std::cerr << "finra(driver): error: " << " audit execution (id: "
65+
<< auditId << ")" << std::endl
66+
<< "finra(driver): error: failed with rc: " << result
6667
<< std::endl;
6768
return 1;
6869
}
@@ -72,8 +73,7 @@ int main(int argc, char** argv)
7273
int mergeId = faasmChainNamed("merge", nullptr, 0);
7374
result = faasmAwaitCall(mergeId);
7475
if (result != 0) {
75-
std::cout << "finra(driver): merge execution failed with rc "
76-
<< result
76+
std::cout << "finra(driver): merge execution failed with rc " << result
7777
<< std::endl;
7878
return 1;
7979
}

0 commit comments

Comments
 (0)