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

make the node use multiaddr for the listen_addr #736

Merged
merged 2 commits into from
Sep 3, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 6 additions & 1 deletion doc/configuration/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ p2p:
bootstrap the p2p topology (and bootstrap our local blockchain);
- *public_id*: (optional) the public identifier send to the other nodes in the
p2p network. If not set it will be randomly generated.
- *public_address*: the address to listen from and accept connection
- *public_address*: [multiaddr][multiaddr] the address to listen from and accept connection
from. This is the public address that will be distributed to other peers
of the network that may find interest into participating to the blockchain
dissemination with the node;
- `listen_address`: (optional) [multiaddr][multiaddr] specifies the address the node
will listen to to receive p2p connection. Can be left empty and the node will listen
to whatever value was given to `public_address`.
- *topics_of_interest*: the different topics we are interested to hear about:
- *messages*: notify other peers this node is interested about Transactions
typical setting for a non mining node: `"low"`. For a stakepool: `"high"`;
- *blocks*: notify other peers this node is interested about new Blocs.
typical settings for a non mining node: `"normal"`. For a stakepool: `"high"`;

[multiaddr]: https://github.com/multiformats/multiaddr
3 changes: 3 additions & 0 deletions doc/quickstart/02_passive_node.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Description of the fields:
P2P service. This is the public address that will be distributed to other
peers of the network that may find interest in participating to the
blockchain dissemination with the node.
- `listen_address`: (optional) [multiaddr][multiaddr] specifies the address the node
will listen to to receive p2p connection. Can be left empty and the node will listen
to whatever value was given to `public_address`.
- `topics_of_interest`: The dissemination topics this node is interested to hear about:
- `messages`: Transactions and other ledger entries.
Typical setting for a non-mining node: `low`. For a stakepool: `high`;
Expand Down
4 changes: 2 additions & 2 deletions jormungandr/src/settings/start/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ pub struct P2pConfig {
pub public_id: Option<NodeId>,

/// The public address to which other peers may connect to
pub public_address: Option<Address>,
pub public_address: Address,

/// The socket address to listen on, if different from the public address.
/// The format is "{ip_address}:{port}".
/// The IP address can be specified as 0.0.0.0 or :: to listen on
/// all network interfaces.
pub listen: Option<SocketAddr>,
pub listen_address: Option<Address>,

/// the rendezvous points for the peer to connect to in order to initiate
/// the p2p discovery from.
Expand Down
24 changes: 18 additions & 6 deletions jormungandr/src/settings/start/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ custom_error! {pub Error
MissingNodeConfig = "--config is mandatory to start the node",
ExpectedBlock0Info = "Cannot start the node without the information to retrieve the genesis block",
TooMuchBlock0Info = "Use only `--genesis-block-hash' or `--genesis-block'",
ListenAddressNotValid = "In the node configuration file, the `p2p.listen_address` value is not a valid address. Use format `/ip4/x.x.x.x/tcp/4920",
}

/// Overall Settings for node
Expand Down Expand Up @@ -92,7 +93,7 @@ impl RawSettings {
config,
} = self;
let command_arguments = &command_line.start_arguments;
let network = generate_network(&command_arguments, &config);
let network = generate_network(&command_arguments, &config)?;

let storage = match (command_arguments.storage.as_ref(), config.storage) {
(Some(path), _) => Some(path.clone()),
Expand Down Expand Up @@ -141,12 +142,21 @@ impl RawSettings {
fn generate_network(
_command_arguments: &StartArguments,
config: &Config,
) -> network::Configuration {
) -> Result<network::Configuration, Error> {
let p2p = &config.p2p;
network::Configuration {
let network = network::Configuration {
public_id: p2p.public_id.clone(),
public_address: p2p.public_address.clone(),
listen: p2p.listen.clone(),
public_address: Some(p2p.public_address.clone()),
listen_address: match &p2p.listen_address {
None => None,
Some(v) => {
if let Some(addr) = v.to_socketaddr() {
Some(addr)
} else {
return Err(Error::ListenAddressNotValid);
}
}
},
trusted_peers: p2p.trusted_peers.clone().unwrap_or(vec![]),
protocol: Protocol::Grpc,
subscriptions: config
Expand All @@ -155,5 +165,7 @@ fn generate_network(
.clone()
.unwrap_or(BTreeMap::new()),
timeout: std::time::Duration::from_secs(15),
}
};

Ok(network)
}
4 changes: 2 additions & 2 deletions jormungandr/src/settings/start/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub struct Configuration {
/// Local socket address to listen to, if different from public address.
/// The IP address can be given as 0.0.0.0 or :: to bind to all
/// network interfaces.
pub listen: Option<SocketAddr>,
pub listen_address: Option<SocketAddr>,

/// list of trusted addresses
pub trusted_peers: Vec<TrustedPeer>,
Expand Down Expand Up @@ -100,7 +100,7 @@ impl Configuration {
/// Returns the listener configuration, if the options defining it
/// were set.
pub fn listen(&self) -> Option<Listen> {
self.listen
self.listen_address
.or(self
.public_address
.as_ref()
Expand Down