mirror of
https://github.com/farcasterxyz/hub-monorepo.git
synced 2026-04-18 03:00:22 -04:00
fix: Have gossip node listen on 0.0.0.0 by default (#770)
* fix: Have gossip node listen on 0.0.0.0 by default * changeset
This commit is contained in:
5
.changeset/sour-experts-poke.md
Normal file
5
.changeset/sour-experts-poke.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@farcaster/hubble': patch
|
||||
---
|
||||
|
||||
Gossip server listens on 0.0.0.0 by default
|
||||
@@ -24,7 +24,7 @@ export const Config = {
|
||||
// '12D3KooWMDdQaMWCkQ8Gf3C6zdJdMEfFs8R2pw8YQw2HgoY8qhzA', // @adityapk00
|
||||
// ],
|
||||
/** The IP address libp2p should listen on. */
|
||||
ip: '127.0.0.1',
|
||||
ip: '0.0.0.0',
|
||||
/** The IP address that libp2p should announce to peers */
|
||||
// announceIp: '',
|
||||
/** The server name to announce to peers */
|
||||
|
||||
@@ -251,6 +251,7 @@ app
|
||||
const options: HubOptions = {
|
||||
peerId,
|
||||
ipMultiAddr: ipMultiAddrResult.value,
|
||||
rpcServerHost: hubAddressInfo.value.address,
|
||||
announceIp: cliOptions.announceIp ?? hubConfig.announceIp,
|
||||
announceServerName: cliOptions.announceServerName ?? hubConfig.announceServerName,
|
||||
gossipPort: hubAddressInfo.value.port,
|
||||
|
||||
@@ -78,9 +78,12 @@ export interface HubOptions {
|
||||
/** A list of PeerId strings to allow connections with */
|
||||
allowedPeers?: string[];
|
||||
|
||||
/** IP address string in MultiAddr format to bind to */
|
||||
/** IP address string in MultiAddr format to bind the gossip node to */
|
||||
ipMultiAddr?: string;
|
||||
|
||||
/** IP address string to bind the RPC server to */
|
||||
rpcServerHost?: string;
|
||||
|
||||
/** External IP address to announce to peers. If not provided, it'll fetch the IP from an external service */
|
||||
announceIp?: string;
|
||||
|
||||
@@ -321,7 +324,7 @@ export class Hub implements HubInterface {
|
||||
});
|
||||
|
||||
// Start the RPC server
|
||||
await this.rpcServer.start(this.options.rpcPort ? this.options.rpcPort : 0);
|
||||
await this.rpcServer.start(this.options.rpcServerHost, this.options.rpcPort ? this.options.rpcPort : 0);
|
||||
if (this.options.adminServerEnabled) {
|
||||
await this.adminServer.start(this.options.adminServerHost ?? '127.0.0.1');
|
||||
}
|
||||
|
||||
@@ -137,6 +137,7 @@ export default class Server {
|
||||
private gossipNode: GossipNode | undefined;
|
||||
|
||||
private grpcServer: GrpcServer;
|
||||
private listenIp: string;
|
||||
private port: number;
|
||||
|
||||
private rpcAuthUser: string | undefined;
|
||||
@@ -158,6 +159,8 @@ export default class Server {
|
||||
this.gossipNode = gossipNode;
|
||||
|
||||
this.grpcServer = getServer();
|
||||
|
||||
this.listenIp = '';
|
||||
this.port = 0;
|
||||
|
||||
const [rpcAuthUser, rpcAuthPass] = rpcAuth?.split(':') ?? [undefined, undefined];
|
||||
@@ -182,14 +185,16 @@ export default class Server {
|
||||
});
|
||||
}
|
||||
|
||||
async start(port = 0): Promise<number> {
|
||||
async start(ip = '0.0.0.0', port = 0): Promise<number> {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.grpcServer.bindAsync(`0.0.0.0:${port}`, ServerCredentials.createInsecure(), (err, port) => {
|
||||
this.grpcServer.bindAsync(`${ip}:${port}`, ServerCredentials.createInsecure(), (err, port) => {
|
||||
if (err) {
|
||||
logger.error({ component: 'gRPC Server', err }, 'Failed to start gRPC Server');
|
||||
reject(err);
|
||||
} else {
|
||||
this.grpcServer.start();
|
||||
|
||||
this.listenIp = ip;
|
||||
this.port = port;
|
||||
|
||||
logger.info({ component: 'gRPC Server', address: this.address }, 'Starting gRPC Server');
|
||||
@@ -220,7 +225,7 @@ export default class Server {
|
||||
}
|
||||
|
||||
get address() {
|
||||
const addr = addressInfoFromParts('0.0.0.0', this.port);
|
||||
const addr = addressInfoFromParts(this.listenIp, this.port);
|
||||
return addr;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user