Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jpillora committed Jan 6, 2024
1 parent 1a741e3 commit 50a5ad5
Show file tree
Hide file tree
Showing 920 changed files with 937 additions and 442,042 deletions.
16 changes: 16 additions & 0 deletions .github/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# build stage
FROM golang:alpine AS build
RUN apk update && apk add git
ADD . /src
WORKDIR /src
ENV CGO_ENABLED 0
RUN go build \
-trimpath \
-ldflags "-s -w -X main.version=$(git describe --abbrev=0 --tags)" \
-o /tmp/bin
# run stage
FROM scratch
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
WORKDIR /app
COPY --from=build /tmp/bin /app/bin
ENTRYPOINT ["/app/bin"]
39 changes: 39 additions & 0 deletions .github/goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# test this file with
# goreleaser --skip-publish --rm-dist --config goreleaser.yml
builds:
- env:
- CGO_ENABLED=0
flags:
- -trimpath
ldflags:
- -s -w -X main.version={{.Version}}
goos:
- linux
- darwin
- windows
- openbsd
goarch:
- '386'
- amd64
- arm
- arm64
goarm:
- '6'
- '7'
nfpms:
- maintainer: "https://github.com/{{ .Env.GITHUB_USER }}"
formats:
- deb
- rpm
- apk
archives:
- format: gz
files:
- none*
rlcp: true
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
90 changes: 90 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: CI
on:
pull_request: {}
push: {}
permissions: write-all
jobs:
# ================
# BUILD AND TEST JOB
# ================
test:
name: Build & Test
strategy:
matrix:
# optionally test/build across multiple platforms/Go-versions
go-version: ['1.21'] # '1.16', '1.17', '1.18,
platform: [ubuntu-latest] # , macos-latest, windows-latest
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
check-latest: true
- name: Build
run: go build -v -o /dev/null .
- name: Test
run: go test -v ./...
# ================
# RELEASE BINARIES (on push "v*" tag)
# ================
release_binaries:
name: Release Binaries
needs: test
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: goreleaser
uses: docker://goreleaser/goreleaser:latest
env:
GITHUB_USER: ${{ github.repository_owner }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
args: release --config .github/goreleaser.yml
# ================
# RELEASE DOCKER IMAGES (on push "v*" tag)
# ================
release_docker:
name: Release Docker Images
needs: test
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
- name: Build and push
uses: docker/build-push-action@v3
with:
file: .github/Dockerfile
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/386,linux/arm/v7,linux/arm/v6
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

19 changes: 7 additions & 12 deletions engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"sync"
"time"

"github.com/anacrolix/dht"
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/metainfo"
)

