-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
182 additions
and
70 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
# how ofter the cache respond of a respondd request is calculated | ||
data_interval = "3m" | ||
|
||
# if set true, respond will contain data from batman interface | ||
multi_instance = false | ||
interfaces = [ "wlp4s0" ] | ||
|
||
[[listen]] | ||
address = "ff02::2:1001" | ||
address = "ff02::2:1001" | ||
interface = "" | ||
port = 1001 | ||
port = 1001 | ||
|
||
# manuelle data for respond | ||
[data.nodeinfo.location] | ||
latitude = 53.112446246 | ||
[defaults] | ||
node_id = "" | ||
hostname = "" | ||
site_code = "ffhb" | ||
domain_code = "" | ||
vpn = false | ||
|
||
[defaults.location] | ||
latitude = 53.112446246 | ||
longitude = 8.734087944 | ||
|
||
|
||
# if divergent configuration of defaults are wanted by respond on interface/zones example with bat0 | ||
[zones.bat0] | ||
node_id = "" | ||
hostname = "" |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package respondd | ||
|
||
import ( | ||
"io/ioutil" | ||
"strings" | ||
|
||
"github.com/FreifunkBremen/yanic/data" | ||
"github.com/FreifunkBremen/yanic/lib/duration" | ||
) | ||
|
||
func trim(s string) string { | ||
return strings.TrimSpace(strings.Trim(s, "\n")) | ||
} | ||
|
||
type Daemon struct { | ||
DataInterval duration.Duration `toml:"data_interval"` | ||
Listen []struct { | ||
Address string `toml:"address"` | ||
Interface string `toml:"interface"` | ||
Port int `toml:"port"` | ||
} `toml:"listen"` | ||
InterfacesBatman []string `toml:"interfaces_batman"` | ||
Interfaces []string `toml:"interfaces"` | ||
|
||
dataByInterface map[string]*data.ResponseData | ||
|
||
Answer *AnswerConfig `toml:"defaults"` | ||
AnswerByZones map[string]*AnswerConfig `toml:"zones"` | ||
} | ||
|
||
type AnswerConfig struct { | ||
NodeID string `toml:"node_id"` | ||
Hostname string `toml:"hostname"` | ||
SiteCode string `toml:"site_code"` | ||
DomainCode string `toml:"domain_code"` | ||
Location *data.Location `json:"location,omitempty"` | ||
VPN bool `toml:"vpn"` | ||
} | ||
|
||
func (d *Daemon) getAnswer(iface string) (*AnswerConfig, string) { | ||
config := d.Answer | ||
if v, ok := d.AnswerByZones[iface]; iface == "" && ok { | ||
config = v | ||
} | ||
|
||
nodeID := config.NodeID | ||
if nodeID == "" { | ||
if v, err := ioutil.ReadFile("/etc/machine-id"); err == nil { | ||
nodeID = trim(string(v))[:12] | ||
} | ||
} | ||
return config, nodeID | ||
} |
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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package respondd | ||
|
||
import ( | ||
"github.com/FreifunkBremen/yanic/data" | ||
) | ||
|
||
func (d *Daemon) updateNeighbours(iface string, data *data.ResponseData) { | ||
_, nodeID := d.getAnswer(iface) | ||
data.Neighbours.NodeID = nodeID | ||
} |
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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package respondd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"runtime" | ||
"net" | ||
|
||
"github.com/FreifunkBremen/yanic/data" | ||
) | ||
|
||
func (d *Daemon) updateNodeinfo(iface string, data *data.ResponseData) { | ||
config, nodeID := d.getAnswer(iface) | ||
data.Nodeinfo.NodeID = nodeID | ||
|
||
if config.Hostname == "" { | ||
data.Nodeinfo.Hostname, _ = os.Hostname() | ||
} else { | ||
data.Nodeinfo.Hostname = config.Hostname | ||
} | ||
|
||
data.Nodeinfo.VPN = config.VPN | ||
data.Nodeinfo.Location = config.Location | ||
|
||
data.Nodeinfo.System.SiteCode = config.SiteCode | ||
data.Nodeinfo.System.DomainCode = config.DomainCode | ||
|
||
data.Nodeinfo.Hardware.Nproc = runtime.NumCPU() | ||
|
||
if data.Nodeinfo.Network.Mac == "" { | ||
data.Nodeinfo.Network.Mac = fmt.Sprintf("%s:%s:%s:%s:%s:%s", nodeID[0:2], nodeID[2:4], nodeID[4:6], nodeID[6:8], nodeID[8:10], nodeID[10:12]) | ||
} | ||
|
||
if iface == "" { | ||
data.Nodeinfo.Network.Addresses = []string{} | ||
for _, i := range d.Interfaces { | ||
addrs := getAddresses(i) | ||
data.Nodeinfo.Network.Addresses = append(data.Nodeinfo.Network.Addresses, addrs...) | ||
} | ||
} else { | ||
data.Nodeinfo.Network.Addresses = getAddresses(iface) | ||
} | ||
} | ||
|
||
func getAddresses(iface string) (addrs []string) { | ||
in, err := net.InterfaceByName(iface) | ||
if err != nil { | ||
return | ||
} | ||
inAddrs, err := in.Addrs() | ||
if err != nil { | ||
return | ||
} | ||
for _, a := range inAddrs { | ||
var ip net.IP | ||
switch v := a.(type) { | ||
case *net.IPNet: | ||
ip = v.IP | ||
case *net.IPAddr: | ||
ip = v.IP | ||
default: | ||
continue | ||
} | ||
if ip4 := ip.To4(); ip4 == nil { | ||
addrs = append(addrs, ip.String()) | ||
} | ||
} | ||
return | ||
} |
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package respondd | ||
|
||
import ( | ||
"github.com/shirou/gopsutil/host" | ||
|
||
"github.com/FreifunkBremen/yanic/data" | ||
) | ||
|
||
func (d *Daemon) updateStatistics(iface string, data *data.ResponseData) { | ||
_, nodeID := d.getAnswer(iface) | ||
data.Statistics.NodeID = nodeID | ||
if uptime, err := host.Uptime(); err == nil { | ||
data.Statistics.Uptime = float64(uptime) | ||
} | ||
} |