-
Notifications
You must be signed in to change notification settings - Fork 301
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
multi: Add getaddrv2 and addrv2. #2627
Open
sefbkn
wants to merge
9
commits into
decred:master
Choose a base branch
from
sefbkn:add_addrv2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
650a935
addrmgr: Track network address types.
sefbkn 77e2118
addrmgr: Add network address type filter.
sefbkn 2d13ac7
peer: Partially decouple peer from wire.
sefbkn a32aa05
addrmgr: Remove DNS lookups from address manager.
sefbkn ddf3d7d
addrmgr: Add TORv3 network address type.
sefbkn 27215a0
multi: Remove TORv2 network address type.
sefbkn 404ec69
peer/wire: Add addrv2 and getaddrv2 message types.
sefbkn c8b98b1
connmgr: Allow seeding additional address types.
sefbkn 3632c29
peer/wire: Relay TORv3 addresses.
sefbkn 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 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 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 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 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 |
---|---|---|
|
@@ -639,20 +639,15 @@ func (sp *serverPeer) relayTxDisabled() bool { | |
return isDisabled | ||
} | ||
|
||
// wireToAddrmgrNetAddress converts a wire NetAddress to an address manager | ||
// NetAddress. | ||
func wireToAddrmgrNetAddress(netAddr *wire.NetAddress) *addrmgr.NetAddress { | ||
newNetAddr := addrmgr.NewNetAddressIPPort(netAddr.IP, netAddr.Port, netAddr.Services) | ||
newNetAddr.Timestamp = netAddr.Timestamp | ||
return newNetAddr | ||
} | ||
|
||
// wireToAddrmgrNetAddresses converts a collection of wire net addresses to a | ||
// collection of address manager net addresses. | ||
// wireToAddrmgrNetAddresses converts a collection of version 1 wire network | ||
// addresses to a collection of address manager network addresses. | ||
func wireToAddrmgrNetAddresses(netAddr []*wire.NetAddress) []*addrmgr.NetAddress { | ||
addrs := make([]*addrmgr.NetAddress, len(netAddr)) | ||
for i, wireAddr := range netAddr { | ||
addrs[i] = wireToAddrmgrNetAddress(wireAddr) | ||
newNetAddr := addrmgr.NewNetAddressIPPort(wireAddr.IP, wireAddr.Port, | ||
wireAddr.Services) | ||
newNetAddr.Timestamp = wireAddr.Timestamp | ||
addrs[i] = newNetAddr | ||
} | ||
return addrs | ||
} | ||
|
@@ -674,21 +669,6 @@ func wireToAddrmgrNetAddressesV2(netAddr []*wire.NetAddressV2) ([]*addrmgr.NetAd | |
return addrs, nil | ||
} | ||
|
||
// addrmgrToWireNetAddress converts an address manager net address to a wire net | ||
// address. | ||
func addrmgrToWireNetAddress(netAddr *addrmgr.NetAddress) *wire.NetAddress { | ||
return wire.NewNetAddressTimestamp(netAddr.Timestamp, netAddr.Services, | ||
netAddr.IP, netAddr.Port) | ||
} | ||
|
||
// addrmgrToWireNetAddressV2 converts an address manager net address to a wire net | ||
// address. | ||
func addrmgrToWireNetAddressV2(netAddr *addrmgr.NetAddress) *wire.NetAddressV2 { | ||
wireNetAddrType := wire.NetAddressType(netAddr.Type) | ||
return wire.NewNetAddressV2(wireNetAddrType, netAddr.IP, netAddr.Port, | ||
netAddr.Timestamp, netAddr.Services) | ||
} | ||
|
||
// pushAddrMsg sends an addr message to the connected peer using the provided | ||
// addresses. Any network address passed to this function must have | ||
// already been filtered to ensure that it is supported by the protocol | ||
|
@@ -698,7 +678,8 @@ func (sp *serverPeer) pushAddrMsg(addresses []*addrmgr.NetAddress) { | |
addrs := make([]*wire.NetAddress, 0, len(addresses)) | ||
for _, addr := range addresses { | ||
if !sp.addressKnown(addr) { | ||
wireNetAddr := addrmgrToWireNetAddress(addr) | ||
wireNetAddr := wire.NewNetAddressTimestamp(addr.Timestamp, | ||
addr.Services, addr.IP, addr.Port) | ||
addrs = append(addrs, wireNetAddr) | ||
} | ||
} | ||
|
@@ -723,7 +704,9 @@ func (sp *serverPeer) pushAddrV2Msg(addresses []*addrmgr.NetAddress) { | |
addrs := make([]*wire.NetAddressV2, 0, len(addresses)) | ||
for _, addr := range addresses { | ||
if !sp.addressKnown(addr) { | ||
addrV2 := addrmgrToWireNetAddressV2(addr) | ||
wireNetAddrType := wire.NetAddressType(addr.Type) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Calling this out again about the cast since I see the function I commented on in an earlier commit is removed. |
||
addrV2 := wire.NewNetAddressV2(wireNetAddrType, addr.IP, addr.Port, | ||
addr.Timestamp, addr.Services) | ||
addrs = append(addrs, addrV2) | ||
} | ||
} | ||
|
@@ -1981,7 +1964,14 @@ func (s *server) handleAddPeerMsg(state *peerState, sp *serverPeer) bool { | |
net = addrmgr.IPv6Address | ||
} | ||
|
||
localAddr := wireToAddrmgrNetAddress(na) | ||
localAddr, err := addrmgr.NewNetAddressByType(net, na.IP, na.Port, | ||
na.Timestamp, na.Services) | ||
if err != nil { | ||
srvrLog.Errorf("unable to construct peer network address: %v", | ||
err) | ||
return true | ||
} | ||
|
||
valid, reach := s.addrManager.ValidatePeerNa(localAddr, remoteAddr) | ||
if !valid { | ||
return true | ||
|
@@ -3292,10 +3282,9 @@ func (s *server) querySeeders(ctx context.Context) { | |
const httpsPort = 443 | ||
srcAddr, err := cfg.hostToNetAddress(seeder, httpsPort, 0) | ||
if err != nil { | ||
srcAddr = wireToAddrmgrNetAddress(addrs[0]) | ||
srcAddr = addrs[0] | ||
} | ||
addresses := wireToAddrmgrNetAddresses(addrs) | ||
s.addrManager.AddAddresses(addresses, srcAddr) | ||
s.addrManager.AddAddresses(addrs, srcAddr) | ||
}(seeder) | ||
} | ||
} | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Breaking change to the API.
connmgr
needs a major module version bump for this since it hasn't been done since the last release.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, for reasons mentioned elsewhere, please prefer
[]addrmgr.NetAddress
over the pointer variant.