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.7 kB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/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. cmdSvr, err := rasvr.NewAgentServer(NewCommandService(ipfs), config.Cfg().ID)
  40. if err != nil {
  41. log.Fatalf("new agent server failed, err: %s", err.Error())
  42. }
  43. go serveCommandServer(cmdSvr, &wg)
  44. go reportStatus(&wg) //网络延迟感知
  45. //面向客户端收发数据
  46. listenAddr := config.Cfg().GRPCListenAddress
  47. lis, err := net.Listen("tcp", listenAddr)
  48. if err != nil {
  49. log.Fatalf("listen on %s failed, err: %s", listenAddr, err.Error())
  50. }
  51. s := grpc.NewServer()
  52. agentserver.RegisterFileTransportServer(s, NewGPRCService(ipfs))
  53. s.Serve(lis)
  54. wg.Wait()
  55. }
  56. func serveCommandServer(server *rasvr.AgentServer, wg *sync.WaitGroup) {
  57. server.Serve()
  58. wg.Done()
  59. }

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