mirror of
https://github.com/brianshea2/meshmap.net.git
synced 2025-03-05 21:00:01 -08:00
Compare commits
4 commits
98cb8c734c
...
95cae1c6d0
Author | SHA1 | Date | |
---|---|---|---|
|
95cae1c6d0 | ||
|
37945aa4bc | ||
|
31cf966142 | ||
|
754f73fe8a |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
internal/meshtastic/generated/*
|
internal/meshtastic/generated/*
|
||||||
website/nodes.json
|
website/nodes.json
|
||||||
|
blocklist.txt
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
|
@ -8,6 +9,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
@ -173,8 +175,9 @@ func handleMessage(from uint32, topic string, portNum generated.PortNum, payload
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var dbPath string
|
var dbPath, blockedPath string
|
||||||
flag.StringVar(&dbPath, "f", "", "node database `file`")
|
flag.StringVar(&dbPath, "f", "", "node database `file`")
|
||||||
|
flag.StringVar(&blockedPath, "b", "", "node blocklist `file`")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
// load or make NodeDB
|
// load or make NodeDB
|
||||||
if len(dbPath) > 0 {
|
if len(dbPath) > 0 {
|
||||||
|
@ -187,9 +190,34 @@ func main() {
|
||||||
if Nodes == nil {
|
if Nodes == nil {
|
||||||
Nodes = make(meshtastic.NodeDB)
|
Nodes = make(meshtastic.NodeDB)
|
||||||
}
|
}
|
||||||
|
// load node blocklist
|
||||||
|
blocked := make(map[uint32]struct{})
|
||||||
|
if len(blockedPath) > 0 {
|
||||||
|
f, err := os.Open(blockedPath)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("[error] open blocklist: %v", err)
|
||||||
|
}
|
||||||
|
s := bufio.NewScanner(f)
|
||||||
|
for s.Scan() {
|
||||||
|
n, err := strconv.ParseUint(s.Text(), 10, 32)
|
||||||
|
if err == nil {
|
||||||
|
blocked[uint32(n)] = struct{}{}
|
||||||
|
log.Printf("[info] node %v blocked", n)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
err = s.Err()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("[error] read blocklist: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
// connect to MQTT
|
// connect to MQTT
|
||||||
client := &meshtastic.MQTTClient{
|
client := &meshtastic.MQTTClient{
|
||||||
TopicRegex: regexp.MustCompile(`/2/e/[^/]+/![0-9a-f]+$|/2/map/$`),
|
TopicRegex: regexp.MustCompile(`/2/e/[^/]+/![0-9a-f]+$|/2/map/$`),
|
||||||
|
Accept: func(from uint32) bool {
|
||||||
|
_, found := blocked[from]
|
||||||
|
return !found
|
||||||
|
},
|
||||||
BlockCipher: meshtastic.NewBlockCipher(meshtastic.DefaultKey),
|
BlockCipher: meshtastic.NewBlockCipher(meshtastic.DefaultKey),
|
||||||
MessageHandler: handleMessage,
|
MessageHandler: handleMessage,
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ func NewBlockCipher(key []byte) cipher.Block {
|
||||||
|
|
||||||
type MQTTClient struct {
|
type MQTTClient struct {
|
||||||
TopicRegex *regexp.Regexp
|
TopicRegex *regexp.Regexp
|
||||||
|
Accept func(from uint32) bool
|
||||||
BlockCipher cipher.Block
|
BlockCipher cipher.Block
|
||||||
MessageHandler func(from uint32, topic string, portNum generated.PortNum, payload []byte)
|
MessageHandler func(from uint32, topic string, portNum generated.PortNum, payload []byte)
|
||||||
topics []string
|
topics []string
|
||||||
|
@ -105,6 +106,10 @@ func (c *MQTTClient) handleMessage(_ mqtt.Client, msg mqtt.Message) {
|
||||||
log.Printf("[warn] skipping MeshPacket from unknown on %v", topic)
|
log.Printf("[warn] skipping MeshPacket from unknown on %v", topic)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
// check sender
|
||||||
|
if c.Accept != nil && !c.Accept(from) {
|
||||||
|
return
|
||||||
|
}
|
||||||
// get Data, try decoded first
|
// get Data, try decoded first
|
||||||
data := packet.GetDecoded()
|
data := packet.GetDecoded()
|
||||||
if data == nil {
|
if data == nil {
|
||||||
|
|
|
@ -7,4 +7,5 @@ docker run --name meshobserv \
|
||||||
--restart unless-stopped \
|
--restart unless-stopped \
|
||||||
-v /data:/data \
|
-v /data:/data \
|
||||||
-d meshobserv \
|
-d meshobserv \
|
||||||
-f /data/meshmap.net/website/nodes.json
|
-f /data/meshmap.net/website/nodes.json \
|
||||||
|
-b /data/meshmap.net/blocklist.txt
|
||||||
|
|
Loading…
Reference in a new issue