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

Add timestamp to mobymask p2p messages #340

Merged
merged 2 commits into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 6 additions & 1 deletion packages/mobymask-v2-watcher/src/libp2p-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function sendMessageToL2 (
}

export function parseLibp2pMessage (log: debug.Debugger, peerId: string, data: any): void {
log('Received a message on mobymask P2P network from peer:', peerId);
log(`[${getCurrentTime()}] Received a message on mobymask P2P network from peer:`, peerId);
const { kind, message } = data;

switch (kind) {
Expand All @@ -107,6 +107,11 @@ export function parseLibp2pMessage (log: debug.Debugger, peerId: string, data: a
log('------------------------------------------');
}

export const getCurrentTime = (): string => {
const now = new Date();
return `${now.getHours()}:${now.getMinutes()}:${now.getSeconds()}`;
};

function _parseInvocation (log: debug.Debugger, msg: any): void {
log('Signed invocations:');
log(JSON.stringify(msg, null, 2));
Expand Down
4 changes: 2 additions & 2 deletions packages/mobymask-v2-watcher/src/peer-listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1319854183
} from '@cerc-io/peer';

import { sendMessageToL2 } from './libp2p-utils';
import { getCurrentTime, sendMessageToL2 } from './libp2p-utils';
import { readPeerId } from '@cerc-io/cli';
import { ethers } from 'ethers';

Expand Down Expand Up @@ -57,7 +57,7 @@ export const main = async (): Promise<any> => {
const wallet = new ethers.Wallet(argv.privateKey, ethProvider);

peer.subscribeTopic(peerConfig.pubSubTopic, (peerId, data) => {
log('Received a message on mobymask P2P network from peer:', peerId);
log(`[${getCurrentTime()}] Received a message on mobymask P2P network from peer:`, peerId);

// TODO: throttle message handler
sendMessageToL2(wallet, argv, data);
Expand Down