Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/charles-m-knox/go-wgnetlib
Wireguard net library - quickly create wireguard networks with thousands of peers!
https://github.com/charles-m-knox/go-wgnetlib
generator go golang mesh-networks peers wireguard
Last synced: 10 days ago
JSON representation
Wireguard net library - quickly create wireguard networks with thousands of peers!
- Host: GitHub
- URL: https://github.com/charles-m-knox/go-wgnetlib
- Owner: charles-m-knox
- License: agpl-3.0
- Created: 2024-09-09T22:11:00.000Z (2 months ago)
- Default Branch: main
- Last Pushed: 2024-09-10T00:22:41.000Z (2 months ago)
- Last Synced: 2024-09-11T03:44:52.854Z (2 months ago)
- Topics: generator, go, golang, mesh-networks, peers, wireguard
- Language: Go
- Homepage:
- Size: 56.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wgnetlib
wgnetlib (Wireguard Net Lib) is a Go library that allows generating complete networks of Wireguard peers.
For example, if you wanted to have a set of peers that all exist under `192.168.5.0/24`, this library will allow you to quickly generate a private & public Wireguard key for each peer on the network.
## Usage
### Go library
`wgnetlib` can be used as a Go package like this:
```bash
go get -v github.com/charles-m-knox/go-wgnetlib@latest
```Then:
```go
package mainimport (
"github.com/charles-m-knox/go-wgnetlib/gen"
)func main() {
conf := gen.Configuration{
GenerationParams: gen.GenerationForm{
CIDR: "10.0.0.0/24",
DNS: "10.0.0.1",
Server: "10.0.0.1",
ServerInterface: "eth0",
Endpoint: "5.5.5.5",
EndpointPort: 51820,
MTU: 1280,
AllowedIPs: "0.0.0.0/0",
PersistentKeepAlive: 25,
},
}err = conf.Generate(false)
if err != nil {
log.Fatalf("failed to generate: %v", err.Error())
}b, err := yaml.Marshal(conf)
if err != nil {
log.Fatalf("failed to marshal conf: %v", err.Error())
}err = os.WriteFile("output.yml", b, 0o644)
if err != nil {
log.Fatalf("failed to write output to %v: %v", "output.yml", err.Error())
}
}
```### CLI
```bash
go install github.com/charles-m-knox/go-wgnetlib@latest
````wgnetlib` can be used as a CLI tool, if desired - specify the `-i` flag for fancier terminal output:
```bash
./wgnetlib -i -f config.example.yml -o output.yml
```- specifying the `-f config.example.yml` flag will cause `config.example.yml` to be loaded on startup and its values will be reused for the next run
- specifying `-o output.yml` will write the output to `output.yml`## Rough benchmarks
- `/16`:
- 65,000 IP addresses
- ~2GB RAM usage
- 3.6 seconds
- `/12`:
- 260,000 IP addresses
- ~8-10GB RAM usage
- 15.7 seconds
- `/8` networks and any networks larger than `/12` are currently untested.## Optimization discussion
- This library is more focused on speed than on RAM usage.
- All operations take place directly in RAM. This is intentional for now.
- In the future, I'd like to experiment with writing the data to disk (via a toggleable option, and another option for gzipping to disk) to allow for using disk space as a resource instead of RAM.
- However, the `yaml` serializable format may not be the best choice for accomplishing this.
- When using `wgnetlib` as a library, it may be most desirable to write everything to a `tmp` directory for this use case## Other notes
- I'd like to eventually offer different file formats, such as:
- each peer gets its own file (this will be very useful for the above discussion about using the disk instead of RAM)
- offer gzip/xz compression for each file too
- sqlite (I formerly wrote this to only work with sqlite so I do have the code elsewhere)
- json- **TODO:** remove pkg/wgnetlib's dependency on pterm and instead allow for a function to be passed in that updates progress. `pterm` brings in a few unnecessary dependencies.