Skip to content
This repository was archived by the owner on Sep 12, 2023. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: hopglass/node-respondd
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: freifunk-saar/node-respondd
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Jun 28, 2020

  1. Copy the full SHA
    fe828c7 View commit details
  2. Copy the full SHA
    2124253 View commit details
Showing with 48 additions and 31 deletions.
  1. +21 −18 bat-list-neighbours
  2. +27 −13 respondd
39 changes: 21 additions & 18 deletions bat-list-neighbours
Original file line number Diff line number Diff line change
@@ -4,30 +4,33 @@ const fs = require('fs')
const netIfaces = require('os').networkInterfaces()
const exec = require('child_process').execSync

var batIface = "bat0"
var batIfaces = ["bat0"]
try {
var c = JSON.parse(fs.readFileSync("./config.json")).bat_iface
if (c != null) batIface = c.replace(/[^A-Za-z0-9\-_\.]/g, '')
if (typeof c === "string") c = [c]
if (c) batIfaces = c.map(b => b.replace(/[^A-Za-z0-9\-_\.]/g, ''))
} catch (ignored) {
}

var res = {}
var origs = exec("batctl meshif " + batIface + " originators").toString().trim()
if (origs) {
origs = origs.split("\n")
origs.forEach((orig) => {
var mac = orig.substring(3,20)
if (orig.substring(39,56) != mac) return
var lastSeen = parseFloat(orig.substring(21,29).trim())
var tq = parseInt(orig.substring(34,37).trim())
var iface = orig.split('[')[1].split(']')[0].trim()
var mac2 = netIfaces[iface][0].mac
if (!(mac2 in res)) res[mac2] = {"neighbours": {}}
res[mac2].neighbours[mac] = {
"tq": tq,
"lastseen": lastSeen
}
})
for(const batIface of batIfaces) {
var origs = exec("batctl meshif " + batIface + " originators").toString().trim()
if (origs) {
origs = origs.split("\n")
origs.forEach((orig) => {
var mac = orig.substring(3,20)
if (orig.substring(39,56) != mac) return
var lastSeen = parseFloat(orig.substring(21,29).trim())
var tq = parseInt(orig.substring(34,37).trim())
var iface = orig.split('[')[1].split(']')[0].trim()
var mac2 = netIfaces[iface][0].mac
if (!(mac2 in res)) res[mac2] = {"neighbours": {}}
res[mac2].neighbours[mac] = {
"tq": tq,
"lastseen": lastSeen
}
})
}
}

console.log(JSON.stringify(res))
40 changes: 27 additions & 13 deletions respondd
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@ const process = require('child_process')
const myproc = require('process')

const defConfig = {
"bat_iface": "bat0",
"bat_iface": ["bat0"],
"mcast_group": "ff02::2:1001",
"mcast_iface": "bat0",
"port": "1001",
@@ -74,7 +74,7 @@ function getV6AddrForInterface(iface) {
try {
return os.networkInterfaces()[iface].filter((a) => a.family == "IPv6").map((a) => a.address)
} catch (e) {
return undefined
return []
}
}

@@ -105,7 +105,13 @@ function getFileContents(name) {
function getTrafficStats() {
try {
var res = {}
var vs = evalExec("/sbin/ethtool -S " + getConfig("bat_iface") + " | head -n 12 | tail -n 11").split("\n")
var vs = getConfig("bat_iface").flatMap((b) => {
try {
return evalExec("/sbin/ethtool -S " + b + " | head -n 12 | tail -n 11").split("\n")
} catch (e) {
return []
}
})
vs.forEach((v) => {
var x = v.split(": ")
var group = x[0].trim()
@@ -129,15 +135,18 @@ function getTrafficStats() {
}

function getMeshAddresses() {
var bat = getConfig("bat_iface")
var data = {
"interfaces": {
"tunnel": evalExec("cat /sys/class/net/"+bat+"/lower_*/address").split("\n"),
"other": [getPrimaryMac()]
}
}
var res = {}
res[bat] = data
getConfig("bat_iface").forEach((b) => {
try {
var data = {
"interfaces": {
"tunnel": evalExec("cat /sys/class/net/"+b+"/lower_*/address").split("\n"),
"other": [getPrimaryMac()]
}
}
res[b] = data
} catch (ignored) {}
})
return res
}

@@ -180,9 +189,14 @@ try {
}

function getConfig(opt) {
if (opt == "listen")
if (opt in config) {
const c = config[opt]
if (opt === "bat_iface" && typeof c === "string") return [c]
return c
}
if (opt == "listen") {
return getV6AddrForInterface(getConfig("mcast_iface")).filter((a) => a.startsWith("fe80:"))[0] + "%" + getConfig("mcast_iface")
if (opt in config) return config[opt]
}
if (opt == "hostname") return os.hostname()
else return defConfig[opt]
}