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

config: p2p, fix parsing HostDNS #1995

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Changes from all commits
Commits
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
21 changes: 11 additions & 10 deletions network/p2p/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@

TCPPort uint16 `yaml:"TcpPort" env:"TCP_PORT" env-default:"13001" env-description:"TCP port for p2p transport"`
UDPPort uint16 `yaml:"UdpPort" env:"UDP_PORT" env-default:"12001" env-description:"UDP port for discovery"`
HostAddress string `yaml:"HostAddress" env:"HOST_ADDRESS" env-description:"External ip node is exposed for discovery"`
HostDNS string `yaml:"HostDNS" env:"HOST_DNS" env-description:"External DNS node is exposed for discovery"`
HostAddress string `yaml:"HostAddress" env:"HOST_ADDRESS" env-description:"External ip node is exposed for discovery, can be overridden by HostDNS"`
HostDNS string `yaml:"HostDNS" env:"HOST_DNS" env-description:"External DNS node is exposed for discovery, overrides HostAddress if both are specified"`

RequestTimeout time.Duration `yaml:"RequestTimeout" env:"P2P_REQUEST_TIMEOUT" env-default:"10s"`
MaxBatchResponse uint64 `yaml:"MaxBatchResponse" env:"P2P_MAX_BATCH_RESPONSE" env-default:"25" env-description:"Maximum number of returned objects in a batch"`
Expand Down Expand Up @@ -149,24 +149,25 @@
}
opts = append(opts, libp2p.ListenAddrs(addrs...))

// AddrFactory for host address if provided
if c.HostAddress != "" {
// note, only one of (HostDNS, HostAddress) can be used with libp2p - if multiple of these
// are set we have to prioritize between them.
if c.HostDNS != "" {
// AddrFactory for DNS address if provided

Check warning on line 155 in network/p2p/config.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/config.go#L155

Added line #L155 was not covered by tests
opts = append(opts, libp2p.AddrsFactory(func(addrs []ma.Multiaddr) []ma.Multiaddr {
external, err := commons.BuildMultiAddress(c.HostAddress, "tcp", uint(c.TCPPort), "")
external, err := ma.NewMultiaddr(fmt.Sprintf("/dns4/%s/tcp/%d", c.HostDNS, c.TCPPort))

Check warning on line 157 in network/p2p/config.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/config.go#L157

Added line #L157 was not covered by tests
if err != nil {
logger.Error("unable to create external multiaddress", zap.Error(err))
} else {
addrs = append(addrs, external)
}
return addrs
}))
}
// AddrFactory for DNS address if provided
if c.HostDNS != "" {
} else if c.HostAddress != "" {
// AddrFactory for host address if provided

Check warning on line 166 in network/p2p/config.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/config.go#L166

Added line #L166 was not covered by tests
opts = append(opts, libp2p.AddrsFactory(func(addrs []ma.Multiaddr) []ma.Multiaddr {
external, err := ma.NewMultiaddr(fmt.Sprintf("/dns4/%s/tcp/%d", c.HostDNS, c.TCPPort))
external, err := commons.BuildMultiAddress(c.HostAddress, "tcp", uint(c.TCPPort), "")

Check warning on line 168 in network/p2p/config.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/config.go#L168

Added line #L168 was not covered by tests
if err != nil {
logger.Warn("unable to create external multiaddress", zap.Error(err))
logger.Error("unable to create external multiaddress", zap.Error(err))

Check warning on line 170 in network/p2p/config.go

View check run for this annotation

Codecov / codecov/patch

network/p2p/config.go#L170

Added line #L170 was not covered by tests
} else {
addrs = append(addrs, external)
}
Expand Down
Loading