fixed some go vet warnings, fixed formatting
This commit is contained in:
parent
e4bb7b5b35
commit
4b9b354171
13
Makefile
13
Makefile
@ -7,3 +7,16 @@ magneticow:
|
|||||||
# TODO: minify files!
|
# TODO: minify files!
|
||||||
go-bindata -o="magneticow/bindata.go" -prefix="magneticow/data/" magneticow/data/...
|
go-bindata -o="magneticow/bindata.go" -prefix="magneticow/data/" magneticow/data/...
|
||||||
go install magnetico/magneticow
|
go install magnetico/magneticow
|
||||||
|
|
||||||
|
test:
|
||||||
|
go test github.com/boramalper/magnetico/cmd/magneticod/...
|
||||||
|
@echo
|
||||||
|
go test github.com/boramalper/magnetico/cmd/magneticow/...
|
||||||
|
@echo
|
||||||
|
go test github.com/boramalper/magnetico/pkg/persistence/...
|
||||||
|
|
||||||
|
format:
|
||||||
|
gofmt -w cmd/magneticod
|
||||||
|
gofmt -w cmd/magneticow
|
||||||
|
gofmt -w pkg/persistence
|
||||||
|
|
||||||
|
@ -86,7 +86,9 @@ func (l *Leech) doBtHandshake() error {
|
|||||||
))
|
))
|
||||||
|
|
||||||
// ASSERTION
|
// ASSERTION
|
||||||
if len(lHandshake) != 68 { panic(fmt.Sprintf("len(lHandshake) == %d", len(lHandshake))) }
|
if len(lHandshake) != 68 {
|
||||||
|
panic(fmt.Sprintf("len(lHandshake) == %d", len(lHandshake)))
|
||||||
|
}
|
||||||
|
|
||||||
err := l.writeAll(lHandshake)
|
err := l.writeAll(lHandshake)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -148,15 +150,15 @@ func (l *Leech) doExHandshake() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *Leech) requestAllPieces() error {
|
func (l *Leech) requestAllPieces() error {
|
||||||
/*
|
// reqq
|
||||||
* reqq
|
// An integer, the number of outstanding request messages this client supports without
|
||||||
* An integer, the number of outstanding request messages this client supports without
|
// dropping any. The default in in libtorrent is 250.
|
||||||
* dropping any. The default in in libtorrent is 250.
|
//
|
||||||
* "handshake message" @ "Extension Protocol" @ http://www.bittorrent.org/beps/bep_0010.html
|
// "handshake message" @ "Extension Protocol" @ http://www.bittorrent.org/beps/bep_0010.html
|
||||||
*
|
//
|
||||||
* TODO: maybe by requesting all pieces at once we are exceeding this limit? maybe we should
|
// TODO: maybe by requesting all pieces at once we are exceeding this limit? maybe we should
|
||||||
* request as we receive pieces?
|
// request as we receive pieces?
|
||||||
*/
|
|
||||||
// Request all the pieces of metadata
|
// Request all the pieces of metadata
|
||||||
nPieces := int(math.Ceil(float64(l.metadataSize) / math.Pow(2, 14)))
|
nPieces := int(math.Ceil(float64(l.metadataSize) / math.Pow(2, 14)))
|
||||||
for piece := 0; piece < nPieces; piece++ {
|
for piece := 0; piece < nPieces; piece++ {
|
||||||
@ -213,7 +215,7 @@ func (l *Leech) readExMessage() ([]byte, error) {
|
|||||||
|
|
||||||
// Every extension message has at least 2 bytes.
|
// Every extension message has at least 2 bytes.
|
||||||
if len(rMessage) < 2 {
|
if len(rMessage) < 2 {
|
||||||
continue;
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// We are interested only in extension messages, whose first byte is always 20
|
// We are interested only in extension messages, whose first byte is always 20
|
||||||
@ -483,4 +485,3 @@ func toBigEndian(i uint, n int) []byte {
|
|||||||
|
|
||||||
return b
|
return b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,7 +258,6 @@ func (e *Error) UnmarshalBencode(b []byte) (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(matches[2]) != msgLen {
|
if len(matches[2]) != msgLen {
|
||||||
return
|
|
||||||
return fmt.Errorf("error message have different lengths (%d vs %d) \"%s\"!", len(matches[2]), msgLen, matches[2])
|
return fmt.Errorf("error message have different lengths (%d vs %d) \"%s\"!", len(matches[2]), msgLen, matches[2])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -221,9 +221,8 @@ func (p *Protocol) CalculateToken(address net.IP) []byte {
|
|||||||
func (p *Protocol) VerifyToken(address net.IP, token []byte) bool {
|
func (p *Protocol) VerifyToken(address net.IP, token []byte) bool {
|
||||||
p.tokenLock.Lock()
|
p.tokenLock.Lock()
|
||||||
defer p.tokenLock.Unlock()
|
defer p.tokenLock.Unlock()
|
||||||
|
// TODO: implement VerifyToken()
|
||||||
panic("VerifyToken() not implemented yet!")
|
panic("VerifyToken() not implemented yet!")
|
||||||
// TODO
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Protocol) updateTokenSecret() {
|
func (p *Protocol) updateTokenSecret() {
|
||||||
|
@ -113,7 +113,7 @@ func (s *TrawlingService) bootstrap() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
zap.L().Error("Could NOT resolve (UDP) address of the bootstrapping node!",
|
zap.L().Error("Could NOT resolve (UDP) address of the bootstrapping node!",
|
||||||
zap.String("node", node))
|
zap.String("node", node))
|
||||||
continue;
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
s.protocol.SendMessage(NewFindNodeQuery(s.trueNodeID, target), addr)
|
s.protocol.SendMessage(NewFindNodeQuery(s.trueNodeID, target), addr)
|
||||||
|
@ -83,7 +83,7 @@ func (t *Transport) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Transport) Terminate() {
|
func (t *Transport) Terminate() {
|
||||||
unix.Close(t.fd);
|
unix.Close(t.fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// readMessages is a goroutine!
|
// readMessages is a goroutine!
|
||||||
@ -131,7 +131,7 @@ func (t *Transport) WriteMessages(msg *Message, addr *net.UDPAddr) {
|
|||||||
if addrSA == nil {
|
if addrSA == nil {
|
||||||
zap.L().Debug("Wrong net address for the remote peer!",
|
zap.L().Debug("Wrong net address for the remote peer!",
|
||||||
zap.String("addr", addr.String()))
|
zap.String("addr", addr.String()))
|
||||||
return;
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = unix.Sendto(t.fd, data, 0, addrSA)
|
err = unix.Sendto(t.fd, data, 0, addrSA)
|
||||||
|
@ -16,8 +16,7 @@ import (
|
|||||||
func apiTorrentsHandler(w http.ResponseWriter, r *http.Request) {
|
func apiTorrentsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
// @lastOrderedValue AND @lastID are either both supplied or neither of them should be supplied
|
// @lastOrderedValue AND @lastID are either both supplied or neither of them should be supplied
|
||||||
// at all; and if that is NOT the case, then return an error.
|
// at all; and if that is NOT the case, then return an error.
|
||||||
if q := r.URL.Query(); !(
|
if q := r.URL.Query(); !((q.Get("lastOrderedValue") != "" && q.Get("lastID") != "") ||
|
||||||
(q.Get("lastOrderedValue") != "" && q.Get("lastID") != "") ||
|
|
||||||
(q.Get("lastOrderedValue") == "" && q.Get("lastID") == "")) {
|
(q.Get("lastOrderedValue") == "" && q.Get("lastID") == "")) {
|
||||||
respondError(w, 400, "`lastOrderedValue`, `lastID` must be supplied altogether, if supplied.")
|
respondError(w, 400, "`lastOrderedValue`, `lastID` must be supplied altogether, if supplied.")
|
||||||
return
|
return
|
||||||
|
@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
// DONE
|
// DONE
|
||||||
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
nTorrents, err := database.GetNumberOfTorrents()
|
nTorrents, err := database.GetNumberOfTorrents()
|
||||||
|
@ -175,7 +175,6 @@ func respondError(w http.ResponseWriter, statusCode int, format string, a ...int
|
|||||||
w.Write([]byte(fmt.Sprintf(format, a...)))
|
w.Write([]byte(fmt.Sprintf(format, a...)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func mustAsset(name string) []byte {
|
func mustAsset(name string) []byte {
|
||||||
data, err := Asset(name)
|
data, err := Asset(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -249,7 +248,7 @@ func loadCred(cred string) error {
|
|||||||
line, err := reader.ReadBytes('\n')
|
line, err := reader.ReadBytes('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
return fmt.Errorf("error while reading line %d: %s", lineno, err.Error())
|
return fmt.Errorf("error while reading line %d: %s", lineno, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -26,9 +26,15 @@ func TestSchemaUnsuppliedNil(t *testing.T) {
|
|||||||
t.Error("decoding error", err.Error())
|
t.Error("decoding error", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if ss.PString != nil { t.Error("PString is not nil") }
|
if ss.PString != nil {
|
||||||
if ss.PUint64 != nil { t.Error("PUint64 is not nil") }
|
t.Error("PString is not nil")
|
||||||
if ss.PBool != nil { t.Error("PBool is not nil") }
|
}
|
||||||
|
if ss.PUint64 != nil {
|
||||||
|
t.Error("PUint64 is not nil")
|
||||||
|
}
|
||||||
|
if ss.PBool != nil {
|
||||||
|
t.Error("PBool is not nil")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSchemaInvalidUint64 tests that an invalid uint64 value yields nil.
|
// TestSchemaInvalidUint64 tests that an invalid uint64 value yields nil.
|
||||||
@ -38,7 +44,9 @@ func TestSchemaInvalidUint64(t *testing.T) {
|
|||||||
|
|
||||||
ss := new(schemaStruct)
|
ss := new(schemaStruct)
|
||||||
err := decoder.Decode(ss, dict)
|
err := decoder.Decode(ss, dict)
|
||||||
if err == nil { t.Error("err is nil") }
|
if err == nil {
|
||||||
|
t.Error("err is nil")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSchemaInvalidBool tests that an invalid bool value yields nil.
|
// TestSchemaInvalidBool tests that an invalid bool value yields nil.
|
||||||
@ -48,7 +56,9 @@ func TestSchemaInvalidBool(t *testing.T) {
|
|||||||
|
|
||||||
ss := new(schemaStruct)
|
ss := new(schemaStruct)
|
||||||
err := decoder.Decode(ss, dict)
|
err := decoder.Decode(ss, dict)
|
||||||
if err == nil { t.Error("err is nil") }
|
if err == nil {
|
||||||
|
t.Error("err is nil")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSchemaOverflow tests that integer values greater than the maximum value a field can store
|
// TestSchemaOverflow tests that integer values greater than the maximum value a field can store
|
||||||
@ -59,7 +69,9 @@ func TestSchemaOverflow(t *testing.T) {
|
|||||||
|
|
||||||
ss := new(schemaStruct)
|
ss := new(schemaStruct)
|
||||||
err := decoder.Decode(ss, dict)
|
err := decoder.Decode(ss, dict)
|
||||||
if err == nil { t.Error("err is nil") }
|
if err == nil {
|
||||||
|
t.Error("err is nil")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSchemaEmptyString tests that empty string yields nil.
|
// TestSchemaEmptyString tests that empty string yields nil.
|
||||||
@ -72,7 +84,9 @@ func TestSchemaEmptyString(t *testing.T) {
|
|||||||
t.Error("decoding error", err.Error())
|
t.Error("decoding error", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if ss.PString != nil { t.Error("PString is not nil") }
|
if ss.PString != nil {
|
||||||
|
t.Error("PString is not nil")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSchemaDefault tests if unsupplied values defaults to "zero" and doesn't err
|
// TestSchemaDefault tests if unsupplied values defaults to "zero" and doesn't err
|
||||||
@ -82,14 +96,22 @@ func TestSchemaDefault(t *testing.T) {
|
|||||||
t.Error("decoding error", err.Error())
|
t.Error("decoding error", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if ss.String != "" { t.Error("String is not empty") }
|
if ss.String != "" {
|
||||||
if ss.Uint64 != 0 { t.Error("Uint64 is not 0") }
|
t.Error("String is not empty")
|
||||||
if ss.Bool != false { t.Error("Bool is not false") }
|
}
|
||||||
|
if ss.Uint64 != 0 {
|
||||||
|
t.Error("Uint64 is not 0")
|
||||||
|
}
|
||||||
|
if ss.Bool != false {
|
||||||
|
t.Error("Bool is not false")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSchemaRequired(t *testing.T) {
|
func TestSchemaRequired(t *testing.T) {
|
||||||
rs := new(schemaRStruct)
|
rs := new(schemaRStruct)
|
||||||
err := decoder.Decode(rs, make(map[string][]string))
|
err := decoder.Decode(rs, make(map[string][]string))
|
||||||
if err == nil { t.Error("err is nil") }
|
if err == nil {
|
||||||
|
t.Error("err is nil")
|
||||||
|
}
|
||||||
fmt.Printf(err.Error())
|
fmt.Printf(err.Error())
|
||||||
}
|
}
|
@ -42,6 +42,7 @@ type Database interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type OrderingCriteria uint8
|
type OrderingCriteria uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ByRelevance OrderingCriteria = iota
|
ByRelevance OrderingCriteria = iota
|
||||||
ByTotalSize
|
ByTotalSize
|
||||||
@ -51,9 +52,11 @@ const (
|
|||||||
ByNLeechers
|
ByNLeechers
|
||||||
ByUpdatedOn
|
ByUpdatedOn
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: search `swtich (orderBy)` and see if all cases are covered all the time
|
// TODO: search `swtich (orderBy)` and see if all cases are covered all the time
|
||||||
|
|
||||||
type databaseEngine uint8
|
type databaseEngine uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Sqlite3 databaseEngine = 1
|
Sqlite3 databaseEngine = 1
|
||||||
)
|
)
|
||||||
|
@ -14,6 +14,7 @@ var dayRE = regexp.MustCompile(`^(\d{4})-(\d{2})-(\d{2})$`)
|
|||||||
var hourRE = regexp.MustCompile(`^(\d{4})-(\d{2})-(\d{2})T(\d{2})$`)
|
var hourRE = regexp.MustCompile(`^(\d{4})-(\d{2})-(\d{2})T(\d{2})$`)
|
||||||
|
|
||||||
type Granularity int
|
type Granularity int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Year Granularity = iota
|
Year Granularity = iota
|
||||||
Month
|
Month
|
||||||
|
@ -147,7 +147,7 @@ func (db *sqlite3Database) GetNumberOfTorrents() (uint, error) {
|
|||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
if rows.Next() != true {
|
if rows.Next() != true {
|
||||||
fmt.Errorf("No rows returned from `SELECT MAX(ROWID)`")
|
return 0, fmt.Errorf("No rows returned from `SELECT MAX(ROWID)`")
|
||||||
}
|
}
|
||||||
|
|
||||||
var n uint
|
var n uint
|
||||||
|
Loading…
Reference in New Issue
Block a user