rename module name from bt to go-bt

This commit is contained in:
xgfone
2023-04-01 21:07:18 +08:00
parent fad4a74a4a
commit a212793117
46 changed files with 84 additions and 78 deletions

View File

@ -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
View File

@ -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
.*
_*

View File

@ -1,11 +1,11 @@
# BT - Another Implementation For Golang [![Build Status](https://github.com/xgfone/bt/actions/workflows/go.yml/badge.svg)](https://github.com/xgfone/bt/actions/workflows/go.yml) [![GoDoc](https://pkg.go.dev/badge/github.com/xgfone/bt)](https://pkg.go.dev/github.com/xgfone/bt) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](https://raw.githubusercontent.com/xgfone/bt/master/LICENSE)
# BT - Another Implementation For Golang [![Build Status](https://github.com/xgfone/go-bt/actions/workflows/go.yml/badge.svg)](https://github.com/xgfone/go-bt/actions/workflows/go.yml) [![GoDoc](https://pkg.go.dev/badge/github.com/xgfone/go-bt)](https://pkg.go.dev/github.com/xgfone/go-bt) [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg?style=flat-square)](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).

View File

@ -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.

View File

@ -19,7 +19,7 @@ import (
"testing"
"time"
"github.com/xgfone/bt/krpc"
"github.com/xgfone/go-bt/krpc"
)
func (bl *blacklist) portsLen() (n int) {

View File

@ -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 (

View File

@ -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 {

View File

@ -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.

View File

@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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 {

View File

@ -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 {

View File

@ -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.

View File

@ -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
View File

@ -1,3 +1,3 @@
module github.com/xgfone/bt
module github.com/xgfone/go-bt
go 1.11

View File

@ -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,

View File

@ -19,7 +19,7 @@ import (
"net"
"testing"
"github.com/xgfone/bt/bencode"
"github.com/xgfone/go-bt/bencode"
)
func TestAddr(t *testing.T) {

View File

@ -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.

View File

@ -17,7 +17,7 @@ package krpc
import (
"testing"
"github.com/xgfone/bt/bencode"
"github.com/xgfone/go-bt/bencode"
)
func TestMessage(t *testing.T) {

View File

@ -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.

View File

@ -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,

View File

@ -19,7 +19,7 @@ import (
"net"
"testing"
"github.com/xgfone/bt/bencode"
"github.com/xgfone/go-bt/bencode"
)
func TestCompactAddr(t *testing.T) {

View File

@ -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.

View File

@ -17,7 +17,7 @@ package metainfo
import (
"testing"
"github.com/xgfone/bt/bencode"
"github.com/xgfone/go-bt/bencode"
)
func TestAddress(t *testing.T) {

View File

@ -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)
}
}

View File

@ -24,7 +24,7 @@ import (
"fmt"
"io"
"github.com/xgfone/bt/bencode"
"github.com/xgfone/go-bt/bencode"
)
var zeroHash Hash

View File

@ -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.

View File

@ -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.

View File

@ -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")

View File

@ -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) {

View File

@ -18,7 +18,7 @@ import (
"net"
"testing"
"github.com/xgfone/bt/metainfo"
"github.com/xgfone/go-bt/metainfo"
)
func TestGenerateAllowedFastSet(t *testing.T) {

View File

@ -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")

View File

@ -14,9 +14,7 @@
package peerprotocol
import (
"testing"
)
import "testing"
func TestBitField(t *testing.T) {
bf := NewBitFieldFromBools([]bool{

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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")

View File

@ -18,7 +18,7 @@ import (
"reflect"
"testing"
"github.com/xgfone/bt/metainfo"
"github.com/xgfone/go-bt/metainfo"
)
func TestHTTPAnnounceRequest(t *testing.T) {

View File

@ -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.

View File

@ -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{}

View File

@ -25,7 +25,7 @@ import (
"fmt"
"net"
"github.com/xgfone/bt/metainfo"
"github.com/xgfone/go-bt/metainfo"
)
const maxBufSize = 2048

View File

@ -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.

View File

@ -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.

View File

@ -22,7 +22,7 @@ import (
"net"
"time"
"github.com/xgfone/bt/metainfo"
"github.com/xgfone/go-bt/metainfo"
)
type testHandler struct{}