Skip to content

Commit

Permalink
fix: local peers display (#1323)
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
  • Loading branch information
hacdias authored Nov 20, 2019
1 parent f62372e commit b0f7792
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/bundles/peer-locations.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,6 @@ export const isPrivateAndNearby = (maddr, identity) => {
let isNearby = false
let addr

if (!publicIP) {
return { isPrivate, isNearby }
}

try {
addr = maddr.nodeAddress()
} catch (_) {
Expand All @@ -158,12 +154,14 @@ export const isPrivateAndNearby = (maddr, identity) => {
// none of the calls bellow for ip library should fail.
isPrivate = ip.isPrivate(addr.address)

if (ip.isV4Format(addr.address)) {
isNearby = ip.cidrSubnet(`${publicIP}/24`).contains(addr.address)
} else if (ip.isV6Format(addr.address)) {
isNearby = ip.cidrSubnet(`${publicIP}/48`).contains(addr.address) &&
!ip.cidrSubnet('fc00::/8').contains(addr.address)
// peerIP6 ∉ fc00::/8 to fix case of cjdns where IPs are not spatial allocated.
if (publicIP) {
if (ip.isV4Format(addr.address)) {
isNearby = ip.cidrSubnet(`${publicIP}/24`).contains(addr.address)
} else if (ip.isV6Format(addr.address)) {
isNearby = ip.cidrSubnet(`${publicIP}/48`).contains(addr.address) &&
!ip.cidrSubnet('fc00::/8').contains(addr.address)
// peerIP6 ∉ fc00::/8 to fix case of cjdns where IPs are not spatial allocated.
}
}

return { isPrivate, isNearby }
Expand Down

0 comments on commit b0f7792

Please sign in to comment.