Sync with d7d7dac8ce830d77cd13324b392ddd1cda35976d
This commit is contained in:
parent
b85c206777
commit
dbf4196854
34
.drone.yml
34
.drone.yml
|
@ -5,12 +5,12 @@ type: docker
|
|||
|
||||
steps:
|
||||
- name: gofmt
|
||||
image: golangci/golangci-lint:v1.50.1-alpine
|
||||
image: golangci/golangci-lint:v1.52.0-alpine
|
||||
commands:
|
||||
- golangci-lint run --color always --no-config --disable-all -E gofmt
|
||||
depends_on: [ clone ]
|
||||
- name: linter
|
||||
image: golangci/golangci-lint:v1.50.1-alpine
|
||||
image: golangci/golangci-lint:v1.52.0-alpine
|
||||
commands:
|
||||
- golangci-lint run --color always
|
||||
depends_on: [ clone ]
|
||||
|
@ -30,7 +30,7 @@ type: docker
|
|||
|
||||
services:
|
||||
- name: mariadb
|
||||
image: mariadb:10.10
|
||||
image: mariadb:10.11
|
||||
pull: always
|
||||
environment:
|
||||
MYSQL_RANDOM_ROOT_PASSWORD: yes
|
||||
|
@ -46,7 +46,7 @@ steps:
|
|||
PLUGIN_HOST: mariadb
|
||||
PLUGIN_PORT: 3306
|
||||
- name: test
|
||||
image: golang:1.19-alpine
|
||||
image: golang:1.20-alpine
|
||||
pull: always
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
|
@ -58,7 +58,7 @@ steps:
|
|||
- go get -v -t -d ./...
|
||||
- go test ./... -v -buildvcs=false -coverprofile=coverage.out
|
||||
- name: coverage
|
||||
image: golang:1.19-alpine
|
||||
image: golang:1.20-alpine
|
||||
commands:
|
||||
- go tool cover -func=coverage.out
|
||||
|
||||
|
@ -100,27 +100,7 @@ steps:
|
|||
commands:
|
||||
- export PLUGIN_REPO=$DOCKER_REGISTRY/chihaya
|
||||
- /usr/local/bin/dockerd-entrypoint.sh /bin/drone-docker
|
||||
when:
|
||||
event:
|
||||
- promote
|
||||
- name: dry-run
|
||||
image: plugins/docker
|
||||
pull: always
|
||||
settings:
|
||||
dry_run: true
|
||||
repo: animebytes/chihaya
|
||||
tags: latest
|
||||
when:
|
||||
event:
|
||||
exclude:
|
||||
- promote
|
||||
|
||||
trigger:
|
||||
ref:
|
||||
- refs/heads/master
|
||||
- refs/pull/**
|
||||
- refs/tags/**
|
||||
|
||||
depends_on:
|
||||
- compliance
|
||||
- tests
|
||||
event:
|
||||
- promote
|
||||
|
|
|
@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
||||
|
||||
## v10.2.0
|
||||
### Changed
|
||||
- Increase announce interval for non-existing torrents
|
||||
|
||||
## v10.1.0
|
||||
### Changed
|
||||
- Use new `util.Semaphore` (introduced in `v10.0.0`) in `database/flush`
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
FROM golang:1.19-alpine AS builder
|
||||
FROM golang:1.20-alpine AS builder
|
||||
WORKDIR /opt/chihaya
|
||||
|
||||
ARG CGO_ENABLED=0
|
||||
|
|
|
@ -298,12 +298,12 @@ func perform(exec func() (interface{}, error)) (result interface{}) {
|
|||
time.Sleep(wait)
|
||||
|
||||
continue
|
||||
} else {
|
||||
log.Error.Printf("SQL error %d: %s", merr.Number, merr.Message)
|
||||
log.WriteStack()
|
||||
|
||||
collectors.IncrementSQLErrorCount()
|
||||
}
|
||||
|
||||
log.Error.Printf("SQL error %d: %s", merr.Number, merr.Message)
|
||||
log.WriteStack()
|
||||
|
||||
collectors.IncrementSQLErrorCount()
|
||||
} else {
|
||||
log.Panic.Printf("Error executing SQL: %s", err)
|
||||
panic(err)
|
||||
|
|
|
@ -791,7 +791,7 @@ func TestRecordAndFlushTorrents(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestTerminate(t *testing.T) {
|
||||
func TestTerminate(_ *testing.T) {
|
||||
prepareTestDatabase()
|
||||
|
||||
db.Terminate()
|
||||
|
|
4
go.mod
4
go.mod
|
@ -7,7 +7,7 @@ require (
|
|||
github.com/go-testfixtures/testfixtures/v3 v3.8.1
|
||||
github.com/jinzhu/copier v0.3.5
|
||||
github.com/prometheus/client_golang v1.14.0
|
||||
github.com/prometheus/common v0.39.0
|
||||
github.com/prometheus/common v0.42.0
|
||||
github.com/zeebo/bencode v1.0.0
|
||||
)
|
||||
|
||||
|
@ -19,7 +19,7 @@ require (
|
|||
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
|
||||
github.com/prometheus/client_model v0.3.0 // indirect
|
||||
github.com/prometheus/procfs v0.8.0 // indirect
|
||||
golang.org/x/sys v0.3.0 // indirect
|
||||
golang.org/x/sys v0.5.0 // indirect
|
||||
google.golang.org/protobuf v1.28.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
|
10
go.sum
10
go.sum
|
@ -41,8 +41,8 @@ github.com/prometheus/client_golang v1.14.0 h1:nJdhIvne2eSX/XRAFV9PcvFFRbrjbcTUj
|
|||
github.com/prometheus/client_golang v1.14.0/go.mod h1:8vpkKitgIVNcqrRBWh1C4TIUQgYNtG/XQE4E/Zae36Y=
|
||||
github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4=
|
||||
github.com/prometheus/client_model v0.3.0/go.mod h1:LDGWKZIo7rky3hgvBe+caln+Dr3dPggB5dvjtD7w9+w=
|
||||
github.com/prometheus/common v0.39.0 h1:oOyhkDq05hPZKItWVBkJ6g6AtGxi+fy7F4JvUV8uhsI=
|
||||
github.com/prometheus/common v0.39.0/go.mod h1:6XBZ7lYdLCbkAVhwRsWTZn+IN5AB9F/NXd5w0BbEX0Y=
|
||||
github.com/prometheus/common v0.42.0 h1:EKsfXEYo4JpWMHH5cg+KOUWeuJSov1Id8zGR8eeI1YM=
|
||||
github.com/prometheus/common v0.42.0/go.mod h1:xBwqVerjNdUDjgODMpudtOMwlOwf2SaTr1yjz4b7Zbc=
|
||||
github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo=
|
||||
github.com/prometheus/procfs v0.8.0/go.mod h1:z7EfXMXOkbkqb9IINtpCn86r/to3BnA0uaxHdg830/4=
|
||||
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
|
||||
|
@ -51,9 +51,9 @@ github.com/zeebo/bencode v1.0.0 h1:zgop0Wu1nu4IexAZeCZ5qbsjU4O1vMrfCrVgUjbHVuA=
|
|||
github.com/zeebo/bencode v1.0.0/go.mod h1:Ct7CkrWIQuLWAy9M3atFHYq4kG9Ao/SsY5cdtCXmp9Y=
|
||||
golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b h1:Qwe1rC8PSniVfAFPFJeyUkB+zcysC3RgJBAGk7eqBEU=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
|
||||
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
|
||||
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
|
|
|
@ -25,7 +25,8 @@
|
|||
],
|
||||
"extends": [
|
||||
"schedule:weekends"
|
||||
]
|
||||
],
|
||||
"automerge": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
@ -175,7 +175,7 @@ func announce(ctx context.Context, qs string, header http.Header, remoteAddr str
|
|||
ip, exists := getPublicIPV4(qp.Get("ip")) // ... then try to get public IP if sent by client
|
||||
|
||||
// Fail if ip and ipv4 are not same, and both are provided
|
||||
if existsV4 && exists && ip != ipV4 {
|
||||
if (existsV4 && exists) && (ip != ipV4) {
|
||||
return ""
|
||||
}
|
||||
|
||||
|
@ -188,10 +188,8 @@ func announce(ctx context.Context, qs string, header http.Header, remoteAddr str
|
|||
}
|
||||
|
||||
// Check for proxied IP header
|
||||
proxyHeader, exists := config.Section("http").Get("proxy_header", "")
|
||||
if exists {
|
||||
ips, exists := header[proxyHeader]
|
||||
if exists && len(ips) > 0 {
|
||||
if proxyHeader, exists := config.Section("http").Get("proxy_header", ""); exists {
|
||||
if ips, exists := header[proxyHeader]; exists && len(ips) > 0 {
|
||||
return ips[0]
|
||||
}
|
||||
}
|
||||
|
@ -225,7 +223,7 @@ func announce(ctx context.Context, qs string, header http.Header, remoteAddr str
|
|||
|
||||
torrent, exists := db.Torrents[infoHashes[0]]
|
||||
if !exists {
|
||||
failure("This torrent does not exist", buf, 30*time.Second)
|
||||
failure("This torrent does not exist", buf, 5*time.Minute)
|
||||
return http.StatusOK // Required by torrent clients to interpret failure response
|
||||
}
|
||||
|
||||
|
@ -239,7 +237,7 @@ func announce(ctx context.Context, qs string, header http.Header, remoteAddr str
|
|||
boolean type so there is no risk of data loss. */
|
||||
go db.UnPrune(torrent)
|
||||
} else if torrent.Status != 0 {
|
||||
failure(fmt.Sprintf("This torrent does not exist (status: %d, left: %d)", torrent.Status, left), buf, 5*time.Minute)
|
||||
failure(fmt.Sprintf("This torrent does not exist (status: %d, left: %d)", torrent.Status, left), buf, 15*time.Minute)
|
||||
return http.StatusOK // Required by torrent clients to interpret failure response
|
||||
}
|
||||
|
||||
|
|
|
@ -36,7 +36,6 @@ import (
|
|||
"chihaya/util"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/zeebo/bencode"
|
||||
)
|
||||
|
||||
type httpHandler struct {
|
||||
|
@ -63,24 +62,6 @@ var (
|
|||
listener net.Listener
|
||||
)
|
||||
|
||||
func failure(err string, buf *bytes.Buffer, interval time.Duration) {
|
||||
failureData := make(map[string]interface{})
|
||||
failureData["failure reason"] = err
|
||||
failureData["interval"] = interval / time.Second // Assuming in seconds
|
||||
failureData["min interval"] = interval / time.Second // Assuming in seconds
|
||||
|
||||
data, errz := bencode.EncodeBytes(failureData)
|
||||
if errz != nil {
|
||||
panic(errz)
|
||||
}
|
||||
|
||||
buf.Reset()
|
||||
|
||||
if _, errz = buf.Write(data); errz != nil {
|
||||
panic(errz)
|
||||
}
|
||||
}
|
||||
|
||||
func (handler *httpHandler) respond(r *http.Request, buf *bytes.Buffer) int {
|
||||
dir, action := path.Split(r.URL.Path)
|
||||
if action == "" {
|
||||
|
|
|
@ -18,13 +18,34 @@
|
|||
package server
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"github.com/zeebo/bencode"
|
||||
"time"
|
||||
|
||||
"chihaya/database"
|
||||
cdb "chihaya/database/types"
|
||||
"chihaya/util"
|
||||
)
|
||||
|
||||
func failure(err string, buf *bytes.Buffer, interval time.Duration) {
|
||||
data := make(map[string]interface{})
|
||||
data["failure reason"] = err
|
||||
data["interval"] = interval / time.Second // Assuming in seconds
|
||||
data["min interval"] = interval / time.Second // Assuming in seconds
|
||||
|
||||
encoded, errz := bencode.EncodeBytes(data)
|
||||
if errz != nil {
|
||||
panic(errz)
|
||||
}
|
||||
|
||||
buf.Reset()
|
||||
|
||||
if _, errz = buf.Write(encoded); errz != nil {
|
||||
panic(errz)
|
||||
}
|
||||
}
|
||||
|
||||
func clientApproved(peerID string, db *database.Database) (uint16, bool) {
|
||||
util.TakeSemaphore(db.ClientsSemaphore)
|
||||
defer util.ReturnSemaphore(db.ClientsSemaphore)
|
||||
|
|
Loading…
Reference in a new issue