join.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. Copyright © 2021-2022 Ettore Di Giacinto <[email protected]>
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package cmd
  14. import (
  15. "context"
  16. "github.com/mudler/edgevpn/pkg/node"
  17. "github.com/urfave/cli/v2"
  18. )
  19. func Start() *cli.Command {
  20. return &cli.Command{
  21. Name: "start",
  22. Usage: "Start the network without activating any interface",
  23. Description: `Connect over the p2p network without establishing a VPN.
  24. Useful for setting up relays or hop nodes to improve the network connectivity.`,
  25. UsageText: "edgevpn start",
  26. Flags: CommonFlags,
  27. Action: func(c *cli.Context) error {
  28. o, _, ll := cliToOpts(c)
  29. e, err := node.New(o...)
  30. if err != nil {
  31. return err
  32. }
  33. displayStart(ll)
  34. go handleStopSignals()
  35. // Start the node to the network, using our ledger
  36. if err := e.Start(context.Background()); err != nil {
  37. return err
  38. }
  39. ll.Info("Joining p2p network")
  40. <-context.Background().Done()
  41. return nil
  42. },
  43. }
  44. }