diff options
author | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-26 15:35:41 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2016-07-26 15:35:41 +0900 |
commit | e7354de8bbc20bc507723dc185940f7368723ca4 (patch) | |
tree | 156e74ae7c307747c6fb6be295f491ad6c486f7c | |
parent | 5aea2d93fd6fa41cef42cfb311e4b185725672ac (diff) |
move gRPC-related code for REQ_GET_SERVER to grpc_server.go
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | server/grpc_server.go | 8 | ||||
-rw-r--r-- | server/server.go | 19 |
2 files changed, 15 insertions, 12 deletions
diff --git a/server/grpc_server.go b/server/grpc_server.go index cd5d6a4e..34aa1f9d 100644 --- a/server/grpc_server.go +++ b/server/grpc_server.go @@ -1706,11 +1706,7 @@ func (s *Server) ReplacePolicyAssignment(ctx context.Context, arg *api.ReplacePo } func (s *Server) GetServer(ctx context.Context, arg *api.GetServerRequest) (*api.GetServerResponse, error) { - d, err := s.get(REQ_GET_SERVER, arg) - if err != nil { - return nil, err - } - g := d.(*config.Global) + g := s.bgpServer.GetServer() return &api.GetServerResponse{ Global: &api.Global{ As: g.Config.As, @@ -1720,7 +1716,7 @@ func (s *Server) GetServer(ctx context.Context, arg *api.GetServerRequest) (*api MplsLabelMin: g.MplsLabelRange.MinLabel, MplsLabelMax: g.MplsLabelRange.MaxLabel, }, - }, err + }, nil } func (s *Server) StartServer(ctx context.Context, arg *api.StartServerRequest) (*api.StartServerResponse, error) { diff --git a/server/server.go b/server/server.go index 15bd90de..17d42ce5 100644 --- a/server/server.go +++ b/server/server.go @@ -1361,12 +1361,6 @@ func (server *BgpServer) handleGrpc(grpcReq *GrpcRequest) { var err error switch grpcReq.RequestType { - case REQ_GET_SERVER: - g := server.bgpConfig.Global - grpcReq.ResponseCh <- &GrpcResponse{ - Data: &g, - } - close(grpcReq.ResponseCh) case REQ_GLOBAL_RIB, REQ_LOCAL_RIB: arg := grpcReq.Data.(*api.GetRibRequest) rib := server.globalRib @@ -1717,6 +1711,19 @@ ERROR: return } +func (s *BgpServer) GetServer() (c *config.Global) { + ch := make(chan struct{}) + defer func() { <-ch }() + + s.mgmtCh <- func() { + defer close(ch) + + g := s.bgpConfig.Global + c = &g + } + return c +} + func (s *BgpServer) GetNeighbor() (l []*config.Neighbor) { ch := make(chan struct{}) defer func() { <-ch }() |