Skip to content

Commit

Permalink
chore: grimd -> leng rename (#31)
Browse files Browse the repository at this point in the history
* chore: grimd -> leng rename

* update README
  • Loading branch information
cottand authored Nov 13, 2023
1 parent 048a5e0 commit 7bf0238
Show file tree
Hide file tree
Showing 19 changed files with 114 additions and 119 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ env:
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
REGISTRY_IMAGE: "ghcr.io/cottand/grimd"
REGISTRY_IMAGE: "ghcr.io/cottand/leng"


jobs:
docker:
Expand Down
8 changes: 4 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.vscode
*.test
pprof/
grimd.exe
leng.exe
*.swp
.idea
sources
grimd
grimd.log
grimd.toml
leng
leng.log
leng.toml
.DS_Store

result
60 changes: 27 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# grimd
# leng

[![Go Report Card](https://goreportcard.com/badge/github.com/cottand/grimd?style=flat-square)](https://goreportcard.com/report/github.com/cottand/grimd)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](http://godoc.org/github.com/cottand/grimd)
[![Release](https://github.com/cottand/grimd/actions/workflows/release.yaml/badge.svg)](https://github.com/cottand/grimd/releases)
[![Go Report Card](https://goreportcard.com/badge/github.com/cottand/leng?style=flat-square)](https://goreportcard.com/report/github.com/cottand/leng)
[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat-square)](http://godoc.org/github.com/cottand/leng)
[![Build](https://github.com/Cottand/leng/actions/workflows/build.yml/badge.svg?branch=master)](https://github.com/Cottand/leng/actions/workflows/build.yml)

:zap: Fast dns proxy, built to black-hole internet advertisements and malware servers. Capable of custom DNS.
:zap: fast dns server, built to block advertisements and malware servers

Forked from [looterz/grimd](https://github.com/looterz/grimd)
Forked from [looterz/grimd](https://github.com/looterz/leng)

# Features

Expand All @@ -18,51 +18,51 @@ Forked from [looterz/grimd](https://github.com/looterz/grimd)
- [x] Blocklist fetching
- [x] Hardcoded blocklist config
- [x] Hardcoded whitelist config
- [x] Fast startup _(so it can be used with templating for service discovery)_
- [x] Fast startup and tiny image _(so it can be quickly redeployed for use with templating for service discovery)_
- [x] Small memory footprint (~50MBs with metrics and DoH enabled)

# Installation

```
go install github.com/cottand/grimd@latest
go install github.com/cottand/leng@latest
```

You can also
- download one of the binary [releases](https://github.com/cottand/grimd/releases)
- use the [Docker image](https://github.com/cottand/grimd/pkgs/container/grimd)
- `docker run -d -p 53:53/udp -p 53:53/tcp -p 8080:8080/tcp ghcr.io/cottand/grimd`
- use [Docker compose YML](https://raw.githubusercontent.com/cottand/grimd/master/docker-compose.yml)
- use the [Nix flake](https://github.com/Cottand/grimd/tree/master/flake.nix)
- `nix run github:cottand/grimd`
- download one of the binary [releases](https://github.com/cottand/leng/releases)
- use the [Docker image](https://github.com/cottand/leng/pkgs/container/leng)
- `docker run -d -p 53:53/udp -p 53:53/tcp -p 8080:8080/tcp ghcr.io/cottand/leng`
- use [Docker compose YML](https://raw.githubusercontent.com/cottand/leng/master/docker-compose.yml)
- use the [Nix flake](https://github.com/Cottand/leng/tree/master/flake.nix)
- `nix run github:cottand/leng`

Detailed guides and resources can be found on the [wiki](https://github.com/cottand/grimd/wiki).
Detailed guides and resources can be found on the [wiki](https://github.com/cottand/leng/wiki).

# Configuration

By default, grimd binds DNS to `0.0.0.0:53` and loads a few known blocklists. The default settings should be enough for
By default, leng binds DNS to `0.0.0.0:53` and loads a few known blocklists. The default settings should be enough for
most.
See [the wiki](https://github.com/Cottand/grimd/wiki/Configuration) for the full config, including defaults and dynamic
See [the wiki](https://github.com/Cottand/leng/wiki/Configuration) for the full config, including defaults and dynamic
config reloading.

### CLI Flags

```bash
$ grimd -help
$ leng -help

Usage of grimd:
Usage of leng:
-config string
location of the config file (default "grimd.toml")
location of the config file (default "leng.toml")
-update
force an update of the blocklist database

```

# Building

Requires golang 1.21 or higher, you build grimd like any other golang application, for example to build for linux x64
Requires golang 1.21 or higher, you build leng like any other golang application, for example to build for linux x64

```shell
env GOOS=linux GOARCH=amd64 go build -v github.com/cottand/grimd
env GOOS=linux GOARCH=amd64 go build -v github.com/cottand/leng
```

# Building Docker
Expand All @@ -71,8 +71,8 @@ Run container and test

```shell
mkdir sources
docker build -t grimd:latest -f docker/alpine.Dockerfile . && \
docker run -v $PWD/sources:/sources --rm -it -P --name grimd-test grimd:latest --config /sources/grimd.toml --update
docker build -t leng:latest -f docker/alpine.Dockerfile . && \
docker run -v $PWD/sources:/sources --rm -it -P --name leng-test leng:latest --config /sources/leng.toml --update
```

By default, if the program runs in a docker, it will automatically replace `127.0.0.1` in the default configuration
Expand All @@ -82,16 +82,10 @@ with `0.0.0.0` to ensure that the API interface is available.
curl -H "Accept: application/json" http://127.0.0.1:55006/application/active
```

# Speed

Incoming requests spawn a goroutine and are served concurrently, and the block cache resides in-memory to allow for
rapid lookups, while answered queries are cached allowing grimd to serve thousands of queries at once while maintaining
a memory footprint of under 30mb for 100,000 blocked domains!

# Daemonize

You can find examples of different daemon scripts for grimd on
the [wiki](https://github.com/looterz/grimd/wiki/Daemon-Scripts).
You can find examples of different daemon scripts for leng on
the [wiki](https://github.com/looterz/leng/wiki/Daemon-Scripts).

# Objectives

Expand All @@ -108,7 +102,7 @@ the [wiki](https://github.com/looterz/grimd/wiki/Daemon-Scripts).

## Non-objectives

**Not keeping it simple**: I would like grimd to become
**Not keeping it simple**: I would like leng to become
a reliable custom DNS provider (like CoreDNS) and a reliable
adblocker (like Blocky) that has the perfect set of features
for self-hosters, and potentially for more critical setups.
18 changes: 9 additions & 9 deletions activation.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,35 +40,35 @@ forever:
case <-quit:
break forever
case <-a.queryChannel:
a.queryChannel <- grimdActive
a.queryChannel <- lengActive
case v := <-a.toggleChannel:
// Firefox is sending 2 queries in a row, so debouncing is needed.
if v.Mode == 1 && nextToggleTime.After(time.Now()) {
logger.Warning("Toggle is too close: wait 10 seconds\n")
} else {
if v.Mode == 1 {
grimdActive = !grimdActive
lengActive = !lengActive
} else {
grimdActive = false
lengActive = false
}
nextToggleTime = time.Now().Add(time.Duration(10) * time.Second)
if !grimdActive && reactivationDelay > 0 {
if !lengActive && reactivationDelay > 0 {
reactivate = time.Now().Add(time.Duration(v.Data) * time.Second)
reactivatePending = true
} else {
reactivatePending = false
}
a.queryChannel <- grimdActive
a.queryChannel <- lengActive
}
case v := <-a.setChannel:
grimdActive = v
lengActive = v
reactivatePending = false
a.setChannel <- grimdActive
a.setChannel <- lengActive
case <-ticker:
now := time.Now()
if reactivatePending && now.After(reactivate) {
logger.Notice("Reactivating grimd (timer)")
grimdActive = true
logger.Notice("Reactivating leng (timer)")
lengActive = true
reactivatePending = false
}
}
Expand Down
14 changes: 7 additions & 7 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func StartAPIServer(config *Config,
})

router.GET("/application/active", func(c *gin.Context) {
c.IndentedJSON(http.StatusOK, gin.H{"active": grimdActive})
c.IndentedJSON(http.StatusOK, gin.H{"active": lengActive})
})

// Handle the setting of active state.
Expand All @@ -234,20 +234,20 @@ func StartAPIServer(config *Config,
} else {
switch active {
case "On":
grimdActivation.set(true)
c.IndentedJSON(http.StatusOK, gin.H{"active": grimdActive})
lengActivation.set(true)
c.IndentedJSON(http.StatusOK, gin.H{"active": lengActive})
case "Off":
grimdActivation.set(false)
c.IndentedJSON(http.StatusOK, gin.H{"active": grimdActive})
lengActivation.set(false)
c.IndentedJSON(http.StatusOK, gin.H{"active": lengActive})
case "Snooze":
timeoutString := c.DefaultQuery("timeout", "300")
timeout, err := strconv.ParseUint(timeoutString, 0, 0)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "Illegal value for 'timeout'"})
} else {
grimdActivation.toggleOff(uint(timeout))
lengActivation.toggleOff(uint(timeout))
c.IndentedJSON(http.StatusOK, gin.H{
"active": grimdActive,
"active": lengActive,
"timeout": timeout,
})
}
Expand Down
18 changes: 9 additions & 9 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
cTls "crypto/tls"
"errors"
"fmt"
"github.com/cottand/grimd/tls"
"github.com/cottand/leng/tls"
"github.com/jonboulle/clockwork"
"github.com/pelletier/go-toml/v2"
"log"
Expand All @@ -13,10 +13,10 @@ import (
"strings"
)

// BuildVersion returns the build version of grimd, this should be incremented every new release
// BuildVersion returns the build version of leng, this should be incremented every new release
var BuildVersion = "1.3.0"

// ConfigVersion returns the version of grimd, this should be incremented every time the config changes so grimd presents a warning
// ConfigVersion returns the version of leng, this should be incremented every time the config changes so leng presents a warning
var ConfigVersion = "1.3.0"

// Config holds the configuration parameters
Expand Down Expand Up @@ -99,7 +99,7 @@ sourcedirs = [
# stderr>@<loglevel>
# syslog@<loglevel>
# loglevel: 0 = errors and important operations, 1 = dns queries, 2 = debug
# e.g. logconfig = "file:grimd.log@2,syslog@1,stderr@2"
# e.g. logconfig = "file:leng.log@2,syslog@1,stderr@2"
logconfig = "stderr@2"
# apidebug enables the debug mode of the http api library
Expand Down Expand Up @@ -153,10 +153,10 @@ customdnsrecords = [
# "example.other.tld IN CNAME wikipedia.org"
]
# When this string is queried, toggle grimd on and off
# When this string is queried, toggle leng on and off
togglename = ""
# If not zero, the delay in seconds before grimd automaticall reactivates after
# If not zero, the delay in seconds before leng automaticall reactivates after
# having been turned off.
reactivationdelay = 300
Expand All @@ -166,7 +166,7 @@ DoH = "https://cloudflare-dns.com/dns-query"
# How deep to follow chains of CNAME records
# set to 0 to disable CNAME-following entirely
# (anything more than 10 should be more than plenty)
# see https://github.com/Cottand/grimd/wiki/CNAME%E2%80%90following-DNS
# see https://github.com/Cottand/leng/wiki/CNAME%E2%80%90following-DNS
followCnameDepth = 12
# Prometheus metrics - disabled by default
Expand Down Expand Up @@ -254,9 +254,9 @@ func LoadConfig(path string) (*Config, error) {
config.Version = "none"
}

log.Printf("warning, grimd.toml is out of date!\nconfig v%s\ngrimd config v%s\ngrimd v%s\nplease update your config\n", config.Version, ConfigVersion, BuildVersion)
log.Printf("warning, leng.toml is out of date!\nconfig v%s\nleng config v%s\nleng v%s\nplease update your config\n", config.Version, ConfigVersion, BuildVersion)
} else {
log.Printf("grimd v%s\n", BuildVersion)
log.Printf("leng v%s\n", BuildVersion)
}

return &config, nil
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
grimd:
image: ghcr.io/cottand/grimd:latest
leng:
image: ghcr.io/cottand/leng:latest
ports:
- "53:53/udp"
- "53:53/tcp"
Expand Down
2 changes: 1 addition & 1 deletion doh.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"crypto/tls"
"encoding/base64"
"fmt"
"github.com/cottand/grimd/internal/metric"
"github.com/cottand/leng/internal/metric"
"github.com/miekg/dns"
"github.com/prometheus/client_golang/prometheus"
"io"
Expand Down
16 changes: 8 additions & 8 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
description = "Grimd, a fast dns proxy, built to black-hole internet advertisements and malware servers";
description = "Leng, a fast dns proxy, built to black-hole internet advertisements and malware servers";


inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
Expand All @@ -12,34 +12,34 @@
# Build & packaging
## use with `nix build`
packages = rec {
grimd = pkgs.buildGo121Module {
leng = pkgs.buildGo121Module {
inherit system;
vendorSha256 = "sha256-5dIZzqaw88lKuh1JHJurRZCPgrNzDHK/53bXKNGQBvQ=";
pname = "grimd";
pname = "leng";
version = "0.0.1-test";
src = ./.;
};
default = grimd;
default = leng;
};


# Dev environment
## use with `nix develop`
devShells = rec {
grimd = pkgs.mkShell {
leng = pkgs.mkShell {
packages = [ pkgs.fish pkgs.go_1_21 ];
# Note that `shellHook` still uses bash syntax. This starts fish, then exists the bash shell when fish exits.
shellHook = "fish && exit";
};
default = grimd;
default = leng;
};


# App
## use with `nix run`
apps = rec {
grimd = flake-utils.lib.mkApp { drv = self.packages.${system}.grimd; };
default = grimd;
leng = flake-utils.lib.mkApp { drv = self.packages.${system}.leng; };
default = leng;
};

}));
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/cottand/grimd
module github.com/cottand/leng

require (
github.com/gin-gonic/gin v1.9.1
Expand Down
6 changes: 3 additions & 3 deletions grimd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func integrationTest(changeConfig func(c *Config), test func(client *dns.Client,
actChannel := make(chan *ActivationHandler)

go startActivation(actChannel, quitActivation, config.ReactivationDelay)
grimdActivation = <-actChannel
grimdActive = true
lengActivation = <-actChannel
lengActive = true
close(actChannel)

server := &Server{
Expand Down Expand Up @@ -290,7 +290,7 @@ func TestConfigReloadForCustomRecords(t *testing.T) {
actChannel := make(chan *ActivationHandler)

go startActivation(actChannel, quitActivation, config.ReactivationDelay)
grimdActivation = <-actChannel
lengActivation = <-actChannel
close(actChannel)

server := &Server{
Expand Down
Loading

0 comments on commit 7bf0238

Please sign in to comment.