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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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"
  14. )
  15. // TODO 此数据是否在运行时会发生变化?
  16. var AgentIpList []string
  17. const (
  18. // TODO 考虑从保存的配置文件中读取
  19. NodeID = 0
  20. )
  21. func main() {
  22. // TODO 放到配置里读取
  23. AgentIpList = []string{"pcm01", "pcm1", "pcm2"}
  24. err := config.Init()
  25. if err != nil {
  26. fmt.Printf("init config failed, err: %s", err.Error())
  27. os.Exit(1)
  28. }
  29. err = logger.Init(&config.Cfg().Logger)
  30. if err != nil {
  31. fmt.Printf("init logger failed, err: %s", err.Error())
  32. os.Exit(1)
  33. }
  34. ipfs, err := ipfs.NewIPFS(config.Cfg().IPFSPort)
  35. if err != nil {
  36. log.Fatalf("new ipfs failed, err: %s", err.Error())
  37. }
  38. //处置协调端、客户端命令(可多建几个)
  39. wg := sync.WaitGroup{}
  40. wg.Add(2)
  41. // 启动命令服务器
  42. // TODO 需要设计AgentID持久化机制
  43. cmdSvr, err := rasvr.NewAgentServer(NewCommandService(ipfs), NodeID)
  44. if err != nil {
  45. log.Fatalf("new agent server failed, err: %s", err.Error())
  46. }
  47. go serveCommandServer(cmdSvr, &wg)
  48. go reportStatus(&wg) //网络延迟感知
  49. //面向客户端收发数据
  50. listenAddr := fmt.Sprintf("127.0.0.1:%d", config.Cfg().GRPCPort)
  51. lis, err := net.Listen("tcp", listenAddr)
  52. if err != nil {
  53. log.Fatalf("listen on %s failed, err: %s", listenAddr, err.Error())
  54. }
  55. s := grpc.NewServer()
  56. agentserver.RegisterFileTransportServer(s, NewGPRCService(ipfs))
  57. s.Serve(lis)
  58. wg.Wait()
  59. }
  60. func serveCommandServer(server *rasvr.AgentServer, wg *sync.WaitGroup) {
  61. server.Serve()
  62. wg.Done()
  63. }

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