//the Engine Cloud Torrent engine, backed by anacrolix/torrent
// the Engine Cloud Torrent engine, backed by anacrolix/torrent
type Engine struct {
mut sync.Mutex
cacheDir string
Expand All @@ -40,16 +38,13 @@ func (e *Engine) Configure(c Config) error {
if c.IncomingPort <= 0 {
return fmt.Errorf("Invalid incoming port (%d)", c.IncomingPort)
}
tc := torrent.Config{
DHTConfig: dht.ServerConfig{
StartingNodes: dht.GlobalBootstrapAddrs,
},
tc := torrent.ClientConfig{
DataDir: c.DownloadDirectory,
ListenAddr: "0.0.0.0:" + strconv.Itoa(c.IncomingPort),
NoUpload: !c.EnableUpload,
Seed: c.EnableSeeding,
ListenHost: func(network string) string { return "0.0.0.0" },
ListenPort: c.IncomingPort,
}
tc.DisableEncryption = c.DisableEncryption

client, err := torrent.NewClient(&tc)
if err != nil {
Expand Down Expand Up @@ -91,8 +86,8 @@ func (e *Engine) newTorrent(tt *torrent.Torrent) error {
return nil
}

//GetTorrents moves torrents out of the anacrolix/torrent
//and into the local cache
// GetTorrents moves torrents out of the anacrolix/torrent
// and into the local cache
func (e *Engine) GetTorrents() map[string]*Torrent {
e.mut.Lock()
defer e.mut.Unlock()
Expand Down Expand Up @@ -218,7 +213,7 @@ func (e *Engine) StartFile(infohash, filepath string) error {
}
t.Started = true
f.Started = true
f.f.PrioritizeRegion(0, f.Size)
// f.f.PrioritizeRegion(0, f.Size)
return nil
}

Expand Down
115 changes: 115 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
module github.com/jpillora/cloud-torrent

go 1.21

require (
github.com/NYTimes/gziphandler v1.1.1
github.com/anacrolix/dht v1.0.1
github.com/anacrolix/torrent v1.53.2
github.com/elazarl/go-bindata-assetfs v1.0.1
github.com/jpillora/archive v0.0.0-20160301031048-e0b3681851f1
github.com/jpillora/backoff v1.0.0
github.com/jpillora/cookieauth v1.1.1
github.com/jpillora/opts v1.2.3
github.com/jpillora/requestlog v1.0.0
github.com/jpillora/scraper v0.3.0
github.com/jpillora/velox v0.4.1
github.com/shirou/gopsutil v3.21.11+incompatible
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
)

require (
github.com/PuerkitoBio/goquery v1.8.1 // indirect
github.com/RoaringBitmap/roaring v1.2.3 // indirect
github.com/ajwerner/btree v0.0.0-20211221152037-f427b3e689c0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/anacrolix/chansync v0.3.0 // indirect
github.com/anacrolix/dht/v2 v2.19.2-0.20221121215055-066ad8494444 // indirect
github.com/anacrolix/envpprof v1.3.0 // indirect
github.com/anacrolix/generics v0.0.0-20230816105729-c755655aee45 // indirect
github.com/anacrolix/go-libutp v1.3.1 // indirect
github.com/anacrolix/log v0.14.3-0.20230823030427-4b296d71a6b4 // indirect
github.com/anacrolix/missinggo v1.3.0 // indirect
github.com/anacrolix/missinggo/perf v1.0.0 // indirect
github.com/anacrolix/missinggo/v2 v2.7.2-0.20230527121029-a582b4f397b9 // indirect
github.com/anacrolix/mmsg v1.0.0 // indirect
github.com/anacrolix/multiless v0.3.0 // indirect
github.com/anacrolix/stm v0.4.0 // indirect
github.com/anacrolix/sync v0.5.1 // indirect
github.com/anacrolix/upnp v0.1.3-0.20220123035249-922794e51c96 // indirect
github.com/anacrolix/utp v0.1.0 // indirect
github.com/andrew-d/go-termutil v0.0.0-20150726205930-009166a695a2 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/bahlo/generic-list-go v0.2.0 // indirect
github.com/benbjohnson/immutable v0.3.0 // indirect
github.com/bits-and-blooms/bitset v1.2.2 // indirect
github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/edsrzf/mmap-go v1.1.0 // indirect
github.com/elithrar/simple-scrypt v1.3.0 // indirect
github.com/floatdrop/lru v1.3.0 // indirect
github.com/go-llsqlite/adapter v0.0.0-20230927005056-7f5ce7f0c916 // indirect
github.com/go-llsqlite/crawshaw v0.4.0 // indirect
github.com/go-logr/logr v1.2.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/websocket v1.5.0 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/hashicorp/go-multierror v1.0.0 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/jpillora/ansi v1.0.3 // indirect
github.com/jpillora/eventsource v1.0.0 // indirect
github.com/jpillora/sizestr v1.0.0 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mschoch/smat v0.2.0 // indirect
github.com/pion/datachannel v1.5.2 // indirect
github.com/pion/dtls/v2 v2.2.4 // indirect
github.com/pion/ice/v2 v2.2.6 // indirect
github.com/pion/interceptor v0.1.11 // indirect
github.com/pion/logging v0.2.2 // indirect
github.com/pion/mdns v0.0.5 // indirect
github.com/pion/randutil v0.1.0 // indirect
github.com/pion/rtcp v1.2.9 // indirect
github.com/pion/rtp v1.7.13 // indirect
github.com/pion/sctp v1.8.2 // indirect
github.com/pion/sdp/v3 v3.0.5 // indirect
github.com/pion/srtp/v2 v2.0.9 // indirect
github.com/pion/stun v0.3.5 // indirect
github.com/pion/transport v0.13.1 // indirect
github.com/pion/transport/v2 v2.0.0 // indirect
github.com/pion/turn/v2 v2.0.8 // indirect
github.com/pion/udp v0.1.4 // indirect
github.com/pion/webrtc/v3 v3.1.42 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/posener/complete v1.2.2-0.20190308074557-af07aa5181b3 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417 // indirect
github.com/ryszard/goskiplist v0.0.0-20150312221310-2dfbae5fcf46 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/tidwall/btree v1.6.0 // indirect
github.com/tklauser/go-sysconf v0.3.13 // indirect
github.com/tklauser/numcpus v0.7.0 // indirect
github.com/tomasen/realip v0.0.0-20180522021738-f0c99a92ddce // indirect
github.com/willf/bitset v1.1.10 // indirect
github.com/willf/bloom v2.0.3+incompatible // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.etcd.io/bbolt v1.3.6 // indirect
go.opentelemetry.io/otel v1.8.0 // indirect
go.opentelemetry.io/otel/trace v1.8.0 // indirect
golang.org/x/crypto v0.5.0 // indirect
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
gomodules.xyz/jsonpatch/v3 v3.0.1 // indirect
gomodules.xyz/orderedmap v0.1.0 // indirect
modernc.org/libc v1.22.3 // indirect
modernc.org/mathutil v1.5.0 // indirect
modernc.org/memory v1.5.0 // indirect
modernc.org/sqlite v1.21.1 // indirect
zombiezen.com/go/sqlite v0.13.1 // indirect
)
Loading

0 comments on commit 50a5ad5

Please sign in to comment.