You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
639 B

  1. package cmd
  2. import (
  3. "go-dht/config"
  4. "go-dht/node"
  5. log "github.com/sirupsen/logrus"
  6. "github.com/urfave/cli"
  7. )
  8. var NodeCommands = []cli.Command{
  9. {
  10. Name: "start",
  11. Usage: "start the node",
  12. Action: cmdStart,
  13. },
  14. }
  15. func cmdStart(c *cli.Context) error {
  16. if err := config.MustRead(c); err != nil {
  17. return err
  18. }
  19. var n node.Node
  20. var err error
  21. if config.C.ID != "" {
  22. n, err = node.LoadNode(config.C.ID)
  23. if err != nil {
  24. return err
  25. }
  26. log.Info("Node loaded with ID: ", n.ID())
  27. } else {
  28. n, err = node.NewNode()
  29. if err != nil {
  30. return err
  31. }
  32. log.Info("New node created with ID: ", n.ID())
  33. }
  34. return nil
  35. }