Compare commits
	
		
			1 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
						 | 
					438425c872 | 
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@ -25,4 +25,3 @@ _testmain.go
 | 
			
		||||
webroot
 | 
			
		||||
/config.toml
 | 
			
		||||
/vendor
 | 
			
		||||
/bin
 | 
			
		||||
@ -6,7 +6,7 @@ stages:
 | 
			
		||||
before_script:
 | 
			
		||||
  - curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
 | 
			
		||||
  - mkdir -p /go/src/github.com/FreifunkBremen/
 | 
			
		||||
  - cp -R /builds/freifunkbremen/yanic /go/src/github.com/FreifunkBremen/yanic
 | 
			
		||||
  - cp -R /builds/FreifunkBremen/yanic /go/src/github.com/FreifunkBremen/yanic
 | 
			
		||||
  - cd /go/src/github.com/FreifunkBremen/yanic
 | 
			
		||||
  - dep ensure
 | 
			
		||||
 | 
			
		||||
@ -14,13 +14,9 @@ build-my-project:
 | 
			
		||||
  stage: build
 | 
			
		||||
  script:
 | 
			
		||||
    - go install -ldflags "-X github.com/FreifunkBremen/yanic/cmd.VERSION=`git -C $GOPATH/src/github.com/FreifunkBremen/yanic rev-parse HEAD`" github.com/FreifunkBremen/yanic
 | 
			
		||||
    - mkdir /builds/freifunkbremen/yanic/bin/
 | 
			
		||||
    - cp /go/bin/yanic /builds/freifunkbremen/yanic/bin/yanic
 | 
			
		||||
  artifacts:
 | 
			
		||||
    paths:
 | 
			
		||||
      - bin/yanic
 | 
			
		||||
      - config_example.toml
 | 
			
		||||
      - config-respondd_example.toml
 | 
			
		||||
      - /go/bin/yanic
 | 
			
		||||
 | 
			
		||||
test-my-project:
 | 
			
		||||
  stage: test
 | 
			
		||||
@ -28,7 +24,6 @@ test-my-project:
 | 
			
		||||
    - ./.circleci/check-gofmt
 | 
			
		||||
    - ./.circleci/check-testfiles
 | 
			
		||||
    - go test $(go list ./... | grep -v /vendor/) -v -coverprofile .testCoverage.txt
 | 
			
		||||
    - go tool cover -func=.testCoverage.txt
 | 
			
		||||
 | 
			
		||||
test-race-my-project:
 | 
			
		||||
  stage: test
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										117
									
								
								Gopkg.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										117
									
								
								Gopkg.lock
									
									
									
										generated
									
									
									
								
							@ -2,166 +2,87 @@
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:af6e785bedb62fc2abb81977c58a7a44e5cf9f7e41b8d3c8dd4d872edea0ce08"
 | 
			
		||||
  name = "github.com/NYTimes/gziphandler"
 | 
			
		||||
  packages = ["."]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "dd0439581c7657cb652dfe5c71d7d48baf39541d"
 | 
			
		||||
  version = "v1.1.1"
 | 
			
		||||
  revision = "2600fb119af974220d3916a5916d6e31176aac1b"
 | 
			
		||||
  version = "v1.0.1"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:616fe3fc0d5eb7b89324dc5e47aef8cf05f3b0aed0bfe908e62516da4c638647"
 | 
			
		||||
  name = "github.com/bdlm/log"
 | 
			
		||||
  packages = ["."]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "b8b76dd35f1d7fdf6a49497c8ac22e6554efffed"
 | 
			
		||||
  version = "v0.1.18"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  branch = "master"
 | 
			
		||||
  digest = "1:9da00d14e7f20473d129be028aa99a2f47859aed17e58cd24c5108df76ad3959"
 | 
			
		||||
  name = "github.com/bdlm/std"
 | 
			
		||||
  packages = ["logger"]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "fd3b596111c78b7d14f1e1308ebdb1153013f1a8"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:ffe9824d294da03b391f44e1ae8281281b4afc1bdaa9588c9097785e3af10cec"
 | 
			
		||||
  name = "github.com/davecgh/go-spew"
 | 
			
		||||
  packages = ["spew"]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "8991bc29aa16c548c550c7ff78260e27b9ab7c73"
 | 
			
		||||
  version = "v1.1.1"
 | 
			
		||||
  revision = "346938d642f2ec3594ed81d874461961cd0faa76"
 | 
			
		||||
  version = "v1.1.0"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:6bea4bd16434bc6699590ed025152b690d08f552eeabfdc3258bd3aff738958c"
 | 
			
		||||
  name = "github.com/fgrosse/graphigo"
 | 
			
		||||
  packages = ["."]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "55a0a92a703041a55ad5ee2c2647f9577a87fdc1"
 | 
			
		||||
  version = "v2"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:870d441fe217b8e689d7949fef6e43efbc787e50f200cb1e70dbca9204a1d6be"
 | 
			
		||||
  name = "github.com/inconshreveable/mousetrap"
 | 
			
		||||
  packages = ["."]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "76626ae9c91c4f2a10f34cad8ce83ea42c93bb75"
 | 
			
		||||
  version = "v1.0"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  branch = "master"
 | 
			
		||||
  digest = "1:50708c8fc92aec981df5c446581cf9f90ba9e2a5692118e0ce75d4534aaa14a2"
 | 
			
		||||
  name = "github.com/influxdata/influxdb1-client"
 | 
			
		||||
  name = "github.com/influxdata/influxdb"
 | 
			
		||||
  packages = [
 | 
			
		||||
    "client/v2",
 | 
			
		||||
    "models",
 | 
			
		||||
    "pkg/escape",
 | 
			
		||||
    "v2",
 | 
			
		||||
    "pkg/escape"
 | 
			
		||||
  ]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "8ff2fc3824fcb533795f9a2f233275f0bb18d6c5"
 | 
			
		||||
  revision = "02d7d4f043b34ecb4e9b2dbec298c6f9450c2a32"
 | 
			
		||||
  version = "v1.5.2"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:b56c589214f01a5601e0821387db484617392d0042f26234bf2da853a2f498a1"
 | 
			
		||||
  name = "github.com/naoina/go-stringutil"
 | 
			
		||||
  packages = ["."]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "6b638e95a32d0c1131db0e7fe83775cbea4a0d0b"
 | 
			
		||||
  version = "v0.1.0"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:f58c3d0e46b64878d00652fedba24ee879725191ab919dca7b62586859281c04"
 | 
			
		||||
  name = "github.com/naoina/toml"
 | 
			
		||||
  packages = [
 | 
			
		||||
    ".",
 | 
			
		||||
    "ast",
 | 
			
		||||
    "ast"
 | 
			
		||||
  ]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "e6f5723bf2a66af014955e0888881314cf294129"
 | 
			
		||||
  version = "v0.1.1"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:36cfc0b6facbc68c92a4d55f32eff22b872a899ab75c384ac24a08dd33bc1380"
 | 
			
		||||
  name = "github.com/paulmach/go.geojson"
 | 
			
		||||
  packages = ["."]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "a5c451da2d9c67c590ae6be92565b67698286a1a"
 | 
			
		||||
  version = "v1.4"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:cf31692c14422fa27c83a05292eb5cbe0fb2775972e8f1f8446a71549bd8980b"
 | 
			
		||||
  name = "github.com/pkg/errors"
 | 
			
		||||
  packages = ["."]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "ba968bfe8b2f7e042a574c888954fccecfa385b4"
 | 
			
		||||
  version = "v0.8.1"
 | 
			
		||||
  revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
 | 
			
		||||
  version = "v0.8.0"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:0028cb19b2e4c3112225cd871870f2d9cf49b9b4276531f03438a88e94be86fe"
 | 
			
		||||
  name = "github.com/pmezard/go-difflib"
 | 
			
		||||
  packages = ["difflib"]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "792786c7400a136282c1664665ae0a8db921c6c2"
 | 
			
		||||
  version = "v1.0.0"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:22799aea8fe96dd5693abdd1eaa14b1b29e3eafbdc7733fa155b3cb556c8a7ae"
 | 
			
		||||
  name = "github.com/spf13/cobra"
 | 
			
		||||
  packages = ["."]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "67fc4837d267bc9bfd6e47f77783fcc3dffc68de"
 | 
			
		||||
  version = "v0.0.4"
 | 
			
		||||
  revision = "a1f051bc3eba734da4772d60e2d677f47cf93ef4"
 | 
			
		||||
  version = "v0.0.2"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:c1b1102241e7f645bc8e0c22ae352e8f0dc6484b6cb4d132fa9f24174e0119e2"
 | 
			
		||||
  name = "github.com/spf13/pflag"
 | 
			
		||||
  packages = ["."]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "298182f68c66c05229eb03ac171abe6e309ee79a"
 | 
			
		||||
  version = "v1.0.3"
 | 
			
		||||
  revision = "583c0c0531f06d5278b7d917446061adc344b5cd"
 | 
			
		||||
  version = "v1.0.1"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  digest = "1:972c2427413d41a1e06ca4897e8528e5a1622894050e2f527b38ddf0f343f759"
 | 
			
		||||
  name = "github.com/stretchr/testify"
 | 
			
		||||
  packages = ["assert"]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "ffdc059bfe9ce6a4e144ba849dbedead332c6053"
 | 
			
		||||
  version = "v1.3.0"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  branch = "master"
 | 
			
		||||
  digest = "1:bbe51412d9915d64ffaa96b51d409e070665efc5194fcf145c4a27d4133107a4"
 | 
			
		||||
  name = "golang.org/x/crypto"
 | 
			
		||||
  packages = ["ssh/terminal"]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "22d7a77e9e5f409e934ed268692e56707cd169e5"
 | 
			
		||||
 | 
			
		||||
[[projects]]
 | 
			
		||||
  branch = "master"
 | 
			
		||||
  digest = "1:160e165ef13917405d1ebfde865cb9c292b8635f83655e3932662d5586d300ee"
 | 
			
		||||
  name = "golang.org/x/sys"
 | 
			
		||||
  packages = [
 | 
			
		||||
    "unix",
 | 
			
		||||
    "windows",
 | 
			
		||||
  ]
 | 
			
		||||
  pruneopts = "UT"
 | 
			
		||||
  revision = "c432e742b0af385916e013f6a34e9e73d139cf82"
 | 
			
		||||
  revision = "12b6f73e6084dad08a7c6e575284b177ecafbc71"
 | 
			
		||||
  version = "v1.2.1"
 | 
			
		||||
 | 
			
		||||
[solve-meta]
 | 
			
		||||
  analyzer-name = "dep"
 | 
			
		||||
  analyzer-version = 1
 | 
			
		||||
  input-imports = [
 | 
			
		||||
    "github.com/NYTimes/gziphandler",
 | 
			
		||||
    "github.com/bdlm/log",
 | 
			
		||||
    "github.com/bdlm/std/logger",
 | 
			
		||||
    "github.com/fgrosse/graphigo",
 | 
			
		||||
    "github.com/influxdata/influxdb1-client/models",
 | 
			
		||||
    "github.com/influxdata/influxdb1-client/v2",
 | 
			
		||||
    "github.com/naoina/toml",
 | 
			
		||||
    "github.com/paulmach/go.geojson",
 | 
			
		||||
    "github.com/pkg/errors",
 | 
			
		||||
    "github.com/spf13/cobra",
 | 
			
		||||
    "github.com/stretchr/testify/assert",
 | 
			
		||||
  ]
 | 
			
		||||
  inputs-digest = "fdc5af68ea0267bb24f1826cbc35358e22fc67f2eec5c7ebf91cb6392836a064"
 | 
			
		||||
  solver-name = "gps-cdcl"
 | 
			
		||||
  solver-version = 1
 | 
			
		||||
 | 
			
		||||
@ -33,6 +33,10 @@
 | 
			
		||||
  name = "github.com/fgrosse/graphigo"
 | 
			
		||||
  version = "2.0.0"
 | 
			
		||||
 | 
			
		||||
[[constraint]]
 | 
			
		||||
  name = "github.com/influxdata/influxdb"
 | 
			
		||||
  version = "1.5.2"
 | 
			
		||||
 | 
			
		||||
[[constraint]]
 | 
			
		||||
  name = "github.com/naoina/toml"
 | 
			
		||||
  version = "0.1.1"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										10
									
								
								INSTALL.md
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								INSTALL.md
									
									
									
									
									
								
							@ -5,7 +5,7 @@
 | 
			
		||||
### Install
 | 
			
		||||
```sh
 | 
			
		||||
cd /usr/local/
 | 
			
		||||
wget https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz -O go-release-linux-amd64.tar.gz
 | 
			
		||||
wget https://storage.googleapis.com/golang/go1.9.1.linux-amd64.tar.gz -O go-release-linux-amd64.tar.gz
 | 
			
		||||
tar xvf go-release-linux-amd64.tar.gz
 | 
			
		||||
rm go-release-linux-amd64.tar.gz
 | 
			
		||||
```
 | 
			
		||||
@ -62,15 +62,7 @@ the same directory as the `dataPath`. Change the path in the section
 | 
			
		||||
```sh
 | 
			
		||||
cp /opt/go/src/github.com/FreifunkBremen/yanic/contrib/init/linux-systemd/yanic.service /lib/systemd/system/yanic.service
 | 
			
		||||
systemctl daemon-reload
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Before start, you should configure yanic by the file `/etc/yanic.conf`:
 | 
			
		||||
```sh
 | 
			
		||||
systemctl start yanic
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Enable to start on boot:
 | 
			
		||||
```sh
 | 
			
		||||
systemctl enable yanic
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										66
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										66
									
								
								README.md
									
									
									
									
									
								
							@ -19,25 +19,25 @@ Yet another node info collector
 | 
			
		||||
* Provide a little webserver for a standalone installation with a meshviewer
 | 
			
		||||
 | 
			
		||||
## How it works
 | 
			
		||||
In the first step Yanic sends a multicast message to the group `ff05::2:1001` and port `1001`.
 | 
			
		||||
 | 
			
		||||
In the first step Yanic sends a multicast message to the group `ff02:0:0:0:0:0:2:1001` and port `1001`.
 | 
			
		||||
Recently seen nodes that does not reply are requested via a unicast message.
 | 
			
		||||
 | 
			
		||||
## Documentation
 | 
			
		||||
Take a look at the [git](https://github.com/FreifunkBremen/yanic/blob/master/SUMMARY.md) or [Gitbook](https://freifunkbremen.gitbooks.io/yanic/content/)
 | 
			
		||||
 | 
			
		||||
# Installation
 | 
			
		||||
Take a look into the Documentation (see above) or for Quick Overview in [INSTALL.md](INSTALL.md).
 | 
			
		||||
 | 
			
		||||
If you like Docker you may want to take a look [here](https://github.com/christf/docker-yanic).
 | 
			
		||||
 | 
			
		||||
## Configuration
 | 
			
		||||
Read comments in [config_example.toml](config_example.toml) for more information.
 | 
			
		||||
 | 
			
		||||
## Running
 | 
			
		||||
 | 
			
		||||
Yanic provides several commands:
 | 
			
		||||
 | 
			
		||||
### Usage
 | 
			
		||||
 | 
			
		||||
Run Yanic without any arguments to get the usage information:
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
Usage:
 | 
			
		||||
  yanic [command]
 | 
			
		||||
@ -50,71 +50,57 @@ Available Commands:
 | 
			
		||||
 | 
			
		||||
Flags:
 | 
			
		||||
  -h, --help         help for yanic
 | 
			
		||||
      --loglevel uint32   Show log message starting at level (default 40)
 | 
			
		||||
      --timestamps   Enables timestamps for log output
 | 
			
		||||
 | 
			
		||||
Use "yanic [command] --help" for more information about a command.
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
#### Serve
 | 
			
		||||
Runs the yanic server
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
Usage:
 | 
			
		||||
  yanic serve [flags]
 | 
			
		||||
 | 
			
		||||
Examples:
 | 
			
		||||
yanic serve --config /etc/yanic.toml
 | 
			
		||||
  yanic serve --config /etc/yanic.toml
 | 
			
		||||
 | 
			
		||||
Flags:
 | 
			
		||||
  -c, --config string   Path to configuration file (default "config.toml")
 | 
			
		||||
  -h, --help            help for serve
 | 
			
		||||
 | 
			
		||||
Global Flags:
 | 
			
		||||
      --loglevel uint32   Show log message starting at level (default 40)
 | 
			
		||||
      --timestamps        Enables timestamps for log output
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
#### Query
 | 
			
		||||
Sends a query on the interface to the destination and waits for a response
 | 
			
		||||
```
 | 
			
		||||
