mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-22 15:20:30 +00:00
Use full node ID for CKR routes instead of truncated node IDs from the address/subnet
This commit is contained in:
parent
39dab53ac7
commit
fbfae473d4
@ -125,20 +125,21 @@ func (r *router) sendPacket(bs []byte) {
|
|||||||
panic("Tried to send a packet shorter than a header...")
|
panic("Tried to send a packet shorter than a header...")
|
||||||
}
|
}
|
||||||
var sourceAddr address
|
var sourceAddr address
|
||||||
var dest address
|
var destAddr address
|
||||||
var snet subnet
|
var destSnet subnet
|
||||||
|
var destNodeID *NodeID
|
||||||
var addrlen int
|
var addrlen int
|
||||||
if bs[0]&0xf0 == 0x60 {
|
if bs[0]&0xf0 == 0x60 {
|
||||||
// IPv6 address
|
// IPv6 address
|
||||||
addrlen = 16
|
addrlen = 16
|
||||||
copy(sourceAddr[:addrlen], bs[8:])
|
copy(sourceAddr[:addrlen], bs[8:])
|
||||||
copy(dest[:addrlen], bs[24:])
|
copy(destAddr[:addrlen], bs[24:])
|
||||||
copy(snet[:addrlen/2], bs[24:])
|
copy(destSnet[:addrlen/2], bs[24:])
|
||||||
} else if bs[0]&0xf0 == 0x40 {
|
} else if bs[0]&0xf0 == 0x40 {
|
||||||
// IPv4 address
|
// IPv4 address
|
||||||
addrlen = 4
|
addrlen = 4
|
||||||
copy(sourceAddr[:addrlen], bs[12:])
|
copy(sourceAddr[:addrlen], bs[12:])
|
||||||
copy(dest[:addrlen], bs[16:])
|
copy(destAddr[:addrlen], bs[16:])
|
||||||
} else {
|
} else {
|
||||||
// Unknown address length
|
// Unknown address length
|
||||||
return
|
return
|
||||||
@ -146,12 +147,13 @@ func (r *router) sendPacket(bs []byte) {
|
|||||||
if !r.cryptokey.isValidSource(sourceAddr, addrlen) {
|
if !r.cryptokey.isValidSource(sourceAddr, addrlen) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !dest.isValid() && !snet.isValid() {
|
if !destAddr.isValid() && !destSnet.isValid() {
|
||||||
if key, err := r.cryptokey.getPublicKeyForAddress(dest, addrlen); err == nil {
|
if key, err := r.cryptokey.getPublicKeyForAddress(destAddr, addrlen); err == nil {
|
||||||
addr := *address_addrForNodeID(getNodeID(&key))
|
destNodeID = getNodeID(&key)
|
||||||
copy(dest[:], addr[:])
|
addr := *address_addrForNodeID(destNodeID)
|
||||||
copy(snet[:], addr[:])
|
copy(destAddr[:], addr[:])
|
||||||
if !dest.isValid() && !snet.isValid() {
|
copy(destSnet[:], addr[:])
|
||||||
|
if !destAddr.isValid() && !destSnet.isValid() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -160,11 +162,26 @@ func (r *router) sendPacket(bs []byte) {
|
|||||||
}
|
}
|
||||||
doSearch := func(packet []byte) {
|
doSearch := func(packet []byte) {
|
||||||
var nodeID, mask *NodeID
|
var nodeID, mask *NodeID
|
||||||
if dest.isValid() {
|
switch {
|
||||||
nodeID, mask = dest.getNodeIDandMask()
|
case destNodeID != nil:
|
||||||
}
|
// We already know the full node ID, probably because it's from a CKR
|
||||||
if snet.isValid() {
|
// route in which the public key is known ahead of time
|
||||||
nodeID, mask = snet.getNodeIDandMask()
|
nodeID = destNodeID
|
||||||
|
var m NodeID
|
||||||
|
for i := range m {
|
||||||
|
m[i] = 0xFF
|
||||||
|
}
|
||||||
|
mask = &m
|
||||||
|
case destAddr.isValid():
|
||||||
|
// We don't know the full node ID - try and use the address to generate
|
||||||
|
// a truncated node ID
|
||||||
|
nodeID, mask = destAddr.getNodeIDandMask()
|
||||||
|
case destSnet.isValid():
|
||||||
|
// We don't know the full node ID - try and use the subnet to generate
|
||||||
|
// a truncated node ID
|
||||||
|
nodeID, mask = destSnet.getNodeIDandMask()
|
||||||
|
default:
|
||||||
|
return
|
||||||
}
|
}
|
||||||
sinfo, isIn := r.core.searches.searches[*nodeID]
|
sinfo, isIn := r.core.searches.searches[*nodeID]
|
||||||
if !isIn {
|
if !isIn {
|
||||||
@ -177,11 +194,11 @@ func (r *router) sendPacket(bs []byte) {
|
|||||||
}
|
}
|
||||||
var sinfo *sessionInfo
|
var sinfo *sessionInfo
|
||||||
var isIn bool
|
var isIn bool
|
||||||
if dest.isValid() {
|
if destAddr.isValid() {
|
||||||
sinfo, isIn = r.core.sessions.getByTheirAddr(&dest)
|
sinfo, isIn = r.core.sessions.getByTheirAddr(&destAddr)
|
||||||
}
|
}
|
||||||
if snet.isValid() {
|
if destSnet.isValid() {
|
||||||
sinfo, isIn = r.core.sessions.getByTheirSubnet(&snet)
|
sinfo, isIn = r.core.sessions.getByTheirSubnet(&destSnet)
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case !isIn || !sinfo.init:
|
case !isIn || !sinfo.init:
|
||||||
|
Loading…
Reference in New Issue
Block a user