Compare commits

..

2 Commits

Author SHA1 Message Date
e85b644e82 Add maxjitter flag to hyp client
All checks were successful
continuous-integration/drone/push Build is passing
This to allow configurable time between knock sequence transmissions.  It's important the sequence arrive in the correct order, and some networks have multiple paths.
2024-04-16 19:44:25 -06:00
2c43affac9 fix typo in help message 2024-04-16 19:43:39 -06:00
2 changed files with 12 additions and 3 deletions

View File

@ -38,6 +38,14 @@ Example usage:
panic(fmt.Errorf("failed to parse command flag 'secret': %w", err)) panic(fmt.Errorf("failed to parse command flag 'secret': %w", err))
} }
maxJitter, err := cmd.Flags().GetInt("maxjitter")
if err != nil {
panic(fmt.Errorf("failed to parse command flag 'maxjitter': %w", err))
}
if maxJitter < 1 || maxJitter > 1500 {
panic(fmt.Errorf("maxjitter must be value between 1 and 1500"))
}
secretBytes, err := os.ReadFile(secretFilePath) secretBytes, err := os.ReadFile(secretFilePath)
if err != nil { if err != nil {
log.Fatalf("failed to read file 'hyp.secret': %v", err) log.Fatalf("failed to read file 'hyp.secret': %v", err)
@ -50,12 +58,12 @@ Example usage:
} }
// Transmit // Transmit
fmt.Println("Transmitting knock sequence:", ports)
for _, port := range ports { for _, port := range ports {
fmt.Printf("knock | %s:%d\n", args[0], port)
conn, _ := net.Dial("udp", fmt.Sprintf("%s:%d", args[0], port)) conn, _ := net.Dial("udp", fmt.Sprintf("%s:%d", args[0], port))
conn.Write([]byte{0}) conn.Write([]byte{0})
conn.Close() conn.Close()
time.Sleep(time.Millisecond * 200) // TBD: Make this configurable with flag (maxJitter) time.Sleep(time.Millisecond * time.Duration(maxJitter)) // TBD: Make this configurable with flag (maxJitter)
} }
}, },
} }
@ -64,4 +72,5 @@ func init() {
rootCmd.AddCommand(knockCmd) rootCmd.AddCommand(knockCmd)
knockCmd.PersistentFlags().String("secret", "hyp.secret", "Path to the file containing the hyp secret.") knockCmd.PersistentFlags().String("secret", "hyp.secret", "Path to the file containing the hyp secret.")
knockCmd.PersistentFlags().Int("maxjitter", 200, "Specifies the time in milliseconds between knock sequence transmissions.")
} }

View File

@ -19,7 +19,7 @@ server and to clients.
Example: Example:
hypd generatesecret > hyp.secret`, hypd generate secret > hyp.secret`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
sharedSecret, err := otphyp.GenerateSecret() sharedSecret, err := otphyp.GenerateSecret()
if err != nil { if err != nil {