Skip to content

Commit

Permalink
Move PubsubType to peer package
Browse files Browse the repository at this point in the history
  • Loading branch information
prathamesh0 committed Sep 11, 2023
1 parent d5ff8f0 commit d82cc67
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 18 deletions.
4 changes: 2 additions & 2 deletions packages/cli/src/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import path from 'path';

import {
PeerInitConfig,
PeerIdObj
PeerIdObj,
PubsubType
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1319854183
} from '@cerc-io/peer';
import { PubsubType } from '@cerc-io/util';

import { readPeerId } from './utils';

Expand Down
7 changes: 4 additions & 3 deletions packages/cli/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import {
RelayNodeInitConfig,
PeerInitConfig,
PeerIdObj,
Peer
Peer,
PubsubType
// @ts-expect-error https://github.com/microsoft/TypeScript/issues/49721#issuecomment-1319854183
} from '@cerc-io/peer';

Expand Down Expand Up @@ -191,7 +192,7 @@ export class ServerCmd {
redialInterval: relayConfig.redialInterval ?? RELAY_REDIAL_INTERVAL,
maxDialRetry: relayConfig.maxDialRetry ?? RELAY_DEFAULT_MAX_DIAL_RETRY,
peerIdObj,
pubsub: relayConfig.pubsub,
pubsub: (relayConfig.pubsub as PubsubType | undefined),
enableDebugInfo: relayConfig.enableDebugInfo
};
await createRelayNode(relayNodeInit);
Expand All @@ -217,7 +218,7 @@ export class ServerCmd {
relayRedialInterval: peerConfig.relayRedialInterval,
maxConnections: peerConfig.maxConnections,
dialTimeout: peerConfig.dialTimeout,
pubsub: peerConfig.pubsub,
pubsub: (peerConfig.pubsub as PubsubType | undefined),
enableDebugInfo: peerConfig.enableDebugInfo
};
await this._peer.init(peerNodeInit, peerIdObj);
Expand Down
1 change: 0 additions & 1 deletion packages/peer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"dependencies": {
"@cerc-io/libp2p": "0.42.2-laconic-0.1.4",
"@cerc-io/prometheus-metrics": "1.1.4",
"@cerc-io/util": "^0.2.56",
"@chainsafe/libp2p-gossipsub": "^6.0.0",
"@chainsafe/libp2p-noise": "^11.0.0",
"@libp2p/floodsub": "^6.0.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/peer/src/cli/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { hideBin } from 'yargs/helpers';
import fs from 'fs';
import path from 'path';

import { PubsubType } from '@cerc-io/util';

import { RelayNodeInitConfig, createRelayNode } from '../relay.js';
import { PeerIdObj } from '../peer.js';
import {
Expand All @@ -15,6 +13,7 @@ import {
DEFAULT_PING_INTERVAL,
DIAL_TIMEOUT
} from '../constants.js';
import { PubsubType } from '../utils/index.js';

interface Arguments {
host: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/peer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

export { Peer, PeerIdObj, PeerInitConfig, createPeerId } from './peer.js';
export { RelayNodeInitConfig, createRelayNode } from './relay.js';
export { getPseudonymForPeerId } from './utils/index.js';
export { getPseudonymForPeerId, PubsubType } from './utils/index.js';
export {
RELAY_DEFAULT_HOST,
RELAY_DEFAULT_PORT,
Expand Down
3 changes: 1 addition & 2 deletions packages/peer/src/peer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
import debug from 'debug';

import { PubsubType } from '@cerc-io/util';
import { createLibp2p, Libp2p, Libp2pInit } from '@cerc-io/libp2p';
import { webSockets } from '@libp2p/websockets';
import { noise } from '@chainsafe/libp2p-noise';
Expand Down Expand Up @@ -42,7 +41,7 @@ import {
P2P_WEBRTC_STAR_ID
} from './constants.js';
import { PeerHearbeatChecker } from './peer-heartbeat-checker.js';
import { debugInfoRequestHandler, dialWithRetry, getConnectionsInfo, getPseudonymForPeerId, getSelfInfo, initPubsub, isMultiaddrBlacklisted, wsPeerFilter } from './utils/index.js';
import { debugInfoRequestHandler, dialWithRetry, getConnectionsInfo, getPseudonymForPeerId, getSelfInfo, initPubsub, isMultiaddrBlacklisted, PubsubType, wsPeerFilter } from './utils/index.js';
import { ConnectionType, DebugPeerInfo, DebugRequest, PeerConnectionInfo, PeerSelfInfo } from './types/debug-info.js';

const log = debug('laconic:peer');
Expand Down
3 changes: 1 addition & 2 deletions packages/peer/src/relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import debug from 'debug';
import assert from 'assert';
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';

import { PubsubType } from '@cerc-io/util';
import { Libp2p, createLibp2p } from '@cerc-io/libp2p';
import { noise } from '@chainsafe/libp2p-noise';
import { mplex } from '@libp2p/mplex';
Expand All @@ -27,7 +26,7 @@ import {
DEBUG_INFO_TOPIC
} from './constants.js';
import { PeerHearbeatChecker } from './peer-heartbeat-checker.js';
import { debugInfoRequestHandler, dialWithRetry, getConnectionsInfo, getPseudonymForPeerId, getSelfInfo, initPubsub, isMultiaddrBlacklisted } from './utils/index.js';
import { PubsubType, debugInfoRequestHandler, dialWithRetry, getConnectionsInfo, getPseudonymForPeerId, getSelfInfo, initPubsub, isMultiaddrBlacklisted } from './utils/index.js';
import { PeerIdObj } from './peer.js';
import { SelfInfo, ConnectionInfo } from './types/debug-info.js';

Expand Down
3 changes: 2 additions & 1 deletion packages/peer/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { gossipsub } from '@chainsafe/libp2p-gossipsub';
import { ConnectionInfo, ConnectionType, DebugMsg, DebugPeerInfo, DebugResponse, SelfInfo } from '../types/debug-info.js';
import { DEBUG_INFO_TOPIC, DEFAULT_PUBSUB_TYPE, P2P_WEBRTC_STAR_ID, PUBSUB_SIGNATURE_POLICY } from '../constants.js';
import { PeerHearbeatChecker } from '../peer-heartbeat-checker.js';
import { PubsubType } from '@cerc-io/util';

const log = debug('laconic:utils');

Expand All @@ -28,6 +27,8 @@ export const CODE_CIRCUIT = 290;

const ERR_INVALID_PUBSUB_TYPE = 'Invalid pubsub type';

export type PubsubType = 'floodsub' | 'gossipsub';

interface DialWithRetryOptions {
redialInterval: number
maxRetry: number
Expand Down
1 change: 1 addition & 0 deletions packages/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"dependencies": {
"@apollo/utils.keyvaluecache": "^1.0.1",
"@cerc-io/nitro-node": "^0.1.8",
"@cerc-io/peer": "^0.2.56",
"@cerc-io/solidity-mapper": "^0.2.56",
"@cerc-io/ts-channel": "1.0.3-ts-nitro-0.1.1",
"@ethersproject/providers": "^5.4.4",
Expand Down
6 changes: 2 additions & 4 deletions packages/util/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import { Config as CacheConfig } from '@cerc-io/cache';

const log = debug('vulcanize:config');

export type PubsubType = 'floodsub' | 'gossipsub';

export interface JobQueueConfig {
dbConnectionString: string;
maxCompletionLagInSecs: number;
Expand Down Expand Up @@ -66,7 +64,7 @@ export interface RelayConfig {
maxDialRetry?: number;

// Pubsub to use ('floodsub' | 'gossipsub')
pubsub?: PubsubType;
pubsub?: string;

// Broadcast node's info over pubsub on requests
enableDebugInfo?: boolean;
Expand Down Expand Up @@ -117,7 +115,7 @@ export interface PeerConfig {
peerIdFile?: string;

// Pubsub to use ('floodsub' | 'gossipsub')
pubsub?: PubsubType;
pubsub?: string;

// Participate in exchange of debug info over pubsub
enableDebugInfo?: boolean;
Expand Down

0 comments on commit d82cc67

Please sign in to comment.