aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorXe <me@christine.website>2022-09-02 18:55:18 +0000
committerXe <me@christine.website>2022-09-02 18:55:18 +0000
commit75a1ed48b9ca46788edd5ee597d357700326c0d4 (patch)
tree118502449ea4330d89bd3b82dad93f1dfc38860a /cmd
parente6329f22d52770cc09e5268183630045e2b038d9 (diff)
downloadx-75a1ed48b9ca46788edd5ee597d357700326c0d4.tar.xz
x-75a1ed48b9ca46788edd5ee597d357700326c0d4.zip
don't group groupcache i guess
Signed-off-by: Xe <me@christine.website>
Diffstat (limited to 'cmd')
-rw-r--r--cmd/xedn/fly.toml4
-rw-r--r--cmd/xedn/main.go63
2 files changed, 61 insertions, 6 deletions
diff --git a/cmd/xedn/fly.toml b/cmd/xedn/fly.toml
index b0c9374..a1ad8c0 100644
--- a/cmd/xedn/fly.toml
+++ b/cmd/xedn/fly.toml
@@ -23,8 +23,8 @@ processes = []
script_checks = []
[services.concurrency]
- hard_limit = 25
- soft_limit = 20
+ hard_limit = 100
+ soft_limit = 75
type = "connections"
[[services.ports]]
diff --git a/cmd/xedn/main.go b/cmd/xedn/main.go
index b0327d4..30dc159 100644
--- a/cmd/xedn/main.go
+++ b/cmd/xedn/main.go
@@ -5,11 +5,15 @@ import (
"bytes"
"context"
"encoding/gob"
+ "errors"
"flag"
"fmt"
"io"
"log"
+ "net"
"net/http"
+ "net/netip"
+ "net/url"
"os"
"strings"
@@ -26,7 +30,6 @@ import (
var (
b2Backend = flag.String("b2-backend", "https://f001.backblazeb2.com", "Backblaze B2 base URL")
addr = flag.String("addr", ":8080", "server address")
- peers = flag.String("peers", "http://localhost:8080", "server pool list")
)
const cacheSize = 128 * 1024 * 1024 // 128 mebibytes
@@ -72,6 +75,60 @@ var Group = groupcache.NewGroup("b2-bucket", cacheSize, groupcache.GetterFunc(
},
))
+func findLocalPeer(peers []string) (string, error) {
+ var addrs []net.Addr
+ ifaces, err := net.Interfaces()
+ if err != nil {
+ return "", err
+ }
+
+ for _, iface := range ifaces {
+ ifaceAddrs, err := iface.Addrs()
+ if err != nil {
+ return "", err
+ }
+
+ addrs = append(addrs, ifaceAddrs...)
+ }
+
+ for _, addr := range addrs {
+ prefix, err := netip.ParsePrefix(addr.String())
+ if err != nil {
+ return "", err
+ }
+
+ for _, peer := range peers {
+ ln.Log(context.Background(), ln.F{"peer": peer, "addr": prefix.Addr().String()})
+ if strings.Contains(peer, prefix.Addr().String()) {
+ return peer, nil
+ }
+ }
+ }
+
+ return "", errors.New("can't find local peer somehow")
+}
+
+func discoverPeers() ([]string, error) {
+ ips, err := net.LookupIP("xedn.internal")
+ if err != nil {
+return nil, err
+ }
+
+ var result []string
+
+ for _, ip := range ips {
+ nip, _ := netip.AddrFromSlice(ip)
+ ipp := netip.AddrPortFrom(nip, 8081)
+ u, err := url.Parse("http://" + ipp.String())
+ if err != nil {
+ return nil, err
+ }
+ result = append(result, u.String())
+ }
+
+ return result, nil
+}
+
func main() {
internal.HandleStartup()
ctx := opname.With(context.Background(), "startup")
@@ -123,9 +180,7 @@ func main() {
w.WriteHeader(http.StatusOK)
w.Write(result.Body)
})
- p := strings.Split(*peers, ",")
- pool := groupcache.NewHTTPPool(p[0])
- pool.Set(p...)
+
ln.Log(context.Background(), ln.F{"addr": *addr})
http.ListenAndServe(*addr, xffMW.Handler(ex.HTTPLog(mux)))
}