mirror of
https://github.com/ap-pauloafonso/ratio-spoof.git
synced 2026-03-11 17:45:32 +00:00
moved interface on the file that uses it
This commit is contained in:
parent
5a461e3564
commit
42ec97200b
5 changed files with 22 additions and 23 deletions
|
|
@ -26,13 +26,24 @@ type ClientInfo struct {
|
|||
Headers map[string]string `json:"headers"`
|
||||
}
|
||||
|
||||
type KeyGenerator interface {
|
||||
Key() string
|
||||
}
|
||||
|
||||
type PeerIdGenerator interface {
|
||||
PeerId() string
|
||||
}
|
||||
type RoundingGenerator interface {
|
||||
Round(downloadCandidateNextAmount, uploadCandidateNextAmount, leftCandidateNextAmount, pieceSize int) (downloaded, uploaded, left int)
|
||||
}
|
||||
|
||||
type Emulation struct {
|
||||
PeerIdGenerator generator.PeerIdGenerator
|
||||
KeyGenerator generator.KeyGenerator
|
||||
PeerIdGenerator PeerIdGenerator
|
||||
KeyGenerator KeyGenerator
|
||||
Query string
|
||||
Name string
|
||||
Headers map[string]string
|
||||
RoudingGenerator generator.RoundingGenerator
|
||||
RoudingGenerator RoundingGenerator
|
||||
}
|
||||
|
||||
func NewEmulation(code string) (*Emulation, error) {
|
||||
|
|
@ -41,17 +52,17 @@ func NewEmulation(code string) (*Emulation, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
peerG, err := generator.NewPeerIdGenerator(c.PeerID.Generator, c.PeerID.Regex)
|
||||
peerG, err := generator.NewRegexPeerIdGenerator(c.PeerID.Generator, c.PeerID.Regex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
keyG, err := generator.NewKeyGenerator(c.Key.Generator)
|
||||
keyG, err := generator.NewDefaultKeyGenerator(c.Key.Generator)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
roudingG, err := generator.NewRoundingGenerator(c.Rounding.Generator)
|
||||
roudingG, err := generator.NewDefaultRoudingGenerator(c.Rounding.Generator)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,11 +6,7 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
type KeyGenerator interface {
|
||||
Key() string
|
||||
}
|
||||
|
||||
func NewKeyGenerator(generatorCode string) (KeyGenerator, error) {
|
||||
func NewDefaultKeyGenerator(generatorCode string) (*DefaultKeyGenerator, error) {
|
||||
randomBytes := make([]byte, 4)
|
||||
rand.Read(randomBytes)
|
||||
str := hex.EncodeToString(randomBytes)
|
||||
|
|
|
|||
|
|
@ -4,15 +4,11 @@ import (
|
|||
regen "github.com/zach-klippenstein/goregen"
|
||||
)
|
||||
|
||||
type PeerIdGenerator interface {
|
||||
PeerId() string
|
||||
}
|
||||
|
||||
type RegexPeerIdGenerator struct {
|
||||
generated string
|
||||
}
|
||||
|
||||
func NewPeerIdGenerator(generatorCode, pattern string) (PeerIdGenerator, error) {
|
||||
func NewRegexPeerIdGenerator(generatorCode, pattern string) (*RegexPeerIdGenerator, error) {
|
||||
result, err := regen.Generate(pattern)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -1,16 +1,12 @@
|
|||
package generator
|
||||
|
||||
type RoundingGenerator interface {
|
||||
Round(downloadCandidateNextAmount, uploadCandidateNextAmount, leftCandidateNextAmount, pieceSize int) (downloaded, uploaded, left int)
|
||||
}
|
||||
type DefaultRoundingGenerator struct{}
|
||||
|
||||
func NewRoundingGenerator(code string) (RoundingGenerator, error) {
|
||||
func NewDefaultRoudingGenerator(code string) (*DefaultRoundingGenerator, error) {
|
||||
return &DefaultRoundingGenerator{}, nil
|
||||
|
||||
}
|
||||
|
||||
type DefaultRoundingGenerator struct{}
|
||||
|
||||
func (d *DefaultRoundingGenerator) Round(downloadCandidateNextAmount, uploadCandidateNextAmount, leftCandidateNextAmount, pieceSize int) (downloaded, uploaded, left int) {
|
||||
|
||||
down := downloadCandidateNextAmount
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package generator
|
|||
import "testing"
|
||||
|
||||
func TestNextAmountReport(t *testing.T) {
|
||||
r, _ := NewRoundingGenerator("")
|
||||
r, _ := NewDefaultRoudingGenerator("")
|
||||
|
||||
d, u, l := r.Round(656497856, 46479878, 7879879, 1024)
|
||||
//same
|
||||
|
|
|
|||
Loading…
Reference in a new issue