Skip to content

Commit

Permalink
Add timestamp to mobymask p2p messages (#340)
Browse files Browse the repository at this point in the history
* Add timestamps to mobymask logs

* Fix getCurrentTime method calls

---------

Co-authored-by: Dhruv Srivastava <[email protected]>
  • Loading branch information
nikugogoi and dafaqdhruv authored Mar 17, 2023
1 parent c44eff3 commit d221704
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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

0 comments on commit d221704

Please sign in to comment.