frontend/udp: generate private key when empty
This commit is contained in:
parent
a48b9a50c3
commit
6deebdd6d4
2 changed files with 15 additions and 1 deletions
|
@ -25,7 +25,6 @@ config:
|
||||||
addr: 0.0.0.0:6881
|
addr: 0.0.0.0:6881
|
||||||
allow_ip_spoofing: true
|
allow_ip_spoofing: true
|
||||||
max_clock_skew: 10s
|
max_clock_skew: 10s
|
||||||
private_key: "/K8AybyuKkob03fZJb+3Fu87eVcBNWsvVyDDxGd3wfvVGix10j6iGDEyS/ELPvQIIZvUPl2PnyfnpG6g1YJ/sw=="
|
|
||||||
storage:
|
storage:
|
||||||
gc_interval: 14m
|
gc_interval: 14m
|
||||||
peer_lifetime: 15m
|
peer_lifetime: 15m
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
@ -18,6 +19,8 @@ import (
|
||||||
"github.com/chihaya/chihaya/frontend/udp/bytepool"
|
"github.com/chihaya/chihaya/frontend/udp/bytepool"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var allowedGeneratedPrivateKeyRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
prometheus.MustRegister(promResponseDurationMilliseconds)
|
prometheus.MustRegister(promResponseDurationMilliseconds)
|
||||||
}
|
}
|
||||||
|
@ -68,6 +71,18 @@ type Frontend struct {
|
||||||
|
|
||||||
// NewFrontend allocates a new instance of a Frontend.
|
// NewFrontend allocates a new instance of a Frontend.
|
||||||
func NewFrontend(logic frontend.TrackerLogic, cfg Config) *Frontend {
|
func NewFrontend(logic frontend.TrackerLogic, cfg Config) *Frontend {
|
||||||
|
// Generate a private key if one isn't provided by the user.
|
||||||
|
if cfg.PrivateKey == "" {
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
pkeyRunes := make([]rune, 64)
|
||||||
|
for i := range pkeyRunes {
|
||||||
|
pkeyRunes[i] = allowedGeneratedPrivateKeyRunes[rand.Intn(len(allowedGeneratedPrivateKeyRunes))]
|
||||||
|
}
|
||||||
|
cfg.PrivateKey = string(pkeyRunes)
|
||||||
|
|
||||||
|
log.Warn("UDP private key was not provided, using generated key: ", cfg.PrivateKey)
|
||||||
|
}
|
||||||
|
|
||||||
return &Frontend{
|
return &Frontend{
|
||||||
closing: make(chan struct{}),
|
closing: make(chan struct{}),
|
||||||
logic: logic,
|
logic: logic,
|
||||||
|
|
Loading…
Reference in a new issue