Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alaingilbert committed Aug 21, 2022
1 parent e6dcffb commit a1c0ede
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wrapper
package exponentialBackoff

import (
"context"
Expand All @@ -15,8 +15,8 @@ type ExponentialBackoff struct {
max int
}

// NewExponentialBackoff ...
func NewExponentialBackoff(ctx context.Context, clock clockwork.Clock, max int) *ExponentialBackoff {
// New ...
func New(ctx context.Context, clock clockwork.Clock, max int) *ExponentialBackoff {
if max < 0 {
max = 0
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package wrapper
package exponentialBackoff

import (
"context"
Expand Down Expand Up @@ -28,7 +28,7 @@ func TestExponentialBackoff_Wait(t *testing.T) {
atomic.AddUint32(&counter, 1)
wg.Done()
}()
e := NewExponentialBackoff(context.Background(), clock, 60)
e := New(context.Background(), clock, 60)
e.Wait() // First time has no wait
e.Wait() // Wait 1s
e.Wait() // Wait 2s
Expand Down
9 changes: 5 additions & 4 deletions pkg/wrapper/ogame.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
err2 "errors"
"fmt"
"github.com/alaingilbert/clockwork"
"github.com/alaingilbert/ogame/pkg/exponentialBackoff"
"github.com/alaingilbert/ogame/pkg/extractor"
"github.com/alaingilbert/ogame/pkg/extractor/v6"
"github.com/alaingilbert/ogame/pkg/extractor/v7"
Expand Down Expand Up @@ -665,7 +666,7 @@ func (b *OGame) loginPart3(userAccount Account, page parser.OverviewPage) error
b.closeChatCh = make(chan struct{})
go func(b *OGame) {
defer atomic.StoreInt32(&b.chatConnectedAtom, 0)
chatRetry := NewExponentialBackoff(context.Background(), clockwork.NewRealClock(), 60)
chatRetry := exponentialBackoff.New(context.Background(), clockwork.NewRealClock(), 60)
chatRetry.LoopForever(func() bool {
select {
case <-b.closeChatCh:
Expand Down Expand Up @@ -919,7 +920,7 @@ func (b *OGame) SetProxy(proxyAddress, username, password, proxyType string, log
return b.setProxy(proxyAddress, username, password, proxyType, loginOnly, config)
}

func (b *OGame) connectChat(chatRetry *ExponentialBackoff, host, port string) {
func (b *OGame) connectChat(chatRetry *exponentialBackoff.ExponentialBackoff, host, port string) {
if b.IsV8() || b.IsV9() {
b.connectChatV8(chatRetry, host, port)
} else {
Expand All @@ -940,7 +941,7 @@ func yeast(num int64) (encoded string) {
return
}

func (b *OGame) connectChatV8(chatRetry *ExponentialBackoff, host, port string) {
func (b *OGame) connectChatV8(chatRetry *exponentialBackoff.ExponentialBackoff, host, port string) {
token := yeast(time.Now().UnixNano() / 1000000)
req, err := http.NewRequest(http.MethodGet, "https://"+host+":"+port+"/socket.io/?EIO=4&transport=polling&t="+token, nil)
if err != nil {
Expand Down Expand Up @@ -1118,7 +1119,7 @@ LOOP:
}
}

func (b *OGame) connectChatV7(chatRetry *ExponentialBackoff, host, port string) {
func (b *OGame) connectChatV7(chatRetry *exponentialBackoff.ExponentialBackoff, host, port string) {
req, err := http.NewRequest(http.MethodGet, "https://"+host+":"+port+"/socket.io/1/?t="+utils.FI64(time.Now().UnixNano()/int64(time.Millisecond)), nil)
if err != nil {
b.error("failed to create request:", err)
Expand Down

0 comments on commit a1c0ede

Please sign in to comment.