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