Usage:
 | 
			
		||||
  yanic query <interfaces> <destination> [flags]
 | 
			
		||||
 | 
			
		||||
Examples:
 | 
			
		||||
yanic query "eth0,wlan0" "fe80::eade:27ff:dead:beef"
 | 
			
		||||
 | 
			
		||||
Flags:
 | 
			
		||||
  -h, --help        help for query
 | 
			
		||||
      --ip string   ip address which is used for sending (optional - without definition used the link-local address)
 | 
			
		||||
      --port int    define a port to listen (if not set or set to 0 the kernel will use a random free port at its own)
 | 
			
		||||
      --wait int    Seconds to wait for a response (default 1)
 | 
			
		||||
 | 
			
		||||
Global Flags:
 | 
			
		||||
      --loglevel uint32   Show log message starting at level (default 40)
 | 
			
		||||
      --timestamps        Enables timestamps for log output
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
#### Import
 | 
			
		||||
Imports global statistics from the given RRD files (ffmap-backend).
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
Usage:
 | 
			
		||||
  yanic import <file.rrd> <site> <domain> [flags]
 | 
			
		||||
  yanic import <file.rrd> [flags]
 | 
			
		||||
 | 
			
		||||
Examples:
 | 
			
		||||
yanic import --config /etc/yanic.toml olddata.rrd global global
 | 
			
		||||
  yanic import --config /etc/yanic.toml olddata.rrd
 | 
			
		||||
 | 
			
		||||
Flags:
 | 
			
		||||
  -c, --config string   Path to configuration file (default "config.toml")
 | 
			
		||||
  -h, --help            help for import
 | 
			
		||||
 | 
			
		||||
Global Flags:
 | 
			
		||||
      --loglevel uint32   Show log message starting at level (default 40)
 | 
			
		||||
      --timestamps        Enables timestamps for log output
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#### Query
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
Usage:
 | 
			
		||||
  yanic query <interface> <destination> [flags]
 | 
			
		||||
 | 
			
		||||
Examples:
 | 
			
		||||
  yanic query wlan0 "fe80::eade:27ff:dead:beef"
 | 
			
		||||
 | 
			
		||||
Flags:
 | 
			
		||||
  -h, --help       help for query
 | 
			
		||||
      --wait int   Seconds to wait for a response (default 1)
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## Communities using Yanic
 | 
			
		||||
 | 
			
		||||
