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

DNS support for static nodes and discovery #885

Merged
merged 30 commits into from
Nov 29, 2019
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
c15fb0a
Update raft to accept a hostname instead of only an IP address
prd-fox Jul 3, 2019
1bb23fe
Export struct members so they can be RLP decoded.
prd-fox Nov 6, 2019
ec1264b
Fix doc typo and make doc use clearer language.
prd-fox Nov 6, 2019
6399709
Add hostname parameter to TOML file and run goimports on badly formatted
prd-fox Nov 7, 2019
b5d5572
Review feedback:
prd-fox Nov 13, 2019
8794b6e
Review feedback:
prd-fox Nov 13, 2019
ed468ab
Review feedback:
prd-fox Nov 13, 2019
1f9160e
Review feedback:
prd-fox Nov 13, 2019
3b2ab89
Fallback to IP address if no hostname specified for discovered nodes.
prd-fox Nov 14, 2019
115a61c
Add document describing DNS in more detail.
prd-fox Nov 18, 2019
5575c0a
Remove debug line and expand document explaining the features of DNS
prd-fox Nov 19, 2019
b412f3f
Rearrange document to make it clearer why DNS is always enabled for
prd-fox Nov 19, 2019
1b85903
Include DNS document in root tree so it appears on the docs site.
prd-fox Nov 19, 2019
cd5dbc9
Merge branch 'master' into dns-support
Krish1979 Nov 19, 2019
854818f
Move out common functionality between enode object creation (IP vs
prd-fox Nov 20, 2019
5004609
Remove commandline page since it only contains changes related to DNS.
prd-fox Nov 20, 2019
1209968
Merge branch 'dns-support' of https://github.com/prd-fox/quorum into …
prd-fox Nov 20, 2019
1750db9
p2p: use the same interface to avoid duplication
trung Nov 20, 2019
6138aca
Remove discovery based DNS support.
prd-fox Nov 22, 2019
7dc874b
Fix newline formatting and update documentation for the removal of
prd-fox Nov 22, 2019
ce3dbf6
Merge branch 'master' into dns-support
prd-fox Nov 22, 2019
987f0c5
Update node parsing tests to include hostnames.
prd-fox Nov 22, 2019
2dcb51c
Merge remote-tracking branch 'prd-fox/dns-support' into dns-support
prd-fox Nov 22, 2019
bfb0781
Removed hostname from discovery test.
prd-fox Nov 22, 2019
a252071
Allow continuous hostname resolution for static nodes, not just at boot
prd-fox Nov 22, 2019
1ff3b3b
Moved a test to not be included in the full suite. This is because the
prd-fox Nov 22, 2019
f18a70e
Update documentation to reflect the fact that defined bootnodes will
prd-fox Nov 25, 2019
2e925bf
Make snapshot struct names clearer as to their contents, instead of "…
prd-fox Nov 27, 2019
04605ce
Add trace log for when hostname resolution fails, letting the user know
prd-fox Nov 27, 2019
883c9e1
Merge branch 'master' into dns-support
jpmsam Nov 27, 2019
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
2 changes: 1 addition & 1 deletion cmd/bootnode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func main() {
PrivateKey: nodeKey,
NetRestrict: restrictList,
}
if _, err := discover.ListenUDP(conn, ln, cfg); err != nil {
if _, err := discover.ListenUDPQuorum(conn, ln, cfg); err != nil {
utils.Fatalf("%v", err)
}
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/geth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func RegisterRaftService(stack *node.Node, ctx *cli.Context, cfg gethConfig, eth
blockTimeMillis := ctx.GlobalInt(utils.RaftBlockTimeFlag.Name)
datadir := ctx.GlobalString(utils.DataDirFlag.Name)
joinExistingId := ctx.GlobalInt(utils.RaftJoinExistingFlag.Name)
useDns := ctx.GlobalBool(utils.RaftDNSEnabledFlag.Name)

raftPort := uint16(ctx.GlobalInt(utils.RaftPortFlag.Name))

Expand Down Expand Up @@ -255,7 +256,7 @@ func RegisterRaftService(stack *node.Node, ctx *cli.Context, cfg gethConfig, eth
}

ethereum := <-ethChan
return raft.New(ctx, ethereum.ChainConfig(), myId, raftPort, joinExisting, blockTimeNanos, ethereum, peers, datadir)
return raft.New(ctx, ethereum.ChainConfig(), myId, raftPort, joinExisting, blockTimeNanos, ethereum, peers, datadir, useDns)
}); err != nil {
utils.Fatalf("Failed to register the Raft service: %v", err)
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,18 @@ var (
utils.EWASMInterpreterFlag,
utils.EVMInterpreterFlag,
configFileFlag,
// Quorum
utils.EnableNodePermissionFlag,
utils.HostnameFlag,
utils.RaftModeFlag,
utils.RaftBlockTimeFlag,
utils.RaftJoinExistingFlag,
utils.RaftPortFlag,
utils.RaftDNSEnabledFlag,
utils.EmitCheckpointsFlag,
utils.IstanbulRequestTimeoutFlag,
utils.IstanbulBlockPeriodFlag,
// End-Quorum
}

rpcFlags = []cli.Flag{
Expand Down
2 changes: 2 additions & 0 deletions cmd/geth/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ var AppHelpFlagGroups = []flagGroup{
Name: "QUORUM",
Flags: []cli.Flag{
utils.EnableNodePermissionFlag,
utils.HostnameFlag,
},
},
{
Expand All @@ -161,6 +162,7 @@ var AppHelpFlagGroups = []flagGroup{
utils.RaftBlockTimeFlag,
utils.RaftJoinExistingFlag,
utils.RaftPortFlag,
utils.RaftDNSEnabledFlag,
},
},
{
Expand Down
14 changes: 14 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,13 @@ var (
Name: "nodiscover",
Usage: "Disables the peer discovery mechanism (manual peer addition)",
}
// Quorum
HostnameFlag = cli.StringFlag{
Name: "hostname",
Usage: "Sets the hostname to use for p2p",
Value: "",
}
// End-Quorum
DiscoveryV5Flag = cli.BoolFlag{
Name: "v5disc",
Usage: "Enables the experimental RLPx V5 (Topic Discovery) mechanism",
Expand Down Expand Up @@ -603,6 +610,10 @@ var (
Usage: "The port to bind for the raft transport",
Value: 50400,
}
RaftDNSEnabledFlag = cli.BoolFlag{
Name: "raftdnsenable",
Usage: "Enable DNS resolution of peers",
}

// Quorum
EnableNodePermissionFlag = cli.BoolFlag{
Expand Down Expand Up @@ -987,6 +998,9 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
if ctx.GlobalIsSet(NoDiscoverFlag.Name) || lightClient {
cfg.NoDiscovery = true
}
if ctx.GlobalIsSet(HostnameFlag.Name) {
cfg.Hostname = ctx.GlobalString(HostnameFlag.Name)
}

// if we're running a light client or server, force enable the v5 peer discovery
// unless it is explicitly disabled with --nodiscover note that explicitly specifying
Expand Down
32 changes: 32 additions & 0 deletions docs/Features/dns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# DNS for Quorum

DNS support in Quorum has two distinct areas, usage in the static nodes file and usage in the
node discovery protocol. You are free to use one and not the other, or to mix them as the use case
requires.

## Static nodes

Static nodes are nodes we keep reference to even if the node is not alive, so that is the nodes comes alive,
then we can connect to it. Using DNS names in the static node definitions means that if the node is offline and
it's IP changes, we will still be able to connect to it when it comes back online, unlike Ethereum.

## Discovery

If using the DiscoveryV4 protocol with DNS resolution, then you will need to provide the hostname that you wish
for others to see to use to connect to you. This is achieved with the `--hostname <hostname>` flag. If this
flag is set to something that does not resolve to your IP address, then other peers will try to connect to
the wrong address and fail, so it is important that this value is correct.
If you provide a value that does not resolve to any IP address, the node will fail to start up and emit an error
notifying the node operator of such; but it cannot protect against valid but incorrect hostname being provided.

Note: the hostname of connected peers can be seen in the `admin.peers` list, but only for outgoing connections. For
incoming connections, we don't know the hostname (if there even is one), so it will still display the remote IP address.

## Compatibility
For Raft, the whole network must be on version 2.3.1 of Quorum for DNS to function properly; because of this, DNS must
be explicitly enabled using the `--raftdnsenable` flag.
The network will support older nodes mixed with newer nodes if DNS is not enabled via this flag, and it is safe to
enable DNS only on some nodes if all nodes are on at least version 2.3.1. This allows for a clear upgrade path.

For IBFT and Clique, nodes are compatible with all versions of Quorum (insofar as DNS), which means that DNS can
(and is) always enabled. Note that if performing discovery, older nodes will only propagate the IP address.
4 changes: 3 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ nav:
- Overview: Cakeshop/Overview.md
- Getting Started: Cakeshop/Getting started.md
- Cakeshop FAQ: Cakeshop/Cakeshop FAQ.md
- Product Roadmap: roadmap.md
- Quorum Features:
trung marked this conversation as resolved.
Show resolved Hide resolved
- DNS: Features/dns.md
- Product Roadmap: roadmap.md
- FAQ: FAQ.md

theme:
Expand Down
2 changes: 1 addition & 1 deletion p2p/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ func (t *dialTask) dial(srv *Server, dest *enode.Node) error {

func (t *dialTask) String() string {
id := t.dest.ID()
return fmt.Sprintf("%v %x %v:%d", t.flags, id[:8], t.dest.IP(), t.dest.TCP())
return fmt.Sprintf("%v %x %v:%d", t.flags, id[:8], t.dest.Host(), t.dest.TCP())
}

func (t *discoverTask) Do(srv *Server) {
Expand Down
33 changes: 33 additions & 0 deletions p2p/discover/udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,39 @@ func newUDP(c conn, ln *enode.LocalNode, cfg Config) (*Table, *udp, error) {
return udp.tab, udp, nil
}

// Quorum

// ListenUDPExisting uses an existing table that listens for UDP packets on the connection.
func ListenUDPExisting(c conn, ln *enode.LocalNode, cfg Config, tab *Table) (*Table, error) {
prd-fox marked this conversation as resolved.
Show resolved Hide resolved
tab, _, err := newUDPExisting(c, ln, cfg, tab)
if err != nil {
return nil, err
}
return tab, nil
}

func newUDPExisting(c conn, ln *enode.LocalNode, cfg Config, tab *Table) (*Table, *udp, error) {
udp := &udp{
conn: c,
priv: cfg.PrivateKey,
netrestrict: cfg.NetRestrict,
localNode: ln,
db: ln.Database(),
closing: make(chan struct{}),
gotreply: make(chan reply),
addpending: make(chan *pending),
}

udp.tab = tab

udp.wg.Add(2)
go udp.loop()
go udp.readLoop(cfg.Unhandled)
return udp.tab, udp, nil
}

// End-Quorum

func (t *udp) self() *enode.Node {
return t.localNode.Node()
}
Expand Down
Loading