sync with 9c7eb597b677558078f9ae7d440b6c45a4eaa85a

This commit is contained in:
AnimeBytes 2019-11-30 16:27:08 +01:00
parent 8084931022
commit 0f99611d44
6 changed files with 5 additions and 81 deletions

View file

@ -1,17 +1,6 @@
chihaya (kuroneko)
=======
Due to the many inconsistencies AB has with Gazelle, Chihaya is not ready for general use. Currently the way Chihaya finds out about new and deleted data is by polling the database server, which is highly inefficent and introduces a race condition when data is deleted from the source (due to `INSERT INTO x ON DUPLICATE KEY UPDATE` being used).
Compiling
---------
(Assuming that source tree is under /home/user/go/src/chihaya)
`export GOPATH=$HOME/go` and `export PATH=$PATH:$GOROOT/bin:$GOPATH/bin` to set env
`go get` to fetch dependencies, `go build` to compile.
Configuration
-------------

3
go.mod Normal file
View file

@ -0,0 +1,3 @@
module chihaya
require github.com/ziutek/mymysql v1.5.4

2
go.sum Normal file
View file

@ -0,0 +1,2 @@
ithub.com/ziutek/mymysql v1.5.4 h1:GB0qdRGsTwQSBVYuVShFBKaXSnSnYYC2d9knnE1LHFs=
github.com/ziutek/mymysql v1.5.4/go.mod h1:LMSpPZ6DbqWFxNCHW77HeMg9I646SAhApZ/wKdgO/C0=

View file

@ -283,7 +283,6 @@ func announce(params *queryParams, user *cdb.User, ipAddr string, db *cdb.Databa
db.RecordTorrent(torrent, deltaSnatch)
db.RecordTransferHistory(peer, rawDeltaUpload, rawDeltaDownload, deltaTime, deltaSeedTime, deltaSnatch, active)
db.RecordUser(user, rawDeltaUpload, rawDeltaDownload, deltaUpload, deltaDownload)
record(peer.TorrentId, user.Id, rawDeltaUpload, rawDeltaDownload, uploaded, event, ipAddr)
db.RecordTransferIp(peer, rawDeltaUpload, rawDeltaDownload)
// Generate response

View file

@ -1,69 +0,0 @@
package server
import (
"bytes"
"os"
"strconv"
"time"
)
var recordChan chan []byte
func openEventFile(t time.Time) (*os.File, error) {
return os.OpenFile("events/events_"+t.Format("2006-01-02T15")+".json", os.O_RDWR|os.O_APPEND|os.O_CREATE, 0644)
}
func init() {
err := os.Mkdir("events", 0755)
if err != nil && !os.IsExist(err) {
panic(err)
}
start := time.Now()
recordChan = make(chan []byte)
recordFile, err := openEventFile(start)
if err != nil {
panic(err)
}
go func() {
for buf := range recordChan {
now := time.Now()
if now.Hour() != start.Hour() {
start = now
recordFile.Close()
recordFile, err = openEventFile(start)
if err != nil {
panic(err)
}
}
recordFile.Write(buf)
}
}()
}
func record(tid, uid uint64, up, down int64, absup uint64, event, ip string) {
if up == 0 && down == 0 {
return
}
b := make([]byte, 0, 64)
buf := bytes.NewBuffer(b)
buf.WriteString("[")
buf.WriteString(strconv.FormatUint(tid, 10))
buf.WriteString(",")
buf.WriteString(strconv.FormatUint(uid, 10))
buf.WriteString(",")
buf.WriteString(strconv.FormatInt(up, 10))
buf.WriteString(",")
buf.WriteString(strconv.FormatInt(down, 10))
buf.WriteString(",")
buf.WriteString(strconv.FormatUint(absup, 10))
buf.WriteString(",\"")
buf.WriteString(event)
buf.WriteString("\",\"")
buf.WriteString(ip)
buf.WriteString("\"]\n")
recordChan <- buf.Bytes()
}