Add scheduler, rate limiting and headless mode.
Hard-coded 60s URL and 10s host floors with jitter and per-host backoff, shared between dibs processes through a locked state file. The scheduler shuffles due URLs each round and runs one worker per host; 'dibs --headless' watches and logs JSON.
This commit is contained in:
1 parent
bb010356a0
commit
2175c0e5aa
30 files changed
+1434
-126
No files matched your search
+3
-28
@@ -7,7 +7,6 @@ import (
|
||||
"maps"
|
||||
"net/url"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"slices"
|
||||
"strings"
|
||||
"sync"
|
||||
@@ -16,6 +15,8 @@ import (
|
||||
http "github.com/bogdanfinn/fhttp"
|
||||
"github.com/bogdanfinn/fhttp/cookiejar"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
|
||||
"git.security-command.org/Overlord/dibs/internal/fsutil"
|
||||
)
|
||||
|
||||
// Cookie is a stored cookie, in a form that survives a restart and can be
|
||||
@@ -54,7 +55,6 @@ func NewJar() *Jar {
|
||||
}
|
||||
}
|
||||
|
||||
// SetCookies implements http.CookieJar.
|
||||
func (j *Jar) SetCookies(u *url.URL, cookies []*http.Cookie) {
|
||||
j.mu.Lock()
|
||||
defer j.mu.Unlock()
|
||||
@@ -91,7 +91,6 @@ func (j *Jar) SetCookies(u *url.URL, cookies []*http.Cookie) {
|
||||
}
|
||||
}
|
||||
|
||||
// Cookies implements http.CookieJar.
|
||||
func (j *Jar) Cookies(u *url.URL) []*http.Cookie {
|
||||
j.mu.Lock()
|
||||
defer j.mu.Unlock()
|
||||
@@ -160,7 +159,7 @@ func (j *Jar) Save(path string) error {
|
||||
data, err := json.MarshalIndent(j.Export(), "", " ")
|
||||
if err != nil { return err }
|
||||
|
||||
return writeFileAtomic(path, data, 0o600)
|
||||
return fsutil.WriteFileAtomic(path, data, 0o600)
|
||||
}
|
||||
|
||||
// Load imports the cookies saved at path. A missing file is not an error.
|
||||
@@ -186,27 +185,3 @@ func defaultPath(p string) string {
|
||||
|
||||
return p[:i]
|
||||
}
|
||||
|
||||
// writeFileAtomic replaces path with data, so a crash never leaves a
|
||||
// half-written file behind.
|
||||
func writeFileAtomic(path string, data []byte, perm fs.FileMode) error {
|
||||
if err := os.MkdirAll(filepath.Dir(path), 0o700); err != nil { return err }
|
||||
|
||||
tmp, err := os.CreateTemp(filepath.Dir(path), "."+filepath.Base(path)+".*")
|
||||
if err != nil { return err }
|
||||
defer func() { _ = os.Remove(tmp.Name()) }()
|
||||
|
||||
if err := tmp.Chmod(perm); err != nil {
|
||||
_ = tmp.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := tmp.Write(data); err != nil {
|
||||
_ = tmp.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
if err := tmp.Close(); err != nil { return err }
|
||||
|
||||
return os.Rename(tmp.Name(), path)
|
||||
}
|
||||
Reference in new issue
Block a user