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

main.go 1.8 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package main
  2. import (
  3. "fmt"
  4. "net"
  5. "os"
  6. "sync"
  7. log "github.com/sirupsen/logrus"
  8. "gitlink.org.cn/cloudream/agent/internal/config"
  9. agentserver "gitlink.org.cn/cloudream/proto"
  10. "gitlink.org.cn/cloudream/utils/ipfs"
  11. "gitlink.org.cn/cloudream/utils/logger"
  12. "google.golang.org/grpc"
  13. rasvr "gitlink.org.cn/cloudream/rabbitmq/server/agent"
  14. )
  15. // TODO 此数据是否在运行时会发生变化?
  16. var AgentIpList []string
  17. func main() {
  18. // TODO 放到配置里读取
  19. AgentIpList = []string{"pcm01", "pcm1", "pcm2"}
  20. err := config.Init()
  21. if err != nil {
  22. fmt.Printf("init config failed, err: %s", err.Error())
  23. os.Exit(1)
  24. }
  25. err = logger.Init(&config.Cfg().Logger)
  26. if err != nil {
  27. fmt.Printf("init logger failed, err: %s", err.Error())
  28. os.Exit(1)
  29. }
  30. ipfs, err := ipfs.NewIPFS(config.Cfg().IPFSPort)
  31. if err != nil {
  32. log.Fatalf("new ipfs failed, err: %s", err.Error())
  33. }
  34. //处置协调端、客户端命令(可多建几个)
  35. wg := sync.WaitGroup{}
  36. wg.Add(2)
  37. // 启动命令服务器
  38. // TODO 需要设计AgentID持久化机制
  39. agtSvr, err := rasvr.NewAgentServer(NewCommandService(ipfs), config.Cfg().ID, &config.Cfg().RabbitMQ)
  40. if err != nil {
  41. log.Fatalf("new agent server failed, err: %s", err.Error())
  42. }
  43. agtSvr.OnError = func(err error) {
  44. log.Warnf("agent server err: %s", err.Error())
  45. }
  46. go serveAgentServer(agtSvr, &wg)
  47. go reportStatus(&wg) //网络延迟感知
  48. //面向客户端收发数据
  49. listenAddr := config.Cfg().GRPCListenAddress
  50. lis, err := net.Listen("tcp", listenAddr)
  51. if err != nil {
  52. log.Fatalf("listen on %s failed, err: %s", listenAddr, err.Error())
  53. }
  54. s := grpc.NewServer()
  55. agentserver.RegisterFileTransportServer(s, NewGPRCService(ipfs))
  56. s.Serve(lis)
  57. wg.Wait()
  58. }
  59. func serveAgentServer(server *rasvr.AgentServer, wg *sync.WaitGroup) {
  60. server.Serve()
  61. wg.Done()
  62. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。