file.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package cmd
  2. import (
  3. "github.com/mudler/edgevpn/pkg/blockchain"
  4. "github.com/mudler/edgevpn/pkg/edgevpn"
  5. "github.com/urfave/cli"
  6. )
  7. func FileSend() cli.Command {
  8. return cli.Command{
  9. Name: "file-send",
  10. Aliases: []string{"fs"},
  11. Usage: "Serve a file to the network",
  12. Description: `Serve a file to the network without connecting over VPN`,
  13. UsageText: "edgevpn file-send --name 'unique-id' --path '/src/path'",
  14. Flags: append(CommonFlags,
  15. cli.StringFlag{
  16. Name: "name",
  17. Required: true,
  18. Usage: `Unique name of the file to be served over the network.
  19. This is also the ID used to refer when receiving it.`,
  20. },
  21. cli.StringFlag{
  22. Name: "path",
  23. Usage: `File to serve`,
  24. Required: true,
  25. },
  26. ),
  27. Action: func(c *cli.Context) error {
  28. e := edgevpn.New(cliToOpts(c)...)
  29. displayStart(e)
  30. mw, err := e.MessageWriter()
  31. if err != nil {
  32. return err
  33. }
  34. ledger := blockchain.New(mw, 1000)
  35. // Join the node to the network, using our ledger
  36. e.SendFile(ledger, c.String("name"), c.String("path"))
  37. // Join the node to the network, using our ledger
  38. if err := e.Join(ledger); err != nil {
  39. return err
  40. }
  41. for {
  42. }
  43. },
  44. }
  45. }
  46. func FileReceive() cli.Command {
  47. return cli.Command{
  48. Name: "file-receive",
  49. Aliases: []string{"fr"},
  50. Usage: "Receive a file which is served from the network",
  51. Description: `Receive a file from the network without connecting over VPN`,
  52. UsageText: "edgevpn file-receive --name 'unique-id' --path '/dst/path'",
  53. Flags: append(CommonFlags,
  54. cli.StringFlag{
  55. Name: "name",
  56. Usage: `Unique name of the file to be received over the network.`,
  57. Required: true,
  58. },
  59. cli.StringFlag{
  60. Name: "path",
  61. Usage: `Destination where to save the file`,
  62. Required: true,
  63. },
  64. ),
  65. Action: func(c *cli.Context) error {
  66. e := edgevpn.New(cliToOpts(c)...)
  67. displayStart(e)
  68. mw, err := e.MessageWriter()
  69. if err != nil {
  70. return err
  71. }
  72. ledger := blockchain.New(mw, 1000)
  73. // Join the node to the network, using our ledger
  74. if err := e.Join(ledger); err != nil {
  75. return err
  76. }
  77. return e.ReceiveFile(ledger, c.String("name"), c.String("path"))
  78. },
  79. }
  80. }