* **Freifunk Bremen** uses InfluxDB, [Grafana](https://grafana.bremen.freifunk.net), and [Meshviewer](https://map.bremen.freifunk.net) with a patch to show state-version of `nodes.json`. 
 | 
			
		||||
* **Freifunk Nord** uses [hopglass](https://github.com/hopglass/hopglass) (commit 587740a) as frontend:  https://mesh.freifunknord.de/
 | 
			
		||||
* **Freifunk Kiel** uses [Meshviewer](https://github.com/ffrgb/meshviewer/) as frontend: https://map.freifunk.in-kiel.de/
 | 
			
		||||
@ -122,6 +108,7 @@ Global Flags:
 | 
			
		||||
Do you know someone else using Yanic? Create a [pull request](https://github.com/FreifunkBremen/yanic/issues/new?template=community.md&title=Mention+community+$name)!
 | 
			
		||||
 | 
			
		||||
## Related projects
 | 
			
		||||
 | 
			
		||||
Collecting data from respondd:
 | 
			
		||||
* [HopGlass Server](https://github.com/plumpudding/hopglass-server) written in Node.js
 | 
			
		||||
 | 
			
		||||
@ -131,4 +118,5 @@ Respondd for servers:
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## License
 | 
			
		||||
 | 
			
		||||
This software is licensed under the terms of the [AGPL v3 License](LICENSE).
 | 
			
		||||
 | 
			
		||||
@ -5,12 +5,11 @@ import (
 | 
			
		||||
	"io/ioutil"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"github.com/naoina/toml"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/database"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/respond"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/webserver"
 | 
			
		||||
	"github.com/naoina/toml"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Config represents the whole configuration
 | 
			
		||||
 | 
			
		||||
@ -25,7 +25,7 @@ func TestReadConfig(t *testing.T) {
 | 
			
		||||
	assert.Contains(config.Respondd.Sites["ffhb"].Domains, "city")
 | 
			
		||||
 | 
			
		||||
	// Test output plugins
 | 
			
		||||
	assert.Len(config.Nodes.Output, 4)
 | 
			
		||||
	assert.Len(config.Nodes.Output, 3)
 | 
			
		||||
	outputs := config.Nodes.Output["meshviewer"].([]interface{})
 | 
			
		||||
	assert.Len(outputs, 1)
 | 
			
		||||
	meshviewer := outputs[0]
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,12 @@
 | 
			
		||||
package cmd
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	allDatabase "github.com/FreifunkBremen/yanic/database/all"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/rrd"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// importCmd represents the import command
 | 
			
		||||
@ -23,11 +23,11 @@ var importCmd = &cobra.Command{
 | 
			
		||||
 | 
			
		||||
		err := allDatabase.Start(config.Database)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Panicf("could not connect to database: %s", err)
 | 
			
		||||
			panic(err)
 | 
			
		||||
		}
 | 
			
		||||
		defer allDatabase.Close()
 | 
			
		||||
 | 
			
		||||
		log.Infof("importing RRD from %s", path)
 | 
			
		||||
		log.Println("importing RRD from", path)
 | 
			
		||||
 | 
			
		||||
		for ds := range rrd.Read(path) {
 | 
			
		||||
			allDatabase.Conn.InsertGlobals(
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										17
									
								
								cmd/query.go
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								cmd/query.go
									
									
									
									
									
								
							@ -2,16 +2,14 @@ package cmd
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/respond"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
@ -30,10 +28,7 @@ var queryCmd = &cobra.Command{
 | 
			
		||||
		ifaces := strings.Split(args[0], ",")
 | 
			
		||||
		dstAddress := net.ParseIP(args[1])
 | 
			
		||||
 | 
			
		||||
		log.WithFields(map[string]interface{}{
 | 
			
		||||
			"address": dstAddress,
 | 
			
		||||
			"ifaces":  ifaces,
 | 
			
		||||
		}).Info("sending request")
 | 
			
		||||
		log.Printf("Sending request address=%s ifaces=%s", dstAddress, ifaces)
 | 
			
		||||
 | 
			
		||||
		var ifacesConfigs []respond.InterfaceConfig
 | 
			
		||||
		for _, iface := range ifaces {
 | 
			
		||||
@ -57,13 +52,13 @@ var queryCmd = &cobra.Command{
 | 
			
		||||
		for id, data := range nodes.List {
 | 
			
		||||
			jq, err := json.Marshal(data)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				fmt.Printf("%s: %+v", id, data)
 | 
			
		||||
				log.Printf("%s: %+v", id, data)
 | 
			
		||||
			} else {
 | 
			
		||||
				jqNeighbours, err := json.Marshal(data.Neighbours)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					fmt.Printf("%s: %s neighbours: %+v", id, string(jq), data.Neighbours)
 | 
			
		||||
					log.Printf("%s: %s neighbours: %+v", id, string(jq), data.Neighbours)
 | 
			
		||||
				} else {
 | 
			
		||||
					fmt.Printf("%s: %s neighbours: %s", id, string(jq), string(jqNeighbours))
 | 
			
		||||
					log.Printf("%s: %s neighbours: %s", id, string(jq), string(jqNeighbours))
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								cmd/root.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								cmd/root.go
									
									
									
									
									
								
							@ -2,16 +2,14 @@ package cmd
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
	"github.com/bdlm/std/logger"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	timestamps bool
 | 
			
		||||
	loglevel   uint32
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// RootCmd represents the base command when called without any subcommands
 | 
			
		||||
@ -37,12 +35,12 @@ func init() {
 | 
			
		||||
	// Cobra supports persistent flags, which, if defined here,
 | 
			
		||||
	// will be global for your application.
 | 
			
		||||
	RootCmd.PersistentFlags().BoolVar(×tamps, "timestamps", false, "Enables timestamps for log output")
 | 
			
		||||
	RootCmd.PersistentFlags().Uint32Var(&loglevel, "loglevel", 40, "Show log message starting at level")
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func initConfig() {
 | 
			
		||||
	log.SetLevel(logger.Level(loglevel))
 | 
			
		||||
	log.SetFormatter(&log.TextFormatter{
 | 
			
		||||
		DisableTimestamp: timestamps,
 | 
			
		||||
	})
 | 
			
		||||
	if timestamps {
 | 
			
		||||
		log.SetFlags(log.Lshortfile)
 | 
			
		||||
	} else {
 | 
			
		||||
		log.SetFlags(log.LstdFlags | log.Lshortfile)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										15
									
								
								cmd/serve.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								cmd/serve.go
									
									
									
									
									
								
							@ -1,19 +1,18 @@
 | 
			
		||||
package cmd
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
	"os"
 | 
			
		||||
	"os/signal"
 | 
			
		||||
	"syscall"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
 | 
			
		||||
	allDatabase "github.com/FreifunkBremen/yanic/database/all"
 | 
			
		||||
	allOutput "github.com/FreifunkBremen/yanic/output/all"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/respond"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/webserver"
 | 
			
		||||
	"github.com/spf13/cobra"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// serveCmd represents the serve command
 | 
			
		||||
@ -26,7 +25,7 @@ var serveCmd = &cobra.Command{
 | 
			
		||||
 | 
			
		||||
		err := allDatabase.Start(config.Database)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Panicf("could not connect to database: %s", err)
 | 
			
		||||
			panic(err)
 | 
			
		||||
		}
 | 
			
		||||
		defer allDatabase.Close()
 | 
			
		||||
 | 
			
		||||
@ -35,12 +34,12 @@ var serveCmd = &cobra.Command{
 | 
			
		||||
 | 
			
		||||
		err = allOutput.Start(nodes, config.Nodes)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.Panicf("error on init outputs: %s", err)
 | 
			
		||||
			panic(err)
 | 
			
		||||
		}
 | 
			
		||||
		defer allOutput.Close()
 | 
			
		||||
 | 
			
		||||
		if config.Webserver.Enable {
 | 
			
		||||
			log.Infof("starting webserver on %s", config.Webserver.Bind)
 | 
			
		||||
			log.Println("starting webserver on", config.Webserver.Bind)
 | 
			
		||||
			srv := webserver.New(config.Webserver.Bind, config.Webserver.Webroot)
 | 
			
		||||
			go webserver.Start(srv)
 | 
			
		||||
			defer srv.Close()
 | 
			
		||||
@ -51,7 +50,7 @@ var serveCmd = &cobra.Command{
 | 
			
		||||
			if duration := config.Respondd.Synchronize.Duration; duration > 0 {
 | 
			
		||||
				now := time.Now()
 | 
			
		||||
				delay := duration - now.Sub(now.Truncate(duration))
 | 
			
		||||
				log.Infof("delaying %0.1f seconds", delay.Seconds())
 | 
			
		||||
				log.Printf("delaying %0.1f seconds", delay.Seconds())
 | 
			
		||||
				time.Sleep(delay)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
@ -64,7 +63,7 @@ var serveCmd = &cobra.Command{
 | 
			
		||||
		sigs := make(chan os.Signal, 1)
 | 
			
		||||
		signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
 | 
			
		||||
		sig := <-sigs
 | 
			
		||||
		log.Infof("received %s", sig)
 | 
			
		||||
		log.Println("received", sig)
 | 
			
		||||
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,6 +1,6 @@
 | 
			
		||||
# This is the config file for Yanic written in "Tom's Obvious, Minimal Language."
 | 
			
		||||
# syntax: https://github.com/toml-lang/toml
 | 
			
		||||
# (if you need something multiple times, checkout out the [[array of table]] section)
 | 
			
		||||
# (if you need somethink multiple times, checkout out the [[array of table]] section)
 | 
			
		||||
 | 
			
		||||
# Send respondd request to update information
 | 
			
		||||
[respondd]
 | 
			
		||||
@ -23,14 +23,14 @@ domains            = ["city"]
 | 
			
		||||
# name of interface on which this collector is running
 | 
			
		||||
ifname = "br-ffhb"
 | 
			
		||||
# ip address which is used for sending
 | 
			
		||||
# (optional - without definition used a address of ifname - preferred link local)
 | 
			
		||||
# (optional - without definition used a address of ifname)
 | 
			
		||||
ip_address = "fd2f:5119:f2d::5"
 | 
			
		||||
# disable sending multicast respondd request
 | 
			
		||||
# (for receiving only respondd packages e.g. database respondd)
 | 
			
		||||
#send_no_request = false
 | 
			
		||||
# multicast address to destination of respondd
 | 
			
		||||
# (optional - without definition used default ff05::2:1001)
 | 
			
		||||
#multicast_address = "ff02::2:1001"
 | 
			
		||||
# (optional - without definition used batman default ff02::2:1001)
 | 
			
		||||
multicast_address = "ff05::2:1001"
 | 
			
		||||
# define a port to listen
 | 
			
		||||
# if not set or set to 0 the kernel will use a random free port at its own
 | 
			
		||||
#port = 10001
 | 
			
		||||
@ -93,11 +93,6 @@ offline_after = "10m"
 | 
			
		||||
#longitude_max = 39.72
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# outputs all nodes as points into nodes.geojson
 | 
			
		||||
[[nodes.output.geojson]]
 | 
			
		||||
enable   = true
 | 
			
		||||
path = "/var/www/html/meshviewer/data/nodes.geojson"
 | 
			
		||||
 | 
			
		||||
# definition for the new more compressed meshviewer.json
 | 
			
		||||
[[nodes.output.meshviewer-ffrgb]]
 | 
			
		||||
enable   = true
 | 
			
		||||
 | 
			
		||||
@ -1,7 +1,7 @@
 | 
			
		||||
package data
 | 
			
		||||
 | 
			
		||||
// Nodeinfo struct
 | 
			
		||||
type Nodeinfo struct {
 | 
			
		||||
// NodeInfo struct
 | 
			
		||||
type NodeInfo struct {
 | 
			
		||||
	NodeID   string            `json:"node_id"`
 | 
			
		||||
	Network  Network           `json:"network"`
 | 
			
		||||
	Owner    *Owner            `json:"owner"`
 | 
			
		||||
@ -12,6 +12,7 @@ type Nodeinfo struct {
 | 
			
		||||
	Hardware Hardware          `json:"hardware"`
 | 
			
		||||
	VPN      bool              `json:"vpn"`
 | 
			
		||||
	Wireless *Wireless         `json:"wireless,omitempty"`
 | 
			
		||||
	Wifictld *WifiCTLDNodeinfo `json:"wifictld,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NetworkInterface struct
 | 
			
		||||
 | 
			
		||||
@ -3,6 +3,6 @@ package data
 | 
			
		||||
// ResponseData struct
 | 
			
		||||
type ResponseData struct {
 | 
			
		||||
	Neighbours *Neighbours `json:"neighbours"`
 | 
			
		||||
	Nodeinfo   *Nodeinfo   `json:"nodeinfo"`
 | 
			
		||||
	NodeInfo   *NodeInfo   `json:"nodeinfo"`
 | 
			
		||||
	Statistics *Statistics `json:"statistics"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -32,6 +32,7 @@ type Statistics struct {
 | 
			
		||||
	} `json:"traffic,omitempty"`
 | 
			
		||||
	Switch    map[string]*SwitchPort `json:"switch,omitempty"`
 | 
			
		||||
	Wireless  WirelessStatistics     `json:"wireless,omitempty"`
 | 
			
		||||
	Wifictld *WifiCTLDStatistics     `json:"wifictld,omitempty"`
 | 
			
		||||
	ProcStats *ProcStats             `json:"stat,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										26
									
								
								data/wifictld.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										26
									
								
								data/wifictld.go
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,26 @@
 | 
			
		||||
package data
 | 
			
		||||
 | 
			
		||||
// WifiCTLDNodeinfo struct (defined in: https://chaos.expert/genofire/wifictld/blob/preview/wireless/wifictld/src/ubus_service.c - ubus_get_config)
 | 
			
		||||
type WifiCTLDNodeinfo struct {
 | 
			
		||||
	Verbose                uint8  `json:"verbose,omitempty"`
 | 
			
		||||
	ClientTryThreashold    uint32 `json:"client_try_threashold,omitempty"`
 | 
			
		||||
	ClientSignalThreashold int32  `json:"client_signal_threashold,omitempty"`
 | 
			
		||||
	ClientCleanEvery       uint32 `json:"client_clean_every,omitempty"`
 | 
			
		||||
	ClientCleanOlderThen   uint32 `json:"client_clean_older_then,omitempty"`
 | 
			
		||||
	ClientCleanAuthed      uint8  `json:"client_clean_authed,omitempty"`
 | 
			
		||||
	ClientForce            uint8  `json:"client_force,omitempty"`
 | 
			
		||||
	ClientForceProbe       uint8  `json:"client_force_probe,omitempty"`
 | 
			
		||||
	ClientProbeSteering    uint8  `json:"client_probe_steering,omitempty"`
 | 
			
		||||
	ClientProbeLearning    uint8  `json:"client_probe_learning,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// WifiCTLDStatistics struct (defined in: https://chaos.expert/genofire/wifictld/blob/preview/wireless/respondd-module-wifictld/src/respondd.c - respondd_provider_statistics)
 | 
			
		||||
type WifiCTLDStatistics struct {
 | 
			
		||||
	Total           uint32 `json:"total,omitempty"`
 | 
			
		||||
	Client24        uint32 `json:"client24,omitempty"`
 | 
			
		||||
	Client5         uint32 `json:"client5,omitempty"`
 | 
			
		||||
	Authed          uint32 `json:"authed,omitempty"`
 | 
			
		||||
	Connected       uint32 `json:"connected,omitempty"`
 | 
			
		||||
	HighestTryProbe uint32 `json:"highest_try_probe,omitempty"`
 | 
			
		||||
	HighestTryAuth  uint32 `json:"highest_try_auth,omitempty"`
 | 
			
		||||
}
 | 
			
		||||
@ -2,10 +2,9 @@ package all
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/database"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
)
 | 
			
		||||
@ -20,7 +19,7 @@ func Connect(allConnection map[string]interface{}) (database.Connection, error)
 | 
			
		||||
	for dbType, conn := range database.Adapters {
 | 
			
		||||
		configForType := allConnection[dbType]
 | 
			
		||||
		if configForType == nil {
 | 
			
		||||
			log.WithField("database", dbType).Infof("no configuration found")
 | 
			
		||||
			log.Printf("the output type '%s' has no configuration", dbType)
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		dbConfigs, ok := configForType.([]interface{})
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,11 @@
 | 
			
		||||
package graphite
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
	"sync"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
	"github.com/fgrosse/graphigo"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/database"
 | 
			
		||||
	"github.com/fgrosse/graphigo"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
@ -70,7 +69,7 @@ func (c *Connection) addWorker() {
 | 
			
		||||
	for point := range c.points {
 | 
			
		||||
		err := c.client.SendAll(point)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.WithField("database", "graphite").Fatal(err)
 | 
			
		||||
			log.Fatal(err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -30,36 +30,25 @@ func (c *Connection) InsertNode(node *runtime.Node) {
 | 
			
		||||
		fields = append(fields, graphigo.Metric{Name: node_prefix + "." + name, Value: value})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	vpnInterfaces := make(map[string]bool)
 | 
			
		||||
	for _, mIface := range nodeinfo.Network.Mesh {
 | 
			
		||||
		for _, tunnel := range mIface.Interfaces.Tunnel {
 | 
			
		||||
			vpnInterfaces[tunnel] = true
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if neighbours := node.Neighbours; neighbours != nil {
 | 
			
		||||
		vpn := 0
 | 
			
		||||
 | 
			
		||||
		if meshvpn := stats.MeshVPN; meshvpn != nil {
 | 
			
		||||
			for _, group := range meshvpn.Groups {
 | 
			
		||||
				for _, link := range group.Peers {
 | 
			
		||||
					if link != nil && link.Established > 1 {
 | 
			
		||||
						vpn++
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		addField("neighbours.vpn", vpn)
 | 
			
		||||
		// protocol: Batman Advance
 | 
			
		||||
		batadv := 0
 | 
			
		||||
		for mac, batadvNeighbours := range neighbours.Batadv {
 | 
			
		||||
		for _, batadvNeighbours := range neighbours.Batadv {
 | 
			
		||||
			batadv += len(batadvNeighbours.Neighbours)
 | 
			
		||||
			if _, ok := vpnInterfaces[mac]; ok {
 | 
			
		||||
				vpn += len(batadvNeighbours.Neighbours)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		addField("neighbours.batadv", batadv)
 | 
			
		||||
 | 
			
		||||
		// protocol: Babel
 | 
			
		||||
		babel := 0
 | 
			
		||||
		for _, babelNeighbours := range neighbours.Babel {
 | 
			
		||||
			babel += len(babelNeighbours.Neighbours)
 | 
			
		||||
			if _, ok := vpnInterfaces[babelNeighbours.LinkLocalAddress]; ok {
 | 
			
		||||
				vpn += len(babelNeighbours.Neighbours)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		addField("neighbours.babel", babel)
 | 
			
		||||
 | 
			
		||||
		// protocol: LLDP
 | 
			
		||||
		lldp := 0
 | 
			
		||||
		for _, lldpNeighbours := range neighbours.LLDP {
 | 
			
		||||
@ -67,10 +56,8 @@ func (c *Connection) InsertNode(node *runtime.Node) {
 | 
			
		||||
		}
 | 
			
		||||
		addField("neighbours.lldp", lldp)
 | 
			
		||||
 | 
			
		||||
		addField("neighbours.vpn", vpn)
 | 
			
		||||
 | 
			
		||||
		// total is the sum of all protocols
 | 
			
		||||
		addField("neighbours.total", batadv+babel+lldp)
 | 
			
		||||
		addField("neighbours.total", batadv+lldp)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if t := stats.Traffic.Rx; t != nil {
 | 
			
		||||
 | 
			
		||||
@ -1,12 +1,12 @@
 | 
			
		||||
package influxdb
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"log"
 | 
			
		||||
	"sync"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
	"github.com/influxdata/influxdb1-client/models"
 | 
			
		||||
	"github.com/influxdata/influxdb1-client/v2"
 | 
			
		||||
	"github.com/influxdata/influxdb/client/v2"
 | 
			
		||||
	"github.com/influxdata/influxdb/models"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/database"
 | 
			
		||||
)
 | 
			
		||||
@ -100,16 +100,13 @@ func (conn *Connection) addPoint(name string, tags models.Tags, fields models.Fi
 | 
			
		||||
			if value, ok := valueInterface.(string); ok && tags.Get([]byte(tag)) == nil {
 | 
			
		||||
				tags.SetString(tag, value)
 | 
			
		||||
			} else {
 | 
			
		||||
				log.WithFields(map[string]interface{}{
 | 
			
		||||
					"name": name,
 | 
			
		||||
					"tag":  tag,
 | 
			
		||||
				}).Warnf("count not save tag configuration on point")
 | 
			
		||||
				log.Println(name, "could not saved configured value of tag", tag)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	point, err := client.NewPoint(name, tags.Map(), fields, t...)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Panicf("count not save points: %s", err)
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	conn.points <- point
 | 
			
		||||
}
 | 
			
		||||
@ -159,10 +156,10 @@ func (conn *Connection) addWorker() {
 | 
			
		||||
 | 
			
		||||
		// write batch now?
 | 
			
		||||
		if bp != nil && (writeNow || closed || len(bp.Points()) >= batchMaxSize) {
 | 
			
		||||
			log.WithField("count", len(bp.Points())).Info("saving points")
 | 
			
		||||
			log.Println("saving", len(bp.Points()), "points")
 | 
			
		||||
 | 
			
		||||
			if err = conn.client.Write(bp); err != nil {
 | 
			
		||||
				log.Error(err)
 | 
			
		||||
				log.Print(err)
 | 
			
		||||
			}
 | 
			
		||||
			writeNow = false
 | 
			
		||||
			bp = nil
 | 
			
		||||
 | 
			
		||||
@ -6,8 +6,8 @@ import (
 | 
			
		||||
	"testing"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/influxdata/influxdb1-client/models"
 | 
			
		||||
	"github.com/influxdata/influxdb1-client/v2"
 | 
			
		||||
	"github.com/influxdata/influxdb/client/v2"
 | 
			
		||||
	"github.com/influxdata/influxdb/models"
 | 
			
		||||
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@ import (
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
	"github.com/influxdata/influxdb1-client/models"
 | 
			
		||||
	"github.com/influxdata/influxdb/models"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// InsertGlobals implementation of database
 | 
			
		||||
 | 
			
		||||
@ -5,7 +5,7 @@ import (
 | 
			
		||||
	"testing"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/influxdata/influxdb1-client/v2"
 | 
			
		||||
	"github.com/influxdata/influxdb/client/v2"
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/data"
 | 
			
		||||
@ -124,7 +124,7 @@ func createTestNodes() *runtime.Nodes {
 | 
			
		||||
				Total: 23,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "abcdef012345",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 841",
 | 
			
		||||
@ -146,7 +146,7 @@ func createTestNodes() *runtime.Nodes {
 | 
			
		||||
				Total: 2,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "112233445566",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 841",
 | 
			
		||||
@ -156,7 +156,7 @@ func createTestNodes() *runtime.Nodes {
 | 
			
		||||
 | 
			
		||||
	nodes.AddNode(&runtime.Node{
 | 
			
		||||
		Online: true,
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "0xdeadbeef0x",
 | 
			
		||||
			VPN:    true,
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@ import (
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
	models "github.com/influxdata/influxdb1-client/models"
 | 
			
		||||
	models "github.com/influxdata/influxdb/models"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// InsertLink adds a link data point
 | 
			
		||||
 | 
			
		||||
@ -5,8 +5,8 @@ import (
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	models "github.com/influxdata/influxdb1-client/models"
 | 
			
		||||
	client "github.com/influxdata/influxdb1-client/v2"
 | 
			
		||||
	client "github.com/influxdata/influxdb/client/v2"
 | 
			
		||||
	models "github.com/influxdata/influxdb/models"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
)
 | 
			
		||||
@ -48,15 +48,7 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
 | 
			
		||||
		"memory.available": stats.Memory.Available,
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	vpnInterfaces := make(map[string]bool)
 | 
			
		||||
 | 
			
		||||
	if nodeinfo := node.Nodeinfo; nodeinfo != nil {
 | 
			
		||||
		for _, mIface := range nodeinfo.Network.Mesh {
 | 
			
		||||
			for _, tunnel := range mIface.Interfaces.Tunnel {
 | 
			
		||||
				vpnInterfaces[tunnel] = true
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		tags.SetString("hostname", nodeinfo.Hostname)
 | 
			
		||||
		if nodeinfo.System.SiteCode != "" {
 | 
			
		||||
			tags.SetString("site", nodeinfo.System.SiteCode)
 | 
			
		||||
@ -83,30 +75,28 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if neighbours := node.Neighbours; neighbours != nil {
 | 
			
		||||
		// VPN Neighbours are Neighbours but includet in one protocol
 | 
			
		||||
		vpn := 0
 | 
			
		||||
		if meshvpn := stats.MeshVPN; meshvpn != nil {
 | 
			
		||||
			for _, group := range meshvpn.Groups {
 | 
			
		||||
				for _, link := range group.Peers {
 | 
			
		||||
					if link != nil && link.Established > 1 {
 | 
			
		||||
						vpn++
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		fields["neighbours.vpn"] = vpn
 | 
			
		||||
 | 
			
		||||
		// protocol: Batman Advance
 | 
			
		||||
		batadv := 0
 | 
			
		||||
		for mac, batadvNeighbours := range neighbours.Batadv {
 | 
			
		||||
		for _, batadvNeighbours := range neighbours.Batadv {
 | 
			
		||||
			batadv += len(batadvNeighbours.Neighbours)
 | 
			
		||||
			if _, ok := vpnInterfaces[mac]; ok {
 | 
			
		||||
				vpn += len(batadvNeighbours.Neighbours)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		fields["neighbours.batadv"] = batadv
 | 
			
		||||
 | 
			
		||||
		// protocol: Babel
 | 
			
		||||
		babel := 0
 | 
			
		||||
		for _, babelNeighbours := range neighbours.Babel {
 | 
			
		||||
			babel += len(babelNeighbours.Neighbours)
 | 
			
		||||
			if _, ok := vpnInterfaces[babelNeighbours.LinkLocalAddress]; ok {
 | 
			
		||||
				vpn += len(babelNeighbours.Neighbours)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		fields["neighbours.babel"] = babel
 | 
			
		||||
 | 
			
		||||
		// protocol: LLDP
 | 
			
		||||
		lldp := 0
 | 
			
		||||
		for _, lldpNeighbours := range neighbours.LLDP {
 | 
			
		||||
@ -114,11 +104,8 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
 | 
			
		||||
		}
 | 
			
		||||
		fields["neighbours.lldp"] = lldp
 | 
			
		||||
 | 
			
		||||
		// vpn  wait for babel
 | 
			
		||||
		fields["neighbours.vpn"] = vpn
 | 
			
		||||
 | 
			
		||||
		// total is the sum of all protocols
 | 
			
		||||
		fields["neighbours.total"] = batadv + babel + lldp
 | 
			
		||||
		fields["neighbours.total"] = batadv + lldp
 | 
			
		||||
	}
 | 
			
		||||
	if procstat := stats.ProcStats; procstat != nil {
 | 
			
		||||
		fields["stat.cpu.user"] = procstat.CPU.User
 | 
			
		||||
@ -166,6 +153,17 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
 | 
			
		||||
		tags.SetString("frequency"+suffix, strconv.Itoa(int(airtime.Frequency)))
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Add Wifictld statistics
 | 
			
		||||
	if wifictld := stats.Wifictld; wifictld != nil {
 | 
			
		||||
		fields["wifictld.total"] = wifictld.Total
 | 
			
		||||
		fields["wifictld.client24"] = wifictld.Client24
 | 
			
		||||
		fields["wifictld.client5"] = wifictld.Client5
 | 
			
		||||
		fields["wifictld.authed"] = wifictld.Authed
 | 
			
		||||
		fields["wifictld.connected"] = wifictld.Connected
 | 
			
		||||
		fields["wifictld.highest_try_probe"] = wifictld.HighestTryProbe
 | 
			
		||||
		fields["wifictld.highest_try_auth"] = wifictld.HighestTryAuth
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	conn.addPoint(MeasurementNode, tags, fields, time)
 | 
			
		||||
 | 
			
		||||
	// Add DHCP statistics
 | 
			
		||||
 | 
			
		||||
@ -3,7 +3,7 @@ package influxdb
 | 
			
		||||
import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/influxdata/influxdb1-client/v2"
 | 
			
		||||
	"github.com/influxdata/influxdb/client/v2"
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/data"
 | 
			
		||||
@ -39,8 +39,20 @@ func TestToInflux(t *testing.T) {
 | 
			
		||||
				MgmtTx:  &data.Traffic{Packets: 2327},
 | 
			
		||||
				MgmtRx:  &data.Traffic{Bytes: 2331},
 | 
			
		||||
			},
 | 
			
		||||
			MeshVPN: &data.MeshVPN{
 | 
			
		||||
				Groups: map[string]*data.MeshVPNPeerGroup{
 | 
			
		||||
					"ffhb": {
 | 
			
		||||
						Peers: map[string]*data.MeshVPNPeerLink{
 | 
			
		||||
							"vpn01": {Established: 3},
 | 
			
		||||
							"vpn02": {},
 | 
			
		||||
							"trash": nil,
 | 
			
		||||
							"vpn03": {Established: 0},
 | 
			
		||||
						},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "deadbeef",
 | 
			
		||||
			Owner: &data.Owner{
 | 
			
		||||
				Contact: "nobody",
 | 
			
		||||
@ -55,17 +67,6 @@ func TestToInflux(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
			Network: data.Network{
 | 
			
		||||
				Mac: "DEADMAC",
 | 
			
		||||
				Mesh: map[string]*data.NetworkInterface{
 | 
			
		||||
					"bat0": {
 | 
			
		||||
						Interfaces: struct {
 | 
			
		||||
							Wireless []string `json:"wireless,omitempty"`
 | 
			
		||||
							Other    []string `json:"other,omitempty"`
 | 
			
		||||
							Tunnel   []string `json:"tunnel,omitempty"`
 | 
			
		||||
						}{
 | 
			
		||||
							Tunnel: []string{"a-interface-mac", "fe80::1"},
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			Software: data.Software{
 | 
			
		||||
				Autoupdater: struct {
 | 
			
		||||
@ -80,7 +81,7 @@ func TestToInflux(t *testing.T) {
 | 
			
		||||
		Neighbours: &data.Neighbours{
 | 
			
		||||
			NodeID: "deadbeef",
 | 
			
		||||
			Batadv: map[string]data.BatadvNeighbours{
 | 
			
		||||
				"a-interface-mac": {
 | 
			
		||||
				"a-interface": {
 | 
			
		||||
					Neighbours: map[string]data.BatmanLink{
 | 
			
		||||
						"BAFF1E5": {
 | 
			
		||||
							Tq: 204,
 | 
			
		||||
@ -88,24 +89,14 @@ func TestToInflux(t *testing.T) {
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			Babel: map[string]data.BabelNeighbours{
 | 
			
		||||
				"wg-01": {
 | 
			
		||||
					LinkLocalAddress: "fe80::1",
 | 
			
		||||
					Neighbours: map[string]data.BabelLink{
 | 
			
		||||
						"fe80::2": {
 | 
			
		||||
							Cost: 0,
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
			LLDP: map[string]data.LLDPNeighbours{
 | 
			
		||||
				"b-interface-mac": {},
 | 
			
		||||
				"b-interface": {},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	neighbour := &runtime.Node{
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "foobar",
 | 
			
		||||
			Network: data.Network{
 | 
			
		||||
				Mac: "BAFF1E5",
 | 
			
		||||
@ -126,7 +117,7 @@ func TestToInflux(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// do not add a empty statistics of a node
 | 
			
		||||
	droppednode := &runtime.Node{
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "notfound",
 | 
			
		||||
			Network: data.Network{
 | 
			
		||||
				Mac: "instats",
 | 
			
		||||
@ -153,10 +144,9 @@ func TestToInflux(t *testing.T) {
 | 
			
		||||
	assert.EqualValues("city", tags["domain"])
 | 
			
		||||
	assert.EqualValues(0.5, fields["load"])
 | 
			
		||||
	assert.EqualValues(0, fields["neighbours.lldp"])
 | 
			
		||||
	assert.EqualValues(1, fields["neighbours.babel"])
 | 
			
		||||
	assert.EqualValues(1, fields["neighbours.batadv"])
 | 
			
		||||
	assert.EqualValues(2, fields["neighbours.vpn"])
 | 
			
		||||
	assert.EqualValues(2, fields["neighbours.total"])
 | 
			
		||||
	assert.EqualValues(1, fields["neighbours.vpn"])
 | 
			
		||||
	assert.EqualValues(1, fields["neighbours.total"])
 | 
			
		||||
 | 
			
		||||
	assert.EqualValues(uint32(3), fields["wireless.txpower24"])
 | 
			
		||||
	assert.EqualValues(uint32(5500), fields["airtime11a.frequency"])
 | 
			
		||||
@ -175,7 +165,7 @@ func TestToInflux(t *testing.T) {
 | 
			
		||||
	assert.EqualValues("link", nPoint.Name())
 | 
			
		||||
	assert.EqualValues(map[string]string{
 | 
			
		||||
		"source.id":   "deadbeef",
 | 
			
		||||
		"source.addr": "a-interface-mac",
 | 
			
		||||
		"source.addr": "a-interface",
 | 
			
		||||
		"target.id":   "foobar",
 | 
			
		||||
		"target.addr": "BAFF1E5",
 | 
			
		||||
	}, tags)
 | 
			
		||||
 | 
			
		||||
@ -7,6 +7,7 @@ package logging
 | 
			
		||||
 */
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"os"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
@ -63,6 +64,6 @@ func (conn *Connection) Close() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (conn *Connection) log(v ...interface{}) {
 | 
			
		||||
	fmt.Println(v...)
 | 
			
		||||
	log.Println(v...)
 | 
			
		||||
	conn.file.WriteString(fmt.Sprintln("[", time.Now().String(), "]", v))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -7,11 +7,10 @@ import (
 | 
			
		||||
	"bufio"
 | 
			
		||||
	"compress/flate"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/data"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/database"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
@ -51,7 +50,7 @@ func Connect(configuration map[string]interface{}) (database.Connection, error)
 | 
			
		||||
 | 
			
		||||
func (conn *Connection) InsertNode(node *runtime.Node) {
 | 
			
		||||
	res := &data.ResponseData{
 | 
			
		||||
		Nodeinfo:   node.Nodeinfo,
 | 
			
		||||
		NodeInfo:   node.Nodeinfo,
 | 
			
		||||
		Statistics: node.Statistics,
 | 
			
		||||
		Neighbours: node.Neighbours,
 | 
			
		||||
	}
 | 
			
		||||
@ -60,7 +59,7 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
 | 
			
		||||
 | 
			
		||||
	flater, err := flate.NewWriter(writer, flate.BestCompression)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Errorf("[database-yanic] could not create flater: %s", err)
 | 
			
		||||
		log.Printf("[database-yanic] could not create flater: %s", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	defer flater.Close()
 | 
			
		||||
@ -70,16 +69,16 @@ func (conn *Connection) InsertNode(node *runtime.Node) {
 | 
			
		||||
		if node.Nodeinfo != nil && node.Nodeinfo.NodeID != "" {
 | 
			
		||||
			nodeid = node.Nodeinfo.NodeID
 | 
			
		||||
		}
 | 
			
		||||
		log.WithField("node_id", nodeid).Errorf("[database-yanic] could not encode node: %s", err)
 | 
			
		||||
		log.Printf("[database-yanic] could not encode %s node: %s", nodeid, err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	err = flater.Flush()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Errorf("[database-yanic] could not compress: %s", err)
 | 
			
		||||
		log.Printf("[database-yanic] could not compress: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
	err = writer.Flush()
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Errorf("[database-yanic] could not send: %s", err)
 | 
			
		||||
		log.Printf("[database-yanic] could not send: %s", err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -25,7 +25,7 @@ func TestStart(t *testing.T) {
 | 
			
		||||
	assert.NoError(err)
 | 
			
		||||
 | 
			
		||||
	conn.InsertNode(&runtime.Node{
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID:   "73deadbeaf13",
 | 
			
		||||
			Hostname: "inject-test",
 | 
			
		||||
			Network: data.Network{
 | 
			
		||||
 | 
			
		||||
@ -52,7 +52,7 @@ synchronize      = "1m"
 | 
			
		||||
{% method %}
 | 
			
		||||
How often send request per respondd.
 | 
			
		||||
 | 
			
		||||
It will send UDP packets with multicast address `ff05::2:1001` and port `1001`.
 | 
			
		||||
It will send UDP packets with multicast address `ff02::2:1001` and port `1001`.
 | 
			
		||||
If a node does not answer after the half time, it will request with the last know address under the port `1001`.
 | 
			
		||||
{% sample lang="toml" %}
 | 
			
		||||
```toml
 | 
			
		||||
@ -110,7 +110,7 @@ ifname              = "br-ffhb"
 | 
			
		||||
{% method %}
 | 
			
		||||
ip address is the own address which is used for sending.
 | 
			
		||||
If not set or set with empty string it will take an address of ifname.
 | 
			
		||||
(It prefers the link local address, so at babel mesh-network it should be configurated)
 | 
			
		||||
(If `multicast_address` is not set the link local address otherwise a global unicast address)
 | 
			
		||||
{% sample lang="toml" %}
 | 
			
		||||
```toml
 | 
			
		||||
ip_address          = "fe80::..."
 | 
			
		||||
@ -130,8 +130,8 @@ send_no_request     = true
 | 
			
		||||
### multicast_address
 | 
			
		||||
{% method %}
 | 
			
		||||
Multicast address to destination of respondd.
 | 
			
		||||
If not set or set with empty string it will take the batman default multicast address `ff05::2:1001`
 | 
			
		||||
(Needed to set for legacy `ff02::2:1001`)
 | 
			
		||||
If not set or set with empty string it will take the batman default multicast address `ff02::2:1001`
 | 
			
		||||
(Needed in babel for a mesh-network wide routeable multicast addreess `ff05::2:1001`)
 | 
			
		||||
{% sample lang="toml" %}
 | 
			
		||||
```toml
 | 
			
		||||
multicast_address    = "ff02::2:1001"
 | 
			
		||||
@ -387,32 +387,6 @@ longitude_max = 39.72
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## [[nodes.output.geojson]]
 | 
			
		||||
{% method %}
 | 
			
		||||
The geojson output produces a geojson file which contains the location data of all monitored nodes to be used to visualize the location of the nodes.
 | 
			
		||||
It is optimized to be used with [UMap](https://github.com/umap-project/umap) but should work with other tools as well.
 | 
			
		||||
 | 
			
		||||
Here is a public demo provided by Freifunk Muenchen: http://u.osmfr.org/m/328494/
 | 
			
		||||
{% sample lang="toml" %}
 | 
			
		||||
```toml
 | 
			
		||||
[[nodes.output.geojson]]
 | 
			
		||||
enable   = true
 | 
			
		||||
path = "/var/www/html/meshviewer/data/nodes.geojson"
 | 
			
		||||
```
 | 
			
		||||
{% endmethod %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
### path
 | 
			
		||||
{% method %}
 | 
			
		||||
The path, where to store nodes.geojson
 | 
			
		||||
{% sample lang="toml" %}
 | 
			
		||||
```toml
 | 
			
		||||
path     = "/var/www/html/meshviewer/data/nodes.geojson"
 | 
			
		||||
```
 | 
			
		||||
{% endmethod %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## [[nodes.output.meshviewer-ffrgb]]
 | 
			
		||||
{% method %}
 | 
			
		||||
The new json file format for the [meshviewer](https://github.com/ffrgb/meshviewer) developed in Regensburg.
 | 
			
		||||
@ -521,21 +495,6 @@ path     = "/var/www/html/meshviewer/data/nodelist.json"
 | 
			
		||||
```
 | 
			
		||||
{% endmethod %}
 | 
			
		||||
 | 
			
		||||
## [[nodes.output.raw]]
 | 
			
		||||
{% method %}
 | 
			
		||||
This output takes the respondd response as sent by the node and includes it in a JSON document.
 | 
			
		||||
{% endmethod %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
### path
 | 
			
		||||
{% method %}
 | 
			
		||||
The path, where to store raw.json
 | 
			
		||||
{% sample lang="toml" %}
 | 
			
		||||
```toml
 | 
			
		||||
path     = "/var/www/html/meshviewer/data/raw.json"
 | 
			
		||||
```
 | 
			
		||||
{% endmethod %}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
## [database]
 | 
			
		||||
 | 
			
		||||
@ -5,13 +5,14 @@
 | 
			
		||||
### Install
 | 
			
		||||
```sh
 | 
			
		||||
cd /usr/local/
 | 
			
		||||
wget https://dl.google.com/go/go1.13.1.linux-amd64.tar.gz -O go-release-linux-amd64.tar.gz
 | 
			
		||||
wget https://storage.googleapis.com/golang/go1.9.1.linux-amd64.tar.gz -O go-release-linux-amd64.tar.gz
 | 
			
		||||
tar xvf go-release-linux-amd64.tar.gz
 | 
			
		||||
rm go-release-linux-amd64.tar.gz
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
### Configure go
 | 
			
		||||
Add these lines in your root shell startup file (e.g. `/root/.bashrc`):
 | 
			
		||||
 | 
			
		||||
```sh
 | 
			
		||||
export GOPATH=/opt/go
 | 
			
		||||
export PATH=$PATH:/usr/local/go/bin:$GOPATH/bin
 | 
			
		||||
@ -33,12 +34,14 @@ systemctl daemon-reload
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Before start, you should configure yanic by the file `/etc/yanic.conf`:
 | 
			
		||||
```sh
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
systemctl start yanic
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Enable to start on boot:
 | 
			
		||||
```sh
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
systemctl enable yanic
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -7,7 +7,7 @@ A little overview of yanic in connection with other software:
 | 
			
		||||
 | 
			
		||||
It sends the `gluon-neighbour-info` request and collects the answers.
 | 
			
		||||
 | 
			
		||||
It will send UDP packets with multicast address `ff05:0:0:0:0:0:2:1001` and port `1001`.
 | 
			
		||||
It will send UDP packets with multicast address `ff02:0:0:0:0:0:2:1001` and port `1001`.
 | 
			
		||||
 | 
			
		||||
If a node does not answer, it will request with the last know address under the port `1001`.
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										37
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										37
									
								
								main.go
									
									
									
									
									
								
							@ -1,42 +1,7 @@
 | 
			
		||||
package main
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
	stdLogger "github.com/bdlm/std/logger"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/cmd"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type hook struct{}
 | 
			
		||||
 | 
			
		||||
func (h *hook) Fire(entry *log.Entry) error {
 | 
			
		||||
	switch entry.Level {
 | 
			
		||||
	case log.PanicLevel:
 | 
			
		||||
		entry.Logger.Out = os.Stderr
 | 
			
		||||
	case log.FatalLevel:
 | 
			
		||||
		entry.Logger.Out = os.Stderr
 | 
			
		||||
	case log.ErrorLevel:
 | 
			
		||||
		entry.Logger.Out = os.Stderr
 | 
			
		||||
	case log.WarnLevel:
 | 
			
		||||
		entry.Logger.Out = os.Stdout
 | 
			
		||||
	case log.InfoLevel:
 | 
			
		||||
		entry.Logger.Out = os.Stdout
 | 
			
		||||
	case log.DebugLevel:
 | 
			
		||||
		entry.Logger.Out = os.Stdout
 | 
			
		||||
	default:
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (h *hook) Levels() []stdLogger.Level {
 | 
			
		||||
	return log.AllLevels
 | 
			
		||||
}
 | 
			
		||||
import "github.com/FreifunkBremen/yanic/cmd"
 | 
			
		||||
 | 
			
		||||
func main() {
 | 
			
		||||
	log.AddHook(&hook{})
 | 
			
		||||
 | 
			
		||||
	cmd.Execute()
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -1,9 +1,7 @@
 | 
			
		||||
package all
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	_ "github.com/FreifunkBremen/yanic/output/geojson"
 | 
			
		||||
	_ "github.com/FreifunkBremen/yanic/output/meshviewer"
 | 
			
		||||
	_ "github.com/FreifunkBremen/yanic/output/meshviewer-ffrgb"
 | 
			
		||||
	_ "github.com/FreifunkBremen/yanic/output/nodelist"
 | 
			
		||||
	_ "github.com/FreifunkBremen/yanic/output/raw"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
@ -2,8 +2,7 @@ package all
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/output"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/output/filter"
 | 
			
		||||
@ -24,7 +23,7 @@ func Register(configuration map[string]interface{}) (output.Output, error) {
 | 
			
		||||
	for outputType, outputRegister := range output.Adapters {
 | 
			
		||||
		configForOutput := allOutputs[outputType]
 | 
			
		||||
		if configForOutput == nil {
 | 
			
		||||
			log.WithField("output", outputType).Infof("no configuration found")
 | 
			
		||||
			log.Printf("the output type '%s' has no configuration\n", outputType)
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		outputConfigs, ok := configForOutput.([]interface{})
 | 
			
		||||
 | 
			
		||||
@ -23,7 +23,7 @@ func TestFilterBlacklist(t *testing.T) {
 | 
			
		||||
	assert.NoError(err)
 | 
			
		||||
 | 
			
		||||
	// keep node without nodeid
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{}})
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{}})
 | 
			
		||||
	assert.NotNil(n)
 | 
			
		||||
 | 
			
		||||
	// tests with blacklist
 | 
			
		||||
@ -31,11 +31,11 @@ func TestFilterBlacklist(t *testing.T) {
 | 
			
		||||
	assert.NoError(err)
 | 
			
		||||
 | 
			
		||||
	// blacklist contains node with nodeid -> drop it
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{NodeID: "a"}})
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{NodeID: "a"}})
 | 
			
		||||
	assert.Nil(n)
 | 
			
		||||
 | 
			
		||||
	// blacklist does not contains node without nodeid -> keep it
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{}})
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{}})
 | 
			
		||||
	assert.NotNil(n)
 | 
			
		||||
 | 
			
		||||
	n = filter.Apply(&runtime.Node{})
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ func (config *domainAppendSite) Apply(node *runtime.Node) *runtime.Node {
 | 
			
		||||
			Lastseen:   node.Lastseen,
 | 
			
		||||
			Online:     node.Online,
 | 
			
		||||
			Statistics: node.Statistics,
 | 
			
		||||
			Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
			Nodeinfo: &data.NodeInfo{
 | 
			
		||||
				NodeID:  nodeinfo.NodeID,
 | 
			
		||||
				Network: nodeinfo.Network,
 | 
			
		||||
				System: data.System{
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@ func TestFilter(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// delete owner by configuration
 | 
			
		||||
	filter, _ = build(true)
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		System: data.System{
 | 
			
		||||
			SiteCode:   "ffhb",
 | 
			
		||||
			DomainCode: "city",
 | 
			
		||||
@ -30,7 +30,7 @@ func TestFilter(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// keep owner configuration
 | 
			
		||||
	filter, _ = build(false)
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		System: data.System{
 | 
			
		||||
			SiteCode:   "ffhb",
 | 
			
		||||
			DomainCode: "city",
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ func (config *domainAsSite) Apply(node *runtime.Node) *runtime.Node {
 | 
			
		||||
			Lastseen:   node.Lastseen,
 | 
			
		||||
			Online:     node.Online,
 | 
			
		||||
			Statistics: node.Statistics,
 | 
			
		||||
			Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
			Nodeinfo: &data.NodeInfo{
 | 
			
		||||
				NodeID:  nodeinfo.NodeID,
 | 
			
		||||
				Network: nodeinfo.Network,
 | 
			
		||||
				System: data.System{
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@ func TestFilter(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// delete owner by configuration
 | 
			
		||||
	filter, _ = build(true)
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		System: data.System{
 | 
			
		||||
			SiteCode:   "ffhb",
 | 
			
		||||
			DomainCode: "city",
 | 
			
		||||
@ -30,7 +30,7 @@ func TestFilter(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// keep owner configuration
 | 
			
		||||
	filter, _ = build(false)
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		System: data.System{
 | 
			
		||||
			SiteCode:   "ffhb",
 | 
			
		||||
			DomainCode: "city",
 | 
			
		||||
 | 
			
		||||
@ -3,10 +3,8 @@ package filter
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
	"github.com/pkg/errors"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
	"github.com/pkg/errors"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// factory function for building a filter
 | 
			
		||||
@ -26,7 +24,7 @@ var filters = make(map[string]factory)
 | 
			
		||||
// Register registers a new filter
 | 
			
		||||
func Register(name string, f factory) {
 | 
			
		||||
	if _, ok := filters[name]; ok {
 | 
			
		||||
		log.WithField("filter", name).Panic("filter already registered")
 | 
			
		||||
		panic("already registered: " + name)
 | 
			
		||||
	}
 | 
			
		||||
	filters[name] = f
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -68,7 +68,7 @@ func TestFilter(t *testing.T) {
 | 
			
		||||
	nodes := &runtime.Nodes{
 | 
			
		||||
		List: map[string]*runtime.Node{
 | 
			
		||||
			"a": {
 | 
			
		||||
				Nodeinfo: &data.Nodeinfo{NodeID: "a"},
 | 
			
		||||
				Nodeinfo: &data.NodeInfo{NodeID: "a"},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
@ -83,7 +83,7 @@ func TestFilter(t *testing.T) {
 | 
			
		||||
	nodes = &runtime.Nodes{
 | 
			
		||||
		List: map[string]*runtime.Node{
 | 
			
		||||
			"a": {
 | 
			
		||||
				Nodeinfo: &data.Nodeinfo{NodeID: "a"},
 | 
			
		||||
				Nodeinfo: &data.NodeInfo{NodeID: "a"},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -20,13 +20,13 @@ func TestFilterHasLocation(t *testing.T) {
 | 
			
		||||
	assert.NoError(err)
 | 
			
		||||
 | 
			
		||||
	// node has location (with 0,0) -> keep it
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		Location: &data.Location{},
 | 
			
		||||
	}})
 | 
			
		||||
	assert.NotNil(n)
 | 
			
		||||
 | 
			
		||||
	// node without location has no location -> drop it
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{}})
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{}})
 | 
			
		||||
	assert.Nil(n)
 | 
			
		||||
 | 
			
		||||
	// node without nodeinfo has no location -> drop it
 | 
			
		||||
@ -38,13 +38,13 @@ func TestFilterHasLocation(t *testing.T) {
 | 
			
		||||
	assert.NoError(err)
 | 
			
		||||
 | 
			
		||||
	// node has location (with 0,0) -> drop it
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		Location: &data.Location{},
 | 
			
		||||
	}})
 | 
			
		||||
	assert.Nil(n)
 | 
			
		||||
 | 
			
		||||
	// node without location has no location -> keep it
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{}})
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{}})
 | 
			
		||||
	assert.NotNil(n)
 | 
			
		||||
 | 
			
		||||
	// node without nodeinfo has no location -> keep it
 | 
			
		||||
 | 
			
		||||
@ -18,7 +18,7 @@ func TestFilterInArea(t *testing.T) {
 | 
			
		||||
		"longitude_max": 12.0,
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		Location: &data.Location{Latitude: 4.0, Longitude: 11.0},
 | 
			
		||||
	}})
 | 
			
		||||
	assert.NotNil(n)
 | 
			
		||||
@ -28,35 +28,35 @@ func TestFilterInArea(t *testing.T) {
 | 
			
		||||
	assert.NotNil(n)
 | 
			
		||||
 | 
			
		||||
	// keep without location -> use has_location for it
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{}})
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{}})
 | 
			
		||||
	assert.NotNil(n)
 | 
			
		||||
 | 
			
		||||
	// zeros not in area (0, 0)
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		Location: &data.Location{},
 | 
			
		||||
	}})
 | 
			
		||||
	assert.Nil(n)
 | 
			
		||||
 | 
			
		||||
	// in area
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		Location: &data.Location{Latitude: 4.0, Longitude: 11.0},
 | 
			
		||||
	}})
 | 
			
		||||
	assert.NotNil(n)
 | 
			
		||||
 | 
			
		||||
	// over max longitude -> dropped
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		Location: &data.Location{Latitude: 4.0, Longitude: 13.0},
 | 
			
		||||
	}})
 | 
			
		||||
	assert.Nil(n)
 | 
			
		||||
 | 
			
		||||
	// over max latitude -> dropped
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		Location: &data.Location{Latitude: 6.0, Longitude: 11.0},
 | 
			
		||||
	}})
 | 
			
		||||
	assert.Nil(n)
 | 
			
		||||
 | 
			
		||||
	// lower then mix latitde -> dropped
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		Location: &data.Location{Latitude: 1.0, Longitude: 2.0},
 | 
			
		||||
	}})
 | 
			
		||||
	assert.Nil(n)
 | 
			
		||||
 | 
			
		||||
@ -29,7 +29,7 @@ func (no *noowner) Apply(node *runtime.Node) *runtime.Node {
 | 
			
		||||
			Lastseen:   node.Lastseen,
 | 
			
		||||
			Online:     node.Online,
 | 
			
		||||
			Statistics: node.Statistics,
 | 
			
		||||
			Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
			Nodeinfo: &data.NodeInfo{
 | 
			
		||||
				NodeID:   nodeinfo.NodeID,
 | 
			
		||||
				Network:  nodeinfo.Network,
 | 
			
		||||
				System:   nodeinfo.System,
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,7 @@ func TestFilter(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// delete owner by configuration
 | 
			
		||||
	filter, _ = build(true)
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		Owner: &data.Owner{
 | 
			
		||||
			Contact: "blub",
 | 
			
		||||
		},
 | 
			
		||||
@ -28,7 +28,7 @@ func TestFilter(t *testing.T) {
 | 
			
		||||
 | 
			
		||||
	// keep owner configuration
 | 
			
		||||
	filter, _ = build(false)
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{
 | 
			
		||||
		Owner: &data.Owner{
 | 
			
		||||
			Contact: "blub",
 | 
			
		||||
		},
 | 
			
		||||
 | 
			
		||||
@ -22,11 +22,11 @@ func TestFilterSite(t *testing.T) {
 | 
			
		||||
	assert.NoError(err)
 | 
			
		||||
 | 
			
		||||
	// wronge node
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{System: data.System{SiteCode: "ffxx"}}})
 | 
			
		||||
	n := filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{System: data.System{SiteCode: "ffxx"}}})
 | 
			
		||||
	assert.Nil(n)
 | 
			
		||||
 | 
			
		||||
	// right node
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.Nodeinfo{System: data.System{SiteCode: "ffhb"}}})
 | 
			
		||||
	n = filter.Apply(&runtime.Node{Nodeinfo: &data.NodeInfo{System: data.System{SiteCode: "ffhb"}}})
 | 
			
		||||
	assert.NotNil(n)
 | 
			
		||||
 | 
			
		||||
	// node without data -> wrong node
 | 
			
		||||
 | 
			
		||||
@ -1,89 +0,0 @@
 | 
			
		||||
package geojson
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
	"github.com/paulmach/go.geojson"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	POINT_UMAP_CLASS         = "Circle"
 | 
			
		||||
	POINT_UMAP_ONLINE_COLOR  = "Green"
 | 
			
		||||
	POINT_UMAP_OFFLINE_COLOR = "Red"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func newNodePoint(n *runtime.Node) (point *geojson.Feature) {
 | 
			
		||||
	nodeinfo := n.Nodeinfo
 | 
			
		||||
	location := nodeinfo.Location
 | 
			
		||||
	point = geojson.NewPointFeature([]float64{
 | 
			
		||||
		location.Longitude,
 | 
			
		||||
		location.Latitude,
 | 
			
		||||
	})
 | 
			
		||||
	point.Properties["id"] = nodeinfo.NodeID
 | 
			
		||||
	point.Properties["name"] = nodeinfo.Hostname
 | 
			
		||||
 | 
			
		||||
	point.Properties["online"] = n.Online
 | 
			
		||||
	var description strings.Builder
 | 
			
		||||
	if n.Online {
 | 
			
		||||
		description.WriteString("Online\n")
 | 
			
		||||
		if statistics := n.Statistics; statistics != nil {
 | 
			
		||||
			point.Properties["clients"] = statistics.Clients.Total
 | 
			
		||||
			description.WriteString("Clients: " + strconv.Itoa(int(statistics.Clients.Total)) + "\n")
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		description.WriteString("Offline\n")
 | 
			
		||||
	}
 | 
			
		||||
	if nodeinfo.Hardware.Model != "" {
 | 
			
		||||
		point.Properties["model"] = nodeinfo.Hardware.Model
 | 
			
		||||
		description.WriteString("Model: " + nodeinfo.Hardware.Model + "\n")
 | 
			
		||||
	}
 | 
			
		||||
	if fw := nodeinfo.Software.Firmware; fw.Release != "" {
 | 
			
		||||
		point.Properties["firmware"] = fw.Release
 | 
			
		||||
		description.WriteString("Firmware: " + fw.Release + "\n")
 | 
			
		||||
	}
 | 
			
		||||
	if nodeinfo.System.SiteCode != "" {
 | 
			
		||||
		point.Properties["site"] = nodeinfo.System.SiteCode
 | 
			
		||||
		description.WriteString("Site: " + nodeinfo.System.SiteCode + "\n")
 | 
			
		||||
	}
 | 
			
		||||
	if nodeinfo.System.DomainCode != "" {
 | 
			
		||||
		point.Properties["domain"] = nodeinfo.System.DomainCode
 | 
			
		||||
		description.WriteString("Domain: " + nodeinfo.System.DomainCode + "\n")
 | 
			
		||||
	}
 | 
			
		||||
	if owner := nodeinfo.Owner; owner != nil && owner.Contact != "" {
 | 
			
		||||
		point.Properties["contact"] = owner.Contact
 | 
			
		||||
		description.WriteString("Contact: " + owner.Contact + "\n")
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	point.Properties["description"] = description.String()
 | 
			
		||||
	point.Properties["_umap_options"] = getUMapOptions(n)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getUMapOptions(n *runtime.Node) map[string]string {
 | 
			
		||||
	result := map[string]string{
 | 
			
		||||
		"iconClass": POINT_UMAP_CLASS,
 | 
			
		||||
	}
 | 
			
		||||
	if n.Online {
 | 
			
		||||
		result["color"] = POINT_UMAP_ONLINE_COLOR
 | 
			
		||||
	} else {
 | 
			
		||||
		result["color"] = POINT_UMAP_OFFLINE_COLOR
 | 
			
		||||
	}
 | 
			
		||||
	return result
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func transform(nodes *runtime.Nodes) *geojson.FeatureCollection {
 | 
			
		||||
	nodelist := geojson.NewFeatureCollection()
 | 
			
		||||
 | 
			
		||||
	for _, n := range nodes.List {
 | 
			
		||||
		if n.Nodeinfo == nil || n.Nodeinfo.Location == nil {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		point := newNodePoint(n)
 | 
			
		||||
		if point != nil {
 | 
			
		||||
			nodelist.Features = append(nodelist.Features, point)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nodelist
 | 
			
		||||
}
 | 
			
		||||
@ -1,129 +0,0 @@
 | 
			
		||||
package geojson
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/data"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	testNodeDescription string = "Online\nClients: 42\nModel: TP-Link 841\n" +
 | 
			
		||||
		"Site: mysite\nDomain: domain_42\n"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestTransform(t *testing.T) {
 | 
			
		||||
	testNodes := createTestNodes()
 | 
			
		||||
	nodes := transform(testNodes)
 | 
			
		||||
 | 
			
		||||
	assert := assert.New(t)
 | 
			
		||||
	assert.Len(testNodes.List, 4)
 | 
			
		||||
	assert.Len(nodes.Features, 3)
 | 
			
		||||
 | 
			
		||||
	node := testNodes.List["abcdef012425"]
 | 
			
		||||
 | 
			
		||||
	umap := getUMapOptions(node)
 | 
			
		||||
	assert.Len(umap, 2)
 | 
			
		||||
 | 
			
		||||
	nodePoint := newNodePoint(node)
 | 
			
		||||
	assert.Equal(
 | 
			
		||||
		"abcdef012425",
 | 
			
		||||
		nodePoint.Properties["id"],
 | 
			
		||||
	)
 | 
			
		||||
	assert.Equal(
 | 
			
		||||
		"TP-Link 841",
 | 
			
		||||
		nodePoint.Properties["model"],
 | 
			
		||||
	)
 | 
			
		||||
	assert.Equal(
 | 
			
		||||
		uint32(42),
 | 
			
		||||
		nodePoint.Properties["clients"],
 | 
			
		||||
	)
 | 
			
		||||
	assert.Equal(
 | 
			
		||||
		testNodeDescription,
 | 
			
		||||
		nodePoint.Properties["description"],
 | 
			
		||||
	)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func createTestNodes() *runtime.Nodes {
 | 
			
		||||
	nodes := runtime.NewNodes(&runtime.NodesConfig{})
 | 
			
		||||
 | 
			
		||||
	nodes.AddNode(&runtime.Node{
 | 
			
		||||
		Online: true,
 | 
			
		||||
		Statistics: &data.Statistics{
 | 
			
		||||
			Clients: data.Clients{
 | 
			
		||||
				Total: 42,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
			NodeID: "abcdef012425",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 841",
 | 
			
		||||
			},
 | 
			
		||||
			Location: &data.Location{
 | 
			
		||||
				Latitude:  24,
 | 
			
		||||
				Longitude: 2,
 | 
			
		||||
			},
 | 
			
		||||
			System: data.System{
 | 
			
		||||
				SiteCode:   "mysite",
 | 
			
		||||
				DomainCode: "domain_42",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	nodeData := &runtime.Node{
 | 
			
		||||
		Online: true,
 | 
			
		||||
		Statistics: &data.Statistics{
 | 
			
		||||
			Clients: data.Clients{
 | 
			
		||||
				Total: 23,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
			NodeID: "abcdef012345",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 842",
 | 
			
		||||
			},
 | 
			
		||||
			System: data.System{
 | 
			
		||||
				SiteCode:   "mysite",
 | 
			
		||||
				DomainCode: "domain_42",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	nodeData.Nodeinfo.Software.Firmware.Release = "2019.1~exp42"
 | 
			
		||||
	nodes.AddNode(nodeData)
 | 
			
		||||
 | 
			
		||||
	nodes.AddNode(&runtime.Node{
 | 
			
		||||
		Statistics: &data.Statistics{
 | 
			
		||||
			Clients: data.Clients{
 | 
			
		||||
				Total: 2,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
			NodeID: "112233445566",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 843",
 | 
			
		||||
			},
 | 
			
		||||
			Location: &data.Location{
 | 
			
		||||
				Latitude:  23,
 | 
			
		||||
				Longitude: 2,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	nodes.AddNode(&runtime.Node{
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
			NodeID: "0xdeadbeef0x",
 | 
			
		||||
			VPN:    true,
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "Xeon Multi-Core",
 | 
			
		||||
			},
 | 
			
		||||
			Location: &data.Location{
 | 
			
		||||
				Latitude:  23,
 | 
			
		||||
				Longitude: 22,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	return nodes
 | 
			
		||||
}
 | 
			
		||||
@ -1,46 +0,0 @@
 | 
			
		||||
package geojson
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/output"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Output struct {
 | 
			
		||||
	output.Output
 | 
			
		||||
	path string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Config map[string]interface{}
 | 
			
		||||
 | 
			
		||||
func (c Config) Path() string {
 | 
			
		||||
	if path, ok := c["path"]; ok {
 | 
			
		||||
		return path.(string)
 | 
			
		||||
	}
 | 
			
		||||
	return ""
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	output.RegisterAdapter("geojson", Register)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Register(configuration map[string]interface{}) (output.Output, error) {
 | 
			
		||||
	var config Config
 | 
			
		||||
	config = configuration
 | 
			
		||||
 | 
			
		||||
	if path := config.Path(); path != "" {
 | 
			
		||||
		return &Output{
 | 
			
		||||
			path: path,
 | 
			
		||||
		}, nil
 | 
			
		||||
	}
 | 
			
		||||
	return nil, errors.New("no path given")
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (o *Output) Save(nodes *runtime.Nodes) {
 | 
			
		||||
	nodes.RLock()
 | 
			
		||||
	defer nodes.RUnlock()
 | 
			
		||||
 | 
			
		||||
	runtime.SaveJSON(transform(nodes), o.path)
 | 
			
		||||
}
 | 
			
		||||
@ -1,28 +0,0 @@
 | 
			
		||||
package geojson
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestOutput(t *testing.T) {
 | 
			
		||||
	assert := assert.New(t)
 | 
			
		||||
 | 
			
		||||
	out, err := Register(map[string]interface{}{})
 | 
			
		||||
	assert.Error(err)
 | 
			
		||||
	assert.Nil(out)
 | 
			
		||||
 | 
			
		||||
	out, err = Register(map[string]interface{}{
 | 
			
		||||
		"path": "/tmp/nodes.geojson",
 | 
			
		||||
	})
 | 
			
		||||
	os.Remove("/tmp/nodes.geojson")
 | 
			
		||||
	assert.NoError(err)
 | 
			
		||||
	assert.NotNil(out)
 | 
			
		||||
 | 
			
		||||
	out.Save(&runtime.Nodes{})
 | 
			
		||||
	_, err = os.Stat("/tmp/nodes.geojson")
 | 
			
		||||
	assert.NoError(err)
 | 
			
		||||
}
 | 
			
		||||
@ -2,10 +2,9 @@ package meshviewerFFRGB
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"strings"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/lib/jsontime"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
)
 | 
			
		||||
@ -82,13 +81,7 @@ func transform(nodes *runtime.Nodes) *Meshviewer {
 | 
			
		||||
					if link.Type == LINK_TYPE_FALLBACK {
 | 
			
		||||
						link.Type = linkType
 | 
			
		||||
					} else {
 | 
			
		||||
						log.WithFields(map[string]interface{}{
 | 
			
		||||
							"link":   fmt.Sprintf("%s-%s", linkOrigin.SourceAddress, linkOrigin.TargetAddress),
 | 
			
		||||
							"prev":   link.Type,
 | 
			
		||||
							"new":    linkType,
 | 
			
		||||
							"source": typeList[linkOrigin.SourceAddress],
 | 
			
		||||
							"target": typeList[linkOrigin.TargetAddress],
 | 
			
		||||
						}).Warn("different linktypes")
 | 
			
		||||
						log.Printf("different linktypes for '%s' - '%s' prev: '%s' new: '%s' source: '%s' target: '%s'", linkOrigin.SourceAddress, linkOrigin.TargetAddress, link.Type, linkType, typeList[linkOrigin.SourceAddress], typeList[linkOrigin.TargetAddress])
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
@ -100,7 +93,7 @@ func transform(nodes *runtime.Nodes) *Meshviewer {
 | 
			
		||||
				Target:        linkOrigin.TargetID,
 | 
			
		||||
				TargetAddress: linkOrigin.TargetAddress,
 | 
			
		||||
				SourceTQ:      linkOrigin.TQ,
 | 
			
		||||
				TargetTQ:      0,
 | 
			
		||||
				TargetTQ:      linkOrigin.TQ,
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			linkType, linkTypeFound := typeList[linkOrigin.SourceAddress]
 | 
			
		||||
@ -109,10 +102,8 @@ func transform(nodes *runtime.Nodes) *Meshviewer {
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			if switchSourceTarget {
 | 
			
		||||
				link.SourceTQ = 0
 | 
			
		||||
				link.Source = linkOrigin.TargetID
 | 
			
		||||
				link.SourceAddress = linkOrigin.TargetAddress
 | 
			
		||||
				link.TargetTQ = linkOrigin.TQ
 | 
			
		||||
				link.Target = linkOrigin.SourceID
 | 
			
		||||
				link.TargetAddress = linkOrigin.SourceAddress
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -14,7 +14,7 @@ func TestTransform(t *testing.T) {
 | 
			
		||||
	nodes := runtime.NewNodes(&runtime.NodesConfig{})
 | 
			
		||||
	nodes.AddNode(&runtime.Node{
 | 
			
		||||
		Online: true,
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "node_a",
 | 
			
		||||
			Network: data.Network{
 | 
			
		||||
				Mac: "node:a:mac",
 | 
			
		||||
@ -51,7 +51,7 @@ func TestTransform(t *testing.T) {
 | 
			
		||||
	})
 | 
			
		||||
	nodes.AddNode(&runtime.Node{
 | 
			
		||||
		Online: true,
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "node_c",
 | 
			
		||||
			Network: data.Network{
 | 
			
		||||
				Mac: "node:c:mac",
 | 
			
		||||
@ -69,7 +69,7 @@ func TestTransform(t *testing.T) {
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Neighbours: &data.Neighbours{
 | 
			
		||||
			NodeID: "node_c",
 | 
			
		||||
			NodeID: "node_b",
 | 
			
		||||
			Batadv: map[string]data.BatadvNeighbours{
 | 
			
		||||
				"node:c:mac:lan": {
 | 
			
		||||
					Neighbours: map[string]data.BatmanLink{
 | 
			
		||||
@ -81,7 +81,7 @@ func TestTransform(t *testing.T) {
 | 
			
		||||
	})
 | 
			
		||||
	nodes.AddNode(&runtime.Node{
 | 
			
		||||
		Online: true,
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "node_b",
 | 
			
		||||
			Network: data.Network{
 | 
			
		||||
				Mac: "node:b:mac",
 | 
			
		||||
@ -117,7 +117,7 @@ func TestTransform(t *testing.T) {
 | 
			
		||||
	})
 | 
			
		||||
	nodes.AddNode(&runtime.Node{
 | 
			
		||||
		Online: false,
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "node_d",
 | 
			
		||||
			Network: data.Network{
 | 
			
		||||
				Mac: "node:d:mac",
 | 
			
		||||
@ -164,7 +164,7 @@ func TestTransform(t *testing.T) {
 | 
			
		||||
			assert.Equal("other", link.Type)
 | 
			
		||||
			assert.Equal("node:b:mac:lan", link.TargetAddress)
 | 
			
		||||
			assert.Equal(float32(0.2), link.SourceTQ)
 | 
			
		||||
			assert.Equal(float32(0), link.TargetTQ)
 | 
			
		||||
			assert.Equal(float32(0.2), link.TargetTQ)
 | 
			
		||||
			break
 | 
			
		||||
 | 
			
		||||
		case "node:a:mac:wifi":
 | 
			
		||||
 | 
			
		||||
@ -41,6 +41,7 @@ type Node struct {
 | 
			
		||||
	Autoupdater    Autoupdater   `json:"autoupdater"`
 | 
			
		||||
	Nproc          int           `json:"nproc"`
 | 
			
		||||
	Model          string        `json:"model,omitempty"`
 | 
			
		||||
	VPN            bool          `json:"vpn"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Firmware out of software
 | 
			
		||||
@ -78,18 +79,15 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node {
 | 
			
		||||
		Lastseen:  n.Lastseen,
 | 
			
		||||
		IsOnline:  n.Online,
 | 
			
		||||
		IsGateway: n.IsGateway(),
 | 
			
		||||
		Addresses: []string{},
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if nodeinfo := n.Nodeinfo; nodeinfo != nil {
 | 
			
		||||
		node.NodeID = nodeinfo.NodeID
 | 
			
		||||
		node.MAC = nodeinfo.Network.Mac
 | 
			
		||||
		node.Addresses = nodeinfo.Network.Addresses
 | 
			
		||||
		node.SiteCode = nodeinfo.System.SiteCode
 | 
			
		||||
		node.DomainCode = nodeinfo.System.DomainCode
 | 
			
		||||
		node.Hostname = nodeinfo.Hostname
 | 
			
		||||
		if addresses := nodeinfo.Network.Addresses; addresses != nil {
 | 
			
		||||
			node.Addresses = nodeinfo.Network.Addresses
 | 
			
		||||
		}
 | 
			
		||||
		if owner := nodeinfo.Owner; owner != nil {
 | 
			
		||||
			node.Owner = owner.Contact
 | 
			
		||||
		}
 | 
			
		||||
@ -106,6 +104,7 @@ func NewNode(nodes *runtime.Nodes, n *runtime.Node) *Node {
 | 
			
		||||
		}
 | 
			
		||||
		node.Nproc = nodeinfo.Hardware.Nproc
 | 
			
		||||
		node.Model = nodeinfo.Hardware.Model
 | 
			
		||||
		node.VPN = nodeinfo.VPN
 | 
			
		||||
	}
 | 
			
		||||
	if statistic := n.Statistics; statistic != nil {
 | 
			
		||||
		if n.Online {
 | 
			
		||||
 | 
			
		||||
@ -12,21 +12,7 @@ func TestRegister(t *testing.T) {
 | 
			
		||||
	assert := assert.New(t)
 | 
			
		||||
	nodes := runtime.NewNodes(&runtime.NodesConfig{})
 | 
			
		||||
	node := NewNode(nodes, &runtime.Node{
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
			Owner: &data.Owner{
 | 
			
		||||
				Contact: "whoami",
 | 
			
		||||
			},
 | 
			
		||||
			Network: data.Network{
 | 
			
		||||
				Mac:       "blub",
 | 
			
		||||
				Addresses: []string{"fe80::1"},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
	assert.NotNil(node)
 | 
			
		||||
	assert.Len(node.Addresses, 1)
 | 
			
		||||
 | 
			
		||||
	node = NewNode(nodes, &runtime.Node{
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			Owner: &data.Owner{
 | 
			
		||||
				Contact: "whoami",
 | 
			
		||||
			},
 | 
			
		||||
@ -60,7 +46,6 @@ func TestRegister(t *testing.T) {
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
	assert.NotNil(node)
 | 
			
		||||
	assert.NotNil(node.Addresses)
 | 
			
		||||
	assert.Equal("whoami", node.Owner)
 | 
			
		||||
	assert.Equal("blub", node.MAC)
 | 
			
		||||
	assert.Equal(13.3, node.Location.Longitude)
 | 
			
		||||
 | 
			
		||||
@ -12,7 +12,7 @@ import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type TestNode struct {
 | 
			
		||||
	Nodeinfo   *data.Nodeinfo   `json:"nodeinfo"`
 | 
			
		||||
	Nodeinfo   *data.NodeInfo   `json:"nodeinfo"`
 | 
			
		||||
	Neighbours *data.Neighbours `json:"neighbours"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -38,7 +38,7 @@ func testGetNodesByFile(files ...string) *runtime.Nodes {
 | 
			
		||||
	for _, file := range files {
 | 
			
		||||
		node := testGetNodeByFile(file)
 | 
			
		||||
		nodes.Update(file, &data.ResponseData{
 | 
			
		||||
			Nodeinfo:   node.Nodeinfo,
 | 
			
		||||
			NodeInfo:   node.Nodeinfo,
 | 
			
		||||
			Neighbours: node.Neighbours,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,7 @@ type Node struct {
 | 
			
		||||
	Lastseen   jsontime.Time    `json:"lastseen"`
 | 
			
		||||
	Flags      Flags            `json:"flags"`
 | 
			
		||||
	Statistics *Statistics      `json:"statistics"`
 | 
			
		||||
	Nodeinfo   *data.Nodeinfo   `json:"nodeinfo"`
 | 
			
		||||
	Nodeinfo   *data.NodeInfo   `json:"nodeinfo"`
 | 
			
		||||
	Neighbours *data.Neighbours `json:"-"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -31,7 +31,7 @@ func createTestNodes() *runtime.Nodes {
 | 
			
		||||
				Total: 23,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "abcdef012345",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 841",
 | 
			
		||||
@ -52,7 +52,7 @@ func createTestNodes() *runtime.Nodes {
 | 
			
		||||
				Free:  8,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "112233445566",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 841",
 | 
			
		||||
@ -61,7 +61,7 @@ func createTestNodes() *runtime.Nodes {
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	nodes.AddNode(&runtime.Node{
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "0xdeadbeef0x",
 | 
			
		||||
			VPN:    true,
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
 | 
			
		||||
@ -2,8 +2,7 @@ package meshviewer
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
	"log"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/output"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
 | 
			
		||||
@ -25,7 +25,7 @@ func createTestNodes() *runtime.Nodes {
 | 
			
		||||
				Total: 23,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "abcdef012345",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 841",
 | 
			
		||||
@ -41,7 +41,7 @@ func createTestNodes() *runtime.Nodes {
 | 
			
		||||
				Total: 2,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "112233445566",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 841",
 | 
			
		||||
@ -54,7 +54,7 @@ func createTestNodes() *runtime.Nodes {
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	nodes.AddNode(&runtime.Node{
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "0xdeadbeef0x",
 | 
			
		||||
			VPN:    true,
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
 | 
			
		||||
@ -1,46 +0,0 @@
 | 
			
		||||
package raw
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/output"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Output struct {
 | 
			
		||||
	output.Output
 | 
			
		||||
	path string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type Config map[string]interface{}
 | 
			
		||||
 | 
			
		||||
func (c Config) Path() string {
 | 
			
		||||
	if path, ok := c["path"]; ok {
 | 
			
		||||
		return path.(string)
 | 
			
		||||
	}
 | 
			
		||||
	return ""
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func init() {
 | 
			
		||||
	output.RegisterAdapter("raw", Register)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func Register(configuration map[string]interface{}) (output.Output, error) {
 | 
			
		||||
	var config Config
 | 
			
		||||
	config = configuration
 | 
			
		||||
 | 
			
		||||
	if path := config.Path(); path != "" {
 | 
			
		||||
		return &Output{
 | 
			
		||||
			path: path,
 | 
			
		||||
		}, nil
 | 
			
		||||
	}
 | 
			
		||||
	return nil, errors.New("no path given")
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (o *Output) Save(nodes *runtime.Nodes) {
 | 
			
		||||
	nodes.RLock()
 | 
			
		||||
	defer nodes.RUnlock()
 | 
			
		||||
 | 
			
		||||
	runtime.SaveJSON(transform(nodes), o.path)
 | 
			
		||||
}
 | 
			
		||||
@ -1,28 +0,0 @@
 | 
			
		||||
package raw
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"os"
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestOutput(t *testing.T) {
 | 
			
		||||
	assert := assert.New(t)
 | 
			
		||||
 | 
			
		||||
	out, err := Register(map[string]interface{}{})
 | 
			
		||||
	assert.Error(err)
 | 
			
		||||
	assert.Nil(out)
 | 
			
		||||
 | 
			
		||||
	out, err = Register(map[string]interface{}{
 | 
			
		||||
		"path": "/tmp/raw.json",
 | 
			
		||||
	})
 | 
			
		||||
	os.Remove("/tmp/raw.json")
 | 
			
		||||
	assert.NoError(err)
 | 
			
		||||
	assert.NotNil(out)
 | 
			
		||||
 | 
			
		||||
	out.Save(&runtime.Nodes{})
 | 
			
		||||
	_, err = os.Stat("/tmp/raw.json")
 | 
			
		||||
	assert.NoError(err)
 | 
			
		||||
}
 | 
			
		||||
@ -1,45 +0,0 @@
 | 
			
		||||
package raw
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/data"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/lib/jsontime"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// Node struct
 | 
			
		||||
type RawNode struct {
 | 
			
		||||
	Firstseen  jsontime.Time    `json:"firstseen"`
 | 
			
		||||
	Lastseen   jsontime.Time    `json:"lastseen"`
 | 
			
		||||
	Online     bool             `json:"online"`
 | 
			
		||||
	Statistics *data.Statistics `json:"statistics"`
 | 
			
		||||
	Nodeinfo   *data.Nodeinfo   `json:"nodeinfo"`
 | 
			
		||||
	Neighbours *data.Neighbours `json:"neighbours"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type NodeList struct {
 | 
			
		||||
	Version   string        `json:"version"`
 | 
			
		||||
	Timestamp jsontime.Time `json:"updated_at"` // Timestamp of the generation
 | 
			
		||||
	List      []*RawNode    `json:"nodes"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func transform(nodes *runtime.Nodes) *NodeList {
 | 
			
		||||
	nodelist := &NodeList{
 | 
			
		||||
		Version:   "1.0.0",
 | 
			
		||||
		Timestamp: jsontime.Now(),
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	for _, nodeOrigin := range nodes.List {
 | 
			
		||||
		if nodeOrigin != nil {
 | 
			
		||||
			node := &RawNode{
 | 
			
		||||
				Firstseen:  nodeOrigin.Firstseen,
 | 
			
		||||
				Lastseen:   nodeOrigin.Lastseen,
 | 
			
		||||
				Online:     nodeOrigin.Online,
 | 
			
		||||
				Statistics: nodeOrigin.Statistics,
 | 
			
		||||
				Nodeinfo:   nodeOrigin.Nodeinfo,
 | 
			
		||||
				Neighbours: nodeOrigin.Neighbours,
 | 
			
		||||
			}
 | 
			
		||||
			nodelist.List = append(nodelist.List, node)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nodelist
 | 
			
		||||
}
 | 
			
		||||
@ -1,67 +0,0 @@
 | 
			
		||||
package raw
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/stretchr/testify/assert"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/data"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/runtime"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestTransform(t *testing.T) {
 | 
			
		||||
	nodes := transform(createTestNodes())
 | 
			
		||||
 | 
			
		||||
	assert := assert.New(t)
 | 
			
		||||
	assert.Len(nodes.List, 3)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func createTestNodes() *runtime.Nodes {
 | 
			
		||||
	nodes := runtime.NewNodes(&runtime.NodesConfig{})
 | 
			
		||||
 | 
			
		||||
	nodeData := &runtime.Node{
 | 
			
		||||
		Statistics: &data.Statistics{
 | 
			
		||||
			Clients: data.Clients{
 | 
			
		||||
				Total: 23,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
			NodeID: "abcdef012345",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 841",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	}
 | 
			
		||||
	nodeData.Nodeinfo.Software.Firmware.Release = "2016.1.6+entenhausen1"
 | 
			
		||||
	nodes.AddNode(nodeData)
 | 
			
		||||
 | 
			
		||||
	nodes.AddNode(&runtime.Node{
 | 
			
		||||
		Statistics: &data.Statistics{
 | 
			
		||||
			Clients: data.Clients{
 | 
			
		||||
				Total: 2,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
			NodeID: "112233445566",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 841",
 | 
			
		||||
			},
 | 
			
		||||
			Location: &data.Location{
 | 
			
		||||
				Latitude:  23,
 | 
			
		||||
				Longitude: 2,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	nodes.AddNode(&runtime.Node{
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
			NodeID: "0xdeadbeef0x",
 | 
			
		||||
			VPN:    true,
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "Xeon Multi-Core",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	return nodes
 | 
			
		||||
}
 | 
			
		||||
@ -5,11 +5,10 @@ import (
 | 
			
		||||
	"compress/flate"
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"log"
 | 
			
		||||
	"net"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/data"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/database"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/lib/jsontime"
 | 
			
		||||
@ -66,9 +65,9 @@ func (coll *Collector) listenUDP(iface InterfaceConfig) {
 | 
			
		||||
	if iface.IPAddress != "" {
 | 
			
		||||
		addr = net.ParseIP(iface.IPAddress)
 | 
			
		||||
	} else {
 | 
			
		||||
		addr, err = getUnicastAddr(iface.InterfaceName)
 | 
			
		||||
		addr, err = getUnicastAddr(iface.InterfaceName, iface.MulticastAddress == "")
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			log.WithField("iface", iface.InterfaceName).Panic(err)
 | 
			
		||||
			log.Panic(err)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -99,7 +98,7 @@ func (coll *Collector) listenUDP(iface InterfaceConfig) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Returns a unicast address of given interface (linklocal or global unicast address)
 | 
			
		||||
func getUnicastAddr(ifname string) (net.IP, error) {
 | 
			
		||||
func getUnicastAddr(ifname string, linklocal bool) (net.IP, error) {
 | 
			
		||||
	iface, err := net.InterfaceByName(ifname)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, err
 | 
			
		||||
@ -116,23 +115,23 @@ func getUnicastAddr(ifname string) (net.IP, error) {
 | 
			
		||||
		if !ok {
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		if (ip == nil && ipnet.IP.IsGlobalUnicast()) || ipnet.IP.IsLinkLocalUnicast() {
 | 
			
		||||
		if (!linklocal && ipnet.IP.IsGlobalUnicast()) || (linklocal && ipnet.IP.IsLinkLocalUnicast()) {
 | 
			
		||||
			ip = ipnet.IP
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if ip != nil {
 | 
			
		||||
		return ip, nil
 | 
			
		||||
	}
 | 
			
		||||
	return nil, fmt.Errorf("unable to find a unicast address")
 | 
			
		||||
	return nil, fmt.Errorf("unable to find a unicast address for %s", ifname)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Start Collector
 | 
			
		||||
func (coll *Collector) Start(interval time.Duration) {
 | 
			
		||||
	if coll.interval != 0 {
 | 
			
		||||
		log.Panic("already started")
 | 
			
		||||
		panic("already started")
 | 
			
		||||
	}
 | 
			
		||||
	if interval <= 0 {
 | 
			
		||||
		log.Panic("invalid collector interval")
 | 
			
		||||
		panic("invalid collector interval")
 | 
			
		||||
	}
 | 
			
		||||
	coll.interval = interval
 | 
			
		||||
 | 
			
		||||
@ -161,7 +160,7 @@ func (coll *Collector) sendOnce() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (coll *Collector) sendMulticast() {
 | 
			
		||||
	log.Info("sending multicasts")
 | 
			
		||||
	log.Println("sending multicasts")
 | 
			
		||||
	for _, conn := range coll.connections {
 | 
			
		||||
		if conn.SendRequest {
 | 
			
		||||
			coll.sendPacket(conn.Conn, conn.MulticastAddress)
 | 
			
		||||
@ -190,16 +189,13 @@ func (coll *Collector) sendUnicasts(seenBefore jsontime.Time) {
 | 
			
		||||
			send++
 | 
			
		||||
		}
 | 
			
		||||
		if send == 0 {
 | 
			
		||||
			log.WithField("iface", node.Address.Zone).Error("unable to find connection")
 | 
			
		||||
			log.Printf("unable to find connection for %s", node.Address.Zone)
 | 
			
		||||
		} else {
 | 
			
		||||
			time.Sleep(10 * time.Millisecond)
 | 
			
		||||
			count += send
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	log.WithFields(map[string]interface{}{
 | 
			
		||||
		"pkg_count":   count,
 | 
			
		||||
		"nodes_count": len(nodes),
 | 
			
		||||
	}).Info("sending unicast pkg")
 | 
			
		||||
	log.Printf("sending %d unicast pkg for %d nodes", count, len(nodes))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// SendPacket sends a UDP request to the given unicast or multicast address on the first UDP socket
 | 
			
		||||
@ -216,7 +212,7 @@ func (coll *Collector) sendPacket(conn *net.UDPConn, destination net.IP) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if _, err := conn.WriteToUDP([]byte("GET nodeinfo statistics neighbours"), &addr); err != nil {
 | 
			
		||||
		log.WithField("address", addr.String()).Errorf("WriteToUDP failed: %s", err)
 | 
			
		||||
		log.Println("WriteToUDP failed:", err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -238,7 +234,7 @@ func (coll *Collector) sender() {
 | 
			
		||||
func (coll *Collector) parser() {
 | 
			
		||||
	for obj := range coll.queue {
 | 
			
		||||
		if data, err := obj.parse(); err != nil {
 | 
			
		||||
			log.WithField("address", obj.Address.String()).Errorf("unable to decode response %s", err)
 | 
			
		||||
			log.Println("unable to decode response from", obj.Address.String(), err)
 | 
			
		||||
		} else {
 | 
			
		||||
			coll.saveResponse(obj.Address, data)
 | 
			
		||||
		}
 | 
			
		||||
@ -260,7 +256,7 @@ func (res *Response) parse() (*data.ResponseData, error) {
 | 
			
		||||
func (coll *Collector) saveResponse(addr *net.UDPAddr, res *data.ResponseData) {
 | 
			
		||||
	// Search for NodeID
 | 
			
		||||
	var nodeID string
 | 
			
		||||
	if val := res.Nodeinfo; val != nil {
 | 
			
		||||
	if val := res.NodeInfo; val != nil {
 | 
			
		||||
		nodeID = val.NodeID
 | 
			
		||||
	} else if val := res.Neighbours; val != nil {
 | 
			
		||||
		nodeID = val.NodeID
 | 
			
		||||
@ -270,10 +266,7 @@ func (coll *Collector) saveResponse(addr *net.UDPAddr, res *data.ResponseData) {
 | 
			
		||||
 | 
			
		||||
	// Check length of nodeID
 | 
			
		||||
	if len(nodeID) != 12 {
 | 
			
		||||
		log.WithFields(map[string]interface{}{
 | 
			
		||||
			"node_id": nodeID,
 | 
			
		||||
			"address": addr.String(),
 | 
			
		||||
		}).Warn("invalid NodeID")
 | 
			
		||||
		log.Printf("invalid NodeID '%s' from %s", nodeID, addr.String())
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -284,8 +277,8 @@ func (coll *Collector) saveResponse(addr *net.UDPAddr, res *data.ResponseData) {
 | 
			
		||||
	if res.Neighbours != nil && res.Neighbours.NodeID != nodeID {
 | 
			
		||||
		res.Neighbours = nil
 | 
			
		||||
	}
 | 
			
		||||
	if res.Nodeinfo != nil && res.Nodeinfo.NodeID != nodeID {
 | 
			
		||||
		res.Nodeinfo = nil
 | 
			
		||||
	if res.NodeInfo != nil && res.NodeInfo.NodeID != nodeID {
 | 
			
		||||
		res.NodeInfo = nil
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// Process the data and update IP address
 | 
			
		||||
@ -313,14 +306,7 @@ func (coll *Collector) receiver(conn *net.UDPConn) {
 | 
			
		||||
		n, src, err := conn.ReadFromUDP(buf)
 | 
			
		||||
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			if conn != nil {
 | 
			
		||||
				log.WithFields(map[string]interface{}{
 | 
			
		||||
					"local":  conn.LocalAddr(),
 | 
			
		||||
					"remote": conn.RemoteAddr(),
 | 
			
		||||
				}).Errorf("ReadFromUDP failed: %s", err)
 | 
			
		||||
			} else {
 | 
			
		||||
				log.Errorf("ReadFromUDP failed: %s", err)
 | 
			
		||||
			}
 | 
			
		||||
			log.Println("ReadFromUDP failed:", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -39,5 +39,5 @@ func TestParse(t *testing.T) {
 | 
			
		||||
	assert.NoError(err)
 | 
			
		||||
	assert.NotNil(data)
 | 
			
		||||
 | 
			
		||||
	assert.Equal("f81a67a5e9c1", data.Nodeinfo.NodeID)
 | 
			
		||||
	assert.Equal("f81a67a5e9c1", data.NodeInfo.NodeID)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -6,7 +6,7 @@ import (
 | 
			
		||||
 | 
			
		||||
const (
 | 
			
		||||
	// default multicast group used by announced
 | 
			
		||||
	multicastAddressDefault = "ff05:0:0:0:0:0:2:1001"
 | 
			
		||||
	multicastAddressDefault = "ff02:0:0:0:0:0:2:1001"
 | 
			
		||||
 | 
			
		||||
	// default udp port used by announced
 | 
			
		||||
	port = 1001
 | 
			
		||||
 | 
			
		||||
@ -9,8 +9,6 @@ import (
 | 
			
		||||
	"strconv"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
var linePattern = regexp.MustCompile("^<!-- ....-..-.. ..:..:.. [A-Z]+ / (\\d+) --> <row><v>([^<]+)</v><v>([^<]+)</v></row>")
 | 
			
		||||
@ -29,10 +27,10 @@ func Read(rrdFile string) chan Dataset {
 | 
			
		||||
	stdout, err := cmd.StdoutPipe()
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		log.Panicf("error on get stdout: %s", err)
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
	if err := cmd.Start(); err != nil {
 | 
			
		||||
		log.Panicf("error on start rrdtool: %s", err)
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	r := bufio.NewReader(stdout)
 | 
			
		||||
 | 
			
		||||
@ -14,7 +14,7 @@ type Node struct {
 | 
			
		||||
	Lastseen   jsontime.Time    `json:"lastseen"`
 | 
			
		||||
	Online     bool             `json:"online"`
 | 
			
		||||
	Statistics *data.Statistics `json:"statistics"`
 | 
			
		||||
	Nodeinfo   *data.Nodeinfo   `json:"nodeinfo"`
 | 
			
		||||
	Nodeinfo   *data.NodeInfo   `json:"nodeinfo"`
 | 
			
		||||
	Neighbours *data.Neighbours `json:"-"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -13,7 +13,7 @@ func TestNode(t *testing.T) {
 | 
			
		||||
	node := &Node{}
 | 
			
		||||
	assert.False(node.IsGateway())
 | 
			
		||||
 | 
			
		||||
	node.Nodeinfo = &data.Nodeinfo{}
 | 
			
		||||
	node.Nodeinfo = &data.NodeInfo{}
 | 
			
		||||
	assert.False(node.IsGateway())
 | 
			
		||||
 | 
			
		||||
	node.Nodeinfo.VPN = true
 | 
			
		||||
 | 
			
		||||
@ -2,12 +2,11 @@ package runtime
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"log"
 | 
			
		||||
	"os"
 | 
			
		||||
	"sync"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/data"
 | 
			
		||||
	"github.com/FreifunkBremen/yanic/lib/jsontime"
 | 
			
		||||
)
 | 
			
		||||
@ -64,8 +63,8 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) *Node {
 | 
			
		||||
		}
 | 
			
		||||
		nodes.List[nodeID] = node
 | 
			
		||||
	}
 | 
			
		||||
	if res.Nodeinfo != nil {
 | 
			
		||||
		nodes.readIfaces(res.Nodeinfo)
 | 
			
		||||
	if res.NodeInfo != nil {
 | 
			
		||||
		nodes.readIfaces(res.NodeInfo)
 | 
			
		||||
	}
 | 
			
		||||
	nodes.Unlock()
 | 
			
		||||
 | 
			
		||||
@ -81,7 +80,7 @@ func (nodes *Nodes) Update(nodeID string, res *data.ResponseData) *Node {
 | 
			
		||||
	node.Lastseen = now
 | 
			
		||||
	node.Online = true
 | 
			
		||||
	node.Neighbours = res.Neighbours
 | 
			
		||||
	node.Nodeinfo = res.Nodeinfo
 | 
			
		||||
	node.Nodeinfo = res.NodeInfo
 | 
			
		||||
	node.Statistics = res.Statistics
 | 
			
		||||
 | 
			
		||||
	return node
 | 
			
		||||
@ -182,12 +181,12 @@ func (nodes *Nodes) expire() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// adds the nodes interface addresses to the internal map
 | 
			
		||||
func (nodes *Nodes) readIfaces(nodeinfo *data.Nodeinfo) {
 | 
			
		||||
func (nodes *Nodes) readIfaces(nodeinfo *data.NodeInfo) {
 | 
			
		||||
	nodeID := nodeinfo.NodeID
 | 
			
		||||
	network := nodeinfo.Network
 | 
			
		||||
 | 
			
		||||
	if nodeID == "" {
 | 
			
		||||
		log.Warn("nodeID missing in nodeinfo")
 | 
			
		||||
		log.Println("nodeID missing in nodeinfo")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@ -203,7 +202,7 @@ func (nodes *Nodes) readIfaces(nodeinfo *data.Nodeinfo) {
 | 
			
		||||
		}
 | 
			
		||||
		if oldNodeID, _ := nodes.ifaceToNodeID[addr]; oldNodeID != nodeID {
 | 
			
		||||
			if oldNodeID != "" {
 | 
			
		||||
				log.Warnf("override nodeID from %s to %s on MAC address %s", oldNodeID, nodeID, addr)
 | 
			
		||||
				log.Printf("override nodeID from %s to %s on MAC address %s", oldNodeID, nodeID, addr)
 | 
			
		||||
			}
 | 
			
		||||
			nodes.ifaceToNodeID[addr] = nodeID
 | 
			
		||||
		}
 | 
			
		||||
@ -215,7 +214,7 @@ func (nodes *Nodes) load() {
 | 
			
		||||
 | 
			
		||||
	if f, err := os.Open(path); err == nil { // transform data to legacy meshviewer
 | 
			
		||||
		if err = json.NewDecoder(f).Decode(nodes); err == nil {
 | 
			
		||||
			log.Infof("loaded %d nodes", len(nodes.List))
 | 
			
		||||
			log.Println("loaded", len(nodes.List), "nodes")
 | 
			
		||||
 | 
			
		||||
			nodes.Lock()
 | 
			
		||||
			for _, node := range nodes.List {
 | 
			
		||||
@ -226,10 +225,10 @@ func (nodes *Nodes) load() {
 | 
			
		||||
			nodes.Unlock()
 | 
			
		||||
 | 
			
		||||
		} else {
 | 
			
		||||
			log.Errorf("failed to unmarshal nodes: %s", err)
 | 
			
		||||
			log.Println("failed to unmarshal nodes:", err)
 | 
			
		||||
		}
 | 
			
		||||
	} else {
 | 
			
		||||
		log.Errorf("failed to load cached nodes: %s", err)
 | 
			
		||||
		log.Println("failed to load cached nodes:", err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -55,8 +55,8 @@ func TestLoadAndSave(t *testing.T) {
 | 
			
		||||
	// not autoload without StatePath
 | 
			
		||||
	NewNodes(config)
 | 
			
		||||
 | 
			
		||||
	// Test unmarshalable
 | 
			
		||||
	config.StatePath = "testdata/nodes-broken.json"
 | 
			
		||||
	// Test unmarshalable /dev/null - autolead with StatePath
 | 
			
		||||
	config.StatePath = "/dev/null"
 | 
			
		||||
	nodes := NewNodes(config)
 | 
			
		||||
	// Test unopen able
 | 
			
		||||
	config.StatePath = "/root/nodes.json"
 | 
			
		||||
@ -70,15 +70,13 @@ func TestLoadAndSave(t *testing.T) {
 | 
			
		||||
	nodes.save()
 | 
			
		||||
	os.Remove(tmpfile.Name())
 | 
			
		||||
 | 
			
		||||
	assert.Panics(func() {
 | 
			
		||||
		SaveJSON(nodes, "/proc/a")
 | 
			
		||||
		// "open /proc/a.tmp: permission denied",
 | 
			
		||||
	assert.PanicsWithValue("open /dev/null.tmp: permission denied", func() {
 | 
			
		||||
		SaveJSON(nodes, "/dev/null")
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	tmpfile, _ = ioutil.TempFile("/tmp", "nodes")
 | 
			
		||||
	assert.Panics(func() {
 | 
			
		||||
	assert.PanicsWithValue("json: unsupported type: func() string", func() {
 | 
			
		||||
		SaveJSON(tmpfile.Name, tmpfile.Name())
 | 
			
		||||
		// "json: unsupported type: func() string",
 | 
			
		||||
	})
 | 
			
		||||
	os.Remove(tmpfile.Name())
 | 
			
		||||
 | 
			
		||||
@ -102,7 +100,7 @@ func TestUpdateNodes(t *testing.T) {
 | 
			
		||||
				&data.WirelessAirtime{},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{},
 | 
			
		||||
		NodeInfo: &data.NodeInfo{},
 | 
			
		||||
	}
 | 
			
		||||
	nodes.Update("abcdef012345", res)
 | 
			
		||||
 | 
			
		||||
@ -146,10 +144,10 @@ func TestAddNode(t *testing.T) {
 | 
			
		||||
	nodes.AddNode(&Node{})
 | 
			
		||||
	assert.Len(nodes.List, 0)
 | 
			
		||||
 | 
			
		||||
	nodes.AddNode(&Node{Nodeinfo: &data.Nodeinfo{}})
 | 
			
		||||
	nodes.AddNode(&Node{Nodeinfo: &data.NodeInfo{}})
 | 
			
		||||
	assert.Len(nodes.List, 0)
 | 
			
		||||
 | 
			
		||||
	nodes.AddNode(&Node{Nodeinfo: &data.Nodeinfo{NodeID: "blub"}})
 | 
			
		||||
	nodes.AddNode(&Node{Nodeinfo: &data.NodeInfo{NodeID: "blub"}})
 | 
			
		||||
	assert.Len(nodes.List, 1)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -162,52 +160,18 @@ func TestLinksNodes(t *testing.T) {
 | 
			
		||||
	}
 | 
			
		||||
	assert.Len(nodes.List, 0)
 | 
			
		||||
 | 
			
		||||
	nodes.Update("f4f26dd7a300", &data.ResponseData{
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
			NodeID: "f4f26dd7a300",
 | 
			
		||||
			Network: data.Network{
 | 
			
		||||
				Mac: "f4:f2:6d:d7:a3:00",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
	nodes.Update("f4f26dd7a30a", &data.ResponseData{
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		NodeInfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "f4f26dd7a30a",
 | 
			
		||||
			Network: data.Network{
 | 
			
		||||
				Mac: "f4:f2:6d:d7:a3:0a",
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Neighbours: &data.Neighbours{
 | 
			
		||||
			NodeID: "f4f26dd7a30a",
 | 
			
		||||
			Babel: map[string]data.BabelNeighbours{
 | 
			
		||||
				"vx_mesh_lan": {
 | 
			
		||||
					LinkLocalAddress: "fe80::2",
 | 
			
		||||
					Neighbours: map[string]data.BabelLink{
 | 
			
		||||
						"fe80::1337": {
 | 
			
		||||
							Cost: 26214,
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	nodes.Update("f4f26dd7a30b", &data.ResponseData{
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		NodeInfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "f4f26dd7a30b",
 | 
			
		||||
			Network: data.Network{
 | 
			
		||||
				Mesh: map[string]*data.NetworkInterface{
 | 
			
		||||
					"babel": {
 | 
			
		||||
						Interfaces: struct {
 | 
			
		||||
							Wireless []string `json:"wireless,omitempty"`
 | 
			
		||||
							Other    []string `json:"other,omitempty"`
 | 
			
		||||
							Tunnel   []string `json:"tunnel,omitempty"`
 | 
			
		||||
						}{
 | 
			
		||||
							Other: []string{"fe80::1337"},
 | 
			
		||||
						},
 | 
			
		||||
					},
 | 
			
		||||
				},
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Neighbours: &data.Neighbours{
 | 
			
		||||
			NodeID: "f4f26dd7a30b",
 | 
			
		||||
@ -223,35 +187,21 @@ func TestLinksNodes(t *testing.T) {
 | 
			
		||||
		},
 | 
			
		||||
	})
 | 
			
		||||
 | 
			
		||||
	// no neighbours nodeid
 | 
			
		||||
	node := nodes.List["f4f26dd7a300"]
 | 
			
		||||
	node := nodes.List["f4f26dd7a30a"]
 | 
			
		||||
	assert.NotNil(node)
 | 
			
		||||
	links := nodes.NodeLinks(node)
 | 
			
		||||
	assert.Len(links, 0)
 | 
			
		||||
 | 
			
		||||
	// babel link
 | 
			
		||||
	node = nodes.List["f4f26dd7a30a"]
 | 
			
		||||
	assert.NotNil(node)
 | 
			
		||||
	links = nodes.NodeLinks(node)
 | 
			
		||||
	assert.Len(links, 1)
 | 
			
		||||
	link := links[0]
 | 
			
		||||
	assert.Equal("f4f26dd7a30a", link.SourceID)
 | 
			
		||||
	assert.Equal("fe80::2", link.SourceAddress)
 | 
			
		||||
	assert.Equal("f4f26dd7a30b", link.TargetID)
 | 
			
		||||
	assert.Equal("fe80::1337", link.TargetAddress)
 | 
			
		||||
	assert.Equal(float32(0.6), link.TQ)
 | 
			
		||||
 | 
			
		||||
	// batman link
 | 
			
		||||
	node = nodes.List["f4f26dd7a30b"]
 | 
			
		||||
	assert.NotNil(node)
 | 
			
		||||
	links = nodes.NodeLinks(node)
 | 
			
		||||
	assert.Len(links, 1)
 | 
			
		||||
	link = links[0]
 | 
			
		||||
	assert.Equal("f4f26dd7a30b", link.SourceID)
 | 
			
		||||
	assert.Equal("f4:f2:6d:d7:a3:0b", link.SourceAddress)
 | 
			
		||||
	assert.Equal("f4f26dd7a30a", link.TargetID)
 | 
			
		||||
	assert.Equal("f4:f2:6d:d7:a3:0a", link.TargetAddress)
 | 
			
		||||
	assert.Equal(float32(0.8), link.TQ)
 | 
			
		||||
	link := links[0]
 | 
			
		||||
	assert.Equal(link.SourceID, "f4f26dd7a30b")
 | 
			
		||||
	assert.Equal(link.SourceAddress, "f4:f2:6d:d7:a3:0b")
 | 
			
		||||
	assert.Equal(link.TargetID, "f4f26dd7a30a")
 | 
			
		||||
	assert.Equal(link.TargetAddress, "f4:f2:6d:d7:a3:0a")
 | 
			
		||||
	assert.Equal(link.TQ, float32(0.8))
 | 
			
		||||
 | 
			
		||||
	nodeid := nodes.GetNodeIDbyAddress("f4:f2:6d:d7:a3:0a")
 | 
			
		||||
	assert.Equal("f4f26dd7a30a", nodeid)
 | 
			
		||||
 | 
			
		||||
@ -84,7 +84,7 @@ func createTestNodes() *Nodes {
 | 
			
		||||
				Total: 23,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "abcdef012345",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 841",
 | 
			
		||||
@ -104,7 +104,7 @@ func createTestNodes() *Nodes {
 | 
			
		||||
				Total: 2,
 | 
			
		||||
			},
 | 
			
		||||
		},
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "112233445566",
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
				Model: "TP-Link 841",
 | 
			
		||||
@ -123,7 +123,7 @@ func createTestNodes() *Nodes {
 | 
			
		||||
 | 
			
		||||
	nodes.AddNode(&Node{
 | 
			
		||||
		Online: true,
 | 
			
		||||
		Nodeinfo: &data.Nodeinfo{
 | 
			
		||||
		Nodeinfo: &data.NodeInfo{
 | 
			
		||||
			NodeID: "0xdeadbeef0x",
 | 
			
		||||
			VPN:    true,
 | 
			
		||||
			Hardware: data.Hardware{
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										4
									
								
								runtime/testdata/nodes-broken.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								runtime/testdata/nodes-broken.json
									
									
									
									
										vendored
									
									
								
							@ -1,4 +0,0 @@
 | 
			
		||||
{
 | 
			
		||||
	// make it invalid by this comment
 | 
			
		||||
	"affe": 3
 | 
			
		||||
}
 | 
			
		||||
@ -4,7 +4,6 @@ import (
 | 
			
		||||
	"net/http"
 | 
			
		||||
 | 
			
		||||
	"github.com/NYTimes/gziphandler"
 | 
			
		||||
	"github.com/bdlm/log"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// New creates a new webserver and starts it
 | 
			
		||||
@ -18,6 +17,6 @@ func New(bindAddr, webroot string) *http.Server {
 | 
			
		||||
func Start(srv *http.Server) {
 | 
			
		||||
	// service connections
 | 
			
		||||
	if err := srv.ListenAndServe(); err != http.ErrServerClosed {
 | 
			
		||||
		log.Panicf("webserver crashed: %s", err)
 | 
			
		||||
		panic(err)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user