Sync with 95644b07f093d4ccb9887bab30d68632e4ab2c8a
This commit is contained in:
parent
8e1247d064
commit
0018afe2cd
12
.drone.yml
12
.drone.yml
|
@ -5,12 +5,12 @@ type: docker
|
|||
|
||||
steps:
|
||||
- name: gofmt
|
||||
image: golangci/golangci-lint:v1.42.1
|
||||
image: golangci/golangci-lint:v1.43.0-alpine
|
||||
commands:
|
||||
- golangci-lint run --color always --no-config --disable-all -E gofmt
|
||||
depends_on: [ clone ]
|
||||
- name: linter
|
||||
image: golangci/golangci-lint:v1.42.1
|
||||
image: golangci/golangci-lint:v1.43.0-alpine
|
||||
commands:
|
||||
- golangci-lint run --color always
|
||||
depends_on: [ clone ]
|
||||
|
@ -38,12 +38,12 @@ services:
|
|||
|
||||
steps:
|
||||
- name: await
|
||||
image: albinodrought/drone-wait-for-it@sha256:3bf668201c6f997b630adbd04289f8d3a9119a6b83204b8dff2da2796b681ae1
|
||||
image: albinodrought/drone-wait-for-it
|
||||
environment:
|
||||
PLUGIN_HOST: mariadb
|
||||
PLUGIN_PORT: 3306
|
||||
- name: test
|
||||
image: golang:1.17-alpine3.13
|
||||
image: golang:1.17-alpine
|
||||
pull: always
|
||||
environment:
|
||||
CGO_ENABLED: 0
|
||||
|
@ -55,7 +55,7 @@ steps:
|
|||
- go get -v -t -d ./...
|
||||
- go test ./... -v -coverprofile=coverage.out
|
||||
- name: coverage
|
||||
image: golang:1.17-alpine3.13
|
||||
image: golang:1.17-alpine
|
||||
commands:
|
||||
- go tool cover -func=coverage.out
|
||||
|
||||
|
@ -74,7 +74,7 @@ platform:
|
|||
|
||||
steps:
|
||||
- name: fetch
|
||||
image: alpine/git@sha256:0590372ee83d4d0ff4f08f8d2a98b0ba413d911a2e89c1d3418a1fed9a66337c
|
||||
image: alpine/git
|
||||
commands:
|
||||
- git fetch --tags
|
||||
- name: build
|
||||
|
|
BIN
.gitea/images/flowcharts/ip.png
Normal file
BIN
.gitea/images/flowcharts/ip.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 31 KiB |
|
@ -1,4 +1,4 @@
|
|||
FROM golang:1.17-alpine3.13 AS builder
|
||||
FROM golang:1.17-alpine AS builder
|
||||
WORKDIR /opt/chihaya
|
||||
|
||||
ARG CGO_ENABLED=0
|
||||
|
|
24
README.md
24
README.md
|
@ -4,7 +4,7 @@ chihaya (kuroneko)
|
|||
Installation
|
||||
-------------
|
||||
|
||||
chihaya requires Golang >= 1.14 and MariaDB >= 10.3.3.
|
||||
chihaya requires Golang >= 1.17 and MariaDB >= 10.3.3.
|
||||
|
||||
```sh
|
||||
go get
|
||||
|
@ -154,7 +154,7 @@ split every hour for easier analysis. Every line in a file should be treated as
|
|||
JSON object. Below is a definition on how to read the data:
|
||||
|
||||
```text
|
||||
[torrentId, userId, ipAddr, port, event, seeding, rawUp, rawDown, up, down, left]
|
||||
[torrentId, userId, ipAddr, port, event, seeding, deltaUp, deltaDown, up, down, left]
|
||||
```
|
||||
|
||||
- `torrentId` - the ID of torrent being announced
|
||||
|
@ -181,22 +181,4 @@ Flowcharts
|
|||
-------------
|
||||
|
||||
#### IP resolve
|
||||
```text
|
||||
`ipv4` exists ->
|
||||
yes -> is it public?
|
||||
yes -> `ip` exists?
|
||||
yes -> is it the same as `ipv4`?
|
||||
yes -> use `ipv4`
|
||||
no -> failure
|
||||
no -> use `ipv4`
|
||||
no -> continue
|
||||
no -> `ip` exists?
|
||||
yes -> is it public?
|
||||
yes -> use `ip`
|
||||
no -> continue
|
||||
no -> is proxy allowed?
|
||||
yes -> is configured header present?
|
||||
yes -> use header
|
||||
no -> continue
|
||||
no -> use socket
|
||||
```
|
||||
![IP resolve flowchart](.gitea/images/flowcharts/ip.png)
|
||||
|
|
|
@ -32,6 +32,7 @@ import (
|
|||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeebo/bencode"
|
||||
|
@ -220,13 +221,7 @@ func announce(qs string, header http.Header, remoteAddr string, user *cdb.User,
|
|||
}
|
||||
|
||||
// check for IP in socket
|
||||
portIndex := len(remoteAddr) - 1
|
||||
for ; portIndex >= 0; portIndex-- {
|
||||
if remoteAddr[portIndex] == ':' {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
portIndex := strings.LastIndex(remoteAddr, ":")
|
||||
if portIndex != -1 {
|
||||
return remoteAddr[0:portIndex], true
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue