-
Notifications
You must be signed in to change notification settings - Fork 284
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
650a935
77e2118
2d13ac7
a32aa05
ddf3d7d
27215a0
404ec69
c8b98b1
3632c29
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,7 +74,7 @@ const ( | |
connectionRetryInterval = time.Second * 5 | ||
|
||
// maxProtocolVersion is the max protocol version the server supports. | ||
maxProtocolVersion = wire.AddrV2Version | ||
maxProtocolVersion = wire.RelayTORv3Version | ||
|
||
// These fields are used to track known addresses on a per-peer basis. | ||
// | ||
|
@@ -783,6 +783,7 @@ func isSupportedNetAddressTypeV2(netAddressType addrmgr.NetAddressType) bool { | |
switch netAddressType { | ||
case addrmgr.IPv4Address: | ||
case addrmgr.IPv6Address: | ||
case addrmgr.TORv3Address: | ||
return true | ||
} | ||
return false | ||
|
@@ -792,7 +793,7 @@ func isSupportedNetAddressTypeV2(netAddressType addrmgr.NetAddressType) bool { | |
// specific address manager network address type is supported by the | ||
// provided protocol version. | ||
func getNetAddressTypeFilter(protocolVersion uint32) addrmgr.NetAddressTypeFilter { | ||
if protocolVersion < wire.AddrV2Version { | ||
if protocolVersion < wire.RelayTORv3Version { | ||
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. Shouldn't this still be |
||
return isSupportedNetAddressTypeV1 | ||
} else { | ||
return isSupportedNetAddressTypeV2 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,23 +90,31 @@ func readNetAddressV2(op string, r io.Reader, pver uint32) (*NetAddressV2, error | |
|
||
// Read the ip bytes with a length varying by the network id type. | ||
var ipBytes []byte | ||
switch na.Type { | ||
case IPv4Address: | ||
switch { | ||
case na.Type == IPv4Address: | ||
var ip [4]byte | ||
err := readElement(r, &ip) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ipBytes = ip[:] | ||
case IPv6Address: | ||
case na.Type == IPv6Address: | ||
var ip [16]byte | ||
err := readElement(r, &ip) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ipBytes = ip[:] | ||
case na.Type == TORv3Address && pver >= RelayTORv3Version: | ||
var ip [32]byte | ||
err := readElement(r, &ip) | ||
if err != nil { | ||
return nil, err | ||
} | ||
ipBytes = ip[:] | ||
default: | ||
msg := fmt.Sprintf("unsupported network address type %v", na.Type) | ||
msg := fmt.Sprintf("unsupported network address type %v for "+ | ||
"protocol version %d", na.Type, pver) | ||
return nil, messageError(op, ErrInvalidMsg, msg) | ||
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. This should be a new error code |
||
} | ||
|
||
|
@@ -133,8 +141,8 @@ func writeNetAddressV2(op string, w io.Writer, pver uint32, na *NetAddressV2) er | |
} | ||
|
||
netAddrIP := na.IP | ||
switch na.Type { | ||
case IPv4Address: | ||
switch { | ||
case na.Type == IPv4Address: | ||
var ip [4]byte | ||
if netAddrIP != nil { | ||
copy(ip[:], netAddrIP) | ||
|
@@ -143,7 +151,7 @@ func writeNetAddressV2(op string, w io.Writer, pver uint32, na *NetAddressV2) er | |
if err != nil { | ||
return err | ||
} | ||
case IPv6Address: | ||
case na.Type == IPv6Address: | ||
var ip [16]byte | ||
if netAddrIP != nil { | ||
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. This seems incorrect to me. An entry without a valid address for an expected net address type is an error. |
||
copy(ip[:], net.IP(netAddrIP).To16()) | ||
|
@@ -152,8 +160,18 @@ func writeNetAddressV2(op string, w io.Writer, pver uint32, na *NetAddressV2) er | |
if err != nil { | ||
return err | ||
} | ||
case na.Type == TORv3Address && pver >= RelayTORv3Version: | ||
var ip [32]byte | ||
if len(na.IP) == 32 { | ||
copy(ip[:], net.IP(na.IP)) | ||
} | ||
err = writeElement(w, ip) | ||
if err != nil { | ||
return err | ||
} | ||
default: | ||
msg := fmt.Sprintf("unrecognized network address type %v", na.Type) | ||
msg := fmt.Sprintf("unsupported network address type %v for "+ | ||
"protocol version %d", na.Type, pver) | ||
return messageError(op, ErrInvalidMsg, msg) | ||
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.
|
||
} | ||
|
||
|
@@ -163,11 +181,25 @@ func writeNetAddressV2(op string, w io.Writer, pver uint32, na *NetAddressV2) er | |
// maxNetAddressPayloadV2 returns the max payload size for an address manager | ||
// network address based on the protocol version. | ||
func maxNetAddressPayloadV2(pver uint32) uint32 { | ||
const timestampSize = 8 | ||
const servicesSize = 8 | ||
const addressTypeSize = 1 | ||
const maxAddressSize = 16 | ||
const portSize = 2 | ||
if pver < RelayTORv3Version { | ||
const ( | ||
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. These could all go outside of the if and be reused since all of them are the same except |
||
timestampSize = 8 | ||
servicesSize = 8 | ||
addressTypeSize = 1 | ||
maxAddressSize = 16 | ||
portSize = 2 | ||
) | ||
return timestampSize + servicesSize + addressTypeSize + maxAddressSize + | ||
portSize | ||
} | ||
|
||
const ( | ||
timestampSize = 8 | ||
servicesSize = 8 | ||
addressTypeSize = 1 | ||
maxAddressSize = 32 | ||
portSize = 2 | ||
) | ||
return timestampSize + servicesSize + addressTypeSize + maxAddressSize + | ||
portSize | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ const ( | |
UnknownAddressType NetAddressType = iota | ||
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. Please don't use iota for constants that can't be changed as it's too easy to accidentally change them when new items are added. |
||
IPv4Address | ||
IPv6Address | ||
TORv3Address | ||
) | ||
|
||
// NetAddressV2 defines information about a peer on the network. | ||
|
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.
Please keep
pver
. It's used everywhere and is thus consistent.