Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
C
Coredns
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Railgun
Coredns
Commits
f21fa187
Commit
f21fa187
authored
Jul 28, 2020
by
Miek Gieben
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move to new torrent lib
Signed-off-by:
Miek Gieben
<
miek@miek.nl
>
parent
37e60387
Changes
12
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
25 additions
and
312 deletions
+25
-312
core/dnsserver/zdirectives.go
core/dnsserver/zdirectives.go
+1
-1
core/plugin/zplugin.go
core/plugin/zplugin.go
+1
-1
go.mod
go.mod
+1
-0
go.sum
go.sum
+21
-0
plugin.cfg
plugin.cfg
+1
-1
plugin/torrent/README.md
plugin/torrent/README.md
+0
-48
plugin/torrent/info.go
plugin/torrent/info.go
+0
-75
plugin/torrent/session.go
plugin/torrent/session.go
+0
-49
plugin/torrent/setup.go
plugin/torrent/setup.go
+0
-58
plugin/torrent/setup_test.go
plugin/torrent/setup_test.go
+0
-53
plugin/torrent/testdata/db.miek.nl
plugin/torrent/testdata/db.miek.nl
+0
-17
plugin/torrent/torrent.go
plugin/torrent/torrent.go
+0
-9
No files found.
core/dnsserver/zdirectives.go
View file @
f21fa187
...
@@ -55,5 +55,5 @@ var Directives = []string{
...
@@ -55,5 +55,5 @@ var Directives = []string{
"whoami"
,
"whoami"
,
"on"
,
"on"
,
"sign"
,
"sign"
,
"torrent"
,
"
bit
torrent"
,
}
}
core/plugin/zplugin.go
View file @
f21fa187
...
@@ -11,6 +11,7 @@ import (
...
@@ -11,6 +11,7 @@ import (
_
"github.com/coredns/coredns/plugin/autopath"
_
"github.com/coredns/coredns/plugin/autopath"
_
"github.com/coredns/coredns/plugin/azure"
_
"github.com/coredns/coredns/plugin/azure"
_
"github.com/coredns/coredns/plugin/bind"
_
"github.com/coredns/coredns/plugin/bind"
_
"github.com/coredns/coredns/plugin/bittorrent"
_
"github.com/coredns/coredns/plugin/bufsize"
_
"github.com/coredns/coredns/plugin/bufsize"
_
"github.com/coredns/coredns/plugin/cache"
_
"github.com/coredns/coredns/plugin/cache"
_
"github.com/coredns/coredns/plugin/cancel"
_
"github.com/coredns/coredns/plugin/cancel"
...
@@ -46,7 +47,6 @@ import (
...
@@ -46,7 +47,6 @@ import (
_
"github.com/coredns/coredns/plugin/sign"
_
"github.com/coredns/coredns/plugin/sign"
_
"github.com/coredns/coredns/plugin/template"
_
"github.com/coredns/coredns/plugin/template"
_
"github.com/coredns/coredns/plugin/tls"
_
"github.com/coredns/coredns/plugin/tls"
_
"github.com/coredns/coredns/plugin/torrent"
_
"github.com/coredns/coredns/plugin/trace"
_
"github.com/coredns/coredns/plugin/trace"
_
"github.com/coredns/coredns/plugin/transfer"
_
"github.com/coredns/coredns/plugin/transfer"
_
"github.com/coredns/coredns/plugin/whoami"
_
"github.com/coredns/coredns/plugin/whoami"
...
...
go.mod
View file @
f21fa187
...
@@ -8,6 +8,7 @@ require (
...
@@ -8,6 +8,7 @@ require (
github.com/Azure/go-autorest/autorest/azure/auth v0.5.0
github.com/Azure/go-autorest/autorest/azure/auth v0.5.0
github.com/DataDog/datadog-go v3.5.0+incompatible // indirect
github.com/DataDog/datadog-go v3.5.0+incompatible // indirect
github.com/Shopify/sarama v1.21.0 // indirect
github.com/Shopify/sarama v1.21.0 // indirect
github.com/anacrolix/torrent v1.0.0
github.com/apache/thrift v0.13.0 // indirect
github.com/apache/thrift v0.13.0 // indirect
github.com/aws/aws-sdk-go v1.33.7
github.com/aws/aws-sdk-go v1.33.7
github.com/caddyserver/caddy v1.0.5
github.com/caddyserver/caddy v1.0.5
...
...
go.sum
View file @
f21fa187
This diff is collapsed.
Click to expand it.
plugin.cfg
View file @
f21fa187
...
@@ -64,4 +64,4 @@ erratic:erratic
...
@@ -64,4 +64,4 @@ erratic:erratic
whoami:whoami
whoami:whoami
on:github.com/caddyserver/caddy/onevent
on:github.com/caddyserver/caddy/onevent
sign:sign
sign:sign
torrent:
torrent
bittorrent:bit
torrent
plugin/torrent/README.md
deleted
100644 → 0
View file @
37e60387
# torrent
## Name
*torrent*
- use BitTorrent to disseminate zone data.
## Description
The
*torrent*
plugin uses the BitTorrent protocol to disseminate zone data. Multiple peers can
connect and down- and upload the data. A couple of nodes can be
`seed`
only meaning they will update
the torrent when their zone data changes. Non-
`seed`
peers will write received data back into the
zonefile - once the torrent is fully downloaded.
## Syntax
The simplest syntax is for a peer wanting to receive the zone data:
~~~
txt
torrent DBFILE
~~~
*
**DBFILE**
the zone database file to torrent. If the path is relative, the path from the
*root*
plugin will be prepended to it.
For peers seeding the torrent use this, slightly expanded, syntax
~~~
txt
torrent DBFILE {
dht
// directory (temp storage)
// port for dth, etc.
}
~~~
*
`dth`
starts a DTH server on address
## Examples
~~~
txt
example.org {
file db.example.org
torrent db.example.org
}
~~~
## Also See
## Bugs
plugin/torrent/info.go
deleted
100644 → 0
View file @
37e60387
package
torrent
import
(
"crypto/sha1"
"io"
"os"
"strings"
"github.com/zeebo/bencode"
)
const
pieceLength
=
2048
*
10
// pieces will hash the file in path on 256kb boundaries and return the (sha1) hashes.
func
pieces
(
path
string
)
(
int
,
string
,
error
)
{
f
,
err
:=
os
.
Open
(
path
)
if
err
!=
nil
{
return
0
,
""
,
err
}
hashes
:=
""
// concatenated string of hash (strings)
buf
:=
make
([]
byte
,
2048
)
h
:=
sha1
.
New
()
chunk
:=
0
length
:=
0
n
,
err
:=
f
.
Read
(
buf
)
for
err
!=
nil
{
h
.
Write
(
buf
[
:
n
])
chunk
++
length
+=
n
if
chunk
>
10
{
chunk
=
0
hashes
+=
string
(
h
.
Sum
(
nil
))
h
=
sha1
.
New
()
}
n
,
err
=
f
.
Read
(
buf
)
}
if
n
>
0
{
length
+=
n
h
.
Write
(
buf
[
:
n
])
hashes
+=
string
(
h
.
Sum
(
nil
))
}
return
length
,
hashes
,
nil
}
// Info is the torrent meta data for a single file.
type
Info
struct
{
Pieces
string
`bencode:"pieces"`
PieceLength
int
`bencode:"piece length"`
Length
int
`bencode:"length"`
Name
string
`bencode:"name"`
}
// TorrentInfo contains the meta data for this torrent.
type
TorrentInfo
struct
{
Nodes
[]
string
`bencode:"nodes"`
Info
Info
`bencode:"info"`
}
func
NewTorrentInfo
(
path
string
)
(
*
TorrentInfo
,
error
)
{
length
,
pieces
,
err
:=
pieces
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
i
:=
Info
{
Pieces
:
pieces
,
PieceLength
:
2048
*
10
,
Length
:
length
,
Name
:
path
}
return
&
TorrentInfo
{
Nodes
:
[]
string
{},
Info
:
i
},
nil
}
func
(
t
*
TorrentInfo
)
ToReader
()
io
.
Reader
{
s
,
err
:=
bencode
.
EncodeString
(
t
)
if
err
!=
nil
{
return
nil
}
return
strings
.
NewReader
(
s
)
}
plugin/torrent/session.go
deleted
100644 → 0
View file @
37e60387
package
torrent
import
(
"io/ioutil"
"log"
"path/filepath"
"time"
rtorrent
"github.com/cenkalti/rain/torrent"
)
func
(
t
*
Torrent
)
Do
()
error
{
dc
:=
rtorrent
.
DefaultConfig
dc
.
DHTEnabled
=
t
.
dht
dc
.
RPCEnabled
=
false
dc
.
DHTBootstrapNodes
=
[]
string
{
"127.0.0.1:7246"
}
// its a me
td
,
err
:=
ioutil
.
TempDir
(
""
,
"example"
)
if
err
!=
nil
{
return
err
}
dc
.
DataDir
=
td
dc
.
Database
=
filepath
.
Join
(
td
,
"session.db"
)
s
,
err
:=
rtorrent
.
NewSession
(
dc
)
if
err
!=
nil
{
return
err
}
ti
,
err
:=
NewTorrentInfo
(
"plugin/torrent/testdata/db.miek.nl"
)
if
err
!=
nil
{
return
err
}
tor
,
err
:=
s
.
AddTorrent
(
ti
.
ToReader
(),
nil
)
if
err
!=
nil
{
return
err
}
// mag, _ := tor.Magnet()
go
s
.
StartAll
()
// Watch the progress
for
range
time
.
Tick
(
time
.
Second
)
{
s
:=
tor
.
Stats
()
log
.
Printf
(
"Status: %s, Downloaded: %d, Peers: %d"
,
s
.
Status
.
String
(),
s
.
Bytes
.
Completed
,
s
.
Peers
.
Total
)
}
return
nil
}
plugin/torrent/setup.go
deleted
100644 → 0
View file @
37e60387
package
torrent
import
(
"path/filepath"
"github.com/coredns/coredns/core/dnsserver"
"github.com/coredns/coredns/plugin"
"github.com/caddyserver/caddy"
)
func
init
()
{
plugin
.
Register
(
"torrent"
,
setup
)
}
func
setup
(
c
*
caddy
.
Controller
)
error
{
tor
,
err
:=
parse
(
c
)
if
err
!=
nil
{
return
plugin
.
Error
(
"torrent"
,
err
)
}
c
.
OnStartup
(
func
()
error
{
err
:=
tor
.
Do
()
return
err
})
c
.
OnShutdown
(
func
()
error
{
close
(
tor
.
stop
)
return
nil
})
// Don't call AddPlugin, *sign* is not a plugin.
return
nil
}
func
parse
(
c
*
caddy
.
Controller
)
(
*
Torrent
,
error
)
{
t
:=
&
Torrent
{
stop
:
make
(
chan
struct
{})}
config
:=
dnsserver
.
GetConfig
(
c
)
for
c
.
Next
()
{
if
!
c
.
NextArg
()
{
return
nil
,
c
.
ArgErr
()
}
dbfile
:=
c
.
Val
()
if
!
filepath
.
IsAbs
(
dbfile
)
&&
config
.
Root
!=
""
{
dbfile
=
filepath
.
Join
(
config
.
Root
,
dbfile
)
}
t
.
dbfile
=
dbfile
for
c
.
NextBlock
()
{
switch
c
.
Val
()
{
case
"dht"
:
t
.
dht
=
true
default
:
return
nil
,
c
.
Errf
(
"unknown property '%s'"
,
c
.
Val
())
}
}
}
return
t
,
nil
}
plugin/torrent/setup_test.go
deleted
100644 → 0
View file @
37e60387
package
torrent
import
(
"testing"
"github.com/caddyserver/caddy"
)
func
TestParse
(
t
*
testing
.
T
)
{
tests
:=
[]
struct
{
input
string
shouldErr
bool
exp
*
Torrent
}{
{
`torrent testdata/db.miek.nl {
dht
}`
,
false
,
&
Torrent
{
dbfile
:
"testdata/db.miek.nl"
,
dht
:
true
},
},
{
`torrent testdata/db.miek.nl`
,
false
,
&
Torrent
{
dbfile
:
"testdata/db.miek.nl"
},
},
// errors
{
`torrent db.example.org {
bla
}`
,
true
,
nil
,
},
}
for
i
,
tc
:=
range
tests
{
c
:=
caddy
.
NewTestController
(
"dns"
,
tc
.
input
)
tor
,
err
:=
parse
(
c
)
if
err
==
nil
&&
tc
.
shouldErr
{
t
.
Fatalf
(
"Test %d expected errors, but got no error"
,
i
)
}
if
err
!=
nil
&&
!
tc
.
shouldErr
{
t
.
Fatalf
(
"Test %d expected no errors, but got '%v'"
,
i
,
err
)
}
if
tc
.
shouldErr
{
continue
}
if
x
:=
tor
.
dbfile
;
x
!=
tc
.
exp
.
dbfile
{
t
.
Errorf
(
"Test %d expected %s as dbfile, got %s"
,
i
,
tc
.
exp
.
dbfile
,
x
)
}
if
x
:=
tor
.
dth
;
x
!=
tc
.
exp
.
dth
{
t
.
Errorf
(
"Test %d expected %T as seed, got %T"
,
i
,
tc
.
exp
.
dth
,
x
)
}
}
}
plugin/torrent/testdata/db.miek.nl
deleted
100644 → 0
View file @
37e60387
$TTL 30M
$ORIGIN miek.nl.
@ IN SOA linode.atoom.net. miek.miek.nl. ( 1282630060 4H 1H 7D 4H )
IN NS linode.atoom.net.
IN MX 1 aspmx.l.google.com.
IN AAAA 2a01:7e00::f03c:91ff:fe79:234c
IN DNSKEY 257 3 13 sfzRg5nDVxbeUc51su4MzjgwpOpUwnuu81SlRHqJuXe3SOYOeypR69tZ52XLmE56TAmPHsiB8Rgk+NTpf0o1Cw==
a IN AAAA 2a01:7e00::f03c:91ff:fe79:234c
www IN CNAME a
bla IN NS ns1.bla.com.
ns3.blaaat.miek.nl. IN AAAA ::1 ; non-glue, should be signed.
; in baliwick nameserver that requires glue, should not be signed
bla IN NS ns2.bla.miek.nl.
ns2.bla.miek.nl. IN A 127.0.0.1
plugin/torrent/torrent.go
deleted
100644 → 0
View file @
37e60387
package
torrent
// Torrent contains the file data that needs to be torrented.
type
Torrent
struct
{
dbfile
string
dht
bool
stop
chan
struct
{}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment