Compare commits

..

No commits in common. "b55a1d35706bf4e13bc32825a3f5d3ac366ff677" and "755b8403a376180921c301a9e96dbc791aae98df" have entirely different histories.

3 changed files with 5 additions and 24 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
internal/meshtastic/generated/* internal/meshtastic/generated/*
website/nodes.json website/nodes.json
blocklist.txt

View file

@ -25,8 +25,6 @@ const (
NeighborExpiration = 7200 // 2 hr NeighborExpiration = 7200 // 2 hr
MetricsExpiration = 7200 // 2 hr MetricsExpiration = 7200 // 2 hr
PruneWriteInterval = time.Minute PruneWriteInterval = time.Minute
RateLimitCount = 4000
RateLimitDuration = time.Hour
) )
var ( var (
@ -227,15 +225,6 @@ func main() {
log.Fatalf("[error] read blocklist: %v", err) log.Fatalf("[error] read blocklist: %v", err)
} }
} }
// maintain per-node message counters for rate limiting
var counters sync.Map // as map[uint32]*uint32
go func() {
for {
time.Sleep(RateLimitDuration)
log.Print("[info] clearing message counters")
counters.Clear()
}
}()
// connect to MQTT // connect to MQTT
client := &meshtastic.MQTTClient{ client := &meshtastic.MQTTClient{
Topics: []string{ Topics: []string{
@ -250,18 +239,8 @@ func main() {
}, },
TopicRegex: regexp.MustCompile(`^msh(?:/[^/]+)+/2/(?:e/[^/]+/![0-9a-f]+|map/)$`), TopicRegex: regexp.MustCompile(`^msh(?:/[^/]+)+/2/(?:e/[^/]+/![0-9a-f]+|map/)$`),
Accept: func(from uint32) bool { Accept: func(from uint32) bool {
if _, found := blocked[from]; found { _, found := blocked[from]
return false return !found
}
v, _ := counters.LoadOrStore(from, new(uint32))
count := atomic.AddUint32(v.(*uint32), 1)
if count >= RateLimitCount {
if count%100 == 0 {
log.Printf("[info] node %v rate limited (%v messages)", from, count)
}
return false
}
return true
}, },
BlockCipher: meshtastic.NewBlockCipher(meshtastic.DefaultKey), BlockCipher: meshtastic.NewBlockCipher(meshtastic.DefaultKey),
MessageHandler: handleMessage, MessageHandler: handleMessage,

View file

@ -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