-
Couldn't load subscription status.
- Fork 146
chore(dot/network): use mdns instead of mdns_legacy
#2794
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1f0b414
chore(dot/network): use `mdns` instead of `mdns_legacy`
qdm12 c66dcbb
`internal/mdns` implementation
qdm12 c5dd63f
Revert to whyrusleeping?
qdm12 16a37c5
Default to nil ips and port 4001 if no dialable found
qdm12 13adee4
Re-use entries channel across ticks
qdm12 30fc2c5
Add ready channels
qdm12 ea22ee8
Return error from handleEntry and log them in handleEntries
qdm12 88e234d
Change place where started is set in Start
qdm12 92d0262
Return `nil` for Start on a started service
qdm12 8ef4b7d
Simplify back entries handling code
qdm12 b5ec107
`pollPeriod` as service struct field
qdm12 92882f4
Small interface changes in dialable.go
qdm12 dd1c1ed
Re-organize service struct fields
qdm12 618e985
Add start stop mutex
qdm12 6da74a2
Fix linting
qdm12 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| // Copyright 2022 ChainSafe Systems (ON) | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| package mdns | ||
|
|
||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "net" | ||
|
|
||
| manet "github.com/multiformats/go-multiaddr/net" | ||
| ) | ||
|
|
||
| var ( | ||
| ErrTCPListenAddressNotFound = errors.New("TCP listen address not found") | ||
| ) | ||
|
|
||
| func getMDNSIPsAndPort(network interfaceListenAddressesGetter) (ips []net.IP, port uint16) { | ||
| tcpAddresses, err := getDialableListenAddrs(network) | ||
| if err != nil { | ||
| const defaultPort = 4001 | ||
| return nil, defaultPort | ||
| } | ||
|
|
||
| ips = make([]net.IP, len(tcpAddresses)) | ||
| for i := range tcpAddresses { | ||
| ips[i] = tcpAddresses[i].IP | ||
| } | ||
| port = uint16(tcpAddresses[0].Port) | ||
|
|
||
| return ips, port | ||
| } | ||
|
|
||
| func getDialableListenAddrs(network interfaceListenAddressesGetter) (tcpAddresses []*net.TCPAddr, err error) { | ||
| multiAddresses, err := network.InterfaceListenAddresses() | ||
| if err != nil { | ||
| return nil, fmt.Errorf("listing host interface listen addresses: %w", err) | ||
| } | ||
|
|
||
| tcpAddresses = make([]*net.TCPAddr, 0, len(multiAddresses)) | ||
| for _, multiAddress := range multiAddresses { | ||
| netAddress, err := manet.ToNetAddr(multiAddress) | ||
| if err != nil { | ||
| continue | ||
| } | ||
|
|
||
| tcpAddress, ok := netAddress.(*net.TCPAddr) | ||
| if !ok { | ||
| continue | ||
| } | ||
|
|
||
| tcpAddresses = append(tcpAddresses, tcpAddress) | ||
| } | ||
|
|
||
| if len(tcpAddresses) == 0 { | ||
| return nil, fmt.Errorf("%w: in %d multiaddresses", ErrTCPListenAddressNotFound, len(multiAddresses)) | ||
| } | ||
|
|
||
| return tcpAddresses, nil | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // Copyright 2022 ChainSafe Systems (ON) | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| package mdns | ||
|
|
||
| import ( | ||
| "github.com/libp2p/go-libp2p-core/network" | ||
| "github.com/libp2p/go-libp2p-core/peer" | ||
| "github.com/multiformats/go-multiaddr" | ||
| ) | ||
|
|
||
| // Logger is a logger interface for the mDNS service. | ||
| type Logger interface { | ||
| Debugf(format string, args ...any) | ||
| Warnf(format string, args ...any) | ||
| } | ||
|
|
||
| // IDNetworker can return the peer ID and a network interface. | ||
| type IDNetworker interface { | ||
| ID() peer.ID | ||
| Networker | ||
| } | ||
|
|
||
| // Networker can return a network interface. | ||
| type Networker interface { | ||
| Network() network.Network | ||
| } | ||
|
|
||
| // interfaceListenAddressesGetter returns the listen addresses of the interfaces. | ||
| type interfaceListenAddressesGetter interface { | ||
| InterfaceListenAddresses() ([]multiaddr.Multiaddr, error) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.