Skip to content

Commit

Permalink
fix: fix pinger
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-bisonai committed Aug 23, 2024
1 parent d30af96 commit 786a5e4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions node/pkg/checker/ping/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
)

const (
DefaultPingerTimeout = 2 * time.Second
DefaultMaxDelay = 100 * time.Millisecond
DefaultMaxFails = 2
DefaultBufferSize = 500
Expand Down Expand Up @@ -97,7 +96,6 @@ func New(opts ...AppOption) (*App, error) {
return nil, err
}

pinger.Timeout = DefaultPingerTimeout
pinger.SetPrivileged(true)

pinger.OnRecv = func(pkt *probing.Packet) {
Expand Down Expand Up @@ -147,6 +145,7 @@ func (app *App) Start(ctx context.Context) {
time.Sleep(DefaultReconnectInterval)
continue
}

}
}(endpoint)
}
Expand All @@ -157,6 +156,7 @@ func (app *App) Start(ctx context.Context) {
return
case result := <-app.ResultsBuffer:
if result.Success && result.Delay < app.MaxDelay {
log.Info().Any("result", result).Msg("ping success")
app.FailCount[result.Address] = 0
} else {
log.Error().Any("result", result).Msg("failed to ping endpoint")
Expand Down
14 changes: 14 additions & 0 deletions node/script/test_pinger/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package main

import (
"context"
"fmt"

"bisonai.com/miko/node/pkg/checker/ping"
)

func main() {
ctx := context.Background()
ping.Run(ctx)
fmt.Println("done")
}
4 changes: 4 additions & 0 deletions node/taskfiles/taskfile.local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ tasks:
dotenv: [".env"]
cmds:
- go run ./script/inspector/main.go
script-pinger:
dotenv: [".env"]
cmds:
- go run ./script/test_pinger/main.go

test-db:
dotenv: [".env"]
Expand Down

0 comments on commit 786a5e4

Please sign in to comment.