Skip to content

Commit

Permalink
nyn: retry support
Browse files Browse the repository at this point in the history
  • Loading branch information
diredocks committed Oct 24, 2024
1 parent c209d88 commit f8f2632
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cmd/nyn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Config struct {
General struct {
ScheduleCallback bool `toml:"schedule_callback"`
TimeOut int `toml:"timeout"`
Retry int `toml:"retry"`
} `toml:"general"`
Crypto struct {
WinVer string `toml:"win_ver"`
Expand Down Expand Up @@ -97,7 +98,8 @@ func main() {
authService := nynAuth.New(device,
cryptoInfo,
user.User,
user.Password)
user.Password,
config.General.Retry)
if err = device.Start(authService); err != nil {
log.Fatal(err)
}
Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

# goimports, godoc, etc.
gotools
graphviz

# https://github.com/golangci/golangci-lint
golangci-lint
Expand Down
18 changes: 14 additions & 4 deletions internal/auth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ type AuthService struct {
h3cBuffer []byte
username string
password string
retry int
}

func New(device DeviceInterface, h3cInfo nynCrypto.H3CInfo, username string, password string) *AuthService {
func New(device DeviceInterface, h3cInfo nynCrypto.H3CInfo, username string, password string, retry int) *AuthService {
return &AuthService{
Device: device,
h3cInfo: h3cInfo,
username: username,
password: password,
retry: retry,
}
}

Expand Down Expand Up @@ -94,7 +96,13 @@ func (as *AuthService) HandlePacket(packet gopacket.Packet) error {
l.server.Error(fmt.Sprintf("%s", failMsg))
l.client.Fatal("fal (o.0)")
} else {
l.client.Fatal("maybe we should re-auth?")
if as.retry > 0 {
as.retry = as.retry - 1
l.client.Error("an error occured qwq! remaining", "retry", as.retry)
as.SendStartPacket()
} else {
l.client.Fatal("retry ran out, maybe we should re-auth?")
}
}
case layers.EAPCodeRequest:
l.server.Info("asking for something...")
Expand All @@ -105,9 +113,11 @@ func (as *AuthService) HandlePacket(packet gopacket.Packet) error {
as.h3cBuffer, err = as.h3cInfo.ChallangeResponse(
eapPacket.TypeData[H3CIntegrityChanllengeHeader:][:H3CIntegrityChanllengeLength])
if err != nil {
l.client.Fatal(err)
l.client.Error("failed to set integrity")
l.client.Error(err)
} else {
l.client.Info("integrity set")
}
l.client.Info("integrity set")
}
default:
l.client.Warn("unknow eap", "Code", eapPacket.Code)
Expand Down

0 comments on commit f8f2632

Please sign in to comment.