Skip to content

Commit

Permalink
feat: adding maxSentData and maxRecv data to prover
Browse files Browse the repository at this point in the history
  • Loading branch information
Codetrauma committed May 14, 2024
1 parent 1eada46 commit 6af9c6d
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
10 changes: 9 additions & 1 deletion src/entries/Background/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export type RequestHistory = {
headers: { [key: string]: string };
body?: string;
maxTranscriptSize: number;
maxSentData: number;
maxRecvData: number;
notaryUrl: string;
websocketProxyUrl: string;
status: '' | 'pending' | 'success' | 'error';
Expand Down Expand Up @@ -212,6 +214,8 @@ async function handleProveRequestStart(
headers,
body,
maxTranscriptSize,
maxSentData,
maxRecvData,
notaryUrl,
websocketProxyUrl,
secretHeaders,
Expand All @@ -223,13 +227,15 @@ async function handleProveRequestStart(
method,
headers,
body,
maxSentData,
maxRecvData,
maxTranscriptSize,
notaryUrl,
websocketProxyUrl,
secretHeaders,
secretResps,
});

console.log(request.data);
await setNotaryRequestStatus(id, 'pending');

await browser.runtime.sendMessage({
Expand All @@ -249,6 +255,8 @@ async function handleProveRequestStart(
headers,
body,
maxTranscriptSize,
maxSentData,
maxRecvData,
notaryUrl,
websocketProxyUrl,
secretHeaders,
Expand Down
4 changes: 4 additions & 0 deletions src/entries/Offscreen/Offscreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const Offscreen = () => {
method,
headers,
body = '',
maxSentData,
maxRecvData,
maxTranscriptSize,
notaryUrl,
websocketProxyUrl,
Expand All @@ -30,6 +32,8 @@ const Offscreen = () => {
method,
headers,
body,
maxSentData,
maxRecvData,
maxTranscriptSize,
notaryUrl,
websocketProxyUrl: websocketProxyUrl + `?token=${token}`,
Expand Down
11 changes: 7 additions & 4 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ import bookmarks from '../../../utils/bookmark/bookmarks.json';
import { replayRequest, urlify } from '../../utils/misc';
import { useDispatch } from 'react-redux';
import {
get,
NOTARY_API_LS_KEY,
PROXY_API_LS_KEY,
getMaxRecv,
getMaxSent,
getNotaryApi,
getProxyApi,
} from '../../utils/storage';
import { MAX_SENT } from '../../utils/constants';

export default function Home(): ReactElement {
const requests = useRequests();
Expand Down Expand Up @@ -127,7 +127,8 @@ export default function Home(): ReactElement {
const hostname = urlify(req.url)?.hostname;
const notaryUrl = await getNotaryApi();
const websocketProxyUrl = await getProxyApi();

const maxSent = await getMaxSent();
const maxRecv = await getMaxRecv();
const headers: { [k: string]: string } =
req.requestHeaders.reduce(
(acc: any, h) => {
Expand All @@ -148,6 +149,8 @@ export default function Home(): ReactElement {
method: req.method,
headers: headers,
body: req.requestBody,
maxSentData: maxSent,
maxRecvData: maxRecv,
maxTranscriptSize: 16384,
notaryUrl,
websocketProxyUrl,
Expand Down
7 changes: 6 additions & 1 deletion src/pages/Notarize/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
PROXY_API_LS_KEY,
getNotaryApi,
getProxyApi,
getMaxSent,
getMaxRecv,
} from '../../utils/storage';
import { useDispatch } from 'react-redux';

Expand All @@ -37,7 +39,8 @@ export default function Notarize(): ReactElement {
const hostname = urlify(req.url)?.hostname;
const notaryUrl = await getNotaryApi();
const websocketProxyUrl = await getProxyApi();

const maxSentData = await getMaxSent();
const maxRecvData = await getMaxRecv();
const headers: { [k: string]: string } = req.requestHeaders.reduce(
(acc: any, h) => {
acc[h.name] = h.value;
Expand All @@ -57,6 +60,8 @@ export default function Notarize(): ReactElement {
method: req.method,
headers,
body: req.requestBody,
maxSentData,
maxRecvData,
maxTranscriptSize,
notaryUrl,
websocketProxyUrl,
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Options/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export default function Options(): ReactElement {
(async () => {
setNotary((await getNotaryApi()) || NOTARY_API);
setProxy((await getProxyApi()) || NOTARY_PROXY);
setMaxReceived(parseInt(await getMaxRecv()) || MAX_RECV);
setMaxSent(parseInt(await getMaxSent()) || MAX_SENT);
setMaxReceived(await getMaxRecv() || MAX_RECV);

Check failure on line 35 in src/pages/Options/index.tsx

View workflow job for this annotation

GitHub Actions / build

Replace `await·getMaxRecv(` with `(await·getMaxRecv()`
setMaxSent(await getMaxSent() || MAX_SENT);

Check failure on line 36 in src/pages/Options/index.tsx

View workflow job for this annotation

GitHub Actions / build

Replace `await·getMaxSent(` with `(await·getMaxSent()`
})();
}, [advanced]);

Expand Down
10 changes: 6 additions & 4 deletions src/reducers/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@ import { useSelector } from 'react-redux';
import { AppRootState } from './index';
import deepEqual from 'fast-deep-equal';
import {
get,
NOTARY_API_LS_KEY,
PROXY_API_LS_KEY,
getNotaryApi,
getProxyApi,
getMaxSent,
getMaxRecv,
} from '../utils/storage';
import { BackgroundActiontype } from '../entries/Background/rpc';
import browser from 'webextension-polyfill';
import { NOTARY_API, NOTARY_PROXY } from '../utils/constants';

enum ActionType {
'/requests/setRequests' = '/requests/setRequests',
Expand Down Expand Up @@ -49,6 +47,8 @@ export const setRequests = (requests: RequestLog[]): Action<RequestLog[]> => ({
export const notarizeRequest = (options: RequestHistory) => async () => {
const notaryUrl = await getNotaryApi();
const websocketProxyUrl = await getProxyApi();
const maxSentData = await getMaxSent();
const maxRecvData = await getMaxRecv();

chrome.runtime.sendMessage<any, string>({
type: BackgroundActiontype.prove_request_start,
Expand All @@ -58,6 +58,8 @@ export const notarizeRequest = (options: RequestHistory) => async () => {
headers: options.headers,
body: options.body,
maxTranscriptSize: options.maxTranscriptSize,
maxSentData,
maxRecvData,
secretHeaders: options.secretHeaders,
secretResps: options.secretResps,
notaryUrl,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ export async function get(key: string, defaultValue?: string) {
}

export async function getMaxSent() {
return await get(MAX_SENT_LS_KEY, '4096');
return parseInt(await get(MAX_SENT_LS_KEY, '4096'));
}

export async function getMaxRecv() {
return await get(MAX_RECEIVED_LS_KEY, '16384');
return parseInt(await get(MAX_RECEIVED_LS_KEY, '16384'));
}

export async function getNotaryApi() {
Expand Down

0 comments on commit 6af9c6d

Please sign in to comment.