rename module name from bt to go-bt
This commit is contained in:
4
.github/workflows/go.yml
vendored
4
.github/workflows/go.yml
vendored
@ -9,6 +9,8 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
go:
|
||||
- '1.9'
|
||||
- '1.10'
|
||||
- '1.11'
|
||||
- '1.12'
|
||||
- '1.13'
|
||||
@ -25,4 +27,4 @@ jobs:
|
||||
uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: ${{ matrix.go }}
|
||||
- run: go test -race ./...
|
||||
- run: go test -race -cover ./...
|
||||
|
11
.gitignore
vendored
11
.gitignore
vendored
@ -33,11 +33,16 @@ test_*
|
||||
# log
|
||||
*.log
|
||||
|
||||
# Mac
|
||||
.DS_Store
|
||||
vendor/
|
||||
|
||||
# VS Code
|
||||
.vscode/
|
||||
debug
|
||||
debug_test
|
||||
|
||||
# Unix hidden files
|
||||
# Mac
|
||||
.DS_Store
|
||||
|
||||
# hidden files
|
||||
.*
|
||||
_*
|
||||
|
@ -1,11 +1,11 @@
|
||||
# BT - Another Implementation For Golang [](https://github.com/xgfone/bt/actions/workflows/go.yml) [](https://pkg.go.dev/github.com/xgfone/bt) [](https://raw.githubusercontent.com/xgfone/bt/master/LICENSE)
|
||||
# BT - Another Implementation For Golang [](https://github.com/xgfone/go-bt/actions/workflows/go.yml) [](https://pkg.go.dev/github.com/xgfone/go-bt) [](https://raw.githubusercontent.com/xgfone/go-bt/master/LICENSE)
|
||||
|
||||
A pure golang implementation of [BitTorrent](http://bittorrent.org/beps/bep_0000.html) library, which is inspired by [dht](https://github.com/shiyanhui/dht) and [torrent](https://github.com/anacrolix/torrent).
|
||||
|
||||
## Install
|
||||
|
||||
```shell
|
||||
$ go get -u github.com/xgfone/bt
|
||||
$ go get -u github.com/xgfone/go-bt
|
||||
```
|
||||
|
||||
## Features
|
||||
@ -38,4 +38,4 @@ $ go get -u github.com/xgfone/bt
|
||||
|
||||
## Example
|
||||
|
||||
See [godoc](https://pkg.go.dev/github.com/xgfone/bt) or [bttools](https://github.com/xgfone/bttools).
|
||||
See [godoc](https://pkg.go.dev/github.com/xgfone/go-bt) or [bttools](https://github.com/xgfone/bttools).
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/krpc"
|
||||
"github.com/xgfone/go-bt/krpc"
|
||||
)
|
||||
|
||||
// Blacklist is used to manage the ip blacklist.
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/krpc"
|
||||
"github.com/xgfone/go-bt/krpc"
|
||||
)
|
||||
|
||||
func (bl *blacklist) portsLen() (n int) {
|
||||
|
@ -25,9 +25,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/bt/krpc"
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
"github.com/xgfone/go-bt/krpc"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -20,9 +20,9 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/internal/helper"
|
||||
"github.com/xgfone/bt/krpc"
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/internal/helper"
|
||||
"github.com/xgfone/go-bt/krpc"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
type testPeerManager struct {
|
||||
|
@ -18,8 +18,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/krpc"
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/krpc"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
// PeerManager is used to manage the peers.
|
||||
|
@ -19,8 +19,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/krpc"
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/krpc"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
const bktlen = 160
|
||||
|
@ -17,8 +17,8 @@ package dht
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/krpc"
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/krpc"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
// RoutingTableNode represents the node with last changed time in the routing table.
|
||||
|
@ -18,8 +18,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/internal/helper"
|
||||
"github.com/xgfone/bt/krpc"
|
||||
"github.com/xgfone/go-bt/internal/helper"
|
||||
"github.com/xgfone/go-bt/krpc"
|
||||
)
|
||||
|
||||
// TokenManager is used to manage and validate the token.
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/krpc"
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/krpc"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
type transaction struct {
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
package downloader
|
||||
|
||||
import pp "github.com/xgfone/bt/peerprotocol"
|
||||
import pp "github.com/xgfone/go-bt/peerprotocol"
|
||||
|
||||
// BlockDownloadHandler is used to downloads the files in the torrent file.
|
||||
type BlockDownloadHandler struct {
|
||||
|
@ -26,8 +26,8 @@ import (
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
pp "github.com/xgfone/bt/peerprotocol"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
pp "github.com/xgfone/go-bt/peerprotocol"
|
||||
)
|
||||
|
||||
// BlockSize is the size of a block of the piece.
|
||||
|
@ -20,9 +20,9 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/bt/peerprotocol"
|
||||
pp "github.com/xgfone/bt/peerprotocol"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
"github.com/xgfone/go-bt/peerprotocol"
|
||||
pp "github.com/xgfone/go-bt/peerprotocol"
|
||||
)
|
||||
|
||||
type bep10Handler struct {
|
||||
|
2
go.mod
2
go.mod
@ -1,3 +1,3 @@
|
||||
module github.com/xgfone/bt
|
||||
module github.com/xgfone/go-bt
|
||||
|
||||
go 1.11
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
)
|
||||
|
||||
// Addr represents an address based on ip and port,
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
)
|
||||
|
||||
func TestAddr(t *testing.T) {
|
||||
|
@ -18,8 +18,8 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
// Predefine some error code.
|
||||
|
@ -17,7 +17,7 @@ package krpc
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
)
|
||||
|
||||
func TestMessage(t *testing.T) {
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
// Node represents a node information.
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
)
|
||||
|
||||
// CompactAddr represents an address based on ip and port,
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
)
|
||||
|
||||
func TestCompactAddr(t *testing.T) {
|
||||
|
@ -20,7 +20,7 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
)
|
||||
|
||||
// HostAddr represents an address based on host and port.
|
||||
|
@ -17,7 +17,7 @@ package metainfo
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
)
|
||||
|
||||
func TestAddress(t *testing.T) {
|
||||
|
@ -89,10 +89,10 @@ func TestNewInfoFromFilePath(t *testing.T) {
|
||||
t.Errorf("invalid info %+v\n", info)
|
||||
}
|
||||
|
||||
info, err = NewInfoFromFilePath("../../bt", PieceSize256KB)
|
||||
info, err = NewInfoFromFilePath("../../go-bt", PieceSize256KB)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else if info.Name != "bt" || info.Files == nil || info.Length > 0 {
|
||||
} else if info.Name != "go-bt" || info.Files == nil || info.Length > 0 {
|
||||
t.Errorf("invalid info %+v\n", info)
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
)
|
||||
|
||||
var zeroHash Hash
|
||||
|
@ -20,8 +20,8 @@ import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/bt/internal/helper"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
"github.com/xgfone/go-bt/internal/helper"
|
||||
)
|
||||
|
||||
// Bytes is the []byte type.
|
||||
|
@ -21,7 +21,7 @@ import (
|
||||
"io"
|
||||
"sort"
|
||||
|
||||
"github.com/xgfone/bt/internal/helper"
|
||||
"github.com/xgfone/go-bt/internal/helper"
|
||||
)
|
||||
|
||||
// BlockSize is the default size of a piece block.
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"errors"
|
||||
"net"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
)
|
||||
|
||||
var errInvalidIP = errors.New("invalid ipv4 or ipv6")
|
||||
|
@ -19,16 +19,17 @@ import (
|
||||
"encoding/binary"
|
||||
"net"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
// GenerateAllowedFastSet generates some allowed fast set of the torrent file.
|
||||
//
|
||||
// Argument:
|
||||
// set: generated piece set, the length of which is the number to be generated.
|
||||
// sz: the number of pieces in torrent.
|
||||
// ip: the of the remote peer of the connection.
|
||||
// infohash: infohash of torrent.
|
||||
//
|
||||
// set: generated piece set, the length of which is the number to be generated.
|
||||
// sz: the number of pieces in torrent.
|
||||
// ip: the of the remote peer of the connection.
|
||||
// infohash: infohash of torrent.
|
||||
//
|
||||
// BEP 6
|
||||
func GenerateAllowedFastSet(set []uint32, sz uint32, ip net.IP, infohash metainfo.Hash) {
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
func TestGenerateAllowedFastSet(t *testing.T) {
|
||||
|
@ -19,7 +19,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
var errInvalidProtocolHeader = fmt.Errorf("unexpected peer protocol header string")
|
||||
|
@ -14,9 +14,7 @@
|
||||
|
||||
package peerprotocol
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
import "testing"
|
||||
|
||||
func TestBitField(t *testing.T) {
|
||||
bf := NewBitFieldFromBools([]bool{
|
||||
|
@ -21,8 +21,8 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
// Predefine some errors about extension support.
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
// Handler is used to handle the incoming peer connection.
|
||||
|
@ -17,7 +17,7 @@ package tracker
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
// GetPeers gets the peers from the tracker.
|
||||
|
@ -28,8 +28,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
// AnnounceRequest is the tracker announce requests.
|
||||
|
@ -18,8 +18,8 @@ import (
|
||||
"errors"
|
||||
"net"
|
||||
|
||||
"github.com/xgfone/bt/bencode"
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/bencode"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
var errInvalidPeer = errors.New("invalid bt peer information format")
|
||||
|
@ -18,7 +18,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
func TestHTTPAnnounceRequest(t *testing.T) {
|
||||
|
@ -26,9 +26,9 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/bt/tracker/httptracker"
|
||||
"github.com/xgfone/bt/tracker/udptracker"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
"github.com/xgfone/go-bt/tracker/httptracker"
|
||||
"github.com/xgfone/go-bt/tracker/udptracker"
|
||||
)
|
||||
|
||||
// Predefine some announce events.
|
||||
|
@ -22,8 +22,8 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/bt/tracker/udptracker"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
"github.com/xgfone/go-bt/tracker/udptracker"
|
||||
)
|
||||
|
||||
type testHandler struct{}
|
||||
|
@ -25,7 +25,7 @@ import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
const maxBufSize = 2048
|
||||
|
@ -26,7 +26,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
// NewClientByDial returns a new Client by dialing.
|
||||
|
@ -24,7 +24,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
// ServerHandler is used to handle the request from the client.
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/xgfone/bt/metainfo"
|
||||
"github.com/xgfone/go-bt/metainfo"
|
||||
)
|
||||
|
||||
type testHandler struct{}
|
||||
|
Reference in New Issue
Block a user